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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
30 MPIWorld::MPIWorld (int& argc, char* const *& argv)
32 MPI::Init (argc, const_cast<char**&>(argv));
33 m_comm = MPI::COMM_WORLD.Dup();
34 m_nProcessors = m_comm.Get_size();
35 m_myRank = m_comm.Get_rank();
36 m_vLocalWorkUnits.reserve (m_nProcessors);
37 m_vStartWorkUnit.reserve (m_nProcessors);
38 m_vEndWorkUnit.reserve (m_nProcessors);
43 MPIWorld::setTotalWorkUnits(int totalWorkUnits)
45 if (m_nProcessors < 1)
48 int baseLocalWorkUnits = totalWorkUnits / m_nProcessors;
49 int remainderWorkUnits = totalWorkUnits % m_nProcessors;
51 int currWorkUnits = 0;
52 for (int iProc = 0; iProc < m_nProcessors; iProc++) {
53 m_vLocalWorkUnits[iProc] = baseLocalWorkUnits;
54 if (iProc < remainderWorkUnits)
55 m_vLocalWorkUnits[iProc]++;
57 m_vStartWorkUnit[iProc] = currWorkUnits;
58 m_vEndWorkUnit[iProc] = m_vStartWorkUnit[iProc] + m_vLocalWorkUnits[iProc] - 1;
60 currWorkUnits += m_vLocalWorkUnits[iProc];
66 MPIWorld::BcastString (string& str)
72 m_comm.Bcast (&len, 1, MPI::INT, 0);
76 strcpy (buf, str.c_str());
78 m_comm.Bcast (buf, len + 1, MPI::CHAR, 0);