]> git.treefish.org Git - phys/latlib.git/commitdiff
Added MPI_DISABLED cmake switch.
authorAlexander Schmidt <alex@treefish.org>
Fri, 29 Nov 2013 12:51:28 +0000 (13:51 +0100)
committerAlexander Schmidt <alex@treefish.org>
Fri, 29 Nov 2013 12:51:28 +0000 (13:51 +0100)
o815/CMakeLists.txt
o815/o815.cpp
o815/obs.cpp

index b50568c5b74c307d810a4ff88e9aa9e8b8ce352a..2d7a10286de14675985cd5fd7f768bfbb03576ba 100644 (file)
@@ -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()
index cc72a149b5073edeea5a0f8498a73b7d18ab8373..b68a38b061df92d0741b4a3bdb6ab0f3ce1093e1 100644 (file)
@@ -2,8 +2,11 @@
 
 #include <sstream>
 #include <iomanip>
+#include <cstring>
 
+#ifndef MPI_DISABLED
 #include <mpi.h>
+#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; idest<numprocs; idest++)
       MPI_Send(&timestamp, 1, MPI_LONG, idest, 123, MPI_COMM_WORLD);
+#endif
   }
+#ifndef MPI_DISABLED
   else if(rank>0)
     MPI_Recv(&timestamp, 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()
index d9e25321c6e267e393f43366d0b95f4697d2c56e..37d1d4ed7f3740f07a3b33684c0af8c24ddde2b4 100644 (file)
@@ -2,7 +2,9 @@
 
 #include "latlib/hypercache.h"
 
+#ifndef MPI_DISABLED
 #include <mpi.h>
+#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();
 }