1 /*****************************************************************************
5 ** Purpose: MPI Support class
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: June 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: mpiworld.cpp,v 1.3 2001/01/16 23:19:03 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
32 MPIWorld::MPIWorld (int& argc, char* const *& argv)
34 MPI::Init (argc, const_cast<char**&>(argv));
35 m_comm = MPI::COMM_WORLD.Dup();
36 m_nProcessors = m_comm.Get_size();
37 m_myRank = m_comm.Get_rank();
38 m_vLocalWorkUnits.reserve (m_nProcessors);
39 m_vStartWorkUnit.reserve (m_nProcessors);
40 m_vEndWorkUnit.reserve (m_nProcessors);
45 MPIWorld::setTotalWorkUnits(int totalWorkUnits)
47 if (m_nProcessors < 1)
50 int baseLocalWorkUnits = totalWorkUnits / m_nProcessors;
51 int remainderWorkUnits = totalWorkUnits % m_nProcessors;
53 int currWorkUnits = 0;
54 for (int iProc = 0; iProc < m_nProcessors; iProc++) {
55 m_vLocalWorkUnits[iProc] = baseLocalWorkUnits;
56 if (iProc < remainderWorkUnits)
57 m_vLocalWorkUnits[iProc]++;
59 m_vStartWorkUnit[iProc] = currWorkUnits;
60 m_vEndWorkUnit[iProc] = m_vStartWorkUnit[iProc] + m_vLocalWorkUnits[iProc] - 1;
62 currWorkUnits += m_vLocalWorkUnits[iProc];
68 MPIWorld::BcastString (string& str)
74 m_comm.Bcast (&len, 1, MPI::INT, 0);
78 strcpy (buf, str.c_str());
80 m_comm.Bcast (buf, len + 1, MPI::CHAR, 0);