Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a parallel program to solve the one-dimensional problem based upon the fin

ID: 665545 • Letter: W

Question

Write a parallel program to solve the one-dimensional problem based upon the finite difference equation x[i] = (x[i-1] + x[i+1])/2 for 0 <= i <= 1000, given that x[0] = 10 and x[1000] = 250.


-Use block partitioning to distribute array elements across processes. Your MPI program should be general (no assumptions on the number of processes used). Use 0.001 as the tolerance to determine the convergence of the iteration and set the maximum number of iterations to 1,000.

-Output requirement: Print the values of x[i * 100] where 0 <= i <= 10 in one line after every 50 iterations (a gather routine should be used to gather all values to Process 0 before printing from Process 0).

Here is the The pseudo code i have so far:

a =0;

b =0;

if(first_element) a=10;

if(last_element) b= 250;

iteration =0;

do {

iteration ++;

x =0.5*(a+b);

if(!first_element)send(&x, Pi-1);

if(!last_element)send(&x, Pi+1);

if(!first_element)recv(&x, Pi-1);

if(!last_element)recv(&x,Pi+1);

}

while((!converged) || (iteration == limit))

send(&x, &iteration, Pmaster);

Need help with actual code!

Explanation / Answer

Use p=10 processors (plus one master if you decide you need one).

for (iteration=1; iteration < MAX; iteration++) {
    for (i=1; i<1000; i++){
        xnew[i] = (x[i-1]+x[i+1])/2.0;
    }
    for (i=1; i<1000; i++){
        x[i] = xnew[i];
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote