Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
io.cpp
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
18#include "shamcomm/io.hpp"
21
22namespace shamcomm {
23
24 void open_reset_file(MPI_File &fh, const std::string &fname) {
25
26 int rc = MPI_File_open(
27 MPI_COMM_WORLD,
28 fname.c_str(),
29 MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_EXCL | MPI_MODE_UNIQUE_OPEN,
30 MPI_INFO_NULL,
31 &fh);
32
33 if (rc != MPI_SUCCESS) {
34
35 if (shamcomm::world_rank() == 0) {
36 MPICHECK(MPI_File_delete(fname.c_str(), MPI_INFO_NULL));
37 }
38
39 int rc = MPI_File_open(
40 MPI_COMM_WORLD,
41 fname.c_str(),
42 MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_EXCL | MPI_MODE_UNIQUE_OPEN,
43 MPI_INFO_NULL,
44 &fh);
45
46 if (rc != MPI_SUCCESS) {
48 }
49 }
50 }
51
52 void open_read_only_file(MPI_File &fh, const std::string &fname) {
53 MPICHECK(MPI_File_open(
54 MPI_COMM_WORLD,
55 fname.c_str(),
56 MPI_MODE_RDONLY | MPI_MODE_UNIQUE_OPEN,
57 MPI_INFO_NULL,
58 &fh));
59 }
60
61} // namespace shamcomm
This header file contains utility functions related to exception handling in the code.
Utility functions for MPI error checking.
#define MPICHECK(mpicall)
Shortcut macro to check MPI return codes.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for communication related stuff
void open_reset_file(MPI_File &fh, const std::string &fname)
Open a MPI file and remove its content.
Definition io.cpp:24
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
void open_read_only_file(MPI_File &fh, const std::string &fname)
Open a mpi file in read only mode.
Definition io.cpp:52
Functions related to the MPI communicator.