【发布时间】:2015-12-25 01:07:54
【问题描述】:
目标是衡量运行时间与#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;
}
帮我弄清楚为什么会出现分段错误?
【问题讨论】:
-
C 区分大小写。 MPI_BARRIER 将在链接时获取 Fortran 符号。
-
仅供参考 这是用 mpicc 编译并由 mpirun 运行