Reputation: 263
I have one program (which calculates the matrix multiplication with cannon algorithm), is implemented in MPI for C, I have set a clock to see the TOTAL time of this program, with total I mean all the process sum.
But as a result I get the time of each process.
Part of my code at the beginning of my main:
clock_t begin, end;
double time_spent;
begin = clock();
/* Initializing */
MPI_Init (&argc, &argv);
Then at the end of my code I have:
MPI_Finalize();
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("\n\nTIME: %f SECONDS\n\n", time_spent);
Upvotes: 3
Views: 3040
Reputation: 9489
Assuming what you want is the sum of the individual times for each of your processes, you will need to:
MPI_Finalize()
, as you'll need an extra communication; MPI_Reduce()
to process #0 (for example); and finallyAside from this, unless you have a compelling reason for doing otherwise, I would encourage you to use MPI_Wtime()
as timer rather than the somewhat misleading clock()
timer.
The code could then look as follow:
int main( int *argc, char* argv[] ) {
MPI_Init( &argc, &argv );
double tbeg = MPI_Wtime();
// a lot of stuff here
// you might want a barrier here...
// MPI_Barrier( MPI_COMM_WORLD );
double elapsedTime = MPI_Wtime() - tbeg;
double totalTime;
MPI_Reduce( &elapsedTime, &totalTime, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
if ( rank == 0 ) {
printf( "Total time spent in seconds id %f\n", totalTime );
}
MPI_Finalize();
return 0;
}
Upvotes: 7
Reputation: 73366
Yes of course what you get is correct.
If you want the TOTAL TIME, i.e. the sum of the time spent in every process, then send the local time_spent
of every node in the master node, perform the summation of the local time_spent
's there and print it.
Upvotes: 0