Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a c++ question. The hw6_input.txt in the question is just a txt file containing 10000 random numbers from the set {0,1,2,3,4,5,6,7,8,9}, like 6
This is a c++ question. The hw6_input.txt in the question is just a txt file containing 10000 random numbers from the set {0,1,2,3,4,5,6,7,8,9}, like 6 9 7 5 7 2 6 6 8 3 6 9 5 4 7 2 9 8 6 1 1 1 0 5 3 7 0 1 1 6 5 5 6 2 8 4 9 6 5 9 3 4 8 1 5 0 0......
The function readSequenceFromFile is a function can read these numbers from that txt file. Can you give me some hint to do the following problems? I appreciate it very much.
Problem 2 Use the function readsequenceFromFile that you created in homework 2 to read the sequence z of non-negative integers from the file hw6 input.txt. You should have downloaded the file while solving the previous problem. The sequence z is written to the file according to the convention we created in homework 2 Read the numbers k and m from the standard input. Each of the elements of the sequence 20], z[1],..., z n-1] corresponds to one of the citizens in a country. The number n is read from the file as explained in the homework 2. The citizens live in a circle. Hence, the first left neighbor of the citizen 0 is n 1; the second from the left neighbor is n 2. The first from the right neighbor of the citizen 0 is the citizen 1 and the second from the right is the citizen 2. The number zij is a politician for whom the citizen i is planning to vote in the upcoming election. As you can see from the file, the politicians are represented by the numbers from the set 10, 1,2,3,...,9 The citizens are talking about the politicians and they often change their opinions on how to vote. During each of the next m days, each citizen looks at k of his(/her nearest neighbors that are located to the left and k of the nearest neighbors that are located to the right. Then during the night, each citizen decides to change the favorite politician to the one that the majority of his/her neighbors preferred the day before (if there is a tie, a politician with the smaller id is chosen). This crazy behavior continues for m days and nights Find out who is going to vote for whom after m days and m nights. Create two functions: a non-parallel version, and a parallel one using openmp and compare their performance Remark: Be careful when designing the algorithms: When changing the opinion of the candidate 8 you will look at the neighbor 7. However you have to keep in mind that you need to consider the value zr7 that was during the day, which could be tricky ifyou already changed 271
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started