--- trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/10/18 16:15:05 146 +++ trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp 2002/10/18 20:35:33 147 @@ -11,6 +11,8 @@ int myNode; #ifdef IS_MPI +#include "mpiForceField.h" + int myNode; // Declare the structures that will be passed by MPI @@ -78,8 +80,11 @@ TraPPE_ExFF::TraPPE_ExFF(){ #ifdef IS_MPI int i; int mpiError; - + mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode); + + // ********************************************************************** + // Init the atomStruct mpi type atomStruct atomProto; // mpiPrototype int atomBC[3] = {15,4,2}; // block counts @@ -102,8 +107,74 @@ TraPPE_ExFF::TraPPE_ExFF(){ MPI_Type_commit(&mpiAtomStructType); + // ********************************************************************** + // 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 @@ -261,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