55 std::vector<int> rankBuffer(cGeometry.getNc(), 0);
56 std::vector<int> locBuffer(cGeometry.getNc(), 0);
57 std::vector<std::uint8_t> platformBuffer(cGeometry.getNc(),
static_cast<std::uint8_t
>(
Platform::CPU_SISD));
62 auto& cuboids = cGeometry.cuboids();
64 std::sort(cuboids.begin(), cuboids.end(),
65 [&](
const auto& lhs,
const auto& rhs) {
66 return lhs.getLatticeVolume() > rhs.getLatticeVolume();
72 std::size_t totalVolume = std::accumulate(cuboids.begin(), cuboids.end(),
74 [](
const auto& currVolume,
const auto& rhs) -> std::size_t {
75 return currVolume + rhs.getLatticeVolume();
78 std::map<int,int> nLoc;
82 std::size_t globalAssignedVolume = 0;
83 std::vector<std::size_t> localAssignedVolume(nRank, 0);
87 jRank = std::distance(localAssignedVolume.begin(),
88 std::min_element(localAssignedVolume.begin(),
89 localAssignedVolume.end()));
90 rankBuffer[iCuboid] = jRank;
92 locBuffer[iCuboid] = nLoc[jRank]++;
93 localAssignedVolume[jRank] += cuboids[iCuboid].getLatticeVolume();
94 globalAssignedVolume += cuboids[iCuboid].getLatticeVolume();
95 clout << iCuboid <<
", " << jRank <<
", assignedVolumeFraction=" << (1.*globalAssignedVolume) / totalVolume << std::endl;
97 }
while (globalAssignedVolume < largeBlockFraction*totalVolume);
100 std::vector<int> preferredRank(cGeometry.getNc(), -1);
101 for (
int jCuboid=iCuboid; jCuboid < cGeometry.getNc(); ++jCuboid) {
102 std::vector<int> neighbours;
103 cGeometry.getNeighbourhood(jCuboid, neighbours, 1);
104 std::vector<int> neighboursInRank(nRank, 0);
105 int nGpuNeighbors = 0;
106 for (
int neighborC : neighbours) {
108 neighboursInRank[rankBuffer[neighborC]] += 1;
112 if (nGpuNeighbors > 0) {
113 preferredRank[jCuboid] = std::distance(neighboursInRank.begin(), std::max_element(neighboursInRank.begin(),
114 neighboursInRank.end()));
115 clout <<
"Preferred rank of " << jCuboid <<
" is " << preferredRank[jCuboid] << std::endl;
120 for (
int jCuboid=iCuboid; jCuboid < cGeometry.getNc(); ++jCuboid) {
121 if (preferredRank[jCuboid] != -1) {
122 auto iRank = preferredRank[jCuboid];
124 rankBuffer[jCuboid] = iRank;
126 locBuffer[jCuboid] = nLoc[iRank]++;
131 std::vector<int> preferredRankFallback(cGeometry.getNc(), -1);
132 for (
int jCuboid=iCuboid; jCuboid < cGeometry.getNc(); ++jCuboid) {
133 if (preferredRank[jCuboid] == -1) {
134 std::vector<int> neighbours;
135 cGeometry.getNeighbourhood(jCuboid, neighbours, 1);
136 std::vector<int> neighboursInRank(nRank, 0);
137 int nCpuNeighbors = 0;
138 for (
int neighborC : neighbours) {
140 neighboursInRank[rankBuffer[neighborC]] += 1;
144 if (nCpuNeighbors > 0) {
145 preferredRankFallback[jCuboid] = std::distance(neighboursInRank.begin(), std::max_element(neighboursInRank.begin(),
146 neighboursInRank.end()));
147 clout <<
"Preferred rank of " << jCuboid <<
" is " << preferredRankFallback[jCuboid] << std::endl;
153 for (
int jCuboid=iCuboid; jCuboid < cGeometry.getNc(); ++jCuboid) {
154 if (preferredRank[jCuboid] == -1) {
155 auto iRank = preferredRankFallback[jCuboid];
157 rankBuffer[jCuboid] = iRank;
159 locBuffer[jCuboid] = nLoc[iRank]++;
165 #ifdef PARALLEL_MODE_MPI
173 for (
int iCuboid=0; iCuboid < cGeometry.getNc(); ++iCuboid) {
174 this->
_rank[iCuboid] = rankBuffer[iCuboid];
175 this->
_loc[iCuboid] = locBuffer[iCuboid];
177 if (rankBuffer[iCuboid] == iRank) {
178 this->
_glob.resize(std::max(
int(this->
_glob.size()), this->_loc[iCuboid]+1));
179 this->_platform.resize(this->
_glob.size());
181 this->
_glob[this->
_loc[iCuboid]] = iCuboid;
182 this->_platform[this->_loc[iCuboid]] =
static_cast<Platform>(platformBuffer[iCuboid]);