【发布时间】:2011-07-14 23:59:37
【问题描述】:
我正在开发一个将数组与矩阵相乘的小应用程序。它可以正常工作。我正在寻找测量应用程序的执行时间。我可以找到每个进程的单独执行时间(它的开始和结束),但我需要全局时间。
这是我的代码:
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;
}
我使用变量 min_start 和 max_end 作为“全局”变量来尝试捕获所有进程的最大和最小温度,但我总是得到最后一个要执行的进程的开始和结束时间,结束时间还可以,但开始时间错误,因为最后一个进程不是第一个开始的。我究竟做错了什么?我可以在 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
【问题讨论】: