From 5bf395f4d73df7b9614c66dfd179e3c052c5099a Mon Sep 17 00:00:00 2001 From: sjplimp Date: Tue, 31 May 2011 22:36:53 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@6263 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/atom.cpp | 2 +- src/force.cpp | 2 +- src/input.cpp | 73 ++++++++++++++++++++++++++++---------------- src/input.h | 5 +-- src/lammps.cpp | 83 ++++++++++++++++++++++++++++---------------------- src/lammps.h | 4 +-- src/modify.cpp | 4 +-- src/output.cpp | 6 ++-- src/update.cpp | 4 +-- 9 files changed, 107 insertions(+), 76 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 2293878c18..e1b459750b 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -287,7 +287,7 @@ void Atom::create_avec(const char *style, int narg, char **arg, char *suffix) AtomVec *Atom::new_avec(const char *style, int narg, char **arg, char *suffix, int &sflag) { - if (suffix && lmp->accelerator) { + if (suffix && lmp->suffix_enable) { sflag = 1; char estyle[256]; sprintf(estyle,"%s/%s",style,suffix); diff --git a/src/force.cpp b/src/force.cpp index eec52f22d4..b7891a37e5 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -144,7 +144,7 @@ void Force::create_pair(const char *style, char *suffix) Pair *Force::new_pair(const char *style, char *suffix, int &sflag) { - if (suffix && lmp->accelerator) { + if (suffix && lmp->suffix_enable) { sflag = 1; char estyle[256]; sprintf(estyle,"%s/%s",style,suffix); diff --git a/src/input.cpp b/src/input.cpp index ca440d2e28..004cb22237 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -418,7 +418,6 @@ int Input::execute_command() else if (!strcmp(command,"shell")) shell(); else if (!strcmp(command,"variable")) variable_command(); - else if (!strcmp(command,"accelerator")) accelerator(); else if (!strcmp(command,"angle_coeff")) angle_coeff(); else if (!strcmp(command,"angle_style")) angle_style(); else if (!strcmp(command,"atom_modify")) atom_modify(); @@ -449,6 +448,7 @@ int Input::execute_command() else if (!strcmp(command,"neigh_modify")) neigh_modify(); else if (!strcmp(command,"neighbor")) neighbor_command(); else if (!strcmp(command,"newton")) newton(); + else if (!strcmp(command,"package")) package(); else if (!strcmp(command,"pair_coeff")) pair_coeff(); else if (!strcmp(command,"pair_modify")) pair_modify(); else if (!strcmp(command,"pair_style")) pair_style(); @@ -459,6 +459,7 @@ int Input::execute_command() else if (!strcmp(command,"restart")) restart(); else if (!strcmp(command,"run_style")) run_style(); else if (!strcmp(command,"special_bonds")) special_bonds(); + else if (!strcmp(command,"suffix")) suffix(); else if (!strcmp(command,"thermo")) thermo(); else if (!strcmp(command,"thermo_modify")) thermo_modify(); else if (!strcmp(command,"thermo_style")) thermo_style(); @@ -803,27 +804,6 @@ void Input::variable_command() one function for each LAMMPS-specific input script command ------------------------------------------------------------------------- */ -void Input::accelerator() -{ - if (domain->box_exist) - error->all("Accelerator command after simulation box is defined"); - if (narg < 1) error->all("Illegal accelerator command"); - - if (strcmp(arg[0],"off") == 0) { - if (narg != 1) error->all("Illegal accelerator command"); - lmp->accelerator = 0; - return; - } else if (strcmp(arg[0],"on") == 0) { - if (narg != 1) error->all("Illegal accelerator command"); - lmp->accelerator = 1; - return; - } else if (strcmp(arg[0],"cuda") == 0) { - if (!lmp->cuda) error->all("Accelerator cuda command without " - "USER-CUDA package installed"); - lmp->cuda->accelerator(narg-1,&arg[1]); - } else error->all("Illegal accelerator command"); -} - /* ---------------------------------------------------------------------- */ void Input::angle_coeff() @@ -862,7 +842,7 @@ void Input::atom_style() if (narg < 1) error->all("Illegal atom_style command"); if (domain->box_exist) error->all("Atom_style command after simulation box is defined"); - atom->create_avec(arg[0],narg-1,&arg[1],lmp->asuffix); + atom->create_avec(arg[0],narg-1,&arg[1],lmp->suffix); } /* ---------------------------------------------------------------------- */ @@ -909,7 +889,7 @@ void Input::communicate() void Input::compute() { - modify->add_compute(narg,arg,lmp->asuffix); + modify->add_compute(narg,arg,lmp->suffix); } /* ---------------------------------------------------------------------- */ @@ -987,7 +967,7 @@ void Input::dump_modify() void Input::fix() { - modify->add_fix(narg,arg,lmp->asuffix); + modify->add_fix(narg,arg,lmp->suffix); } /* ---------------------------------------------------------------------- */ @@ -1127,6 +1107,21 @@ void Input::newton() /* ---------------------------------------------------------------------- */ +void Input::package() +{ + if (domain->box_exist) + error->all("Package command after simulation box is defined"); + if (narg < 1) error->all("Illegal package command"); + + if (strcmp(arg[0],"cuda") == 0) { + if (!lmp->cuda) + error->all("Package cuda command without USER-CUDA installed"); + lmp->cuda->accelerator(narg-1,&arg[1]); + } else error->all("Illegal package command"); +} + +/* ---------------------------------------------------------------------- */ + void Input::pair_coeff() { if (domain->box_exist == 0) @@ -1157,7 +1152,7 @@ void Input::pair_style() force->pair->settings(narg-1,&arg[1]); return; } - force->create_pair(arg[0],lmp->asuffix); + force->create_pair(arg[0],lmp->suffix); if (force->pair) force->pair->settings(narg-1,&arg[1]); } @@ -1216,7 +1211,7 @@ void Input::run_style() { if (domain->box_exist == 0) error->all("Run_style command before simulation box is defined"); - update->create_integrate(narg,arg,lmp->asuffix); + update->create_integrate(narg,arg,lmp->suffix); } /* ---------------------------------------------------------------------- */ @@ -1252,6 +1247,30 @@ void Input::special_bonds() /* ---------------------------------------------------------------------- */ +void Input::suffix() +{ + if (narg != 1) error->all("Illegal package command"); + + if (strcmp(arg[0],"off") == 0) lmp->suffix_enable = 0; + else if (strcmp(arg[0],"on") == 0) lmp->suffix_enable = 1; + else if (strcmp(arg[0],"opt") == 0 || strcmp(arg[0],"gpu") == 0 || + strcmp(arg[0],"cuda") == 0) { + delete [] lmp->suffix; + int n = strlen(arg[0]) + 1; + lmp->suffix = new char[n]; + strcpy(lmp->suffix,arg[0]); + lmp->suffix_enable = 1; + + if (!lmp->cuda && strcmp(lmp->suffix,"cuda") == 0) + error->all("Cannot use suffix cuda without USER-CUDA installed"); + if (lmp->cuda && strcmp(lmp->suffix,"cuda") != 0 && me == 0) + error->warning("Non-cuda suffix used with USER-CUDA mode enabled"); + + } else error->all("Illegal suffix command"); +} + +/* ---------------------------------------------------------------------- */ + void Input::thermo() { if (narg != 1) error->all("Illegal thermo command"); diff --git a/src/input.h b/src/input.h index 2aac7e9646..2e3259b9fe 100644 --- a/src/input.h +++ b/src/input.h @@ -61,8 +61,7 @@ class Input : protected Pointers { void shell(); void variable_command(); - void accelerator(); // LAMMPS commands - void angle_coeff(); + void angle_coeff(); // LAMMPS commands void angle_style(); void atom_modify(); void atom_style(); @@ -92,6 +91,7 @@ class Input : protected Pointers { void neigh_modify(); void neighbor_command(); void newton(); + void package(); void pair_coeff(); void pair_modify(); void pair_style(); @@ -102,6 +102,7 @@ class Input : protected Pointers { void restart(); void run_style(); void special_bonds(); + void suffix(); void thermo(); void thermo_modify(); void thermo_style(); diff --git a/src/lammps.cpp b/src/lammps.cpp index bc3134d5d0..6c3364fe88 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -50,32 +50,16 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) screen = NULL; logfile = NULL; - // create CUDA class if USER-CUDA installed, else dummy - - cuda = new Cuda(this); - if (!cuda->cuda_exists) { - delete cuda; - cuda = NULL; - } - // parse input switches int inflag = 0; int screenflag = 0; int logflag = 0; - - if (cuda) { - int n = strlen("cuda") + 1; - asuffix = new char[n]; - strcpy(asuffix,"cuda"); - accelerator = 1; - } else { - asuffix = NULL; - accelerator = 0; - } + int cudaflag = -1; + suffix = NULL; + suffix_enable = 0; int iarg = 1; - while (iarg < narg) { if (strcmp(arg[iarg],"-partition") == 0 || strcmp(arg[iarg],"-p") == 0) { @@ -92,7 +76,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) inflag = iarg + 1; iarg += 2; } else if (strcmp(arg[iarg],"-screen") == 0 || - strcmp(arg[iarg],"-s") == 0) { + strcmp(arg[iarg],"-sc") == 0) { if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); screenflag = iarg + 1; iarg += 2; @@ -110,23 +94,25 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) strcmp(arg[iarg],"-e") == 0) { if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); iarg += 2; - } else if (strcmp(arg[iarg],"-accel") == 0 || - strcmp(arg[iarg],"-a") == 0) { + } else if (strcmp(arg[iarg],"-cuda") == 0 || + strcmp(arg[iarg],"-c") == 0) { if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); - if (strcmp(arg[iarg+1],"none") == 0) { - delete [] asuffix; - asuffix = NULL; - accelerator = 0; - } else if (strcmp(arg[iarg+1],"opt") == 0 || - strcmp(arg[iarg+1],"gpu") == 0 || - strcmp(arg[iarg+1],"cuda") == 0) { + if (strcmp(arg[iarg+1],"on") == 0) cudaflag = 1; + else if (strcmp(arg[iarg+1],"off") == 0) cudaflag = 0; + else error->universe_all("Invalid command-line argument"); + iarg += 2; + } else if (strcmp(arg[iarg],"-suffix") == 0 || + strcmp(arg[iarg],"-sf") == 0) { + if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); + if (strcmp(arg[iarg+1],"opt") == 0 || + strcmp(arg[iarg+1],"gpu") == 0 || + strcmp(arg[iarg+1],"cuda") == 0) { + delete [] suffix; int n = strlen(arg[iarg+1]) + 1; - asuffix = new char[n]; - strcpy(asuffix,arg[iarg+1]); - accelerator = 1; + suffix = new char[n]; + strcpy(suffix,arg[iarg+1]); + suffix_enable = 1; } - if (strcmp(asuffix,"cuda") == 0 && !cuda) - error->all("Cannot use -a cuda without USER-CUDA package installed"); iarg += 2; } else error->universe_all("Invalid command-line argument"); } @@ -297,6 +283,31 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) if (mpisize != sizeof(bigint)) error->all("MPI_LMP_BIGINT and bigint in lmptype.h are not compatible"); + // create CUDA class if USER-CUDA installed, unless explicitly switched off + // instantiation creates dummy CUDA class if USER-CUDA is not installed + + if (cudaflag == 0) { + cuda = NULL; + if (suffix && strcmp(suffix,"cuda") == 0) + error->all("Cannot use -suffix cuda without USER-CUDA installed"); + } else if (cudaflag == 1) { + cuda = new Cuda(this); + if (!cuda->cuda_exists) + error->all("Cannot use -cuda on without USER-CUDA installed"); + } else { + cuda = new Cuda(this); + if (!cuda->cuda_exists) { + delete cuda; + cuda = NULL; + } + } + + int me; + MPI_Comm_rank(world,&me); + if (cuda && me == 0) error->message("USER-CUDA mode is enabled"); + if (cuda && suffix && strcmp(suffix,"cuda") != 0 && me == 0) + error->warning("Non-cuda suffix used with USER-CUDA mode enabled"); + // allocate input class now that MPI is fully setup input = new Input(this,narg,arg); @@ -328,8 +339,8 @@ LAMMPS::~LAMMPS() if (world != universe->uworld) MPI_Comm_free(&world); - delete [] asuffix; delete cuda; + delete [] suffix; delete input; delete universe; @@ -340,7 +351,7 @@ LAMMPS::~LAMMPS() /* ---------------------------------------------------------------------- allocate single instance of top-level classes fundamental classes are allocated in constructor - some classes have accelerator variants + some classes have package variants ------------------------------------------------------------------------- */ void LAMMPS::create() diff --git a/src/lammps.h b/src/lammps.h index 930eebbab2..71408cc1ef 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -42,8 +42,8 @@ class LAMMPS { FILE *screen; // screen output FILE *logfile; // logfile - char *asuffix; // accelerator suffix - int accelerator; // 1 if asuffix enabled, 0 if disabled + char *suffix; // suffix to add to input script style names + int suffix_enable; // 1 if suffix enabled, 0 if disabled class Cuda *cuda; // CUDA accelerator class LAMMPS(int, char **, MPI_Comm); diff --git a/src/modify.cpp b/src/modify.cpp index 35a05a742a..89bed8d535 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -640,7 +640,7 @@ void Modify::add_fix(int narg, char **arg, char *suffix) int success = 0; - if (suffix && lmp->accelerator) { + if (suffix && lmp->suffix_enable) { char estyle[256]; sprintf(estyle,"%s/%s",arg[2],suffix); success = 1; @@ -784,7 +784,7 @@ void Modify::add_compute(int narg, char **arg, char *suffix) int success = 0; - if (suffix && lmp->accelerator) { + if (suffix && lmp->suffix_enable) { char estyle[256]; sprintf(estyle,"%s/%s",arg[2],suffix); success = 1; diff --git a/src/output.cpp b/src/output.cpp index b376ff5757..de7ed5baa6 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -53,18 +53,18 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) newarg[0] = (char *) "thermo_temp"; newarg[1] = (char *) "all"; newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg,lmp->asuffix); + modify->add_compute(3,newarg,lmp->suffix); newarg[0] = (char *) "thermo_press"; newarg[1] = (char *) "all"; newarg[2] = (char *) "pressure"; newarg[3] = (char *) "thermo_temp"; - modify->add_compute(4,newarg,lmp->asuffix); + modify->add_compute(4,newarg,lmp->suffix); newarg[0] = (char *) "thermo_pe"; newarg[1] = (char *) "all"; newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg,lmp->asuffix); + modify->add_compute(3,newarg,lmp->suffix); delete [] newarg; diff --git a/src/update.cpp b/src/update.cpp index 628a22bf11..d6f8758a47 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -59,7 +59,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) minimize = NULL; str = (char *) "verlet"; - create_integrate(1,&str,lmp->asuffix); + create_integrate(1,&str,lmp->suffix); str = (char *) "cg"; create_minimize(1,&str); @@ -222,7 +222,7 @@ void Update::new_integrate(char *style, int narg, char **arg, { int success = 0; - if (suffix && lmp->accelerator) { + if (suffix && lmp->suffix_enable) { sflag = 1; char estyle[256]; sprintf(estyle,"%s/%s",style,suffix);