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 416 by gezelter, Wed Mar 26 23:14:02 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
10   #endif //is_mpi
# Line 11 | Line 12
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;
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 133 | Line 133 | void DumpWriter::writeDump( double currentTime ){
133              << entry_plug->box_y << "\t"
134              << entry_plug->box_z << "\n";
135      
136 <    for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) {
136 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
137        // Get the Node number which has this molecule:
138        
139        which_node = AtomToProcMap[i];    
140        
141 <      if (which_node == mpiPlug->myNode) {
141 >      if (which_node == mpiSim->getMyNode()) {
142          
143          sprintf( tempBuffer,
144                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
# Line 173 | Line 173 | void DumpWriter::writeDump( double currentTime ){
173        } else {
174          
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 >        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
177                                  TAKE_THIS_TAG, istatus);
178        }
179        
# Line 181 | Line 181 | void DumpWriter::writeDump( double currentTime ){
181      }
182      
183      // kill everyone off:
184 <    for (j = 0; j < mpiPlug->numberProcessors; j++) {
185 <      MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG);
184 >    game_over = -1;
185 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
186 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
187      }
188  
189    } else {
190      
191      done = 0;
192      while (!done) {
193 <      MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0,
193 >      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
194                                TAKE_THIS_TAG, istatus);
195  
196 <      if (which_atom == GAME_OVER) {
196 >      if (which_atom == -1) {
197          done=1;
198          continue;
199        } else {
# Line 241 | Line 242 | void DumpWriter::writeFinal(){
242   }
243  
244   void DumpWriter::writeFinal(){
245 <  
245 >
246    char finalName[500];
247    ofstream finalOut;
248 +
249 +  const int BUFFERSIZE = 2000;
250 +  char tempBuffer[BUFFERSIZE];
251 +  char writeLine[BUFFERSIZE];  
252 +
253 +  double q[4];
254 +  DirectionalAtom* dAtom;
255 +  int nAtoms = entry_plug->n_atoms;
256 +  Atom** atoms = entry_plug->atoms;
257 +  int i, j, which_node, done, game_over, which_atom;
258    
259 +  
260   #ifdef IS_MPI
261    if(worldRank == 0 ){
262   #endif // is_mpi
# Line 278 | Line 290 | void DumpWriter::writeFinal(){
290    finalOut << entry_plug->box_x << "\t"
291             << entry_plug->box_y << "\t"
292             << entry_plug->box_z << "\n";
293 <    
293 >  
294    for( i=0; i<nAtoms; i++ ){
295        
296      sprintf( tempBuffer,
# Line 318 | Line 330 | void DumpWriter::writeFinal(){
330  
331   #else // is_mpi
332    
333 <  MPI_Status istatus[MPI_STATUS_SIZE];
334 <  
333 >  MPI::Status istatus;
334 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
335 >
336    // write out header and node 0's coordinates
337    
338    if( worldRank == 0 ){
# Line 329 | Line 342 | void DumpWriter::writeFinal(){
342              << entry_plug->box_y << "\t"
343              << entry_plug->box_z << "\n";
344      
345 <    for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) {
345 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
346        // Get the Node number which has this molecule:
347        
348        which_node = AtomToProcMap[i];    
349        
350 <      if (which_node == mpiPlug->myNode) {
350 >      if (which_node == mpiSim->getMyNode()) {
351          
352          sprintf( tempBuffer,
353                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
# Line 369 | Line 382 | void DumpWriter::writeFinal(){
382        } else {
383          
384          MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
385 <        MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
385 >        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
386                                  TAKE_THIS_TAG, istatus);
387        }
388        
# Line 377 | Line 390 | void DumpWriter::writeFinal(){
390      }
391      
392      // kill everyone off:
393 <    for (j = 0; j < mpiPlug->numberProcessors; j++) {
394 <      MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG);
393 >    game_over = -1;
394 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
395 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
396      }
397  
398    } else {
399      
400      done = 0;
401      while (!done) {
402 <      MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0,
403 <                              TAKE_THIS_TAG, istatus);
402 >      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
403 >                           TAKE_THIS_TAG, istatus);
404  
405 <      if (which_atom == GAME_OVER) {
405 >      if (which_atom == -1) {
406          done=1;
407          continue;
408        } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines