YAKL
YAKL_verbose.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 namespace yakl {
6 
8  inline void verbose_inform(std::string prefix, std::string label = "", std::string suffix = "") {
9  #ifdef YAKL_VERBOSE
10  // Form the output
11  std::string output = std::string("*** [YAKL_VERBOSE] ") + prefix;
12  if (label != "") output += std::string(" (label: \"") + label + std::string("\")");
13  if (suffix != "") output += std::string("; ") + suffix;
14 
15  // Get MPI rank
16  int rank = 0;
17  #ifdef HAVE_MPI
18  int is_initialized;
19  MPI_Initialized(&is_initialized);
20  if (is_initialized) { MPI_Comm_rank(MPI_COMM_WORLD, &rank); }
21  #endif
22 
23  // Write to file
24  #ifdef YAKL_VERBOSE_FILE
25  std::ofstream myfile;
26  std::string fname = std::string("yakl_verbose_output_task_") + std::to_string(rank) + std::string(".log");
27  myfile.open(fname , std::ofstream::out | std::ofstream::app);
28  myfile << output << std::endl;
29  myfile.close();
30  #endif
31 
32  // Write to stdout for task 0
33  if (rank == 0) std::cout << output << std::endl;
34  #endif
35  }
36 
37 }
39 
40 
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
yakl