Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
indexing.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
21#include "shamcomm/logs.hpp"
24#include "shamcomm/wrapper.hpp"
25
26namespace shamalgs::collective {
27
28 struct ViewInfo {
29 u64 total_byte_count;
30 u64 head_offset;
31 };
32
33 inline ViewInfo fetch_view(u64 byte_count) {
34
35 u64 scan_val;
36 shamcomm::mpi::Exscan(
37 &byte_count, &scan_val, 1, get_mpi_type<u64>(), MPI_SUM, MPI_COMM_WORLD);
38
39 if (shamcomm::world_rank() == 0) {
40 scan_val = 0;
41 }
42
43 u64 sum_val;
44 shamcomm::mpi::Allreduce(
45 &byte_count, &sum_val, 1, get_mpi_type<u64>(), MPI_SUM, MPI_COMM_WORLD);
46
47 shamlog_debug_mpi_ln("fetch view", byte_count, "->", scan_val, "sum:", sum_val);
48
49 return {sum_val, scan_val};
50 }
51
52 inline ViewInfo fetch_view_known_total(u64 byte_count, u64 total_byte) {
53
54 u64 scan_val;
56 &byte_count, &scan_val, 1, get_mpi_type<u64>(), MPI_SUM, MPI_COMM_WORLD);
57
58 if (shamcomm::world_rank() == 0) {
59 scan_val = 0;
60 }
61
62 shamlog_debug_mpi_ln("fetch view", byte_count, "->", scan_val, "sum:", total_byte);
63
64 return {total_byte, scan_val};
65 }
66
67} // namespace shamalgs::collective
std::uint64_t u64
64 bit unsigned integer
Utility functions for MPI error checking.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
Functions related to the MPI communicator.
void Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
MPI wrapper for MPI_Exscan.
Definition wrapper.cpp:166