Skip to content

Commit

Permalink
Fix segfault and add MPI Off as build test
Browse files Browse the repository at this point in the history
  • Loading branch information
koparasy committed Jun 6, 2024
1 parent aca4b75 commit f3cc10f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 39 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,43 @@ jobs:
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
env CTEST_OUTPUT_ON_FAILURE=1 make test
- name: Build Torch=On FAISS=On HDF5=On MPI=Off AMS
shell: bash -l {0}
run: |
module load gcc/11.2.1
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
rm -rf build/
mkdir build
cd build
export AMS_MFEM_PATH=$(spack location -i mfem)
export AMS_TORCH_PATH=$(spack location -i py-torch)/lib/python3.10/site-packages/torch/share/cmake/Torch
export AMS_FAISS_PATH=$(spack location -i faiss)
export AMS_UMPIRE_PATH=$(spack location -i umpire)
export AMS_HDF5_PATH=$(spack location -i hdf5)
cmake \
-DBUILD_SHARED_LIBS=On \
-DCMAKE_PREFIX_PATH=$INSTALL_DIR \
-DWITH_CALIPER=On \
-DWITH_HDF5=On \
-DWITH_EXAMPLES=On \
-DAMS_HDF5_DIR=$AMS_HDF5_PATH \
-DCMAKE_INSTALL_PREFIX=./install \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_CUDA=Off \
-DUMPIRE_DIR=$AMS_UMPIRE_PATH \
-DMFEM_DIR=$AMS_MFEM_PATH \
-DWITH_FAISS=On \
-DWITH_MPI=Off \
-DWITH_TORCH=On \
-DWITH_TESTS=On \
-DTorch_DIR=$AMS_TORCH_PATH \
-DFAISS_DIR=$AMS_FAISS_PATH \
-DWITH_AMS_DEBUG=On \
-DWITH_WORKFLOW=On \
-DWITH_ADIAK=On \
$GITHUB_WORKSPACE
make
- name: Build CALIPER=Off Torch=Off FAISS=On HDF5=On AMS
shell: bash -l {0}
run: |
Expand Down
52 changes: 19 additions & 33 deletions src/AMSlib/AMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,25 +344,13 @@ class AMSWrap
}
}

bool path_exists(std::string &path)
{
fs::path Path(path);
std::error_code ec;

if (!fs::exists(Path, ec)) {
FATAL(AMS, "Path %s does not exist", path.c_str());
return false;
}
return true;
}


std::pair<bool, std::string> setup_loggers()
{
char *ams_logger_level = std::getenv("AMS_LOG_LEVEL");
char *ams_logger_dir = std::getenv("AMS_LOG_DIR");
char *ams_log_prefix = std::getenv("AMS_LOG_PREFIX");
std::string log_path("");
const char *ams_logger_level = std::getenv("AMS_LOG_LEVEL");
const char *ams_logger_dir = std::getenv("AMS_LOG_DIR");
const char *ams_logger_prefix = std::getenv("AMS_LOG_PREFIX");
std::string log_fn("");
std::string log_path("./");

auto logger = ams::util::Logger::getActiveLogger();
bool enable_log = false;
Expand All @@ -373,51 +361,49 @@ class AMSWrap
enable_log = true;
}

if (ams_log_prefix) {
// In the case we specify a directory and we do not specify a file
// by default we write to a file.
if (ams_logger_dir && !ams_logger_prefix) {
ams_logger_prefix = "ams";
}

if (ams_logger_prefix) {
// We are going to redirect stdout to some file
// By default we store to the current directory
std::string log_dir("./");
std::string pattern("");
std::string log_prefix(ams_log_prefix);
std::string log_prefix(ams_logger_prefix);

if (ams_logger_dir) {
log_dir = std::string(ams_logger_dir);
log_path = std::string(ams_logger_dir);
}

char hostname[HOST_NAME_MAX];
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
FATAL(AMS, "Get hostname returns error");
}

CFATAL(AMS, !path_exists(log_dir), "Log Directory does not exist");

int id = 0;
if (log_prefix.find("<RID>") != std::string::npos) {
pattern = std::string("<RID>");
id = get_rank_id();
} else if (log_prefix.find("<PID>") != std::string::npos) {
pattern = std::string("<PID>");
id = getpid();
} else {
log_prefix += "<PID>";
pattern = std::string("<PID>");
id = getpid();
}

// Combine hostname and pid
std::ostringstream combined;
combined << "." << hostname << "." << id;

if (!pattern.empty()) {
log_path =
fs::absolute(log_dir).string() +
log_path = fs::absolute(log_path).string();
log_fn =
std::regex_replace(log_prefix, std::regex(pattern), combined.str());
} else {
log_path =
fs::absolute(log_dir).string() + log_prefix + "." + combined.str();
log_path = fs::absolute(log_path).string();
log_fn = log_prefix + combined.str();
}
}
logger->initialize_std_io_err(enable_log, log_path);
logger->initialize_std_io_err(enable_log, log_path, log_fn);

return std::make_pair(enable_log, log_path);
}
Expand Down
30 changes: 25 additions & 5 deletions src/AMSlib/wf/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm> // for std::equal
#include <cctype> // for std::toupper
#include <cstdlib> // for getenv()
#include <experimental/filesystem>
#include <fstream>
#include <iostream>
#include <ostream>
Expand All @@ -25,6 +26,20 @@ namespace ams
namespace util
{

static bool path_exists(std::string& path)
{
namespace fs = std::experimental::filesystem;
fs::path Path(path);
std::error_code ec;

if (!fs::exists(Path, ec)) {
FATAL(AMS, "Path %s does not exist", path.c_str());
return false;
}
return true;
}


// By default AMS prints only errors
static LogVerbosityLevel defaultLevel = LogVerbosityLevel::Error;

Expand Down Expand Up @@ -75,22 +90,27 @@ Logger* Logger::getActiveLogger()
return &logger;
}

static inline std::string concat_file_name(const std::string& prefix,
static inline std::string concat_file_name(const std::string& path,
const std::string& prefix,
const std::string& suffix)
{
return prefix + "." + suffix;
return path + "/" + prefix + "." + suffix;
}

void Logger::initialize_std_io_err(const bool enable_log, std::string& stdio_fn)
void Logger::initialize_std_io_err(const bool enable_log,
std::string& log_path,
std::string log_fn)
{
ams_out = nullptr;
ams_err = stderr;

CFATAL(AMS, !path_exists(log_path), "Log Directory does not exist");

if (enable_log) {
ams_out = stdout;
// The case we want to just redirect to stdout
if (!stdio_fn.empty()) {
const std::string log_filename{concat_file_name(stdio_fn, "log")};
if (!log_fn.empty()) {
const std::string log_filename{concat_file_name(log_path, log_fn, "log")};
ams_out = fopen(log_filename.c_str(), "a");
CFATAL(Logger,
ams_out == nullptr,
Expand Down
5 changes: 4 additions & 1 deletion src/AMSlib/wf/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class Logger


void setLoggingMsgLevel(LogVerbosityLevel level);
void initialize_std_io_err(const bool enable_log, std::string& stdio_fn);
void initialize_std_io_err(const bool enable_log,
std::string& log_path,
std::string log_fn);


FILE* out() const { return ams_out; }
FILE* err() const { return ams_err; }
Expand Down

0 comments on commit f3cc10f

Please sign in to comment.