From dddf9581bc6442e82a1a9fb626f6c04c9ca7d07a Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 29 Nov 2013 13:51:28 +0100 Subject: [PATCH] Added MPI_DISABLED cmake switch. --- o815/CMakeLists.txt | 15 +++++++++++---- o815/o815.cpp | 18 +++++++++++++++++- o815/obs.cpp | 6 +++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/o815/CMakeLists.txt b/o815/CMakeLists.txt index b50568c..2d7a102 100644 --- a/o815/CMakeLists.txt +++ b/o815/CMakeLists.txt @@ -2,12 +2,19 @@ cmake_minimum_required(VERSION 2.8) project(o815) -find_package(MPI REQUIRED) -set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) -set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}) -include_directories(${MPI_INCLUDE_PATH}) +if(NOT DEFINED ENV{MPI_DISABLED}) + find_package(MPI REQUIRED) + set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) + set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}) + include_directories(${MPI_INCLUDE_PATH}) +else() + message("MPI support is disabled!") +endif() SET(CMAKE_BUILD_TYPE Release) add_library(o815 o815.cpp obs.cpp sim.cpp) target_link_libraries(o815 ${MPI_LIBRARIES} lat_paraq lat_writeout lat_hypercache lat_progress) +if(DEFINED ENV{MPI_DISABLED}) + set_target_properties(o815 PROPERTIES COMPILE_DEFINITIONS "MPI_DISABLED") +endif() diff --git a/o815/o815.cpp b/o815/o815.cpp index cc72a14..b68a38b 100644 --- a/o815/o815.cpp +++ b/o815/o815.cpp @@ -2,8 +2,11 @@ #include #include +#include +#ifndef MPI_DISABLED #include +#endif #include "latlib/progress.h" @@ -25,9 +28,14 @@ o815::o815(int argc, char **argv, const string& _programid, comoption specOps[], comargs.idonly = false; comargs.showjobnum = false; +#ifndef MPI_DISABLED MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); +#else + numprocs = 1; + rank = 0; +#endif addComOption("lsize", required_argument, NULL, 'L', "define lattice size", "xsize:tsize"); addComOption("nmeas", required_argument, NULL, 'N', "set number of measurements", "nmeas"); @@ -112,12 +120,16 @@ void o815::postParaInit() { if(rank==0) { timestamp = time(NULL); +#ifndef MPI_DISABLED for(int idest=1; idest0) MPI_Recv(×tamp, 1, MPI_LONG, 0, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - +#endif + out = new writeout(comargs.outdir, programid+headMaster(), rank, numprocs, timestamp); } @@ -284,13 +296,17 @@ string o815::headMaster() o815::~o815() { if(comargs.outdir=="") { +#ifndef MPI_DISABLED MPI_Barrier(MPI_COMM_WORLD); +#endif if(rank==0) cout << "#end" << endl << flush; } hypercache::finalize(); delete out; +#ifndef MPI_DISABLED MPI_Finalize(); +#endif } int o815::nextParas() diff --git a/o815/obs.cpp b/o815/obs.cpp index d9e2532..37d1d4e 100644 --- a/o815/obs.cpp +++ b/o815/obs.cpp @@ -2,7 +2,9 @@ #include "latlib/hypercache.h" +#ifndef MPI_DISABLED #include +#endif void o815::obs::finish() { _finish(); @@ -14,9 +16,11 @@ void o815::obs::start() { *out << "#" << O815->programid << "-" << obsid << obsidpostfix << O815->headMaster() << "-" << datadesc << endl << flush; } +#ifndef MPI_DISABLED if (O815->comargs.outdir=="") MPI_Barrier(MPI_COMM_WORLD); - +#endif + _start(); } -- 2.39.5