added a basic timing test
git-svn-id: svn://anubis/gvsu@234 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
c20e18d654
commit
f904d3ba15
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -13,13 +14,32 @@ int main(int argc, char * argv[])
|
|||||||
if (my_rank == 0)
|
if (my_rank == 0)
|
||||||
{
|
{
|
||||||
int buf = 0;
|
int buf = 0;
|
||||||
|
struct timeval before, after;
|
||||||
|
|
||||||
|
gettimeofday(&before, NULL); /* Start timing */
|
||||||
|
|
||||||
|
MPI_Send(&buf, sizeof(buf), MPI_CHAR,
|
||||||
|
0, 42, MPI_COMM_WORLD);
|
||||||
|
|
||||||
MPI_Recv(&buf, sizeof(buf), MPI_CHAR,
|
MPI_Recv(&buf, sizeof(buf), MPI_CHAR,
|
||||||
MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
||||||
|
|
||||||
|
gettimeofday(&after, NULL); /* Stop timing */
|
||||||
|
|
||||||
cout << "Master received " << buf << endl;
|
cout << "Master received " << buf << endl;
|
||||||
|
|
||||||
|
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
|
||||||
|
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
|
||||||
|
double diff = time_after - time_before;
|
||||||
|
cout << "Elapsed time: " << diff << " seconds." << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int forty_two = 42;
|
int forty_two = 42;
|
||||||
|
int buf;
|
||||||
|
MPI_Recv(&buf, sizeof(buf), MPI_CHAR,
|
||||||
|
MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
||||||
|
|
||||||
MPI_Send(&forty_two, sizeof(forty_two), MPI_CHAR,
|
MPI_Send(&forty_two, sizeof(forty_two), MPI_CHAR,
|
||||||
0, 42, MPI_COMM_WORLD);
|
0, 42, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user