28 std::string metadata_patch = sched.serialize_patch_metadata().dump(4);
30 using namespace shamrock::patch;
32 std::vector<u64> pids;
33 std::vector<u64> bytecounts;
34 std::vector<sham::DeviceBuffer<u8>> datas;
38 auto ser_sz = pdat.serialize_buf_byte_size();
40 ser.allocate(ser_sz,
true);
41 pdat.serialize_buf(ser);
43 auto tmp = ser.finalize();
47 bytecounts.push_back(bytecount);
48 datas.push_back(std::move(tmp));
51 std::vector<u64> all_pids;
52 std::vector<u64> all_bytecounts;
55 pids, get_mpi_type<u64>(), all_pids, get_mpi_type<u64>(), MPI_COMM_WORLD);
57 bytecounts, get_mpi_type<u64>(), all_bytecounts, get_mpi_type<u64>(), MPI_COMM_WORLD);
59 std::vector<u64> all_offsets = all_bytecounts;
61 std::exclusive_scan(all_offsets.begin(), all_offsets.end(), all_offsets.begin(),
u64{0});
63 using namespace nlohmann;
67 j[
"bytecounts"] = all_bytecounts;
68 j[
"offsets"] = all_offsets;
70 std::string sout = j.dump(4);
83 bool preallocate =
false;
85 MPI_Offset tot_byte = all_offsets.back() + all_bytecounts.back() + metadata_user.size()
86 + metadata_patch.size() + sout.size() +
sizeof(std::size_t) * 3;
87 MPICHECK(MPI_File_preallocate(mfile, tot_byte));
97 "table sizes {} {} {}", metadata_patch.size(), metadata_user.size(), sout.size()));
100 auto check_same_mpi = [](std::string s) {
101 u64 out = shamalgs::collective::allreduce_sum(s.size());
106 "string size mismatch between all processes,\n size : {}\nthe "
111 "size mismatch in shamrock dump header");
115 check_same_mpi(metadata_user);
116 check_same_mpi(metadata_patch);
117 check_same_mpi(sout);
122 MPICHECK(MPI_File_set_view(mfile, 0, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL));
126 std::unordered_map<u64, size_t> map{};
127 for (
u32 i = 0; i < all_pids.size(); i++) {
128 map[all_pids[i]] = i;
131 for (
u32 i = 0; i < datas.size(); i++) {
134 u64 bytecount = bytecounts[i];
136 size_t off = all_offsets[map[pid]];
137 auto &data = datas[i];
146 MPI_File_close(&mfile);
150 size_t plist_len = all_offsets.size();
151 size_t max_head = all_offsets[plist_len - 1] + all_bytecounts[plist_len - 1] + head_ptr;
155 "dump to {}\n - took {}, bandwidth = {}/s",
174 std::string metadata_patch{};
175 std::string patchdata_infos{};
183 MPICHECK(MPI_File_set_view(mfile, 0, MPI_BYTE, MPI_CHAR,
"native", MPI_INFO_NULL));
187 using namespace nlohmann;
189 json jmeta_patch = json::parse(metadata_patch);
190 json jpdat_info = json::parse(patchdata_infos);
192 ctx.pdata_layout_new();
195 jmeta_patch.at(
"crit_patch_split").get<
u64>(),
196 jmeta_patch.at(
"crit_patch_merge").get<
u64>());
202 sched.patch_data.sim_box.from_json(jmeta_patch.at(
"sim_box"));
207 for (
auto &p : sched.patch_list.global) {
212 auto loc_ids = sched.patch_list.build_local();
216 std::vector<u64> all_offsets;
217 std::vector<u64> all_pids;
218 std::vector<u64> all_bytecounts;
220 all_bytecounts = jpdat_info.at(
"bytecounts").get<std::vector<u64>>();
221 all_offsets = jpdat_info.at(
"offsets").get<std::vector<u64>>();
222 all_pids = jpdat_info.at(
"pids").get<std::vector<u64>>();
224 struct PatchFileOffset {
225 u64 offset, bytecount;
228 std::unordered_map<u64, PatchFileOffset> off_table;
230 for (
u32 i = 0; i < all_bytecounts.size(); i++) {
231 off_table[all_pids[i]] = {.offset = all_offsets[i], .bytecount = all_bytecounts[i]};
234 for (
const auto &p : sched.patch_list.local) {
235 u64 pid = p.id_patch;
236 auto loc_file_info = off_table[pid];
239 loc_file_info.bytecount, shamsys::instance::get_compute_scheduler_ptr());
242 mfile, buf.get_ptr(), loc_file_info.bytecount, head_ptr + loc_file_info.offset);
247 shamsys::instance::get_compute_scheduler_ptr(), std::move(out),
true);
251 sched.patch_data.owned_data.add_obj(pid, std::move(pdat));
254 MPI_File_close(&mfile);
258 size_t plist_len = all_offsets.size();
259 size_t max_head = all_offsets[plist_len - 1] + all_bytecounts[plist_len - 1] + head_ptr;
263 "load dump from {}\n - took {}, bandwidth = {}/s",
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
Handle the patch list of the mpi scheduler.
A buffer allocated in USM (Unified Shared Memory).
size_t get_size() const
Gets the number of elements in the buffer.
Class Timer measures the time elapsed since the timer was started.
std::string get_time_str() const
Converts the stored nanosecond time to a string representation.
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
void start()
Starts the timer.
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
Shamrock communication buffers.
static sham::DeviceBuffer< u8 > convert_usm(CommunicationBuffer &&buf)
destroy the buffer and recover the held object
PatchDataLayer container class, the layout is described in patchdata_layout.
Patch Tree : Tree structure organisation for an abstract list of patches Nb : this tree is compatible...
std::vector< int > vector_allgatherv(const std::vector< T > &send_vec, const MPI_Datatype &send_type, std::vector< T > &recv_vec, const MPI_Datatype &recv_type, const MPI_Comm comm)
allgatherv on vector with size query (size querying variant of vector_allgatherv_ks) //TODO add fault...
#define MPICHECK(mpicall)
Shortcut macro to check MPI return codes.
std::string readable_sizeof(double size)
given a sizeof value return a readble string Example : readable_sizeof(1e9) -> "1....
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
std::optional< std::string > getenv_str(const char *env_var)
Get the content of the environment variable if it exist.
void open_reset_file(MPI_File &fh, const std::string &fname)
Open a MPI file and remove its content.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
i32 world_size()
Gives the size of the MPI communicator.
void open_read_only_file(MPI_File &fh, const std::string &fname)
Open a mpi file in read only mode.
namespace for the main framework
void load_shamrock_dump(std::string fname, std::string &metadata_user, ShamrockCtx &ctx)
Load a Shamrock dump file and restore the state of the patches and retreive user metadata.
void write_shamrock_dump(std::string fname, std::string metadata_user, PatchScheduler &sched)
Write a Shamrock dump file containing the current state of the patches and user supplied metadata.
std::string read_header(MPI_File fh, u64 &file_head_ptr)
Reads a string from a file using MPI and updates the file head pointer. The string is preceded by its...
void write_header(MPI_File fh, std::string s, u64 &file_head_ptr)
Writes a string to a file using MPI and updates the file head pointer. The string is preceded by its ...
void write_at_large(MPI_File fh, const u8 *buf, size_t len, u64 file_head_ptr)
Writes a large byte buffer at a given offset in a file using MPI.
void read_at_large(MPI_File fh, u8 *buf, size_t len, u64 file_head_ptr)
Reads a large byte buffer at a given offset in a file using MPI.
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
void err_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.