MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
proc4.cpp File Reference
#include <mpi.h>
#include <vector>
+ Include dependency graph for proc4.cpp:

Go to the source code of this file.

Macros

#define DIETAG   2
 
#define WORKTAG   1
 

Functions

static int clearPending (int numNodes, int myrank, MPI_Request *recvReq, double &tot)
 
static double doWork (double *work)
 
static double * get_next_work_item (int numCalls)
 
int main (int argc, char **argv)
 

Variables

const int numEntries = 10
 
static vector< vector< double > > recvBuf
 
const int totCalls = 2 * 65536
 

Macro Definition Documentation

#define DIETAG   2

Definition at line 9 of file proc4.cpp.

#define WORKTAG   1

Definition at line 8 of file proc4.cpp.

Function Documentation

static int clearPending ( int  numNodes,
int  myrank,
MPI_Request *  recvReq,
double &  tot 
)
static
static double doWork ( double *  work)
static

Definition at line 104 of file proc4.cpp.

References numEntries.

Referenced by main().

105 {
106  double tot = 0;
107  for (int i =0; i < numEntries; ++i )
108  tot += work[i];
109 }
const int numEntries
Definition: proc4.cpp:14

+ Here is the caller graph for this function:

static double* get_next_work_item ( int  numCalls)
static

Definition at line 20 of file proc4.cpp.

References numEntries, and totCalls.

Referenced by main().

21 {
22  static vector< double > ret( numEntries );
23  for ( int i = 0; i < numEntries; ++i )
24  ret[i] = i + numCalls;
25 
26  if ( numCalls >= totCalls )
27  return 0;
28  return &ret[0];
29 }
const int numEntries
Definition: proc4.cpp:14
const int totCalls
Definition: proc4.cpp:15

+ Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file proc4.cpp.

References doWork(), get_next_work_item(), numEntries, numNodes, recvBuf, and totCalls.

34 {
35  double tot = 0.0;
36  double tc = totCalls;
37  double ne = numEntries;
38  double expectedTot =
39  tc * ( ( ne * (ne - 1.0) )/2.0 ) +
40  ne * ( tc * (tc - 1.0) )/2.0;
41  int myrank;
42  int numNodes;
43 
44  /* Initialize MPI */
45 
46  MPI_Init(&argc, &argv);
47 
48  /* Find out my identity in the default communicator */
49 
50  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
51  MPI_Comm_size(MPI_COMM_WORLD, &numNodes);
52 
53  double sendBuf[numNodes * numEntries];
54  double recvBuf[ numEntries * numNodes ];
55 
56  int numCallsPerNode = totCalls / numNodes;
57 
58  int begin = myrank * numCallsPerNode;
59  int end = begin + numCallsPerNode;
60 
61  int k = 0;
62  for ( int i = 0; i < numCallsPerNode; ++i ) {
63  double* work = get_next_work_item( i + begin );
64  int targetNode = i % numNodes;
65  for ( int j = 0; j < numEntries; ++j ) {
66  sendBuf[targetNode * numEntries + j ] = work[j];
67  }
68 
69  if ( targetNode == numNodes - 1 ) {
70  for ( int j = 0; j < numNodes; ++j ) {
71  MPI_Scatter( sendBuf, numEntries, MPI_DOUBLE,
72  recvBuf, numEntries * (1 + j ), MPI_DOUBLE, j,
73  MPI_COMM_WORLD
74  );
75  tot += doWork( recvBuf );
76  }
77  }
78  }
79  // Final pass to consolidate all the data
80  double totBuf[ numNodes ];
81  MPI_Allgather( &tot, 1, MPI_DOUBLE,
82  totBuf, 1, MPI_DOUBLE,
83  MPI_COMM_WORLD
84  );
85  double subtot = tot;
86  tot = 0;
87  for ( int i = 0; i < numNodes; ++i )
88  {
89  tot += totBuf[i];
90  }
91 
92  cout << myrank << ": Tot = " << tot <<
93  ", expected = " << expectedTot <<
94  ", subtot = " << subtot << endl;
95 
96  /* Shut down MPI */
97 
98  MPI_Finalize();
99  return 0;
100 }
const int numEntries
Definition: proc4.cpp:14
const int totCalls
Definition: proc4.cpp:15
static double doWork(double *work)
Definition: proc4.cpp:104
static unsigned int numNodes
static double * get_next_work_item(int numCalls)
Definition: proc4.cpp:20
static vector< vector< double > > recvBuf
Definition: proc4.cpp:16

+ Here is the call graph for this function:

Variable Documentation

const int numEntries = 10

Definition at line 14 of file proc4.cpp.

Referenced by doWork(), get_next_work_item(), and main().

vector< vector< double > > recvBuf
static

Definition at line 16 of file proc4.cpp.

Referenced by main().

const int totCalls = 2 * 65536

Definition at line 15 of file proc4.cpp.

Referenced by get_next_work_item(), and main().