| 2374 | } |
| 2375 | |
| 2376 | void |
| 2377 | FabArrayBase::buildTileArray (const IntVect& tileSize, TileArray& ta) const |
| 2378 | { |
| 2379 | // Note that we store Tiles always as cell-centered boxes, even if the boxarray is nodal. |
| 2380 | const int N = static_cast<int>(indexArray.size()); |
| 2381 | |
| 2382 | if (tileSize == IntVect::TheZeroVector()) |
| 2383 | { |
| 2384 | for (int i = 0; i < N; ++i) |
| 2385 | { |
| 2386 | if (isOwner(i)) |
| 2387 | { |
| 2388 | const int K = indexArray[i]; |
| 2389 | const Box& bx = boxarray.getCellCenteredBox(K); |
| 2390 | ta.indexMap.push_back(K); |
| 2391 | ta.localIndexMap.push_back(i); |
| 2392 | ta.localTileIndexMap.push_back(0); |
| 2393 | ta.numLocalTiles.push_back(1); |
| 2394 | ta.tileArray.push_back(bx); |
| 2395 | } |
| 2396 | } |
| 2397 | } |
| 2398 | else |
| 2399 | { |
| 2400 | std::vector<int> local_idxs(N); |
| 2401 | std::iota(std::begin(local_idxs), std::end(local_idxs), 0); |
| 2402 | |
| 2403 | #if defined(BL_USE_TEAM) |
| 2404 | const int nworkers = ParallelDescriptor::TeamSize(); |
| 2405 | if (nworkers > 1) { |
| 2406 | // reorder it so that each worker will be more likely to work on their own fabs |
| 2407 | std::ranges::stable_sort(local_idxs, [this](int i, int j) |
| 2408 | { return this->distributionMap[this->indexArray[i]] |
| 2409 | < this->distributionMap[this->indexArray[j]]; }); |
| 2410 | } |
| 2411 | #endif |
| 2412 | |
| 2413 | for (int const i : local_idxs) |
| 2414 | { |
| 2415 | const int K = indexArray[i]; // global index |
| 2416 | const Box& bx = boxarray.getCellCenteredBox(K); |
| 2417 | |
| 2418 | // |
| 2419 | // This must be consistent with ParticleContainer::getTileIndex function!!! |
| 2420 | // |
| 2421 | |
| 2422 | IntVect nt_in_fab, tsize, nleft; |
| 2423 | int ntiles = 1; |
| 2424 | for (int d=0; d<AMREX_SPACEDIM; d++) { |
| 2425 | int ncells = bx.length(d); |
| 2426 | nt_in_fab[d] = std::max(ncells/tileSize[d], 1); |
| 2427 | tsize [d] = ncells/nt_in_fab[d]; |
| 2428 | nleft [d] = ncells - nt_in_fab[d]*tsize[d]; |
| 2429 | ntiles *= nt_in_fab[d]; |
| 2430 | } |
| 2431 | |
| 2432 | IntVect sml, big, ijk; // note that the initial values are all zero. |
| 2433 | ijk[0] = -1; |