Question: Developing an efficient parallel numerical integration program on a 2 - D mesh, as described in textbook Chapter 8 Programming Projects, page 3 0 2

Developing an efficient parallel numerical integration program on a 2-D mesh, as described in textbook Chapter 8 Programming Projects, page 302.
I have the following C*(cstar) code for this project and it's compiling without issue, but when I try to run it my environment crashes:
/* Parallel Numerical Integration Program */
#include
#include
#define numproc 40
#define numpoints 30
#define N 6
int MESH_DIM =(int)sqrt(numproc);
float a =0.0, b =2.0, w, globalsum =0.0, answer;
spinlock L;
float local_sums[N][N];
int i, j, row, col;
float f(float t){
return sqrt(4- t * t);
}
void Integrate(int myrow, int mycol){
float localsum =0.0;
float t;
int x;
int myindex = myrow * MESH_DIM + mycol;
t = a + myindex *(b - a)/ numproc;
for (x =1; x <= numpoints; x++){
localsum += f(t);
t += w;
}
localsum = w * localsum;
local_sums[myrow][mycol]= localsum;
}
void meshReduceSum(){
for (row =0; row < MESH_DIM; row++){
for (col =1; col < MESH_DIM; col++){
local_sums[row][0]+= local_sums[row][col];
}
}
for (row =1; row < MESH_DIM; row++){
local_sums[0][0]+= local_sums[row][0];
}
globalsum = local_sums[0][0];
}
main(){
w =(b - a)/(numproc * numpoints);
forall i =0 to MESH_DIM do
forall j =0 to MESH_DIM do
Integrate(i, j);
meshReduceSum();
answer = globalsum + w /2*(f(b)- f(a));
cout << "Approximation to the value of pi: %f
"<< answer;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!