-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpiBaseTest5.cc
71 lines (60 loc) · 1.69 KB
/
mpiBaseTest5.cc
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <omp.h>
#include <time.h>
#include <mpi.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
double doTest5( int rank, int numIterations, char* sendBuf, char* recvBuf, int numThreads, size_t threadPart, double compTime, double noise )
{
// each thread
double start,duration;
start = MPI_Wtime();
long sleep = compTime * 1000000000;
long sleepPlus = (compTime + ( compTime * noise)) * 1000000000 ;
#pragma omp parallel shared(rank,numIterations,sendBuf,recvBuf,sleep,sleepPlus) num_threads(numThreads)
{
int other = (rank + 1) % 2;
int rc;
int tid = omp_get_thread_num();
int iteration;
struct timespec req,rem;
req.tv_sec = 0;
if ( numThreads > 1 && tid == numThreads - 1 ) {
req.tv_nsec = sleepPlus;
} else {
req.tv_nsec = sleep;
}
size_t bufSize = numThreads * threadPart;
for ( iteration = 0; iteration < numIterations; iteration++ ) {
if ( 0 == rank ) {
#pragma omp barrier
rc = clock_nanosleep(CLOCK_REALTIME,0,&req, &rem);
if ( 0 != rc ) {
printf("rc=%s rem %li\n",strerror(rc),rem.tv_nsec);
}
#pragma omp barrier
#pragma omp master
{
rc = MPI_Send( (char*) sendBuf, bufSize, MPI_CHAR, other, 0xdead, MPI_COMM_WORLD );
assert( rc == MPI_SUCCESS );
}
} else {
#pragma omp barrier
#pragma omp master
{
rc = MPI_Recv( (char*) recvBuf, bufSize, MPI_CHAR, other, 0xdead, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
assert( rc == MPI_SUCCESS );
}
}
}
}
duration = MPI_Wtime() - start;
if ( numThreads > 1 ) {
duration -= sleepPlus / 1000000000.0 * numIterations;
} else {
duration -= sleep / 1000000000.0 * numIterations;
}
return duration;
}