Commit 9ea1dacf by Francois Gygi

simplified Context constructors. All contexts are column-major.


git-svn-id: http://qboxcode.org/svn/qb/trunk@292 cba15fb0-1239-40c8-b417-11db7ca47a34
parent c67dc3fb
......@@ -3,7 +3,7 @@
// Context.h
//
////////////////////////////////////////////////////////////////////////////////
// $Id: Context.h,v 1.7 2003-08-18 22:45:57 fgygi Exp $
// $Id: Context.h,v 1.8 2004-11-10 22:34:17 fgygi Exp $
#ifndef CONTEXT_H
#define CONTEXT_H
......@@ -135,36 +135,13 @@ class Context
// default global context: construct a single-row global Context
explicit Context();
// global Context of size nprow * npcol with row
// or column major order
explicit Context(const int nprow, const int npcol, const char order = 'r');
// specialized Context derived from a Context ctxt
// Context(ctxt,'r'): single-row context
// Context(ctxt,'c'): single-column context
// Context(ctxt,'s'): largest possible square context
explicit Context(const Context &ctxt, const char type);
// construct a Context of size nprow * npcol from ctxt with row
// or column major order
explicit Context(const Context &ctxt, const int nprow, const int npcol,
const char order = 'r');
// construct a Context of size nprow*npcol starting at process ipe with row
// or column major order
explicit Context(const Context &ctxt,
const int ipe, const int nprow, const int npcol, const char order = 'r');
// global Context of size nprow * npcol with column major order
explicit Context(int nprow, int npcol);
// construct a Context of size nprow*npcol from the processes
// in context ctxt lying in the rectangle of size nr * nc starting
// at process (irow,icol)
explicit Context(Context &ctxt, const int irow, const int icol, const int nr,
const int nc, const int nprow, const int npcol, const char trans = 'n');
// construct a Context corresponding to row or column i
// of a given context ctxt
// use: Context(ctxt,'r',i) or Context(ctxt,'c',i)
explicit Context(const Context &ctxt, const char type, const int i);
// in context ctxt starting at process (irstart,icstart)
explicit Context(const Context &ctxt, int nprow, int npcol,
int irstart, int icstart);
~Context();
......
......@@ -3,7 +3,7 @@
// testContext.c
//
////////////////////////////////////////////////////////////////////////////////
// $Id: testContext.C,v 1.4 2003-01-10 00:29:38 fgygi Exp $
// $Id: testContext.C,v 1.5 2004-11-10 22:34:17 fgygi Exp $
#include <cassert>
#include <iostream>
......@@ -26,112 +26,75 @@ int main(int argc, char **argv)
MPI_Comm_size(MPI_COMM_WORLD, &npes);
MPI_Comm_rank(MPI_COMM_WORLD, &mype);
{ // start Context scope
// test reference counting
if ( npes%2 == 0 && npes >= 4 )
{
Context *c1 = new Context(npes/2,2);
cout << "c1: " << *c1 << endl;
Context *c2;
if ( c1->active() )
c2 = new Context(*c1,npes/2,npes/2,1);
else
c2 = 0;
// this line causes crash: Context *c2 = new Context(*c1,1,1,1);
delete c1;
if ( c2 != 0 ) cout << c2->mype() << " c2: " << *c2;
delete c2;
}
int nr = atoi(argv[1]);
int nc = atoi(argv[2]);
#if 0
Context c_global;
if ( npes%2 == 0 && npes >= 2 )
{
Context sub(c_global,c_global.size()/2,2);
Context half0(sub,0,c_global.size()/2,1);
Context half1(sub,c_global.size()/2,c_global.size()/2,1);
cout << c_global.mype() << ": half0: " << half0;
cout << c_global.mype() << ": half1: " << half1;
}
{ // start Context scope
if ( npes >= 16 )
{
Context subcontext(c_global,npes/4,4,'c');
cout << c_global.mype() << ": subcontext: " << subcontext;
Context ctxt;
cout << mype << ":" << ctxt.mype() << ":" << ctxt.myproc()
<< " base: " << ctxt;
vector<Context*> c;
if ( subcontext.active() )
c.push_back(new Context(nr,nc));
c.push_back(new Context(*c[0],2,2,1,1));
for ( int icol = 0; icol < c[0]->npcol(); icol++ )
{
Context sd0(subcontext,0,0,4,2,4,2);
Context sd1(subcontext,0,2,4,2,4,2);
cout << c_global.mype() << ": sd0: " << sd0;
cout << c_global.mype() << ": sd1: " << sd1;
ctxt.barrier();
c.push_back(new Context(*c[0],c[0]->nprow(),1,0,icol));
}
}
if ( npes == 6 )
{
Context rowmajor(2,3,'R');
cout << " rowmajor: " << rowmajor;
Context colmajor(2,3,'C');
cout << " colmajor: " << colmajor;
cout << " colmajor.mype(): " << colmajor.mype()
<< " myproc(): " << colmajor.myproc()
<< " myrow(): " << colmajor.myrow()
<< " mycol(): " << colmajor.mycol()
<< endl;
vector<Context*> c;
c.push_back( new Context(c_global,3,2,'r') );
c.push_back( new Context(c_global,'s') );
c.push_back( new Context(c_global,1,3,1,'c') );
c.push_back( new Context(*c[0],1,0,2,2,4,1) );
c.push_back( new Context(*c[0],'r',c[0]->myrow()) );
c.push_back( new Context(*c[0],'c',c[0]->mycol()) );
c.push_back( new Context() );
for ( int i = 0; i < c.size(); i++ )
{
if ( c[i]->myproc() == 0 )
cout << "c[" << i << "]: " << *c[i];
Context* pc = c[i];
cout << mype << ":" << pc->mype() << ":" << pc->myproc()
<< " at (" << pc->myrow() << "," << pc->mycol() << ")"
<< " in c" << i << ": " << *pc;
}
Context c1(2,3,'c');
Context c2 = c1;
Context c3(c1);
Context c4;
c4 = c1;
cout << " c1: " << c1;
cout << " c2: " << c2;
cout << " c3: " << c3;
cout << " c4: " << c4;
vector<Context> cv;
cv.resize(4);
cv.push_back(c1);
cv.push_back(c2);
cv.push_back(c3);
cv.push_back(c4);
#if 0
MPI_Comm comm = c[1]->comm();
int mype_in_c1,size_of_c1;
MPI_Comm_rank(comm,&mype_in_c1);
MPI_Comm_size(comm,&size_of_c1);
cout << mype << ": mype_in_c1: " << mype_in_c1
<< " size_of_c1=" << size_of_c1
<< " comm[c1]=" << comm << endl;
for ( int i = 0; i < cv.size(); i++ )
cout << " cv[" << i << "]: " << cv[i];
// test dgsum2d function
double a = c[0]->mype();
cout << c[0]->mype() << ": a = " << a << endl;
c[0]->dgsum2d('R',1,1,&a,1);
cout << c[0]->mype() << ": a_sum_row = " << a << endl;
c[0]->dgsum2d('C',1,1,&a,1);
cout << c[0]->mype() << ": a_sum_all = " << a << endl;
double a = c[1]->mype();
cout << c[1]->mype() << ": a = " << a << endl;
c[1]->dsum('R',1,1,&a,1);
cout << c[1]->mype() << ": a_sum_row = " << a << endl;
c[1]->dsum('C',1,1,&a,1);
cout << c[1]->mype() << ": a_sum_all = " << a << endl;
#endif
for ( int i = 0; i < c.size(); i++ )
{
delete c[i];
}
// // test reference counting
// if ( npes%2 == 0 && npes >= 4 )
// {
// Context *c1 = new Context(npes/2,2);
// cout << "c1: " << *c1 << endl;
// Context *c2;
// if ( c1->active() )
// c2 = new Context(*c1,npes/2,npes/2,1);
// else
// c2 = 0;
// // this line causes crash: Context *c2 = new Context(*c1,1,1,1);
// delete c1;
// if ( c2 != 0 ) cout << c2->mype() << " c2: " << *c2;
// delete c2;
// }
#if 0
}
#endif
} // end Context scope
MPI_Finalize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment