ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/DumpWriter.cpp (file contents):
Revision 415 by gezelter, Wed Mar 26 22:24:49 2003 UTC vs.
Revision 434 by chuckv, Fri Mar 28 19:30:59 2003 UTC

# Line 4 | Line 4
4  
5   #ifdef IS_MPI
6   #include <mpi.h>
7 + #include <mpi++.h>
8   #include "mpiSimulation.hpp"
9 < #define TAKE_THIS_TAG 0
9 > #define TAKE_THIS_TAG 1
10   #endif //is_mpi
11  
12   #include "ReadWrite.hpp"
13   #include "simError.h"
14  
14 #define GAME_OVER -1
15
15   DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
16  
17    entry_plug = the_entry_plug;
# Line 66 | Line 65 | void DumpWriter::writeDump( double currentTime ){
65    char tempBuffer[BUFFERSIZE];
66    char writeLine[BUFFERSIZE];
67  
68 <  int i;
68 >  int i, j, which_node, done, game_over, which_atom, local_index;
69    double q[4];
70    DirectionalAtom* dAtom;
71    int nAtoms = entry_plug->n_atoms;
# Line 120 | Line 119 | void DumpWriter::writeDump( double currentTime ){
119    outFile.flush();
120  
121   #else // is_mpi
122 +
123 +  MPI::Status istatus;
124 +  int *AtomToProcMap = mpiSim->getAtomToProcMap();
125    
124  MPI_Status istatus[MPI_STATUS_SIZE];
125  
126    // write out header and node 0's coordinates
127    
128    if( worldRank == 0 ){
# Line 132 | Line 132 | void DumpWriter::writeDump( double currentTime ){
132              << entry_plug->box_x << "\t"
133              << entry_plug->box_y << "\t"
134              << entry_plug->box_z << "\n";
135 <    
136 <    for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) {
137 <      // Get the Node number which has this molecule:
135 >    outFile.flush();
136 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
137 >      // Get the Node number which has this atom;
138        
139        which_node = AtomToProcMap[i];    
140        
141 <      if (which_node == mpiPlug->myNode) {
142 <        
143 <        sprintf( tempBuffer,
141 >      if (which_node == mpiSim->getMyNode()) {
142 >                sprintf( tempBuffer,
143                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
144                   atoms[i]->getType(),
145                   atoms[i]->getX(),
# Line 172 | Line 171 | void DumpWriter::writeDump( double currentTime ){
171          
172        } else {
173          
174 +        std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n";
175          MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
176 <        MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
176 >        std::cerr << "node 0: sent!\n";
177 >        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
178                                  TAKE_THIS_TAG, istatus);
179 +        std::cerr << "node 0: got this line: " << writeLine;
180        }
181        
182        outFile << writeLine;
183 +      outFile.flush();
184      }
185      
186      // kill everyone off:
187 <    for (j = 0; j < mpiPlug->numberProcessors; j++) {
188 <      MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG);
187 >    game_over = -1;
188 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
189 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
190      }
191  
192    } else {
193      
194      done = 0;
195      while (!done) {
196 <      MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0,
197 <                              TAKE_THIS_TAG, istatus);
198 <
199 <      if (which_atom == GAME_OVER) {
196 >      std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n";
197 >      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
198 >                           TAKE_THIS_TAG, istatus);
199 >      std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n";
200 >      if (which_atom == -1) {
201          done=1;
202          continue;
203        } else {
204 <
205 <        //format the line
206 <        sprintf( tempBuffer,
207 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
208 <                 atoms[which_atom]->getType(),
209 <                 atoms[which_atom]->getX(),
210 <                 atoms[which_atom]->getY(),
211 <                 atoms[which_atom]->getZ(),
212 <                 atoms[which_atom]->get_vx(),
213 <                 atoms[which_atom]->get_vy(),
214 <                 atoms[which_atom]->get_vz()); // check here.
215 <        strcpy( writeLine, tempBuffer );
204 >        local_index=-1;        
205 >        for (j=0; j < mpiSim->getMyNlocal(); j++) {
206 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
207 >        }
208 >        if (local_index != -1) {
209 >          //format the line
210 >          sprintf( tempBuffer,
211 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
212 >                   atoms[local_index]->getType(),
213 >                   atoms[local_index]->getX(),
214 >                   atoms[local_index]->getY(),
215 >                   atoms[local_index]->getZ(),
216 >                   atoms[local_index]->get_vx(),
217 >                   atoms[local_index]->get_vy(),
218 >                   atoms[local_index]->get_vz()); // check here.
219 >          strcpy( writeLine, tempBuffer );
220            
221 <        if( atoms[which_atom]->isDirectional() ){
222 <            
223 <          dAtom = (DirectionalAtom *)atoms[which_atom];
224 <          dAtom->getQ( q );
225 <            
226 <          sprintf( tempBuffer,
227 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
228 <                   q[0],
229 <                   q[1],
230 <                   q[2],
231 <                   q[3],
232 <                   dAtom->getJx(),
233 <                   dAtom->getJy(),
234 <                   dAtom->getJz());
235 <          strcat( writeLine, tempBuffer );
236 <        }
237 <        else
238 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
239 <        
240 <        MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
241 <                             TAKE_THIS_TAG);
221 >          if( atoms[local_index]->isDirectional() ){
222 >            
223 >            dAtom = (DirectionalAtom *)atoms[local_index];
224 >            dAtom->getQ( q );
225 >            
226 >            sprintf( tempBuffer,
227 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
228 >                     q[0],
229 >                     q[1],
230 >                     q[2],
231 >                     q[3],
232 >                     dAtom->getJx(),
233 >                     dAtom->getJy(),
234 >                     dAtom->getJz());
235 >            strcat( writeLine, tempBuffer );
236 >          }
237 >          else
238 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
239 >          std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine;
240 >          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
241 >                               TAKE_THIS_TAG);
242 >        } else {
243 >          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
244 >          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
245 >                               TAKE_THIS_TAG);
246 >        }
247        }
248      }
249    }  
# Line 241 | Line 255 | void DumpWriter::writeFinal(){
255   }
256  
257   void DumpWriter::writeFinal(){
258 <  
258 >
259    char finalName[500];
260    ofstream finalOut;
261 +
262 +  const int BUFFERSIZE = 2000;
263 +  char tempBuffer[BUFFERSIZE];
264 +  char writeLine[BUFFERSIZE];  
265 +
266 +  double q[4];
267 +  DirectionalAtom* dAtom;
268 +  int nAtoms = entry_plug->n_atoms;
269 +  Atom** atoms = entry_plug->atoms;
270 +  int i, j, which_node, done, game_over, which_atom, local_index;
271    
272 +  
273   #ifdef IS_MPI
274    if(worldRank == 0 ){
275   #endif // is_mpi
# Line 278 | Line 303 | void DumpWriter::writeFinal(){
303    finalOut << entry_plug->box_x << "\t"
304             << entry_plug->box_y << "\t"
305             << entry_plug->box_z << "\n";
306 <    
306 >  
307    for( i=0; i<nAtoms; i++ ){
308        
309      sprintf( tempBuffer,
# Line 318 | Line 343 | void DumpWriter::writeFinal(){
343  
344   #else // is_mpi
345    
346 <  MPI_Status istatus[MPI_STATUS_SIZE];
347 <  
346 >  MPI::Status istatus;
347 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
348 >
349    // write out header and node 0's coordinates
350    
351    if( worldRank == 0 ){
# Line 329 | Line 355 | void DumpWriter::writeFinal(){
355              << entry_plug->box_y << "\t"
356              << entry_plug->box_z << "\n";
357      
358 <    for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) {
358 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
359        // Get the Node number which has this molecule:
360        
361        which_node = AtomToProcMap[i];    
362        
363 <      if (which_node == mpiPlug->myNode) {
363 >      if (which_node == mpiSim->getMyNode()) {
364          
365          sprintf( tempBuffer,
366                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
# Line 369 | Line 395 | void DumpWriter::writeFinal(){
395        } else {
396          
397          MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
398 <        MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
398 >        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
399                                  TAKE_THIS_TAG, istatus);
400        }
401        
# Line 377 | Line 403 | void DumpWriter::writeFinal(){
403      }
404      
405      // kill everyone off:
406 <    for (j = 0; j < mpiPlug->numberProcessors; j++) {
407 <      MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG);
406 >    game_over = -1;
407 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
408 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
409      }
410  
411    } else {
412      
413      done = 0;
414      while (!done) {
415 <      MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0,
416 <                              TAKE_THIS_TAG, istatus);
415 >      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
416 >                           TAKE_THIS_TAG, istatus);
417  
418 <      if (which_atom == GAME_OVER) {
418 >      if (which_atom == -1) {
419          done=1;
420          continue;
421        } else {
422  
423 <        //format the line
424 <        sprintf( tempBuffer,
425 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
426 <                 atoms[which_atom]->getType(),
427 <                 atoms[which_atom]->getX(),
428 <                 atoms[which_atom]->getY(),
429 <                 atoms[which_atom]->getZ(),
430 <                 atoms[which_atom]->get_vx(),
431 <                 atoms[which_atom]->get_vy(),
432 <                 atoms[which_atom]->get_vz()); // check here.
433 <        strcpy( writeLine, tempBuffer );
423 >        local_index=-1;        
424 >        for (j=0; j < mpiSim->getMyNlocal(); j++) {
425 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
426 >        }
427 >        if (local_index != -1) {
428 >
429 >          //format the line
430 >          sprintf( tempBuffer,
431 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
432 >                   atoms[local_index]->getType(),
433 >                   atoms[local_index]->getX(),
434 >                   atoms[local_index]->getY(),
435 >                   atoms[local_index]->getZ(),
436 >                   atoms[local_index]->get_vx(),
437 >                   atoms[local_index]->get_vy(),
438 >                   atoms[local_index]->get_vz()); // check here.
439 >          strcpy( writeLine, tempBuffer );
440            
441 <        if( atoms[which_atom]->isDirectional() ){
441 >          if( atoms[local_index]->isDirectional() ){
442 >            
443 >            dAtom = (DirectionalAtom *)atoms[local_index];
444 >            dAtom->getQ( q );
445              
446 <          dAtom = (DirectionalAtom *)atoms[which_atom];
447 <          dAtom->getQ( q );
448 <            
449 <          sprintf( tempBuffer,
450 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
451 <                   q[0],
452 <                   q[1],
453 <                   q[2],
454 <                   q[3],
455 <                   dAtom->getJx(),
456 <                   dAtom->getJy(),
457 <                   dAtom->getJz());
458 <          strcat( writeLine, tempBuffer );
459 <        }
460 <        else
461 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
462 <        
463 <        MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
464 <                             TAKE_THIS_TAG);
446 >            sprintf( tempBuffer,
447 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
448 >                     q[0],
449 >                     q[1],
450 >                     q[2],
451 >                     q[3],
452 >                     dAtom->getJx(),
453 >                     dAtom->getJy(),
454 >                     dAtom->getJz());
455 >            strcat( writeLine, tempBuffer );
456 >          }
457 >          else
458 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
459 >          
460 >          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
461 >                               TAKE_THIS_TAG);
462 >        } else {
463 >          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
464 >          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
465 >                               TAKE_THIS_TAG);
466 >        }
467        }
468      }
469 <  }  
469 >  }
470    finalOut.flush();
471    sprintf( checkPointMsg,
472             "Sucessfully took a dump.\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines