11 |
|
|
12 |
|
#ifdef IS_MPI |
13 |
|
|
14 |
+ |
#include "mpiForceField.h" |
15 |
+ |
|
16 |
|
int myNode; |
17 |
|
|
18 |
|
// Declare the structures that will be passed by MPI |
76 |
|
char* ffPath_env = "FORCE_PARAM_PATH"; |
77 |
|
char* ffPath; |
78 |
|
char temp[200]; |
79 |
+ |
char errMsg[1000]; |
80 |
|
|
81 |
|
#ifdef IS_MPI |
82 |
|
int i; |
83 |
|
int mpiError; |
84 |
< |
|
84 |
> |
int cleanOpen = 0; |
85 |
> |
|
86 |
|
mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode); |
87 |
+ |
|
88 |
+ |
// ********************************************************************** |
89 |
+ |
// Init the atomStruct mpi type |
90 |
|
|
91 |
|
atomStruct atomProto; // mpiPrototype |
92 |
|
int atomBC[3] = {15,4,2}; // block counts |
108 |
|
MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); |
109 |
|
MPI_Type_commit(&mpiAtomStructType); |
110 |
|
|
111 |
+ |
|
112 |
+ |
// ********************************************************************** |
113 |
+ |
// Init the bondStruct mpi type |
114 |
+ |
|
115 |
+ |
bondStruct bondProto; // mpiPrototype |
116 |
+ |
int bondBC[3] = {60,1,1}; // block counts |
117 |
+ |
MPI_Aint bondDspls[3]; // displacements |
118 |
+ |
MPI_Datatype bondMbrTypes[3]; // member mpi types |
119 |
+ |
|
120 |
+ |
MPI_Address(&bondProto.nameA, &bondDspls[0]); |
121 |
+ |
MPI_Address(&bondProto.d0, &bondDspls[1]); |
122 |
+ |
MPI_Address(&bondProto.last, &bondDspls[2]); |
123 |
+ |
|
124 |
+ |
bondMbrTypes[0] = MPI_CHAR; |
125 |
+ |
bondMbrTypes[1] = MPI_DOUBLE; |
126 |
+ |
bondMbrTypes[2] = MPI_INT; |
127 |
+ |
|
128 |
+ |
for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0]; |
129 |
+ |
|
130 |
+ |
MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType); |
131 |
+ |
MPI_Type_commit(&mpiBondStructType); |
132 |
+ |
|
133 |
+ |
|
134 |
+ |
// ********************************************************************** |
135 |
+ |
// Init the bendStruct mpi type |
136 |
+ |
|
137 |
+ |
bendStruct bendProto; // mpiPrototype |
138 |
+ |
int bendBC[3] = {75,4,1}; // block counts |
139 |
+ |
MPI_Aint bendDspls[3]; // displacements |
140 |
+ |
MPI_Datatype bendMbrTypes[3]; // member mpi types |
141 |
+ |
|
142 |
+ |
MPI_Address(&bendProto.nameA, &bendDspls[0]); |
143 |
+ |
MPI_Address(&bendProto.k1, &bendDspls[1]); |
144 |
+ |
MPI_Address(&bendProto.last, &bendDspls[2]); |
145 |
+ |
|
146 |
+ |
bendMbrTypes[0] = MPI_CHAR; |
147 |
+ |
bendMbrTypes[1] = MPI_DOUBLE; |
148 |
+ |
bendMbrTypes[2] = MPI_INT; |
149 |
+ |
|
150 |
+ |
for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0]; |
151 |
+ |
|
152 |
+ |
MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType); |
153 |
+ |
MPI_Type_commit(&mpiBendStructType); |
154 |
|
|
155 |
|
|
156 |
+ |
// ********************************************************************** |
157 |
+ |
// Init the torsionStruct mpi type |
158 |
+ |
|
159 |
+ |
torsionStruct torsionProto; // mpiPrototype |
160 |
+ |
int torsionBC[3] = {90,4,1}; // block counts |
161 |
+ |
MPI_Aint torsionDspls[3]; // displacements |
162 |
+ |
MPI_Datatype torsionMbrTypes[3]; // member mpi types |
163 |
+ |
|
164 |
+ |
MPI_Address(&torsionProto.nameA, &torsionDspls[0]); |
165 |
+ |
MPI_Address(&torsionProto.k1, &torsionDspls[1]); |
166 |
+ |
MPI_Address(&torsionProto.last, &torsionDspls[2]); |
167 |
+ |
|
168 |
+ |
torsionMbrTypes[0] = MPI_CHAR; |
169 |
+ |
torsionMbrTypes[1] = MPI_DOUBLE; |
170 |
+ |
torsionMbrTypes[2] = MPI_INT; |
171 |
+ |
|
172 |
+ |
for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0]; |
173 |
+ |
|
174 |
+ |
MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes, |
175 |
+ |
&mpiTorsionStructType); |
176 |
+ |
MPI_Type_commit(&mpiTorsionStructType); |
177 |
|
|
178 |
+ |
// *********************************************************************** |
179 |
+ |
|
180 |
|
if( myNode == 0 ){ |
181 |
|
#endif |
182 |
|
|
183 |
|
// generate the force file name |
184 |
|
|
185 |
|
strcpy( fileName, "TraPPE_Ex.frc" ); |
186 |
< |
fprintf( stderr,"Trying to open %s\n", fileName ); |
186 |
> |
// fprintf( stderr,"Trying to open %s\n", fileName ); |
187 |
|
|
188 |
|
// attempt to open the file in the current directory first. |
189 |
|
|
195 |
|
|
196 |
|
ffPath = getenv( ffPath_env ); |
197 |
|
if( ffPath == NULL ) { |
198 |
< |
fprintf( stderr, |
198 |
> |
sprintf( errMsg, |
199 |
|
"Error opening the force field parameter file: %s\n" |
200 |
|
"Have you tried setting the FORCE_PARAM_PATH environment " |
201 |
|
"vairable?\n", |
202 |
|
fileName ); |
203 |
< |
exit( 8 ); |
203 |
> |
#ifdef IS_MPI |
204 |
> |
cleanOpen = 0; |
205 |
> |
mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); |
206 |
> |
#endif |
207 |
> |
ffError( errMsg ); |
208 |
|
} |
209 |
|
|
210 |
|
|
217 |
|
|
218 |
|
if( frcFile == NULL ){ |
219 |
|
|
220 |
< |
fprintf( stderr, |
220 |
> |
sprintf( errMsg, |
221 |
|
"Error opening the force field parameter file: %s\n" |
222 |
|
"Have you tried setting the FORCE_PARAM_PATH environment " |
223 |
|
"vairable?\n", |
224 |
|
fileName ); |
225 |
< |
exit( 8 ); |
225 |
> |
#ifdef IS_MPI |
226 |
> |
cleanOpen = 0; |
227 |
> |
mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); |
228 |
> |
#endif |
229 |
> |
ffError( errMsg ); |
230 |
|
} |
231 |
|
} |
232 |
+ |
cleanOpen = 1; |
233 |
|
#ifdef IS_MPI |
234 |
|
} |
235 |
+ |
|
236 |
+ |
mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD); |
237 |
+ |
if( !cleanOpen ) fferror( NULL ); |
238 |
|
#endif |
239 |
|
} |
240 |
|
|
300 |
|
LinkedType* currentAtomType; |
301 |
|
LinkedType* tempAtomType; |
302 |
|
|
303 |
+ |
#ifdef IS_MPI |
304 |
+ |
atomStruct info; |
305 |
+ |
info.last = -1; // initialize last to have the error set. |
306 |
+ |
// if things go well, last will be set to 0 |
307 |
+ |
#endif |
308 |
+ |
|
309 |
+ |
|
310 |
|
char readLine[500]; |
311 |
|
char* the_token; |
312 |
|
char* eof_test; |
313 |
|
int foundAtom = 0; |
314 |
|
int lineNum = 0; |
315 |
|
int i; |
316 |
+ |
char errMsg[1000]; |
317 |
+ |
|
318 |
|
|
319 |
|
////////////////////////////////////////////////// |
320 |
|
// a quick water fix |
355 |
|
the_atoms = entry_plug->atoms; |
356 |
|
nAtoms = entry_plug->n_atoms; |
357 |
|
|
264 |
– |
// read in the atom types. |
265 |
– |
|
266 |
– |
rewind( frcFile ); |
267 |
– |
headAtomType = new LinkedType; |
268 |
– |
currentAtomType = headAtomType; |
358 |
|
|
359 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
360 |
< |
lineNum++; |
361 |
< |
if( eof_test == NULL ){ |
362 |
< |
fprintf( stderr, "Error in reading Atoms from force file.\n" ); |
363 |
< |
exit(8); |
364 |
< |
} |
365 |
< |
|
366 |
< |
|
367 |
< |
while( !foundAtom ){ |
368 |
< |
while( eof_test != NULL && readLine[0] != '#' ){ |
369 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
370 |
< |
lineNum++; |
282 |
< |
} |
359 |
> |
#ifdef IS_MPI |
360 |
> |
if( myNode == 0 ){ |
361 |
> |
#endif |
362 |
> |
|
363 |
> |
// read in the atom types. |
364 |
> |
|
365 |
> |
rewind( frcFile ); |
366 |
> |
headAtomType = new LinkedType; |
367 |
> |
currentAtomType = headAtomType; |
368 |
> |
|
369 |
> |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
370 |
> |
lineNum++; |
371 |
|
if( eof_test == NULL ){ |
372 |
< |
fprintf( stderr, |
373 |
< |
"Error in reading Atoms from force file at line %d.\n", |
374 |
< |
lineNum ); |
375 |
< |
exit(8); |
372 |
> |
sprintf( errMsg, "Error in reading Atoms from force file.\n" ); |
373 |
> |
#ifdef IS_MPI |
374 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
375 |
> |
#endif |
376 |
> |
ffError(errMsg); |
377 |
|
} |
289 |
– |
|
290 |
– |
the_token = strtok( readLine, " ,;\t#\n" ); |
291 |
– |
foundAtom = !strcmp( "AtomTypes", the_token ); |
378 |
|
|
379 |
< |
if( !foundAtom ){ |
380 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
381 |
< |
lineNum++; |
382 |
< |
|
379 |
> |
|
380 |
> |
while( !foundAtom ){ |
381 |
> |
while( eof_test != NULL && readLine[0] != '#' ){ |
382 |
> |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
383 |
> |
lineNum++; |
384 |
> |
} |
385 |
|
if( eof_test == NULL ){ |
386 |
< |
fprintf( stderr, |
386 |
> |
sprintf( errMsg, |
387 |
|
"Error in reading Atoms from force file at line %d.\n", |
388 |
|
lineNum ); |
389 |
< |
exit(8); |
390 |
< |
} |
391 |
< |
} |
392 |
< |
} |
393 |
< |
|
306 |
< |
// we are now at the AtomTypes section. |
307 |
< |
|
308 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
309 |
< |
lineNum++; |
310 |
< |
|
311 |
< |
if( eof_test == NULL ){ |
312 |
< |
fprintf( stderr, |
313 |
< |
"Error in reading Atoms from force file at line %d.\n", |
314 |
< |
lineNum ); |
315 |
< |
exit(8); |
316 |
< |
} |
317 |
< |
|
318 |
< |
while( readLine[0] != '#' && eof_test != NULL ){ |
319 |
< |
|
320 |
< |
if( readLine[0] != '!' ){ |
389 |
> |
#ifdef IS_MPI |
390 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
391 |
> |
#endif |
392 |
> |
ffError(errMsg); |
393 |
> |
} |
394 |
|
|
395 |
< |
the_token = strtok( readLine, " \n\t,;" ); |
396 |
< |
if( the_token != NULL ){ |
395 |
> |
the_token = strtok( readLine, " ,;\t#\n" ); |
396 |
> |
foundAtom = !strcmp( "AtomTypes", the_token ); |
397 |
> |
|
398 |
> |
if( !foundAtom ){ |
399 |
> |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
400 |
> |
lineNum++; |
401 |
|
|
402 |
< |
strcpy( currentAtomType->name, the_token ); |
403 |
< |
|
404 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
405 |
< |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
406 |
< |
exit(8); |
407 |
< |
} |
408 |
< |
|
409 |
< |
sscanf( the_token, "%d", ¤tAtomType->isDipole ); |
410 |
< |
|
411 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
412 |
< |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
413 |
< |
exit(8); |
414 |
< |
} |
415 |
< |
|
416 |
< |
sscanf( the_token, "%lf", ¤tAtomType->mass ); |
417 |
< |
|
418 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
419 |
< |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
420 |
< |
exit(8); |
421 |
< |
} |
402 |
> |
if( eof_test == NULL ){ |
403 |
> |
sprintf( errMsg, |
404 |
> |
"Error in reading Atoms from force file at line %d.\n", |
405 |
> |
lineNum ); |
406 |
> |
#ifdef IS_MPI |
407 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
408 |
> |
#endif |
409 |
> |
ffError(errMsg); |
410 |
> |
} |
411 |
> |
} |
412 |
> |
} |
413 |
> |
|
414 |
> |
// we are now at the AtomTypes section. |
415 |
> |
|
416 |
> |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
417 |
> |
lineNum++; |
418 |
> |
|
419 |
> |
if( eof_test == NULL ){ |
420 |
> |
sprintf( errMsg, |
421 |
> |
"Error in reading Atoms from force file at line %d.\n", |
422 |
> |
lineNum ); |
423 |
> |
#ifdef IS_MPI |
424 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
425 |
> |
#endif |
426 |
> |
ffError(errMsg); |
427 |
> |
} |
428 |
> |
|
429 |
> |
while( readLine[0] != '#' && eof_test != NULL ){ |
430 |
> |
|
431 |
> |
if( readLine[0] != '!' ){ |
432 |
|
|
433 |
< |
sscanf( the_token, "%lf", ¤tAtomType->epslon ); |
434 |
< |
|
435 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
436 |
< |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
437 |
< |
exit(8); |
351 |
< |
} |
352 |
< |
|
353 |
< |
sscanf( the_token, "%lf", ¤tAtomType->sigma ); |
354 |
< |
|
355 |
< |
if( currentAtomType->isDipole ){ |
433 |
> |
the_token = strtok( readLine, " \n\t,;" ); |
434 |
> |
if( the_token != NULL ){ |
435 |
> |
|
436 |
> |
strcpy( currentAtomType->name, the_token ); |
437 |
> |
|
438 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
439 |
< |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
440 |
< |
exit(8); |
439 |
> |
sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); |
440 |
> |
#ifdef IS_MPI |
441 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
442 |
> |
#endif |
443 |
> |
ffError(errMsg); |
444 |
|
} |
445 |
|
|
446 |
< |
sscanf( the_token, "%lf", ¤tAtomType->dipole ); |
446 |
> |
sscanf( the_token, "%d", ¤tAtomType->isDipole ); |
447 |
> |
|
448 |
> |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
449 |
> |
sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); |
450 |
> |
#ifdef IS_MPI |
451 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
452 |
> |
#endif |
453 |
> |
ffError(errMsg); |
454 |
> |
} |
455 |
> |
|
456 |
> |
sscanf( the_token, "%lf", ¤tAtomType->mass ); |
457 |
> |
|
458 |
> |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
459 |
> |
sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); |
460 |
> |
#ifdef IS_MPI |
461 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
462 |
> |
#endif |
463 |
> |
ffError(errMsg); |
464 |
> |
} |
465 |
> |
|
466 |
> |
sscanf( the_token, "%lf", ¤tAtomType->epslon ); |
467 |
> |
|
468 |
> |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
469 |
> |
sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum ); |
470 |
> |
#ifdef IS_MPI |
471 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
472 |
> |
#endif |
473 |
> |
ffError(errMsg); |
474 |
> |
} |
475 |
> |
|
476 |
> |
sscanf( the_token, "%lf", ¤tAtomType->sigma ); |
477 |
> |
|
478 |
> |
if( currentAtomType->isDipole ){ |
479 |
> |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
480 |
> |
sprintf( errMsg, "Error parseing AtomTypes: line %d\n", |
481 |
> |
lineNum ); |
482 |
> |
#ifdef IS_MPI |
483 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
484 |
> |
#endif |
485 |
> |
ffError(errMsg); |
486 |
> |
} |
487 |
> |
|
488 |
> |
sscanf( the_token, "%lf", ¤tAtomType->dipole ); |
489 |
> |
} |
490 |
|
} |
491 |
|
} |
492 |
+ |
|
493 |
+ |
tempAtomType = new LinkedType; |
494 |
+ |
currentAtomType->next = tempAtomType; |
495 |
+ |
currentAtomType = tempAtomType; |
496 |
+ |
|
497 |
+ |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
498 |
+ |
lineNum++; |
499 |
|
} |
500 |
+ |
|
501 |
+ |
#ifdef IS_MPI |
502 |
|
|
503 |
< |
tempAtomType = new LinkedType; |
367 |
< |
currentAtomType->next = tempAtomType; |
368 |
< |
currentAtomType = tempAtomType; |
503 |
> |
// send out the linked list to all the other processes |
504 |
|
|
505 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
506 |
< |
lineNum++; |
505 |
> |
currentAtomType = headAtomType; |
506 |
> |
while( currentAtomType != NULL ){ |
507 |
> |
currentAtomType->duplicate( info ); |
508 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
509 |
> |
currentAtomType = currentAtomType->next; |
510 |
> |
} |
511 |
> |
info.last = 1; |
512 |
> |
sendFrcStruct( &info, mpiAtomStructType ); |
513 |
> |
|
514 |
> |
} |
515 |
> |
|
516 |
> |
else{ |
517 |
> |
|
518 |
> |
// listen for node 0 to send out the force params |
519 |
> |
|
520 |
> |
headAtomType = new LinkedType; |
521 |
> |
recieveFrcStruct( &info, mpiAtomStructType ); |
522 |
> |
while( !info.last ){ |
523 |
> |
|
524 |
> |
headAtomType->add( info ); |
525 |
> |
recieveFrcStruct( &info, mpiAtomStructType ); |
526 |
> |
} |
527 |
> |
|
528 |
> |
if( info.last < 0 ) ffError( NULL ); // an error has occured, exit quietly. |
529 |
> |
|
530 |
> |
|
531 |
|
} |
532 |
+ |
#endif |
533 |
|
|
534 |
|
|
535 |
|
// initialize the atoms |
540 |
|
|
541 |
|
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
542 |
|
if( currentAtomType == NULL ){ |
543 |
< |
fprintf( stderr, "AtomType error, %s not found in force file.\n", |
543 |
> |
sprintf( errMsg, "AtomType error, %s not found in force file.\n", |
544 |
|
the_atoms[i]->getType() ); |
545 |
< |
exit(8); |
545 |
> |
ffError(errMsg); |
546 |
|
} |
547 |
|
|
548 |
|
the_atoms[i]->setMass( currentAtomType->mass ); |
569 |
|
dAtom->setSSD( 0 ); |
570 |
|
} |
571 |
|
else{ |
572 |
< |
fprintf(stderr, |
572 |
> |
sprintf(errMsg, |
573 |
|
"AtmType error, %s does not have a moment of inertia set.\n", |
574 |
|
the_atoms[i]->getType() ); |
575 |
< |
exit(8); |
575 |
> |
ffError(errMsg); |
576 |
|
} |
577 |
|
entry_plug->n_dipoles++; |
578 |
|
} |
579 |
|
else{ |
580 |
< |
std::cerr |
581 |
< |
<< "TraPPE_ExFF error: Atom \"" |
582 |
< |
<< currentAtomType->name << "\" is a dipole, yet no standard" |
583 |
< |
<< " orientation was specifed in the BASS file.\n"; |
584 |
< |
exit(8); |
580 |
> |
|
581 |
> |
sprintf( errMsg, |
582 |
> |
"TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard" |
583 |
> |
" orientation was specifed in the BASS file.\n", |
584 |
> |
currentAtomType->name ); |
585 |
> |
|
586 |
> |
ffError(errMsg); |
587 |
|
} |
588 |
|
} |
589 |
|
else{ |
590 |
|
if( the_atoms[i]->isDirectional() ){ |
591 |
< |
std::cerr |
592 |
< |
<< "TraPPE_ExFF error: Atom \"" |
593 |
< |
<< currentAtomType->name << "\" was given a standard orientation" |
594 |
< |
<< " in the BASS file, yet it is not a dipole.\n"; |
595 |
< |
exit(8); |
591 |
> |
sprintf( errMsg, |
592 |
> |
"TraPPE_ExFF error: Atom \"%s\" was given a standard" |
593 |
> |
"orientation in the BASS file, yet it is not a dipole.\n", |
594 |
> |
currentAtomType->name); |
595 |
> |
ffError(errMsg); |
596 |
|
} |
597 |
|
} |
598 |
|
} |