utils_mpi_io.h Source File

LibRPA: utils_mpi_io.h Source File
LibRPA
utils_mpi_io.h
1 #pragma once
2 
3 #include "envs_io.h"
4 #include "envs_mpi.h"
5 
6 namespace LIBRPA
7 {
8 
9 namespace utils
10 {
11 
13 template <typename... Args>
14 void lib_printf_root(const char* format, Args&&... args)
15 {
16  if (envs::myid_global == 0)
17  {
19  fprintf(envs::pfile_redirect, format, std::forward<Args>(args)...) :
20  printf(format, std::forward<Args>(args)...);
21  }
22 }
23 
25 template <typename... Args>
26 void lib_printf_coll(const char* format, Args&&... args)
27 {
28  for (int i = 0; i < envs::size_global; i++)
29  {
30  if (envs::myid_global == i)
31  {
33  fprintf(envs::pfile_redirect, format, std::forward<Args>(args)...) :
34  printf(format, std::forward<Args>(args)...);
35  }
36  MPI_Barrier(envs::mpi_comm_global);
37  }
38 }
39 
40 } /* end of name space utils */
41 
42 } /* end of name space LIBRPA */
Environment setup regarding MPI.
int myid_global
Rank of process in the global communciator.
Definition: envs_mpi.cpp:11
bool redirect_stdout
Control whether to redirect stdout (cout, fmt print) to file.
Definition: envs_io.cpp:18
MPI_Comm mpi_comm_global
Global communicator.
Definition: envs_mpi.cpp:15
int size_global
Number of processes in the global communciator.
Definition: envs_mpi.cpp:13
FILE * pfile_redirect
File stream used by fprintf when stdout is redirected.
Definition: envs_io.cpp:19
void lib_printf_coll(const char *format, Args &&... args)
simlar to lib_printf, but all processes will print in the order of myid
Definition: utils_mpi_io.h:26
void lib_printf_root(const char *format, Args &&... args)
simlar to lib_printf, but only proc 0 will dump
Definition: utils_mpi_io.h:14
Definition: analycont.cpp:14