Skip to content

Commit b848783

Browse files
committed
Automagical hierarchical partitioning
1 parent 1670a8f commit b848783

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

dccrg.hpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7489,7 +7489,6 @@ template <
74897489
unsigned int neighborhood_length = 1;
74907490

74917491
std::string load_balancing_method{"RCB"};
7492-
int hierarchical_level_zero {16};
74937492

74947493
// maximum value an MPI tag can have
74957494
unsigned int max_tag;
@@ -7648,6 +7647,7 @@ template <
76487647
Zoltan_Struct* zoltan;
76497648
// number of processes per part in a hierarchy level (numbering starts from 0)
76507649
std::vector<unsigned int> processes_per_part;
7650+
std::vector<unsigned int> partition_number;
76517651
// options for each level of hierarchial load balancing (numbering start from 0)
76527652
std::vector<std::unordered_map<std::string, std::string>> partitioning_options;
76537653
// record whether Zoltan_LB_Partition is expected to fail
@@ -7964,10 +7964,39 @@ template <
79647964

79657965
// Hardcoded for now
79667966
if (this->load_balancing_method == "HIER") {
7967-
add_partitioning_level(this->hierarchical_level_zero); // Level 0 - Nodes
7967+
// Automagical hierarchical partition
7968+
std::hash<std::string> hasher;
7969+
7970+
//get name of this node
7971+
char nodename[MPI_MAX_PROCESSOR_NAME];
7972+
int namelength, nodehash;
7973+
MPI_Get_processor_name(nodename,&namelength);
7974+
nodehash = static_cast<int>(hasher(std::string(nodename, namelength)) % std::numeric_limits<int>::max());
7975+
7976+
//intra-node communicator
7977+
int rank;
7978+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
7979+
MPI_Comm nodeComm;
7980+
MPI_Comm_split(MPI_COMM_WORLD, nodehash, rank, &nodeComm);
7981+
7982+
//inter-node communicator
7983+
int nodeRank;
7984+
MPI_Comm_rank(nodeComm,&nodeRank);
7985+
MPI_Comm interComm;
7986+
MPI_Comm_split(MPI_COMM_WORLD, nodeRank, rank, &interComm);
7987+
int interRank;
7988+
MPI_Comm_rank(interComm, &interRank);
7989+
7990+
// Make sure everyone in node agrees on the number of the node
7991+
int nodeNumber {interRank};
7992+
MPI_Bcast(&nodeNumber, 1, MPI_INT, 0, nodeComm);
7993+
7994+
add_partitioning_level(1); // Level 0 - Nodes
7995+
partition_number.push_back(nodeNumber);
79687996
add_partitioning_option(0, "LB_METHOD", "HYPERGRAPH");
79697997

79707998
add_partitioning_level(1); // Level 1 - Processes
7999+
partition_number.push_back(nodeRank);
79718000
add_partitioning_option(1, "LB_METHOD", "RIB");
79728001
//add_partitioning_option(1, "LB_METHOD", "RCB");
79738002
}
@@ -8500,24 +8529,6 @@ template <
85008529
return this->load_balancing_method;
85018530
}
85028531

8503-
/*!
8504-
Sets amount of tasks for node-level of HIER partition for Zoltan
8505-
8506-
Must be called before initialize().
8507-
8508-
\see balance_load()
8509-
*/
8510-
Dccrg<
8511-
Cell_Data,
8512-
Geometry,
8513-
std::tuple<Additional_Cell_Items...>,
8514-
std::tuple<Additional_Neighbor_Items...>
8515-
>& set_load_balancing_hier_level_zero(const int n) {
8516-
this->hierarchical_level_zero = n;
8517-
return *this;
8518-
}
8519-
8520-
85218532
private:
85228533
/*!
85238534
Initializes local cells' neighbor lists and related data structures.
@@ -11787,15 +11798,17 @@ template <
1178711798
*error = ZOLTAN_OK;
1178811799
}
1178911800

11790-
int process = int(dccrg_instance->rank);
11791-
int part;
11801+
return dccrg_instance->partition_number[level];
1179211802

11793-
for (int i = 0; i <= level; i++) {
11794-
part = process / dccrg_instance->processes_per_part[i];
11795-
process %= dccrg_instance->processes_per_part[i];
11796-
}
11803+
// int process = int(dccrg_instance->rank);
11804+
// int part;
11805+
11806+
// for (int i = 0; i <= level; i++) {
11807+
// part = process / dccrg_instance->processes_per_part[i];
11808+
// process %= dccrg_instance->processes_per_part[i];
11809+
// }
1179711810

11798-
return part;
11811+
// return part;
1179911812
}
1180011813

1180111814

0 commit comments

Comments
 (0)