Commit c5051758 authored by Nitin Malapally's avatar Nitin Malapally
Browse files

Merge branch 'small_changes' into 'master'

Miscellaneous, small changes

See merge request !30
parents 640a124c c4b5a43b
Pipeline #398188824 passed with stages
in 2 minutes and 35 seconds
.DS_Store
CMakeCache.txt
CMakeFiles/
CTestCustom.cmake
CTestTestfile.cmake
DartConfiguration.tcl
Makefile
cmake_install.cmake
include/
lib/
src/.DS_Store
src/CMakeFiles/
src/MCLConfig.h
src/Makefile
src/MiMiCCommLibConfig.cmake
src/MiMiCCommLibConfigVersion.cmake
src/MiMiCCommLibTargets.cmake
src/cmake_install.cmake
tests/CMakeFiles/
tests/CTestTestfile.cmake
tests/Makefile
tests/api
tests/cmake_install.cmake
tests/endpoint
tests/error
tests/mpitransport
tests/mpmdtransport
tests/utils
\ No newline at end of file
......@@ -13,7 +13,7 @@ if(BUILD_FORTRAN_API)
enable_language(Fortran)
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
......
......@@ -7,7 +7,7 @@ Software Requirements
---------------------
- CMake version 3.12+.
- C++ compiler supporting C++14 standard.
- C++ compiler supporting C++17 standard.
- Fortran compiler supporting Fortran 2008 standard (see [Notes for Fortran](README.md#notes-for-fortran)).
- MPI library supporting MPI 2.1 or newer standard.
- GoogleTest to build unit tests.
......
......@@ -61,9 +61,9 @@ int MCL_init(void *param) {
// 1. get the env variable
auto comm_key = MCL_TR_MPMD;
const auto env_var_pair = get_env_var(COMMUNICATION_KEY);
if (env_var_pair.first) {
const auto &env_var = env_var_pair.second;
const auto env_var_opt = get_env_var(COMMUNICATION_KEY);
if (env_var_opt.has_value()) {
const auto& env_var = env_var_opt.value();
if (!represents_integer(env_var)) {
handle_error(ERROR_FATAL, "The environment variable, \"COMMUNICATION_KEY\" is not an integer!", EARGS);
}
......
......@@ -36,10 +36,13 @@
namespace mcl {
std::pair<bool, std::string> get_env_var(const std::string &var_name) {
std::optional<std::string> get_env_var(const std::string &var_name) {
auto env_var = std::getenv(var_name.c_str());
return env_var == nullptr ? std::make_pair(false, std::string{}) : std::make_pair(true, env_var);
if (env_var == nullptr) {
return {};
}
return std::string{env_var};
}
......
......@@ -31,7 +31,7 @@
* \brief A file containing implementation helper functionality (not included in the API)
*/
#include <utility>
#include <optional>
#include <string>
......@@ -40,9 +40,9 @@ namespace mcl {
/**
* \brief A function which returns an environment variable.
* \param [in] var_name The name of the environment variable
* \returns A success/failure flag and the environment variable as a string (as a pair)
* \returns The environment variable as a string (as an optional)
*/
std::pair<bool, std::string> get_env_var(const std::string &var_name);
std::optional<std::string> get_env_var(const std::string &var_name);
/**
* \brief A function which checks if the input string represents an integer.
......
......@@ -50,35 +50,35 @@ void MPITransport::setTimeout() {
// 1. get env variable
this->timeout = TIMEOUT_DEFAULT;
const auto env_var_pair = get_env_var(TIMEOUT_KEY);
if (!env_var_pair.first) {
const auto env_var_opt = get_env_var(TIMEOUT_KEY);
if (!env_var_opt.has_value()) {
return;
}
// 2. convert to integer
const auto &env_var = env_var_pair.second;
const auto& env_var = env_var_opt.value();
if (!represents_integer(env_var)) {
handle_error(ERROR_FATAL, "The requested environment variable, \"TIMEOUT_KEY\" is not"
" of integer type!", EARGS);
" of integer type!", EARGS);
}
const auto timeout = std::stoi(env_var);
// 3. set the converted value (if it's not negative)
if (std::signbit(timeout)) {
handle_error(ERROR_FATAL, "The requested environment variable, \"TIMEOUT_KEY\""
" has a negative value!", EARGS);
" has a negative value!", EARGS);
}
this->timeout = timeout;
}
void MPITransport::initServer(const std::vector<std::string> paths) {
this->setTimeout();
uint client_number = (unsigned int) paths.size();
const auto client_number = paths.size();
ports.reserve(client_number + 1);
intercomm.reserve(client_number + 1);
ports.push_back(Port{});
intercomm.push_back(this->host_comm);
for (uint i = 0; i < client_number; ++i) {
for (auto i = 0; i < client_number; ++i) {
Port port{};
MPI_Open_port(MPI_INFO_NULL, port.name);
ports.push_back(port);
......
......@@ -3,8 +3,9 @@
// Jógvan Magnus Haugaard Olsen,
// Simone Meloni,
// Emiliano Ippoliti,
// Paolo Carloni
// and Ursula Röthlisberger.
// Paolo Carloni,
// Ursula Röthlisberger
// and Nitin Malapally.
//
// This file is part of MCL.
//
......@@ -25,7 +26,7 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#ifndef __linux__
#if defined(_WIN32) || defined(_WIN64)
#define ADD_ENV_VAR(NAME, VALUE) _putenv(NAME "=" VALUE)
#else
#define ADD_ENV_VAR(NAME, VALUE) setenv(NAME, VALUE, 1)
......@@ -38,7 +39,7 @@
TEST(Utils_GetEnvVar, Negative) {
ASSERT_FALSE(mcl::get_env_var("ENV_VAR").first);
ASSERT_FALSE(mcl::get_env_var("ENV_VAR").has_value());
}
......@@ -47,7 +48,7 @@ TEST(Utils_GetEnvVar, Positive) {
if (ADD_ENV_VAR("ENV_VAR", "abcd") != 0) {
throw std::runtime_error("utils_get_env_var_positive_could_not_set_env_var");
}
ASSERT_TRUE(mcl::get_env_var("ENV_VAR").first);
ASSERT_TRUE(mcl::get_env_var("ENV_VAR").has_value());
}
......@@ -57,8 +58,8 @@ TEST(Utils_RepresentsInteger, String) {
throw std::runtime_error("utils_representsinteger_string_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_FALSE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_FALSE(mcl::represents_integer(env_var_opt.value()));
}
......@@ -68,8 +69,8 @@ TEST(Utils_IsEnvvarIntegerType, StringMinus) {
throw std::runtime_error("utils_representsinteger_stringminus_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_FALSE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_FALSE(mcl::represents_integer(env_var_opt.value()));
}
......@@ -79,8 +80,8 @@ TEST(Utils_IsEnvvarIntegerType, StringOnlyMinus) {
throw std::runtime_error("utils_representsinteger_stringonlyminus_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_FALSE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_FALSE(mcl::represents_integer(env_var_opt.value()));
}
......@@ -90,8 +91,8 @@ TEST(Utils_IsEnvvarIntegerType, Float) {
throw std::runtime_error("utils_representsinteger_float_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_FALSE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_FALSE(mcl::represents_integer(env_var_opt.value()));
}
......@@ -101,8 +102,8 @@ TEST(Utils_IsEnvvarIntegerType, Int) {
throw std::runtime_error("utils_representsinteger_int_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_TRUE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_TRUE(mcl::represents_integer(env_var_opt.value()));
}
......@@ -112,8 +113,8 @@ TEST(Utils_IsEnvvarIntegerType, IntMinus) {
throw std::runtime_error("utils_representsinteger_intminus_could_not_set_env_var");
}
const auto env_var_opt = mcl::get_env_var("ENV_VAR");
ASSERT_TRUE(env_var_opt.first);
ASSERT_TRUE(mcl::represents_integer(env_var_opt.second));
ASSERT_TRUE(env_var_opt.has_value());
ASSERT_TRUE(mcl::represents_integer(env_var_opt.value()));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment