int main(int argc, char *argv[]) { const int root = 0; int rank; Params params; const int type_count = 2; int block_lengths[] = {1, 1}; MPI_Aint displacements[] = {0, sizeof(long)}; MPI_Datatype types[] = {MPI_LONG, MPI_INT}; MPI_Datatype params_type; double *limits, local_limits[2], partial_result, result = 0.0; MPI_Init(NULL, NULL); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Type_create_struct(type_count, block_lengths, displacements, types, ¶ms_type); MPI_Type_commit(¶ms_type); if (rank == 0) { params = get_params(argc, argv); } MPI_Bcast(¶ms, 1, params_type, root, MPI_COMM_WORLD); if (rank == 0) { limits = compute_limits(); } MPI_Scatter(limits, 2, MPI_DOUBLE, local_limits, 2, MPI_DOUBLE, root, MPI_COMM_WORLD); if (rank == 0) { free(limits); } if (params.is_verbose) printf("rank %d: %.5lf -> %.5lf (%ld)\n", rank, local_limits[0], local_limits[1], params.n); partial_result = partial_pi(local_limits[0], local_limits[1], params.n); MPI_Reduce(&partial_result, &result, 1, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD); if (rank == 0) { printf("pi = %.8lf\n", result); } MPI_Type_free(¶ms_type); MPI_Finalize(); return EXIT_SUCCESS; }
int _execute(char args[][ACOLS]) { char* cfgpath = NULL; if(!strcmp(EXIT, args[0])) run = 0; else if(!strcmp(EXPORT, args[0])) expenv(args); else if(!strcmp(ECHO, args[0])) echo_text(args); else if(!strcmp(ETIME, args[0])) etime(args); else if(!strcmp(LIMITS, args[0])) compute_limits(args); else if(!strcmp(CD, args[0])) chgdir(args); else if(!findexec(args, &cfgpath)) otroexec(args, &cfgpath); if(cfgpath != NULL) free(cfgpath); return 0; }