目標は、実行時間とプロセス数を測定することです。
私は MPI の初心者で、どこかで行き詰まっています。
hello world プログラムを作成し、グローバル ランタイムをテストしたいと考えています。
システム時間を測定する前にすべてのプロセスが終了することを確認するためにバリアを使用しようとしましたが、セグメンテーション違反が発生します。
私のコード:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
double time1, time2;
double duration=0.0000;
int npes, myrank;
time1 = clock();
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &npes);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
printf("From process %d out of %d, Hello World!\n", myrank, npes);
time2 = clock();
if (time2-time1>duration) {
duration = time2-time1;
}
duration = time2-time1;
MPI_BARRIER(MPI_COMM_WORLD);
printf("runtime is %f ", duration);
MPI_Finalize();
return 0;
}
セグメンテーション違反が発生する理由を理解するのを手伝ってください。