rambrain
mpitest.cpp
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <iostream>
21 #include <mpi.h>
22 #include "managedPtr.h"
23 #include "cyclicManagedMemory.h"
24 #include "managedFileSwap.h"
25 
26 using namespace std;
27 using namespace rambrain;
28 
32 int main ( int argc, char **argv )
33 {
34  const unsigned int dblamount = 100;
35  const global_bytesize mem = dblamount * 2.5 * sizeof ( double );
36  const global_bytesize swapmem = 100 * dblamount * sizeof ( double );
37  int ret = 0;
38 
39  MPI_Init ( &argc, &argv );
40 
41  int tasks = 5;
42  MPI_Comm_size ( MPI_COMM_WORLD, &tasks );
43  cout << "Starting mpi test on " << tasks << " tasks" << endl;
44 
45  managedFileSwap swap ( swapmem, "/tmp/rambrainswap-%d-%d" );
46  cyclicManagedMemory manager ( &swap, mem );
47 
48  managedPtr<double> data1 ( dblamount );
49  managedPtr<double> data3 ( dblamount );
50  {
51  ADHERETOLOC ( double, data1, d1 );
52  for ( unsigned int i = 0; i < dblamount; ++i ) {
53  d1[i] = i * 1.0;
54  }
55  }
56 
57  managedPtr<double> data2 ( dblamount );
58  {
59  ADHERETOLOC ( double, data2, d2 );
60  for ( unsigned int i = 0; i < dblamount; ++i ) {
61  d2[i] = i * dblamount * 1.0;
62  }
63  }
64 
65  {
66  ADHERETOLOC ( double, data1, d1 );
67  ADHERETOLOC ( double, data3, d3 );
68  MPI_Allreduce ( d1, d3, dblamount, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
69  for ( unsigned int i = 0; i < dblamount; ++i ) {
70  d1[i] = d3[i];
71  }
72  }
73 
74  {
75  ADHERETOLOC ( double, data2, d2 );
76  ADHERETOLOC ( double, data3, d3 );
77  MPI_Allreduce ( d2, d3, dblamount, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
78  for ( unsigned int i = 0; i < dblamount; ++i ) {
79  d2[i] = d3[i];
80  }
81  }
82 
83  {
84  ADHERETOLOC ( double, data1, d1 );
85  for ( unsigned int i = 0; i < dblamount; ++i ) {
86  if ( d1[i] != i * 1.0 * tasks ) {
87  cerr << "Result of allreduce not correct! Expected " << i * 1.0 * tasks << " at index d1[" << i << "], got " << d1[i] << endl;
88  ++ ret;
89  }
90  }
91  }
92 
93  {
94  ADHERETOLOC ( double, data2, d2 );
95  for ( unsigned int i = 0; i < dblamount; ++i ) {
96  if ( d2[i] != i * 1.0 * tasks * dblamount ) {
97  cerr << "Result of allreduce not correct! Expected " << i * 1.0 * dblamount *tasks << " at index d2[" << i << "], got " << d2[i] << endl;
98  ++ ret;
99  }
100  }
101  }
102 
103  MPI_Finalize();
104 
105  cout << "Test done" << endl;
106 
107  return ret;
108 }
109 
Main class to allocate memory that is managed by the rambrain memory defaultManager.
Definition: managedMemory.h:54
int main(int argc, char **argv)
Provides a test binary to check the behaviour of mpi in combination with the lib. ...
Definition: mpitest.cpp:32
An implementation of managedSwap that is capable of kernel asynchronousIO.
uint64_t global_bytesize
Definition: common.h:65
scheduler working with a double linked cycle. Details see paper.
STL namespace.