Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "wrapper/Plumed.h" 23 : #include <cstring> 24 : 25 : #ifdef __PLUMED_HAS_MPI 26 : #include <mpi.h> 27 : #endif 28 : 29 : /** 30 : This main uses only the interface published in 31 : Plumed.h. The object file generated from this .cpp 32 : is the only part of the plumed library that should 33 : not be linked with external MD codes, so as 34 : to avoid linker error. 35 : */ 36 5364 : int main(int argc,char**argv) { 37 : #ifdef __PLUMED_HAS_MPI 38 : bool nompi=false; 39 11179 : for(unsigned iarg=1; iarg<argc; iarg++) { 40 10367 : if(!std::strcmp(argv[iarg],"--no-mpi")) { 41 : nompi=true; 42 : } 43 10367 : if(!std::strcmp(argv[iarg],"--mpi")) { 44 : nompi=false; 45 : } 46 : // stop at first non-option 47 10367 : if(argv[iarg] && argv[iarg][0]!='-') { 48 : break; 49 : } 50 : } 51 5364 : if(!nompi) { 52 361 : MPI_Init(&argc,&argv); 53 : } 54 : #endif 55 5364 : int ret=0; 56 : 57 : try { 58 : PLMD::Plumed p; 59 5364 : p.cmd("CLTool setArgc",&argc); 60 5364 : p.cmd("CLTool setArgv",argv, {argc}); 61 : #ifdef __PLUMED_HAS_MPI 62 5364 : if(!nompi) { 63 : MPI_Comm comm; 64 361 : MPI_Comm_dup(MPI_COMM_WORLD,&comm); 65 722 : p.cmd("CLTool setMPIComm",&comm); 66 : } 67 : #endif 68 10728 : p.cmd("CLTool run",&ret); 69 : // end block deletes p also in case an exception occurs 70 0 : } catch(...) { 71 : // exception is rethrown and results in a call to terminate 72 0 : throw; 73 0 : } 74 : 75 : #ifdef __PLUMED_HAS_MPI 76 5364 : if(!nompi) { 77 361 : MPI_Finalize(); 78 : } 79 : #endif 80 5364 : return ret; 81 : }