[MOAB-dev] [patch] Add MBParallelComm member to MBZoltan so that rank can be determined using proc_config()
Jed Brown
jed at 59A2.org
Mon Sep 29 14:52:57 CDT 2008
Patch attached. I think this is the correct way, but maybe Jason had
something else in mind.
Jed
-------------- next part --------------
diff --git a/tools/mbzoltan/MBZoltan.cpp b/tools/mbzoltan/MBZoltan.cpp
index 1055dd6..7709c87 100644
--- a/tools/mbzoltan/MBZoltan.cpp
+++ b/tools/mbzoltan/MBZoltan.cpp
@@ -61,7 +61,7 @@ MBErrorCode MBZoltan::balance_mesh(const char *zmethod,
!strcmp(zmethod, "PHG") && !strcmp(zmethod, "PARMETIS") &&
!strcmp(zmethod, "OCTPART"))
{
- std::cout << "ERROR node " << mbImpl->proc_rank() << ": Method must be "
+ std::cout << "ERROR node " << mbpc->proc_config().proc_rank() << ": Method must be "
<< "RCB, RIB, HSFC, Hypergraph (PHG), PARMETIS, or OCTPART"
<< std::endl;
return MB_FAILURE;
@@ -76,7 +76,7 @@ MBErrorCode MBZoltan::balance_mesh(const char *zmethod,
MBErrorCode result;
- if (mbImpl->proc_rank() == 0) {
+ if (mbpc->proc_config().proc_rank() == 0) {
result = assemble_graph(3, pts, ids, adjs, length, elems); RR;
}
@@ -166,8 +166,8 @@ MBErrorCode MBZoltan::balance_mesh(const char *zmethod,
mbFinalizePoints((int)ids.size(), numExport, exportLocalIds,
exportProcs, &assignment);
- if (mbImpl->proc_rank() == 0) {
- MBErrorCode result = write_partition(mbImpl->proc_size(), elems, assignment,
+ if (mbpc->proc_config().proc_rank() == 0) {
+ MBErrorCode result = write_partition(mbpc->proc_config().proc_size(), elems, assignment,
write_as_sets, write_as_tags);
if (MB_SUCCESS != result) return result;
@@ -202,7 +202,7 @@ MBErrorCode MBZoltan::partition_mesh(const int nparts,
const int part_dim)
{
// should only be called in serial
- if (mbImpl->proc_size() != 1) {
+ if (mbpc->proc_config().proc_size() != 1) {
std::cout << "MBZoltan::partition_mesh must be called in serial."
<< std::endl;
return MB_FAILURE;
@@ -213,7 +213,7 @@ MBErrorCode MBZoltan::partition_mesh(const int nparts,
strcmp(zmethod, "PHG") && strcmp(zmethod, "PARMETIS") &&
strcmp(zmethod, "OCTPART"))
{
- std::cout << "ERROR node " << mbImpl->proc_rank() << ": Method must be "
+ std::cout << "ERROR node " << mbpc->proc_config().proc_rank() << ": Method must be "
<< "RCB, RIB, HSFC, Hypergraph (PHG), PARMETIS, or OCTPART"
<< std::endl;
return MB_FAILURE;
@@ -334,8 +334,7 @@ MBErrorCode MBZoltan::assemble_graph(const int dimension,
if (MB_SUCCESS != result || elems.empty()) return result;
// assign global ids
- MBParallelComm mbpc(mbImpl);
- result = mbpc.assign_global_ids(0, dimension); RR;
+ result = mbpc->assign_global_ids(0, dimension); RR;
// now assemble the graph, calling MeshTopoUtil to get bridge adjacencies through d-1 dimensional
// neighbors
@@ -477,7 +476,7 @@ MBErrorCode MBZoltan::write_partition(const int nparts,
void MBZoltan::SetRCB_Parameters()
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nRecursive Coordinate Bisection" << std::endl;
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nRecursive Coordinate Bisection" << std::endl;
// General parameters:
myZZ->Set_Param("DEBUG_LEVEL", "0"); // no debug messages
@@ -492,7 +491,7 @@ void MBZoltan::SetRCB_Parameters()
void MBZoltan::SetRIB_Parameters()
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nRecursive Inertial Bisection" << std::endl;
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nRecursive Inertial Bisection" << std::endl;
// General parameters:
myZZ->Set_Param("DEBUG_LEVEL", "0"); // no debug messages
@@ -506,7 +505,7 @@ void MBZoltan::SetRIB_Parameters()
void MBZoltan::SetHSFC_Parameters()
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nHilbert Space Filling Curve" << std::endl;
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nHilbert Space Filling Curve" << std::endl;
// General parameters:
myZZ->Set_Param("DEBUG_LEVEL", "0"); // no debug messages
@@ -519,7 +518,7 @@ void MBZoltan::SetHSFC_Parameters()
void MBZoltan::SetHypergraph_Parameters(const char *phg_method)
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nHypergraph (or PHG): " << std::endl;
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nHypergraph (or PHG): " << std::endl;
// General parameters:
myZZ->Set_Param("DEBUG_LEVEL", "0"); // no debug messages
@@ -531,7 +530,7 @@ void MBZoltan::SetHypergraph_Parameters(const char *phg_method)
void MBZoltan::SetPARMETIS_Parameters(const char *parmetis_method)
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nPARMETIS: " << parmetis_method << std::endl;
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nPARMETIS: " << parmetis_method << std::endl;
// General parameters:
myZZ->Set_Param("DEBUG_LEVEL", "0"); // no debug messages
@@ -544,7 +543,7 @@ void MBZoltan::SetPARMETIS_Parameters(const char *parmetis_method)
void MBZoltan::SetOCTPART_Parameters(const char *oct_method)
{
- if (mbImpl->proc_rank() == 0) std::cout << "\nOctree Partitioning: " << oct_method
+ if (mbpc->proc_config().proc_rank() == 0) std::cout << "\nOctree Partitioning: " << oct_method
<< std::endl;
// General parameters:
@@ -571,23 +570,23 @@ int MBZoltan::mbInitializePoints(int npts, double *pts, int *ids,
int *sendNborId;
int *sendProcs;
- if (mbImpl->proc_rank() == 0)
+ if (mbpc->proc_config().proc_rank() == 0)
{
/* divide pts to start */
- numPts = (int *)malloc(sizeof(int) * mbImpl->proc_size());
- ptsPerProc = npts / mbImpl->proc_size();
+ numPts = (int *)malloc(sizeof(int) * mbpc->proc_config().proc_size());
+ ptsPerProc = npts / mbpc->proc_config().proc_size();
ptsAssigned = 0;
- for (i=0; (int) i < mbImpl->proc_size()-1; i++)
+ for (i=0; (int) i < mbpc->proc_config().proc_size()-1; i++)
{
numPts[i] = ptsPerProc;
ptsAssigned += ptsPerProc;
}
- numPts[mbImpl->proc_size()-1] = npts - ptsAssigned;
+ numPts[mbpc->proc_config().proc_size()-1] = npts - ptsAssigned;
- mySize = numPts[mbImpl->proc_rank()];
+ mySize = numPts[mbpc->proc_config().proc_rank()];
sendPts = pts + (3 * numPts[0]);
sendIds = ids + numPts[0];
sendEdges = length + numPts[0];
@@ -604,14 +603,14 @@ int MBZoltan::mbInitializePoints(int npts, double *pts, int *ids,
nborProcs = (int *)malloc(sizeof(int) * sum);
for (j=0; j<sum; j++)
- if ((i = adjs[j]/ptsPerProc) < mbImpl->proc_size())
+ if ((i = adjs[j]/ptsPerProc) < mbpc->proc_config().proc_size())
nborProcs[j] = i;
else
- nborProcs[j] = mbImpl->proc_size() - 1;
+ nborProcs[j] = mbpc->proc_config().proc_size() - 1;
sendProcs = nborProcs + (sendNborId - adjs);
- for (i=1; (int)i<mbImpl->proc_size(); i++)
+ for (i=1; (int)i<mbpc->proc_config().proc_size(); i++)
{
MPI_Send(&numPts[i], 1, MPI_INT, i, 0x00,MPI_COMM_WORLD);
MPI_Send(sendPts, 3 * numPts[i], MPI_DOUBLE, i, 0x01,MPI_COMM_WORLD);
@@ -675,24 +674,24 @@ void MBZoltan::mbFinalizePoints(int npts, int numExport,
/* assign pts to start */
- if (mbImpl->proc_rank() == 0)
+ if (mbpc->proc_config().proc_rank() == 0)
MyAssignment = (int *)malloc(sizeof(int) * npts);
else
MyAssignment = (int *)malloc(sizeof(int) * NumPoints);
for (i=0; i<NumPoints; i++)
- MyAssignment[i] = mbImpl->proc_rank();
+ MyAssignment[i] = mbpc->proc_config().proc_rank();
for (i=0; i<numExport; i++)
MyAssignment[exportLocalIDs[i]] = exportProcs[i];
- if (mbImpl->proc_rank() == 0)
+ if (mbpc->proc_config().proc_rank() == 0)
{
/* collect pts */
recvA = MyAssignment + NumPoints;
- for (i=1; i< (int) mbImpl->proc_size(); i++)
+ for (i=1; i< (int) mbpc->proc_config().proc_size(); i++)
{
MPI_Recv(&numPts, 1, MPI_INT, i, 0x04, MPI_COMM_WORLD, &stat);
MPI_Recv(recvA, numPts, MPI_INT, i, 0x05, MPI_COMM_WORLD, &stat);
@@ -713,13 +712,13 @@ int MBZoltan::mbGlobalSuccess(int rc)
{
int fail = 0;
int i;
- int *vals = (int *)malloc(mbImpl->proc_size() * sizeof(int));
+ int *vals = (int *)malloc(mbpc->proc_config().proc_size() * sizeof(int));
MPI_Allgather(&rc, 1, MPI_INT, vals, 1, MPI_INT, MPI_COMM_WORLD);
- for (i=0; i<mbImpl->proc_size(); i++){
+ for (i=0; i<mbpc->proc_config().proc_size(); i++){
if (vals[i] != ZOLTAN_OK){
- if (0 == mbImpl->proc_rank()){
+ if (0 == mbpc->proc_config().proc_rank()){
mbShowError(vals[i], "Result on process ");
}
fail = 1;
@@ -743,15 +742,15 @@ void MBZoltan::mbPrintGlobalResult(const char *s,
v1[2] = exp;
v1[3] = change;
- if (mbImpl->proc_rank() == 0){
- v2 = (int *)malloc(4 * mbImpl->proc_size() * sizeof(int));
+ if (mbpc->proc_config().proc_rank() == 0){
+ v2 = (int *)malloc(4 * mbpc->proc_config().proc_size() * sizeof(int));
}
MPI_Gather(v1, 4, MPI_INT, v2, 4, MPI_INT, 0, MPI_COMM_WORLD);
- if (mbImpl->proc_rank() == 0){
+ if (mbpc->proc_config().proc_rank() == 0){
fprintf(stdout,"======%s======\n",s);
- for (i=0, v=v2; i<mbImpl->proc_size(); i++, v+=4){
+ for (i=0, v=v2; i<mbpc->proc_config().proc_size(); i++, v+=4){
fprintf(stdout,"%d: originally had %d, import %d, exp %d, %s\n",
i, v[0], v[1], v[2],
v[3] ? "a change of partitioning" : "no change");
@@ -774,19 +773,19 @@ void MBZoltan::mbShowError(int val, const char *s)
switch (val)
{
case ZOLTAN_OK:
- printf("%d: SUCCESSFUL\n", mbImpl->proc_rank());
+ printf("%d: SUCCESSFUL\n", mbpc->proc_config().proc_rank());
break;
case ZOLTAN_WARN:
- printf("%d: WARNING\n", mbImpl->proc_rank());
+ printf("%d: WARNING\n", mbpc->proc_config().proc_rank());
break;
case ZOLTAN_FATAL:
- printf("%d: FATAL ERROR\n", mbImpl->proc_rank());
+ printf("%d: FATAL ERROR\n", mbpc->proc_config().proc_rank());
break;
case ZOLTAN_MEMERR:
- printf("%d: MEMORY ALLOCATION ERROR\n", mbImpl->proc_rank());
+ printf("%d: MEMORY ALLOCATION ERROR\n", mbpc->proc_config().proc_rank());
break;
default:
- printf("%d: INVALID RETURN CODE\n", mbImpl->proc_rank());
+ printf("%d: INVALID RETURN CODE\n", mbpc->proc_config().proc_rank());
break;
}
return;
diff --git a/tools/mbzoltan/MBZoltan.hpp b/tools/mbzoltan/MBZoltan.hpp
index 7fae688..e4ed24c 100644
--- a/tools/mbzoltan/MBZoltan.hpp
+++ b/tools/mbzoltan/MBZoltan.hpp
@@ -57,6 +57,7 @@ extern "C"
#include <vector>
#include "MBInterface.hpp"
+#include "MBParallelComm.hpp"
class MBZoltan
{
@@ -66,7 +67,9 @@ extern "C"
int argc = 0, char **argv = NULL)
: mbImpl(impl), myZZ(NULL), newMoab(false), useCoords(use_coords),
argcArg(argc), argvArg(argv)
- {}
+ {
+ mbpc = MBParallelComm::get_pcomm(mbImpl, 0);
+ }
~MBZoltan();
@@ -111,6 +114,8 @@ extern "C"
MBInterface *mbImpl;
+ MBParallelComm *mbpc;
+
Zoltan *myZZ;
bool newMoab;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <https://lists.mcs.anl.gov/mailman/private/moab-dev/attachments/20080929/2ce900d0/attachment.pgp>
More information about the moab-dev
mailing list