48inline std::string string_format(
const std::string &str) {
return str; }
50template <
typename... Args>
51inline std::string string_format(
const std::string &format, Args... args) {
53 snprintf(
nullptr, 0, format.c_str(), args...) + 1;
55 throw std::runtime_error(
"Error during formatting.");
57 std::unique_ptr<char[]> buf(
new char[size]);
58 snprintf(buf.get(), size, format.c_str(), args...);
59 return std::string(buf.get(),
60 buf.get() + size - 1);
63inline std::string format_with_number(
const std::string &filename,
int increment) {
64 if (filename.find(
'%') != std::string::npos) {
65 return utils::string_format(filename, increment);
71template <
typename T>
size_t sizeof_vec(std::vector<T> &V) {
72 return V.size() *
sizeof(T);
79inline int get_comm_rank(MPI_Comm comm) {
81 MPI_Comm_rank(comm, &rank);
85inline int get_comm_size(MPI_Comm comm) {
87 MPI_Comm_size(comm, &size);