我正在研究一个将矩阵与一个数组相乘的小应用程序。它工作没有任何问题。我正在调侃用于衡量应用程序的执行时间。我可以找到每个进程(它的开始和结束)的执行时间,但我需要全球时间。MPI全局执行时间
这是我的代码:
int main(int argc, char **argv){
int rang, procesus;
MPI_Status statut;
double start, end, max_end = 0, min_start = 10000;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rang);
MPI_Comm_size(MPI_COMM_WORLD, &procesus);
MPI_Barrier(MPI_COMM_WORLD);
start = MPI_Wtime();
printf("Starting time of process n. %d %f\n",rang, start);
if(rang==0){
//Master work
}else{
//slaves work
}
MPI_Barrier(MPI_COMM_WORLD);
end = MPI_Wtime();
printf("Ending time of process n.%d %f\n\n\n",rang, end);
MPI_Finalize();
//Out of the Parallelized task
if(min_start > start){
min_start = start;
printf("New minumum starting time %f\n", min_start);
}
if(max_end < end){
max_end = end;
printf("New maximum ending time %f\n", max_end);
}
if(rang == 0){
printf("Start %f\n", min_start);
printf("End %f\n", max_end);
}
return 0;
}
我使用varables min_start和max_end为“全局”变量,试图赶上max和所有进程的最小的临时工,但我总是在开始和结束要执行的最后一个进程的tme,结束时间是可以的,但开始时间是错误的,因为最后一个进程是第一个开始。我究竟做错了什么?我可以在MPI中为所有进程使用一个真正的全局变量吗?如果我可以怎么做?
这就是我作为输出
Starting time of process n.2. 0.101562
Ending time of process n.2. 0.105469
New minumum starting time 0.101562
New maximum ending time 0.105469
Starting time of process n.3. 0.058594
Ending time of process n.3. 0.062500
New minumum starting time 0.058594
New maximum ending time 0.062500
Starting time of process n. 4. 0.007812
Ending time of process n. 4. 0.011719
New minumum starting time 0.007812
New maximum ending time 0.011719
Starting time of process n.1. 0.148438
Ending time of process n.1. 0.152344
New minumum starting time 0.148438
New maximum ending time 0.152344
Starting time of process n.0. 0.207031
Ending time of process n.0. 0.210938
New minumum starting time 0.207031
New maximum ending time 0.210938
Start 0.207031
End 0.210938
如果时钟未同步,则使用来自不同节点的开始/结束时间计算运行时间可能会导致无效结果。 – 2011-03-14 16:35:25
嗨...是...为了解决这个问题,我添加了MPI_Reduce来查找所有进程的开始和结束时间的最大值和最小值......感谢提示... :) – jomaora 2011-03-16 09:49:06
@ShawnChin,你什么意思?如果时钟不同步,则开始时间和结束时间将会(可能完全)不同,但它们的差别应该是当前进程所用的时间,所以要么我说的是错误的,要么你的意思是别的。你可以解释吗?先谢谢你。 – 2017-04-06 12:03:45