testContext.C 1.97 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15
// testContext.C
Francois Gygi committed
16 17 18 19 20 21
//
////////////////////////////////////////////////////////////////////////////////

#include <cassert>
#include <iostream>
#include <vector>
Francois Gygi committed
22
#include <cstdlib>
Francois Gygi committed
23 24 25 26 27 28 29 30 31 32 33
using namespace std;
#include "Context.h"

int main(int argc, char **argv)
{
  int mype;
  int npes;

  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD, &npes);
  MPI_Comm_rank(MPI_COMM_WORLD, &mype);
34

Francois Gygi committed
35 36 37 38 39
  if ( argc != 3 )
  {
    cout << "use: testContext nrow ncol" << endl;
    return 1;
  }
40 41
  int nr = atoi(argv[1]);
  int nc = atoi(argv[2]);
42

43
  { // start Context scope
44

45
    Context ctxt(MPI_COMM_WORLD);
Francois Gygi committed
46 47 48 49 50
    for ( int i = 0; i < npes; i++ )
    {
      MPI_Barrier(MPI_COMM_WORLD);
      if ( i == mype )
        cout << mype << ":" << ctxt.mype() << ":" << ctxt.myproc()
51
         << " base: " << ctxt;
Francois Gygi committed
52
    }
53
    vector<Context*> c;
54

55 56
    c.push_back(new Context(MPI_COMM_WORLD,nr,nc));
    cout << ctxt.mype() << ": " << *c[0];
57

58 59
    if ( *c[0] )
      cout << ctxt.mype() << ": c[0] is active" << endl;
60

Francois Gygi committed
61
    // test dgsum2d function
62 63 64 65 66 67 68
    // add along rows, then along columns
    double a = c[0]->mype();
    cout << c[0]->mype() << ": a     = " << a << endl;
    c[0]->dsum('R',1,1,&a,1);
    cout << c[0]->mype() << ": a_sum_row = " << a << endl;
    c[0]->dsum('C',1,1,&a,1);
    cout << c[0]->mype() << ": a_sum_all = " << a << endl;
69

70 71 72 73
    for ( int i = 0; i < c.size(); i++ )
    {
      delete c[i];
    }
74

Francois Gygi committed
75 76 77 78
  } // end Context scope

  MPI_Finalize();
}