43 main(
int argc,
char *argv[])
49 MPI_Init(&argc, &argv);
50 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
54 fprintf(stderr,
"specify an input file\n");
56 MPI_Abort(MPI_COMM_WORLD, 1);
62 ifp = fopen(argv[1],
"r");
63 while (fgets(line,
sizeof(line), ifp) != NULL) {
64 char *count_s, *point_s;
66 int len = (int)strlen(line);
69 if (cp[len-1] ==
'\n') {
74 cp = strchr(line,
' ');
78 cp = strchr(line,
'/');
82 sum_count += atoi(count_s);
83 sum_point += atoi(point_s);
87 double pi = 4.0 * sum_count / sum_point;
89 ofp = fopen(
"mpi_pi.out",
"w");
90 fprintf(ofp,
"%f\n", pi);
int main(int argc, char *argv[])
Main function.
#define LINELEN
Maximum length of a line of data.