-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpiWtime.c
48 lines (34 loc) · 915 Bytes
/
mpiWtime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <mpi.h>
#include <stdio.h>
#include <math.h>
void printArgs (int argc, char** argv) {
int i;
for (i = 0; i < argc; ++i) {
printf ("argv[%d] = %s\n", i, argv[i]);
}
}
double doWork (int niter) {
int i;
double result;
for (i = 0; i < niter; ++i) {
result += sqrt ((double) i);
}
return result;
}
int main (int argc, char** argv) {
MPI_Init (&argc, &argv);
int numprocs;
MPI_Comm_size (MPI_COMM_WORLD, &numprocs);
int myid;
MPI_Comm_rank (MPI_COMM_WORLD, &myid);
printf ("Hello World from processor: %d out of %d\n", myid, numprocs);
int namelen;
char myname[MPI_MAX_PROCESSOR_NAME];
MPI_Get_processor_name (myname, &namelen);
printf ("processor id=%d, name=%s\n", myid, myname);
double time = MPI_Wtime ();
double d = doWork (1e7);
time = MPI_Wtime() - time;
printf ("Time taken by proc = %d is = %g\n", myid, time);
MPI_Finalize ();
}