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 434 by chuckv, Fri Mar 28 19:30:59 2003 UTC vs.
Revision 437 by chuckv, Fri Mar 28 22:34:02 2003 UTC

# Line 6 | Line 6
6   #include <mpi.h>
7   #include <mpi++.h>
8   #include "mpiSimulation.hpp"
9 < #define TAKE_THIS_TAG 1
9 > #define TAKE_THIS_TAG_CHAR 1
10 > #define TAKE_THIS_TAG_INT 2
11   #endif //is_mpi
12  
13   #include "ReadWrite.hpp"
# Line 138 | Line 139 | void DumpWriter::writeDump( double currentTime ){
139        
140        which_node = AtomToProcMap[i];    
141        
142 <      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(),
146 <                 atoms[i]->getY(),
147 <                 atoms[i]->getZ(),
148 <                 atoms[i]->get_vx(),
149 <                 atoms[i]->get_vy(),
150 <                 atoms[i]->get_vz());
151 <        strcpy( writeLine, tempBuffer );
142 >      if (which_node == 0 ) {
143          
144 <        if( atoms[i]->isDirectional() ){
145 <          
146 <          dAtom = (DirectionalAtom *)atoms[i];
147 <          dAtom->getQ( q );
157 <          
158 <          sprintf( tempBuffer,
159 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
160 <                   q[0],
161 <                   q[1],
162 <                   q[2],
163 <                   q[3],
164 <                   dAtom->getJx(),
165 <                   dAtom->getJy(),
166 <                   dAtom->getJz());
167 <          strcat( writeLine, tempBuffer );
144 >        which_atom = i;
145 >        local_index=-1;        
146 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
147 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
148          }
149 <        else
150 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
149 >        if (local_index != -1) {
150 >          //format the line
151 >          sprintf( tempBuffer,
152 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
153 >                   atoms[local_index]->getType(),
154 >                   atoms[local_index]->getX(),
155 >                   atoms[local_index]->getY(),
156 >                   atoms[local_index]->getZ(),
157 >                   atoms[local_index]->get_vx(),
158 >                   atoms[local_index]->get_vy(),
159 >                   atoms[local_index]->get_vz()); // check here.
160 >          strcpy( writeLine, tempBuffer );
161 >          
162 >          if( atoms[local_index]->isDirectional() ){
163 >            
164 >            dAtom = (DirectionalAtom *)atoms[local_index];
165 >            dAtom->getQ( q );
166 >            
167 >            sprintf( tempBuffer,
168 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
169 >                     q[0],
170 >                     q[1],
171 >                     q[2],
172 >                     q[3],
173 >                     dAtom->getJx(),
174 >                     dAtom->getJy(),
175 >                     dAtom->getJz());
176 >            strcat( writeLine, tempBuffer );
177 >            
178 >          }
179 >          else
180 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
181 >        }
182 >        else {
183 >          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
184 >        }
185 >      }
186 >      else {
187          
188 <      } else {
189 <        
190 <        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 <        std::cerr << "node 0: sent!\n";
188 >        //std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n";
189 >        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
190 >        //std::cerr << "node 0: sent!\n";
191          MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
192 <                                TAKE_THIS_TAG, istatus);
193 <        std::cerr << "node 0: got this line: " << writeLine;
192 >                             TAKE_THIS_TAG_CHAR, istatus);
193 >        //std::cerr << "node 0: got this line: " << writeLine;
194        }
195        
196        outFile << writeLine;
# Line 186 | Line 200 | void DumpWriter::writeDump( double currentTime ){
200      // kill everyone off:
201      game_over = -1;
202      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
203 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
203 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
204      }
205  
206    } else {
207      
208      done = 0;
209      while (!done) {
210 <      std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n";
210 >      //std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n";
211        MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
212 <                           TAKE_THIS_TAG, istatus);
213 <      std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n";
212 >                           TAKE_THIS_TAG_INT, istatus);
213 >      //std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n";
214        if (which_atom == -1) {
215          done=1;
216          continue;
217        } else {
218          local_index=-1;        
219 <        for (j=0; j < mpiSim->getMyNlocal(); j++) {
219 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
220            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
221          }
222          if (local_index != -1) {
# Line 236 | Line 250 | void DumpWriter::writeDump( double currentTime ){
250            }
251            else
252              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
253 <          std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine;
253 >          // std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine;
254            MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
255 <                               TAKE_THIS_TAG);
255 >                               TAKE_THIS_TAG_CHAR);
256          } else {
257            strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
258            MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
259 <                               TAKE_THIS_TAG);
259 >                               TAKE_THIS_TAG_CHAR);
260          }
261        }
262      }
# Line 361 | Line 375 | void DumpWriter::writeFinal(){
375        which_node = AtomToProcMap[i];    
376        
377        if (which_node == mpiSim->getMyNode()) {
378 <        
379 <        sprintf( tempBuffer,
380 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
381 <                 atoms[i]->getType(),
382 <                 atoms[i]->getX(),
369 <                 atoms[i]->getY(),
370 <                 atoms[i]->getZ(),
371 <                 atoms[i]->get_vx(),
372 <                 atoms[i]->get_vy(),
373 <                 atoms[i]->get_vz());
374 <        strcpy( writeLine, tempBuffer );
375 <        
376 <        if( atoms[i]->isDirectional() ){
377 <          
378 <          dAtom = (DirectionalAtom *)atoms[i];
379 <          dAtom->getQ( q );
380 <          
381 <          sprintf( tempBuffer,
382 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
383 <                   q[0],
384 <                   q[1],
385 <                   q[2],
386 <                   q[3],
387 <                   dAtom->getJx(),
388 <                   dAtom->getJy(),
389 <                   dAtom->getJz());
390 <          strcat( writeLine, tempBuffer );
378 >
379 >        which_atom = i;
380 >        local_index=-1;        
381 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
382 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
383          }
384 <        else
385 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
386 <        
384 >        if (local_index != -1) {        
385 >          sprintf( tempBuffer,
386 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
387 >                   atoms[local_index]->getType(),
388 >                   atoms[local_index]->getX(),
389 >                   atoms[local_index]->getY(),
390 >                   atoms[local_index]->getZ(),
391 >                   atoms[local_index]->get_vx(),
392 >                   atoms[local_index]->get_vy(),
393 >                   atoms[local_index]->get_vz());
394 >          strcpy( writeLine, tempBuffer );
395 >          
396 >          if( atoms[local_index]->isDirectional() ){
397 >            
398 >            dAtom = (DirectionalAtom *)atoms[local_index];
399 >            dAtom->getQ( q );
400 >            
401 >            sprintf( tempBuffer,
402 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
403 >                     q[0],
404 >                     q[1],
405 >                     q[2],
406 >                     q[3],
407 >                     dAtom->getJx(),
408 >                     dAtom->getJy(),
409 >                     dAtom->getJz());
410 >            strcat( writeLine, tempBuffer );
411 >          }
412 >          else
413 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
414 >        }
415 >        else {
416 >          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
417 >        }
418 >    
419        } else {
420          
421 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
421 >        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
422          MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
423 <                                TAKE_THIS_TAG, istatus);
423 >                                TAKE_THIS_TAG_CHAR, istatus);
424        }
425        
426        finalOut << writeLine;
# Line 405 | Line 429 | void DumpWriter::writeFinal(){
429      // kill everyone off:
430      game_over = -1;
431      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
432 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG);
432 >      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
433      }
434  
435    } else {
# Line 413 | Line 437 | void DumpWriter::writeFinal(){
437      done = 0;
438      while (!done) {
439        MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
440 <                           TAKE_THIS_TAG, istatus);
440 >                           TAKE_THIS_TAG_INT, istatus);
441  
442        if (which_atom == -1) {
443          done=1;
# Line 458 | Line 482 | void DumpWriter::writeFinal(){
482              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
483            
484            MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
485 <                               TAKE_THIS_TAG);
485 >                               TAKE_THIS_TAG_CHAR);
486          } else {
487            strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
488            MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
489 <                               TAKE_THIS_TAG);
489 >                               TAKE_THIS_TAG_CHAR);
490          }
491        }
492      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines