diff --git a/CMakeLists.txt b/CMakeLists.txt index c5b58b4..ee263a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,8 @@ endif() # Find OpenMP find_package(OpenMP) - +# Boost +find_package(Boost COMPONENTS program_options REQUIRED) # Set CUDA architecture (change according to your GPU) # set(CUDA_ARCH "-arch=sm_75" CACHE STRING "CUDA architecture") set_property(TARGET ${target} PROPERTY CUDA_ARCHITECTURES native) @@ -29,6 +30,10 @@ set_property(TARGET ${target} PROPERTY CUDA_ARCHITECTURES native) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_FLAGS "-lboost_program_options") + + +include_directories(${Boost_INCLUDE_DIRS}) # Add CUDA include directories include_directories(./include) @@ -40,7 +45,7 @@ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH} -Xcompiler=${OpenMP_CXX_F add_executable(spinwalk ./src/spinwalk.cu ./src/kernels.cu) # Link CUDA and OpenMP libraries -target_link_libraries(spinwalk ${CUDA_LIBRARIES} ${OpenMP_CXX_LIBRARIES}) +target_link_libraries(spinwalk ${CUDA_LIBRARIES} ${OpenMP_CXX_LIBRARIES} ${Boost_LIBRARIES}) if (UNIX) install(TARGETS spinwalk DESTINATION bin) diff --git a/src/miscellaneous.h b/src/miscellaneous.h index 03de968..a6f3b77 100644 --- a/src/miscellaneous.h +++ b/src/miscellaneous.h @@ -17,10 +17,14 @@ #include #include + +#define SPINWALK_VERSION_MAJOR 1 +#define SPINWALK_VERSION_MINOR 4 +#define SPINWALK_VERSION_PATCH 5 + #define DEG2RAD 0.0174532925199433 // = M_PI/180 #define RAD2DEG 57.2957795130823 - #define ERR_MSG "\033[1;31mError:\033[0m " #define ROUND(x) ((long)((x)+0.5)) #define MAX_RF 256 // maximum number of RF @@ -123,6 +127,8 @@ inline void print_logo() " ___) | | |_) | | | | | | | \\ V V / | (_| | | | | < \n" "|____/ | .__/ |_| |_| |_| \\_/\\_/ \\__,_| |_| |_|\\_\\ \n" " |_| \n\n"; + +std::cout << "SpinWalk ver. " << SPINWALK_VERSION_MAJOR << "." << SPINWALK_VERSION_MINOR << "." << SPINWALK_VERSION_PATCH << std::endl; } #endif // __MISCELLANEOUS_H__ \ No newline at end of file diff --git a/src/spinwalk.cu b/src/spinwalk.cu index 6c9c2ab..2164d8e 100644 --- a/src/spinwalk.cu +++ b/src/spinwalk.cu @@ -13,6 +13,7 @@ #include #include #include +#include #include "helper_cuda.h" #include "kernels.cuh" #include "file_utils.h" @@ -20,10 +21,6 @@ #define THREADS_PER_BLOCK 64 -#define SPINWALK_VERSION_MAJOR 1 -#define SPINWALK_VERSION_MINOR 4 -#define SPINWALK_VERSION_PATCH 4 - using namespace std; bool simulate(simulation_parameters param, std::map > filenames, std::vector sample_length_scales) @@ -219,36 +216,31 @@ bool simulate(simulation_parameters param, std::map config_files; - bool bVerbose = false, bHelp = false, bNoSim = false; - for(uint8_t i=1; i>()->multitoken(), "config. files as many as you want. e.g. -c config1.ini config2.ini ... configN.ini"); + + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).allow_unregistered().run(), vm); + boost::program_options::notify(vm); // ========== print help ========== - if(argc < 2 || bHelp || config_files.size() == 0) + if (vm.count("help") || vm.count("configs") == 0 || argc == 1) { - std::cout << "Usage: " << argv[0] << " -options ... " << std::endl; - std::cout << "Options:" << std::endl; - std::cout << " -v: verbose" << std::endl; - std::cout << " -n: only read config" << std::endl; - std::cout << " -h: help (this menu)" << std::endl; + std::cout << desc; print_device_info(); - return 1; + return 1; } + std::vector config_files = vm["configs"].as>(); + bool bVerbose = vm.count("verbose") > 0; + bool bNoSim = vm.count("sim_off") > 0; + std::cout << "Running simulation for " << config_files.size() << " config(s)..." << std::endl; - for(uint8_t cnf=0; cnf > filenames = {{"fieldmap", vector()}, // input: map of off-resonance in Tesla {"xyz0", vector()}, // input: spins starting spatial positions in meters @@ -262,7 +254,7 @@ int main(int argc, char * argv[]) // ========== read config file ========== param.fieldmap_size[0] = param.fieldmap_size[1] = param.fieldmap_size[2] = 0; param.sample_length[0] = param.sample_length[1] = param.sample_length[2] = 0.f; - if(file_utils::read_config(config_files[cnf], param, sample_length_scales, filenames) == false) + if(file_utils::read_config(cfile, param, sample_length_scales, filenames) == false) { std::cout << ERR_MSG << "reading config file failed. Aborting...!" << std::endl; return 1;