EpetraExt_MultiMpiComm.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 /*
00003 ************************************************************************
00004 
00005               EpetraExt: Extended Linear Algebra Services Package 
00006                 Copyright (2001) Sandia Corporation
00007 
00008 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 license for use of this work by or on behalf of the U.S. Government.
00010 
00011 This library is free software; you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as
00013 published by the Free Software Foundation; either version 2.1 of the
00014 License, or (at your option) any later version.
00015  
00016 This library is distributed in the hope that it will be useful, but
00017 WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 Lesser General Public License for more details.
00020  
00021 You should have received a copy of the GNU Lesser General Public
00022 License along with this library; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 USA
00025 Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 
00027 ************************************************************************
00028 */
00029 //@HEADER
00030 
00031 #include "EpetraExt_MultiMpiComm.h" 
00032 
00033 namespace EpetraExt {
00034 
00035 MultiMpiComm::MultiMpiComm(MPI_Comm globalMpiComm, int subDomainProcs, int numTimeSteps_) :
00036         Epetra_MpiComm(globalMpiComm), subComm(0), numSubDomains(-1),
00037         subDomainRank(-1), numTimeSteps(numTimeSteps_),
00038   numTimeStepsOnDomain(-1), firstTimeStepOnDomain(-1)
00039 {
00040   //Need to construct subComm for each sub domain, compute subDomainRank,
00041   //and check that all integer arithmatic works out correctly.
00042  
00043   int ierrmpi, size, rank;
00044   ierrmpi = MPI_Comm_size(globalMpiComm, &size);
00045   ierrmpi = MPI_Comm_rank(globalMpiComm, &rank);
00046 
00047   if (size % subDomainProcs != 0) {cout<<"ERROR: num subDomainProcs "<< subDomainProcs
00048      << " does not divide into num total procs " << size << endl; exit(-1);}
00049 
00050   numSubDomains = size / subDomainProcs;
00051 
00052   // Create split communicators, the size of subDomainProcs
00053   MPI_Comm split_MPI_Comm;
00054   subDomainRank = rank/subDomainProcs;
00055   ierrmpi =  MPI_Comm_split(globalMpiComm, subDomainRank, rank, &split_MPI_Comm);
00056 
00057   // Construct second epetra communicators
00058   subComm = new Epetra_MpiComm(split_MPI_Comm);
00059 
00060   // Compute number of time steps on this sub domain
00061   if (numTimeSteps > 0) {
00062     // Compute part for number of domains dividing evenly into number of steps
00063     numTimeStepsOnDomain = numTimeSteps / numSubDomains; 
00064     firstTimeStepOnDomain = numTimeStepsOnDomain * subDomainRank;
00065 
00066     // Dole out remainder
00067     int remainder = numTimeSteps % numSubDomains;
00068     if (subDomainRank < remainder) {
00069       numTimeStepsOnDomain++; 
00070       firstTimeStepOnDomain += subDomainRank; 
00071     }
00072     else firstTimeStepOnDomain += remainder; 
00073   }
00074   cout << "Processor " << rank << " is on subdomain " << subDomainRank 
00075        << " and owns " << numTimeStepsOnDomain << " time steps, starting with " 
00076        <<  firstTimeStepOnDomain << endl;
00077 }
00078   
00079 //Copy Constructor
00080 MultiMpiComm::MultiMpiComm(const MultiMpiComm &MMC ) :
00081         Epetra_MpiComm(MMC), subComm(new Epetra_MpiComm(*(MMC.subComm))),
00082         numSubDomains(MMC.numSubDomains), subDomainRank(MMC.subDomainRank),
00083   numTimeSteps(MMC.numTimeSteps), 
00084   numTimeStepsOnDomain(MMC.numTimeStepsOnDomain), 
00085   firstTimeStepOnDomain(MMC.firstTimeStepOnDomain) 
00086 {
00087 }
00088 
00089 MultiMpiComm::~MultiMpiComm()
00090 {
00091   delete subComm;
00092 }
00093 
00094 } //namespace EpetraExt

Generated on Thu Sep 18 12:31:44 2008 for EpetraExt by doxygen 1.3.9.1