git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@6263 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2011-05-31 22:36:53 +00:00
parent 7af10d8e0f
commit 5bf395f4d7
9 changed files with 107 additions and 76 deletions

View File

@ -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, AtomVec *Atom::new_avec(const char *style, int narg, char **arg,
char *suffix, int &sflag) char *suffix, int &sflag)
{ {
if (suffix && lmp->accelerator) { if (suffix && lmp->suffix_enable) {
sflag = 1; sflag = 1;
char estyle[256]; char estyle[256];
sprintf(estyle,"%s/%s",style,suffix); sprintf(estyle,"%s/%s",style,suffix);

View File

@ -144,7 +144,7 @@ void Force::create_pair(const char *style, char *suffix)
Pair *Force::new_pair(const char *style, char *suffix, int &sflag) Pair *Force::new_pair(const char *style, char *suffix, int &sflag)
{ {
if (suffix && lmp->accelerator) { if (suffix && lmp->suffix_enable) {
sflag = 1; sflag = 1;
char estyle[256]; char estyle[256];
sprintf(estyle,"%s/%s",style,suffix); sprintf(estyle,"%s/%s",style,suffix);

View File

@ -418,7 +418,6 @@ int Input::execute_command()
else if (!strcmp(command,"shell")) shell(); else if (!strcmp(command,"shell")) shell();
else if (!strcmp(command,"variable")) variable_command(); 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_coeff")) angle_coeff();
else if (!strcmp(command,"angle_style")) angle_style(); else if (!strcmp(command,"angle_style")) angle_style();
else if (!strcmp(command,"atom_modify")) atom_modify(); 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,"neigh_modify")) neigh_modify();
else if (!strcmp(command,"neighbor")) neighbor_command(); else if (!strcmp(command,"neighbor")) neighbor_command();
else if (!strcmp(command,"newton")) newton(); 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_coeff")) pair_coeff();
else if (!strcmp(command,"pair_modify")) pair_modify(); else if (!strcmp(command,"pair_modify")) pair_modify();
else if (!strcmp(command,"pair_style")) pair_style(); 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,"restart")) restart();
else if (!strcmp(command,"run_style")) run_style(); else if (!strcmp(command,"run_style")) run_style();
else if (!strcmp(command,"special_bonds")) special_bonds(); 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")) thermo();
else if (!strcmp(command,"thermo_modify")) thermo_modify(); else if (!strcmp(command,"thermo_modify")) thermo_modify();
else if (!strcmp(command,"thermo_style")) thermo_style(); 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 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() void Input::angle_coeff()
@ -862,7 +842,7 @@ void Input::atom_style()
if (narg < 1) error->all("Illegal atom_style command"); if (narg < 1) error->all("Illegal atom_style command");
if (domain->box_exist) if (domain->box_exist)
error->all("Atom_style command after simulation box is defined"); 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() 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() 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() void Input::pair_coeff()
{ {
if (domain->box_exist == 0) if (domain->box_exist == 0)
@ -1157,7 +1152,7 @@ void Input::pair_style()
force->pair->settings(narg-1,&arg[1]); force->pair->settings(narg-1,&arg[1]);
return; 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]); if (force->pair) force->pair->settings(narg-1,&arg[1]);
} }
@ -1216,7 +1211,7 @@ void Input::run_style()
{ {
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all("Run_style command before simulation box is defined"); 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() void Input::thermo()
{ {
if (narg != 1) error->all("Illegal thermo command"); if (narg != 1) error->all("Illegal thermo command");

View File

@ -61,8 +61,7 @@ class Input : protected Pointers {
void shell(); void shell();
void variable_command(); void variable_command();
void accelerator(); // LAMMPS commands void angle_coeff(); // LAMMPS commands
void angle_coeff();
void angle_style(); void angle_style();
void atom_modify(); void atom_modify();
void atom_style(); void atom_style();
@ -92,6 +91,7 @@ class Input : protected Pointers {
void neigh_modify(); void neigh_modify();
void neighbor_command(); void neighbor_command();
void newton(); void newton();
void package();
void pair_coeff(); void pair_coeff();
void pair_modify(); void pair_modify();
void pair_style(); void pair_style();
@ -102,6 +102,7 @@ class Input : protected Pointers {
void restart(); void restart();
void run_style(); void run_style();
void special_bonds(); void special_bonds();
void suffix();
void thermo(); void thermo();
void thermo_modify(); void thermo_modify();
void thermo_style(); void thermo_style();

View File

@ -50,32 +50,16 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
screen = NULL; screen = NULL;
logfile = 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 // parse input switches
int inflag = 0; int inflag = 0;
int screenflag = 0; int screenflag = 0;
int logflag = 0; int logflag = 0;
int cudaflag = -1;
if (cuda) { suffix = NULL;
int n = strlen("cuda") + 1; suffix_enable = 0;
asuffix = new char[n];
strcpy(asuffix,"cuda");
accelerator = 1;
} else {
asuffix = NULL;
accelerator = 0;
}
int iarg = 1; int iarg = 1;
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg],"-partition") == 0 || if (strcmp(arg[iarg],"-partition") == 0 ||
strcmp(arg[iarg],"-p") == 0) { strcmp(arg[iarg],"-p") == 0) {
@ -92,7 +76,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
inflag = iarg + 1; inflag = iarg + 1;
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"-screen") == 0 || } 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"); if (iarg+2 > narg) error->universe_all("Invalid command-line argument");
screenflag = iarg + 1; screenflag = iarg + 1;
iarg += 2; iarg += 2;
@ -110,23 +94,25 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
strcmp(arg[iarg],"-e") == 0) { strcmp(arg[iarg],"-e") == 0) {
if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); if (iarg+2 > narg) error->universe_all("Invalid command-line argument");
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"-accel") == 0 || } else if (strcmp(arg[iarg],"-cuda") == 0 ||
strcmp(arg[iarg],"-a") == 0) { strcmp(arg[iarg],"-c") == 0) {
if (iarg+2 > narg) error->universe_all("Invalid command-line argument"); if (iarg+2 > narg) error->universe_all("Invalid command-line argument");
if (strcmp(arg[iarg+1],"none") == 0) { if (strcmp(arg[iarg+1],"on") == 0) cudaflag = 1;
delete [] asuffix; else if (strcmp(arg[iarg+1],"off") == 0) cudaflag = 0;
asuffix = NULL; else error->universe_all("Invalid command-line argument");
accelerator = 0; iarg += 2;
} else if (strcmp(arg[iarg+1],"opt") == 0 || } else if (strcmp(arg[iarg],"-suffix") == 0 ||
strcmp(arg[iarg+1],"gpu") == 0 || strcmp(arg[iarg],"-sf") == 0) {
strcmp(arg[iarg+1],"cuda") == 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; int n = strlen(arg[iarg+1]) + 1;
asuffix = new char[n]; suffix = new char[n];
strcpy(asuffix,arg[iarg+1]); strcpy(suffix,arg[iarg+1]);
accelerator = 1; suffix_enable = 1;
} }
if (strcmp(asuffix,"cuda") == 0 && !cuda)
error->all("Cannot use -a cuda without USER-CUDA package installed");
iarg += 2; iarg += 2;
} else error->universe_all("Invalid command-line argument"); } 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)) if (mpisize != sizeof(bigint))
error->all("MPI_LMP_BIGINT and bigint in lmptype.h are not compatible"); 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 // allocate input class now that MPI is fully setup
input = new Input(this,narg,arg); input = new Input(this,narg,arg);
@ -328,8 +339,8 @@ LAMMPS::~LAMMPS()
if (world != universe->uworld) MPI_Comm_free(&world); if (world != universe->uworld) MPI_Comm_free(&world);
delete [] asuffix;
delete cuda; delete cuda;
delete [] suffix;
delete input; delete input;
delete universe; delete universe;
@ -340,7 +351,7 @@ LAMMPS::~LAMMPS()
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
allocate single instance of top-level classes allocate single instance of top-level classes
fundamental classes are allocated in constructor fundamental classes are allocated in constructor
some classes have accelerator variants some classes have package variants
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void LAMMPS::create() void LAMMPS::create()

View File

@ -42,8 +42,8 @@ class LAMMPS {
FILE *screen; // screen output FILE *screen; // screen output
FILE *logfile; // logfile FILE *logfile; // logfile
char *asuffix; // accelerator suffix char *suffix; // suffix to add to input script style names
int accelerator; // 1 if asuffix enabled, 0 if disabled int suffix_enable; // 1 if suffix enabled, 0 if disabled
class Cuda *cuda; // CUDA accelerator class class Cuda *cuda; // CUDA accelerator class
LAMMPS(int, char **, MPI_Comm); LAMMPS(int, char **, MPI_Comm);

View File

@ -640,7 +640,7 @@ void Modify::add_fix(int narg, char **arg, char *suffix)
int success = 0; int success = 0;
if (suffix && lmp->accelerator) { if (suffix && lmp->suffix_enable) {
char estyle[256]; char estyle[256];
sprintf(estyle,"%s/%s",arg[2],suffix); sprintf(estyle,"%s/%s",arg[2],suffix);
success = 1; success = 1;
@ -784,7 +784,7 @@ void Modify::add_compute(int narg, char **arg, char *suffix)
int success = 0; int success = 0;
if (suffix && lmp->accelerator) { if (suffix && lmp->suffix_enable) {
char estyle[256]; char estyle[256];
sprintf(estyle,"%s/%s",arg[2],suffix); sprintf(estyle,"%s/%s",arg[2],suffix);
success = 1; success = 1;

View File

@ -53,18 +53,18 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp)
newarg[0] = (char *) "thermo_temp"; newarg[0] = (char *) "thermo_temp";
newarg[1] = (char *) "all"; newarg[1] = (char *) "all";
newarg[2] = (char *) "temp"; newarg[2] = (char *) "temp";
modify->add_compute(3,newarg,lmp->asuffix); modify->add_compute(3,newarg,lmp->suffix);
newarg[0] = (char *) "thermo_press"; newarg[0] = (char *) "thermo_press";
newarg[1] = (char *) "all"; newarg[1] = (char *) "all";
newarg[2] = (char *) "pressure"; newarg[2] = (char *) "pressure";
newarg[3] = (char *) "thermo_temp"; 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[0] = (char *) "thermo_pe";
newarg[1] = (char *) "all"; newarg[1] = (char *) "all";
newarg[2] = (char *) "pe"; newarg[2] = (char *) "pe";
modify->add_compute(3,newarg,lmp->asuffix); modify->add_compute(3,newarg,lmp->suffix);
delete [] newarg; delete [] newarg;

View File

@ -59,7 +59,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp)
minimize = NULL; minimize = NULL;
str = (char *) "verlet"; str = (char *) "verlet";
create_integrate(1,&str,lmp->asuffix); create_integrate(1,&str,lmp->suffix);
str = (char *) "cg"; str = (char *) "cg";
create_minimize(1,&str); create_minimize(1,&str);
@ -222,7 +222,7 @@ void Update::new_integrate(char *style, int narg, char **arg,
{ {
int success = 0; int success = 0;
if (suffix && lmp->accelerator) { if (suffix && lmp->suffix_enable) {
sflag = 1; sflag = 1;
char estyle[256]; char estyle[256];
sprintf(estyle,"%s/%s",style,suffix); sprintf(estyle,"%s/%s",style,suffix);