目标是测量运行时间与#of 进程。
我只是 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;
}
帮我弄清楚为什么会出现分段错误?