--- branches/mmeineke/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/07/09 18:40:59 10 +++ trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/10/18 20:35:33 147 @@ -9,6 +9,67 @@ TraPPE_ExFF::TraPPE_ExFF(){ #include "SRI.hpp" +#ifdef IS_MPI + +#include "mpiForceField.h" + +int myNode; + +// Declare the structures that will be passed by MPI + +typedef struct{ + char name[15]; + double mass; + double epslon; + double sigma; + double dipole; + int isDipole; + int last; // 0 -> default + // 1 -> tells nodes to stop listening + // -1 -> an error has occured. (handled in mpiForceField) +} atomStruct; +MPI_Datatype mpiAtomStructType; + +typedef struct{ + char nameA[15]; + char nameB[15]; + char type[30]; + double d0; + int last; // 0 -> default + // 1 -> tells nodes to stop listening + // -1 -> an error has occured. (handled in mpiForceField) +} bondStruct; +MPI_Datatype mpiBondStructType; + +typedef struct{ + char nameA[15]; + char nameB[15]; + char nameC[15]; + char type[30]; + double k1, k2, k3, t0; + int last; // 0 -> default + // 1 -> tells nodes to stop listening + // -1 -> an error has occured. (handled in mpiForceField) +} bendStruct; +MPI_Datatype mpiBendStructType; + +typedef struct{ + char nameA[15]; + char nameB[15]; + char nameC[15]; + char nameD[15]; + char type[30]; + double k1, k2, k3, k4; + int last; // 0 -> default + // 1 -> tells nodes to stop listening + // -1 -> an error has occured. (handled in mpiForceField) +} TorsionStruct; +MPI_Datatype mpiTorsionStructType; + +#endif + + + TraPPE_ExFF::TraPPE_ExFF(){ char fileName[200]; @@ -16,38 +77,154 @@ TraPPE_ExFF::TraPPE_ExFF(){ char* ffPath; char temp[200]; - // generate the force file name +#ifdef IS_MPI + int i; + int mpiError; + + mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode); + + // ********************************************************************** + // Init the atomStruct mpi type - strcpy( fileName, "TraPPE_Ex.frc" ); + atomStruct atomProto; // mpiPrototype + int atomBC[3] = {15,4,2}; // block counts + MPI_Aint atomDspls[3]; // displacements + MPI_Datatype atomMbrTypes[3]; // member mpi types - // attempt to open the file in the current directory first. - frcFile = fopen( fileName, "r" ); - if( frcFile == NULL ){ + MPI_Address(&atomProto.name, &atomDspls[0]); + MPI_Address(&atomProto.mass, &atomDspls[1]); + MPI_Address(&atomProto.isDipole, &atomDspls[2]); + + atomMbrTypes[0] = MPI_CHAR; + atomMbrTypes[1] = MPI_DOUBLE; + atomMbrTypes[2] = MPI_INT; + + for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0]; + + MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); + MPI_Type_commit(&mpiAtomStructType); - // next see if the force path enviorment variable is set - - ffPath = getenv( ffPath_env ); - strcpy( temp, ffPath ); - strcat( temp, "/" ); - strcat( temp, fileName ); - strcpy( fileName, temp ); + // ********************************************************************** + // Init the bondStruct mpi type + + bondStruct bondProto; // mpiPrototype + int bondBC[3] = {60,1,1}; // block counts + MPI_Aint bondDspls[3]; // displacements + MPI_Datatype bondMbrTypes[3]; // member mpi types + + MPI_Address(&bondProto.nameA, &bondDspls[0]); + MPI_Address(&bondProto.d0, &bondDspls[1]); + MPI_Address(&bondProto.last, &bondDspls[2]); + + bondMbrTypes[0] = MPI_CHAR; + bondMbrTypes[1] = MPI_DOUBLE; + bondMbrTypes[2] = MPI_INT; + + for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0]; + + MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType); + MPI_Type_commit(&mpiBondStructType); + + + // ********************************************************************** + // Init the bendStruct mpi type + + bendStruct bendProto; // mpiPrototype + int bendBC[3] = {75,4,1}; // block counts + MPI_Aint bendDspls[3]; // displacements + MPI_Datatype bendMbrTypes[3]; // member mpi types + + MPI_Address(&bendProto.nameA, &bendDspls[0]); + MPI_Address(&bendProto.k1, &bendDspls[1]); + MPI_Address(&bendProto.last, &bendDspls[2]); + + bendMbrTypes[0] = MPI_CHAR; + bendMbrTypes[1] = MPI_DOUBLE; + bendMbrTypes[2] = MPI_INT; + + for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0]; + + MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType); + MPI_Type_commit(&mpiBendStructType); + + + // ********************************************************************** + // Init the torsionStruct mpi type + + torsionStruct torsionProto; // mpiPrototype + int torsionBC[3] = {90,4,1}; // block counts + MPI_Aint torsionDspls[3]; // displacements + MPI_Datatype torsionMbrTypes[3]; // member mpi types + + MPI_Address(&torsionProto.nameA, &torsionDspls[0]); + MPI_Address(&torsionProto.k1, &torsionDspls[1]); + MPI_Address(&torsionProto.last, &torsionDspls[2]); + + torsionMbrTypes[0] = MPI_CHAR; + torsionMbrTypes[1] = MPI_DOUBLE; + torsionMbrTypes[2] = MPI_INT; + + for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0]; + + MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes, + &mpiTorsionStructType); + MPI_Type_commit(&mpiTorsionStructType); + + // *********************************************************************** + + if( myNode == 0 ){ +#endif + + // generate the force file name + + strcpy( fileName, "TraPPE_Ex.frc" ); + fprintf( stderr,"Trying to open %s\n", fileName ); + + // attempt to open the file in the current directory first. + frcFile = fopen( fileName, "r" ); if( frcFile == NULL ){ - fprintf( stderr, - "Error opening the force field parameter file: %s\n" - "Have you tried setting the FORCE_PARAM_PATH environment " - "vairable?\n", - fileName ); - exit( 8 ); + // next see if the force path enviorment variable is set + + ffPath = getenv( ffPath_env ); + if( ffPath == NULL ) { + fprintf( stderr, + "Error opening the force field parameter file: %s\n" + "Have you tried setting the FORCE_PARAM_PATH environment " + "vairable?\n", + fileName ); + exit( 8 ); + } + + + strcpy( temp, ffPath ); + strcat( temp, "/" ); + strcat( temp, fileName ); + strcpy( fileName, temp ); + + frcFile = fopen( fileName, "r" ); + + if( frcFile == NULL ){ + + fprintf( stderr, + "Error opening the force field parameter file: %s\n" + "Have you tried setting the FORCE_PARAM_PATH environment " + "vairable?\n", + fileName ); + exit( 8 ); + } } +#ifdef IS_MPI } +#endif } + TraPPE_ExFF::~TraPPE_ExFF(){ fclose( frcFile ); @@ -69,6 +246,33 @@ void TraPPE_ExFF::initializeAtoms( void ){ return NULL; } +#ifdef IS_MPI + void add( atomStruct &info ){ + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->name, info.name); + next->isDipole = info.dipole; + next->mass = info.mass; + next->epslon = info.epslon; + next->sigma = info.sigma; + next->dipole = info.dipole; + } + } + + void duplicate( atomStruct &info ){ + strcpy(info.name, name); + info.isDipole = dipole; + info.mass = mass; + info.epslon = epslon; + info.sigma = sigma; + info.dipole = dipole; + info.last = 0; + } + + +#endif + char name[15]; int isDipole; double mass; @@ -128,115 +332,130 @@ void TraPPE_ExFF::initializeAtoms( void ){ the_atoms = entry_plug->atoms; nAtoms = entry_plug->n_atoms; - // read in the atom types. - - rewind( frcFile ); - headAtomType = new LinkedType; - currentAtomType = headAtomType; - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - if( eof_test == NULL ){ - fprintf( stderr, "Error in reading Atoms from force file.\n" ); - exit(8); - } - - - while( !foundAtom ){ - while( eof_test != NULL && readLine[0] != '#' ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - } +#ifdef IS_MPI + if( myNode == 0 ){ +#endif + + // read in the atom types. + + rewind( frcFile ); + headAtomType = new LinkedType; + currentAtomType = headAtomType; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Atoms from force file at line %d.\n", - lineNum ); + fprintf( stderr, "Error in reading Atoms from force file.\n" ); exit(8); } - - the_token = strtok( readLine, " ,;\t#\n" ); - foundAtom = !strcmp( "AtomTypes", the_token ); - if( !foundAtom ){ - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - + + while( !foundAtom ){ + while( eof_test != NULL && readLine[0] != '#' ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + } if( eof_test == NULL ){ fprintf( stderr, "Error in reading Atoms from force file at line %d.\n", lineNum ); exit(8); - } + } + + the_token = strtok( readLine, " ,;\t#\n" ); + foundAtom = !strcmp( "AtomTypes", the_token ); + + if( !foundAtom ){ + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + fprintf( stderr, + "Error in reading Atoms from force file at line %d.\n", + lineNum ); + exit(8); + } + } } - } - - // we are now at the AtomTypes section. - - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; - - if( eof_test == NULL ){ - fprintf( stderr, - "Error in reading Atoms from force file at line %d.\n", - lineNum ); - exit(8); - } - - while( readLine[0] != '#' && eof_test != NULL ){ - if( readLine[0] != '!' ){ + // we are now at the AtomTypes section. + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; + + if( eof_test == NULL ){ + fprintf( stderr, + "Error in reading Atoms from force file at line %d.\n", + lineNum ); + exit(8); + } + + while( readLine[0] != '#' && eof_test != NULL ){ - the_token = strtok( readLine, " \n\t,;" ); - if( the_token != NULL ){ + if( readLine[0] != '!' ){ - strcpy( currentAtomType->name, the_token ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); - exit(8); - } - - sscanf( the_token, "%d", ¤tAtomType->isDipole ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); - exit(8); - } - - sscanf( the_token, "%lf", ¤tAtomType->mass ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); - exit(8); - } - - sscanf( the_token, "%lf", ¤tAtomType->epslon ); - - if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ - fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); - exit(8); - } - - sscanf( the_token, "%lf", ¤tAtomType->sigma ); - - if( currentAtomType->isDipole ){ + the_token = strtok( readLine, " \n\t,;" ); + if( the_token != NULL ){ + + strcpy( currentAtomType->name, the_token ); + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); exit(8); } - sscanf( the_token, "%lf", ¤tAtomType->dipole ); + sscanf( the_token, "%d", ¤tAtomType->isDipole ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); + exit(8); + } + + sscanf( the_token, "%lf", ¤tAtomType->mass ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); + exit(8); + } + + sscanf( the_token, "%lf", ¤tAtomType->epslon ); + + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); + exit(8); + } + + sscanf( the_token, "%lf", ¤tAtomType->sigma ); + + if( currentAtomType->isDipole ){ + if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ + fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); + exit(8); + } + + sscanf( the_token, "%lf", ¤tAtomType->dipole ); + } } } + + tempAtomType = new LinkedType; + currentAtomType->next = tempAtomType; + currentAtomType = tempAtomType; + + eof_test = fgets( readLine, sizeof(readLine), frcFile ); + lineNum++; } + +#ifdef IS_MPI + } + + else{ - tempAtomType = new LinkedType; - currentAtomType->next = tempAtomType; - currentAtomType = tempAtomType; + // listen for the structs - eof_test = fgets( readLine, sizeof(readLine), frcFile ); - lineNum++; } +#endif // initialize the atoms @@ -325,8 +544,31 @@ void TraPPE_ExFF::initializeBonds( bond_pair* the_bond if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this; if( next != NULL ) return next->find(key1, key2); return NULL; + } + +#ifdef IS_MPI + void add( bondStruct &info ){ + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->type, info.type); + next->d0 = info.d0; + } } + void duplicate( bondStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.type, type); + info.d0 = d0; + info.last = 0; + } + + +#endif + char nameA[15]; char nameB[15]; char type[30]; @@ -517,6 +759,37 @@ void TraPPE_ExFF::initializeBends( bend_set* the_bends return NULL; } +#ifdef IS_MPI + + void add( bendStruct &info ){ + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->nameC, info.nameC); + strcpy(next->type, info.type); + next->k1 = info.k1; + next->k2 = info.k2; + next->k3 = info.k3; + next->t0 = info.t0; + } + } + + void duplicate( bendStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.nameC, nameC); + strcpy(info.type, type); + info.k1 = k1; + info.k2 = k2; + info.k3 = k3; + info.t0 = t0; + info.last = 0; + } + +#endif + char nameA[15]; char nameB[15]; char nameC[15]; @@ -743,8 +1016,40 @@ void TraPPE_ExFF::initializeTorsions( torsion_set* the if( next != NULL ) return next->find(key1, key2, key3, key4); return NULL; + } + +#ifdef IS_MPI + + void add( torsionStruct &info ){ + if( next != NULL ) next->add(info); + else{ + next = new LinkedType(); + strcpy(next->nameA, info.nameA); + strcpy(next->nameB, info.nameB); + strcpy(next->nameC, info.nameC); + strcpy(next->type, info.type); + next->k1 = info.k1; + next->k2 = info.k2; + next->k3 = info.k3; + next->k4 = info.k4; + } } + void duplicate( torsionStruct &info ){ + strcpy(info.nameA, nameA); + strcpy(info.nameB, nameB); + strcpy(info.nameC, nameC); + strcpy(info.nameD, nameD); + strcpy(info.type, type); + info.k1 = k1; + info.k2 = k2; + info.k3 = k3; + info.k4 = k4; + info.last = 0; + } + +#endif + char nameA[15]; char nameB[15]; char nameC[15];