Skip to content

Commit

Permalink
MPI support, one output file per rank (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencopl committed Oct 4, 2022
1 parent 5edf819 commit 338ddb1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ include(cmake/Doxygen.cmake)
enable_doxygen()

# OpenMP required
find_package(OpenMP 2.5 REQUIRED)
find_package(OpenMP 2.5 REQUIRED)

# MPI required
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})

# Defines some standard install directories such as $(prefix)/include.
include(GNUInstallDirs)
Expand Down
3 changes: 2 additions & 1 deletion src/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ add_library(${CMAKE_PROJECT_NAME} SHARED

# Link library to and external libs (also use project warnings and options).
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
OpenMP::OpenMP_CXX)
OpenMP::OpenMP_CXX
MPI::MPI_CXX)

set_project_warnings(${CMAKE_PROJECT_NAME})

Expand Down
20 changes: 14 additions & 6 deletions src/c++/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,25 @@ void Profiler::stop(size_t const hash)

void Profiler::write()
{
// Find current MPI rank
int current_rank;
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm, &current_rank);

// Pickup environment variable filename if it exists, if not use the default
// name of "profiler-output.txt"
const char* filename = getenv("ProfOut");
if (filename != NULL)
// name of "profiler-output.txt". In either case, include the MPI rank in the
// name of the file.
const char* env_variable = std::getenv("PROFILER_OUTFILE");
if (env_variable != NULL)
{
output_stream.open(filename);
const char* user_filename = (env_variable + ("-" + std::to_string(current_rank))).c_str();
output_stream.open(user_filename);
}
else
{
output_stream.open("profiler-output.txt");
delete filename;
delete env_variable;
std::string default_filename = "profiler-output-" + std::to_string(current_rank);
output_stream.open(default_filename);
}

// Write to file
Expand Down
1 change: 1 addition & 0 deletions src/c++/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <vector>

#include "omp.h"
#include "mpi.h"

#include "hashtable.h"

Expand Down

0 comments on commit 338ddb1

Please sign in to comment.