// This is an alternative parallel version of quadrature_sequential.c // // It differs from quadratur_parallel.c by the way work is distributed. // This one uses a 'round robin' strategy. // // To compile: mpicc quadrature_parallel.c -lm // // This code also exhibits linear speedup. See listed output at the // bottom of this file. // // Ole Nielsen, SUT 2003 #include #include #include #include //Define the circle arc to be integrated. long double fct(long double x) { return sqrt(1.0-x*x); } int main(argc,argv) int argc; char *argv[]; { int N, i, lo, hi; long double result=0.0, my_result=0.0; long double reference = 3.1415926535897932; //Reference value, 17 digits double t0; int p; // Myid int P; // Number of processors int namelen, tag=0, j, k; char processor_name[MPI_MAX_PROCESSOR_NAME]; int *C; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &p); MPI_Comm_size(MPI_COMM_WORLD, &P); MPI_Get_processor_name(processor_name, &namelen); printf("This is process %d of %d running on %s\n", p, P, processor_name); N = 100000000; // Resolution //N = 29; // Resolution if (p == 0) { printf("Resolution = %d\n", N); } // Begin computation t0 = MPI_Wtime(); for (k=0; k<15; k++) { //Each process p handles own stride of points my_result = 0.0; for (i=p; i