ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
(Generate patch)

Comparing trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp (file contents):
Revision 137 by chuckv, Wed Oct 16 20:02:05 2002 UTC vs.
Revision 141 by chuckv, Wed Oct 16 22:24:44 2002 UTC

# Line 9 | Line 9 | TraPPE_ExFF::TraPPE_ExFF(){
9   #include "SRI.hpp"
10  
11  
12 + #ifdef IS_MPI
13 +
14 + int myNode;
15 +
16 + // Declare the structures that will be passed by MPI
17 +
18 + typedef struct{
19 +  char name[15];
20 +  double mass;
21 +  double epslon;
22 +  double sigma;
23 +  double dipole;
24 +  int isDipole;
25 +  int last;      //  0  -> default
26 +                 //  1  -> tells nodes to stop listening
27 +                 // -1  -> an error has occured. (handled in mpiForceField)
28 + } atomStruct;
29 + MPI_Datatype mpiAtomStructType;
30 +
31 + #endif
32 +
33 +
34 +
35   TraPPE_ExFF::TraPPE_ExFF(){
36  
37    char fileName[200];
# Line 16 | Line 39 | TraPPE_ExFF::TraPPE_ExFF(){
39    char* ffPath;
40    char temp[200];
41  
42 <  // generate the force file name
42 > #ifdef IS_MPI
43 >  int i;
44 >  int mpiError;
45  
46 +  mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode);
47 +
48 +  atomStruct atomProto; // mpiPrototype
49 +  int atomBC[3] = {15,4,2};  // block counts
50 +  MPI_Aint atomDspls[3];           // displacements
51 +  MPI_Datatype atomMbrTypes[3];    // member mpi types
52 +
53    
22  strcpy( fileName, "TraPPE_Ex.frc" );
23    fprintf( stderr,"Trying to open %s\n", fileName );
54    
55 <  // attempt to open the file in the current directory first.
55 >  MPI_Address(&atomProto.name, &atomDspls[0]);
56 >  MPI_Address(&atomProto.mass, &atomDspls[1]);
57 >  MPI_Address(&atomProto.isDipole, &atomDspls[2]);
58    
59 <  frcFile = fopen( fileName, "r" );
59 >  atomMbrTypes[0] = MPI_CHAR;
60 >  atomMbrTypes[1] = MPI_DOUBLE;
61 >  atomMbrTypes[2] = MPI_INT;
62    
63 <  if( frcFile == NULL ){
63 >  for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0];
64 >  
65 >  MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType);
66 >  MPI_Type_commit(&mpiAtomStructType);
67  
31    // next see if the force path enviorment variable is set
32    
33    ffPath = getenv( ffPath_env );
34    if( ffPath == NULL ) {
35      fprintf( stderr,
36               "Error opening the force field parameter file: %s\n"
37               "Have you tried setting the FORCE_PARAM_PATH environment "
38               "vairable?\n",
39               fileName );
40      exit( 8 );
41    }
68  
69  
44    strcpy( temp, ffPath );
45    strcat( temp, "/" );
46    strcat( temp, fileName );
47    strcpy( fileName, temp );
70  
71 +  if( myNode == 0 ){
72 + #endif
73 +    
74 +    // generate the force file name
75 +    
76 +    strcpy( fileName, "TraPPE_Ex.frc" );
77 +    fprintf( stderr,"Trying to open %s\n", fileName );
78 +    
79 +    // attempt to open the file in the current directory first.
80 +    
81      frcFile = fopen( fileName, "r" );
82      
83      if( frcFile == NULL ){
84        
85 <      fprintf( stderr,
86 <               "Error opening the force field parameter file: %s\n"
87 <               "Have you tried setting the FORCE_PARAM_PATH environment "
88 <               "vairable?\n",
89 <               fileName );
90 <      exit( 8 );
85 >      // next see if the force path enviorment variable is set
86 >      
87 >      ffPath = getenv( ffPath_env );
88 >      if( ffPath == NULL ) {
89 >        fprintf( stderr,
90 >                 "Error opening the force field parameter file: %s\n"
91 >                 "Have you tried setting the FORCE_PARAM_PATH environment "
92 >                 "vairable?\n",
93 >                 fileName );
94 >        exit( 8 );
95 >      }
96 >      
97 >      
98 >      strcpy( temp, ffPath );
99 >      strcat( temp, "/" );
100 >      strcat( temp, fileName );
101 >      strcpy( fileName, temp );
102 >      
103 >      frcFile = fopen( fileName, "r" );
104 >      
105 >      if( frcFile == NULL ){
106 >        
107 >        fprintf( stderr,
108 >                 "Error opening the force field parameter file: %s\n"
109 >                 "Have you tried setting the FORCE_PARAM_PATH environment "
110 >                 "vairable?\n",
111 >                 fileName );
112 >        exit( 8 );
113 >      }
114      }
115 + #ifdef IS_MPI
116    }
117 + #endif
118   }
119  
120 +
121   TraPPE_ExFF::~TraPPE_ExFF(){
122    
123    fclose( frcFile );
# Line 81 | Line 139 | void TraPPE_ExFF::initializeAtoms( void ){
139        return NULL;
140      }
141      
142 + #ifdef IS_MPI
143 +    void add( atomStruct &info ){
144 +      if( next != NULL ) next->add(info);
145 +      else{
146 +        next = new LinkedType();
147 +        strcpy(next->name, info.name);
148 +        next->isDipole = info.dipole;
149 +        next->mass     = info.mass;
150 +        next->epslon   = info.epslon;
151 +        next->sigma    = info.sigma;
152 +        next->dipole   = info.dipole;
153 +      }
154 +    }
155 +    
156 +    void duplicate( atomStruct &info ){
157 +      strcpy(info.name, name);
158 +      info.isDipole = dipole;
159 +      info.mass     = mass;
160 +      info.epslon   = epslon;
161 +      info.sigma    = sigma;
162 +      info.dipole   = dipole;
163 +      info.last     = 0;
164 +    }
165 +
166 +
167 + #endif
168 +
169      char name[15];
170      int isDipole;
171      double mass;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines