Commit 832f1b94 by Francois Gygi

use MPI column communicator instead of Context


git-svn-id: http://qboxcode.org/svn/qb/trunk@1343 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 68b63613
......@@ -36,34 +36,54 @@ using namespace std;
SlaterDet::SlaterDet(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt),
c_(ctxt)
{
//cout << ctxt.mype() << ": SlaterDet::SlaterDet: ctxt.mycol="
// << ctxt.mycol() << " basis_->context(): "
// << basis_->context();
my_col_ctxt_ = 0;
for ( int icol = 0; icol < ctxt_.npcol(); icol++ )
// create cartesian communicator mapped on ctxt
int ndims=2;
// Note: MPI_Cart_comm uses row-major ordering. Need to give
// transposed dimensions as input arguments
int dims[2] = {ctxt.npcol(), ctxt.nprow()};
int periods[2] = { 0, 0};
int reorder = 0;
MPI_Comm comm;
MPI_Cart_create(ctxt.comm(),ndims,dims,periods,reorder,&comm);
int size, myrank;
MPI_Comm_size(comm,&size);
MPI_Comm_rank(comm,&myrank);
int coords[2];
MPI_Cart_coords(comm,myrank,2,coords);
#ifdef DEBUG
for ( int i = 0; i < size; i++ )
{
Context* col_ctxt = new Context(ctxt_,ctxt_.nprow(),1,0,icol);
ctxt_.barrier();
if ( icol == ctxt_.mycol() )
my_col_ctxt_ = col_ctxt;
else
delete col_ctxt;
MPI_Barrier(comm);
if ( myrank == i )
cout << myrank << ": myrow=" << ctxt.myrow() << " mycol=" << ctxt.mycol()
<< " coords= " << coords[0] << ", " << coords[1] << endl;
}
//cout << ctxt_.mype() << ": SlaterDet::SlaterDet: my_col_ctxt: "
// << *my_col_ctxt_;
basis_ = new Basis(*my_col_ctxt_,kpoint);
#endif
// Split the cartesian communicator comm to define my_col_comm_
// MPI_Cart_create uses row-major ordering. Need to keep the second
// dimension to get a communicator corresponding to a column of ctxt
int remain_dims[2] = { 0, 1 };
MPI_Cart_sub(comm, remain_dims, &my_col_comm_);
// Free the cartesian communicator
MPI_Comm_free(&comm);
// define basis on the column subcommunicator
basis_ = new Basis(my_col_comm_,kpoint);
}
////////////////////////////////////////////////////////////////////////////////
SlaterDet::SlaterDet(const SlaterDet& rhs) : ctxt_(rhs.context()),
basis_(new Basis(*(rhs.basis_))),
my_col_ctxt_(new Context(*(rhs.my_col_ctxt_))) , c_(rhs.c_){}
my_col_comm_(rhs.my_col_comm_), c_(rhs.c_){}
////////////////////////////////////////////////////////////////////////////////
SlaterDet::~SlaterDet()
{
delete basis_;
delete my_col_ctxt_;
// cout << ctxt_.mype() << ": SlaterDet::dtor: ctxt=" << ctxt_;
#ifdef TIMING
for ( TimerMap::iterator i = tmap.begin(); i != tmap.end(); i++ )
......@@ -1327,7 +1347,6 @@ void SlaterDet::write(SharedFilePtr& sfp, string encoding, double weight,
#if USE_MPI
char* wbuf = 0;
size_t wbufsize = 0;
const Context& colctxt = basis_->context();
#endif
// Segment n on process iprow is sent to row (n*nprow+iprow)/(nprow)
......@@ -1608,7 +1627,7 @@ void SlaterDet::write(SharedFilePtr& sfp, string encoding, double weight,
scounts[idest] = seg.size();
// send sendcounts to all procs
MPI_Alltoall(&scounts[0],1,MPI_INT,&rcounts[0],1,MPI_INT,colctxt.comm());
MPI_Alltoall(&scounts[0],1,MPI_INT,&rcounts[0],1,MPI_INT,my_col_comm_);
// dimension receive buffer
int rbufsize = rcounts[0];
......@@ -1621,7 +1640,7 @@ void SlaterDet::write(SharedFilePtr& sfp, string encoding, double weight,
char* rbuf = new char[rbufsize];
int err = MPI_Alltoallv((void*)seg.data(),&scounts[0],&sdispl[0],
MPI_CHAR,rbuf,&rcounts[0],&rdispl[0],MPI_CHAR,colctxt.comm());
MPI_CHAR,rbuf,&rcounts[0],&rdispl[0],MPI_CHAR,my_col_comm_);
if ( err != 0 )
cout << ctxt_.mype()
......
......@@ -39,7 +39,7 @@ class SlaterDet
private:
const Context& ctxt_;
Context* my_col_ctxt_;
MPI_Comm my_col_comm_;
Basis* basis_;
ComplexMatrix c_;
std::vector<double> occ_;
......
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