実行時間を測定しようとしている mpi プログラムがあります。そのため、gettimeofday に 2 つの呼び出しを追加すると、そこですべてが機能しなくなります。何らかの理由で、gettimeofday への 2 回目の呼び出しがある場合にのみクラッシュします。これが私が受け取るメッセージです:
MPI アプリケーション ランク 0 がシグナル 11 srun で MPI_Finalize() の前に強制終了されました: エラー: n32: task0: 終了コード 245 で終了しました
これがコードです
struct timeval starttime;
struct timeval endtime;
gettimeofday(&starttime, NULL);
int numDarts = 1000000000;
int numWorkers = 2;
char* args[1];
if(argc >= 2)
{
numWorkers = atoi(argv[1]);
}
if(argc >= 3)
numDarts = atoi(argv[2]);
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
printf("world size = %i\n", world_size);
if (world_size != 1)
printf("Top heavy with management\n");
int numDartsWorker = numDarts/numWorkers;
int numDartsMaster = numDarts/numWorkers + (numDarts % numWorkers); //the master computes the leftover
args[0] = malloc(256 * sizeof(char));
sprintf(args[0], "%i", numDartsWorker);
// printf("argument passing to workers: %s\n", args[0]);
/*
* Now spawn the workers. Note that there is a run-time determination
* of what type of worker to spawn, and presumably this calculation must
* be done at run time and cannot be calculated before starting
* the program. If everything is known when the application is
* first started, it is generally better to start them all at once
* in a single MPI_COMM_WORLD.
*/
// printf("About to call MPI_Comm_spawn with %i workers...\n", numWorkers);
int resultLen = 0;
//the master counts as a worker, hence the -1
MPI_Comm_spawn("piworker", args, numWorkers-1, MPI_INFO_NULL, 0, MPI_COMM_SELF,
&everyone, MPI_ERRCODES_IGNORE);
double pisum = 0;
double myresult = dboard(numDartsMaster);
printf("parent result is %.9f\n", myresult);
int rc = MPI_Reduce(&myresult, &pisum, 1, MPI_DOUBLE, MPI_SUM, MPI_ROOT, everyone);
if (rc != MPI_SUCCESS)
printf("failure on mpi_reduce\n");
free(args[0]);
/*
* Parallel code here. The communicator "everyone" can be used
* to communicate with the spawned processes, which have ranks 0,..
* MPI_UNIVERSE_SIZE-1 in the remote group of the intercommunicator
* "everyone".
*/
//receive the results
int i=1;
MPI_Status status;
double avgpi = pisum;
avgpi += myresult; //include master's average in the result.
avgpi /= numWorkers;
printf("startTime = %d secs, %d microsecs\n", starttime.tv_sec);
// gettimeofday(&endtime, NULL);
// double totalTime = ((double)endtime.tv_sec + (double)endtime.tv_usec/1000000.0f) -
// ((double)starttime.tv_usec + (double)starttime.tv_usec/1000000.0f);
// printf("Total time: %.8f\n", totalTime);
printf("With %i workers, %i darts, estimated value of pi is: %.9f\n", numWorkers, numDarts, avgpi);
MPI_Finalize();
return 0;
}
gettimeofday への 2 回目の呼び出しの直前に printf 呼び出しを入れました。2 番目の呼び出しがコメント アウトされている場合にのみ出力されます。それ以外の場合はクラッシュします。この例では gettimeofday をコメントアウトしましたが、これが mpi のクラッシュの原因となっている呼び出しです。コメントを外すと、言及したエラーメッセージで再びクラッシュし始めます。
gettimeofday がこれを行う理由について誰かが洞察を持っているかどうか疑問に思っています。