Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-2020 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 : #include <memory> 25 : 26 : #ifdef __PLUMED_HAS_MPI 27 : #include <mpi.h> 28 : #endif 29 : 30 : using namespace std; 31 : 32 : /** 33 : This main uses only the interface published in 34 : Plumed.h. The object file generated from this .cpp 35 : is the only part of the plumed library that should 36 : not be linked with external MD codes, so as 37 : to avoid linker error. 38 : */ 39 1820 : int main(int argc,char**argv) { 40 : #ifdef __PLUMED_HAS_MPI 41 : bool nompi=false; 42 4714 : for(unsigned iarg=1; iarg<argc; iarg++) { 43 3239 : if(!strcmp(argv[iarg],"--no-mpi")) nompi=true; 44 3239 : if(!strcmp(argv[iarg],"--mpi")) nompi=false; 45 : // stop at first non-option 46 3239 : if(argv[iarg] && argv[iarg][0]!='-') break; 47 : } 48 1820 : if(!nompi) MPI_Init(&argc,&argv); 49 : #endif 50 1820 : int ret=0; 51 : 52 1820 : std::unique_ptr<PLMD::Plumed> p(new PLMD::Plumed); 53 1820 : p->cmd("CLTool setArgc",&argc); 54 1820 : p->cmd("CLTool setArgv",argv); 55 : #ifdef __PLUMED_HAS_MPI 56 1820 : if(!nompi) { 57 : MPI_Comm comm; 58 401 : MPI_Comm_dup(MPI_COMM_WORLD,&comm); 59 401 : p->cmd("CLTool setMPIComm",&comm); 60 : } 61 : #endif 62 1820 : p->cmd("CLTool run",&ret); 63 : p.reset(); // this is to delete p here 64 : 65 : #ifdef __PLUMED_HAS_MPI 66 1820 : if(!nompi) MPI_Finalize(); 67 : #endif 68 1820 : return ret; 69 5460 : }