ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/RestWriter.cpp
Revision: 2107
Committed: Thu Mar 10 19:11:02 2005 UTC (19 years, 3 months ago) by chrisfen
File size: 6419 byte(s)
Log Message:
Oops...  MPI now builds...

File Contents

# User Rev Content
1 chrisfen 2101 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Acknowledgement of the program authors must be made in any
10     * publication of scientific results based in part on use of the
11     * program. An acceptable form of acknowledgement is citation of
12     * the article in which the program was described (Matthew
13     * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     * Parallel Simulation Engine for Molecular Dynamics,"
16     * J. Comput. Chem. 26, pp. 252-271 (2005))
17     *
18     * 2. Redistributions of source code must retain the above copyright
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42     #include <algorithm>
43     #include <iostream>
44     #include <map>
45    
46     #include "primitives/Molecule.hpp"
47     #include "io/RestWriter.hpp"
48     #include "utils/simError.h"
49    
50    
51     namespace oopse {
52     RestWriter::RestWriter(SimInfo* info) :
53     info_(info) {
54    
55     //we use master - slave mode, only master node writes to disk
56     outName = info_->getRestFileName();
57     }
58    
59     RestWriter::~RestWriter() {}
60    
61     void RestWriter::writeZangle(){
62     const int BUFFERSIZE = 2000;
63     char tempBuffer[BUFFERSIZE];
64     char writeLine[BUFFERSIZE];
65    
66     std::ofstream finalOut;
67    
68     Molecule* mol;
69     StuntDouble* integrableObject;
70     SimInfo::MoleculeIterator mi;
71     Molecule::IntegrableObjectIterator ii;
72    
73     #ifdef IS_MPI
74     if(worldRank == 0 ){
75     #endif
76     finalOut.open( outName.c_str(), std::ios::out | std::ios::trunc );
77     if( !finalOut ){
78     sprintf( painCave.errMsg,
79     "Could not open \"%s\" for zAngle output.\n",
80 chrisfen 2107 outName.c_str() );
81 chrisfen 2101 painCave.isFatal = 1;
82     simError();
83     }
84     #ifdef IS_MPI
85     }
86     #endif // is_mpi
87    
88     #ifndef IS_MPI
89     // first we do output for the single processor version
90     finalOut
91     << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
92     << " : omega values at this time\n";
93    
94     for (mol = info_->beginMolecule(mi); mol != NULL;
95     mol = info_->nextMolecule(mi)) {
96    
97     for (integrableObject = mol->beginIntegrableObject(ii);
98     integrableObject != NULL;
99     integrableObject = mol->nextIntegrableObject(ii)) {
100    
101     sprintf( tempBuffer,
102     "%14.10lf\n",
103     integrableObject->getZangle());
104     strcpy( writeLine, tempBuffer );
105    
106     finalOut << writeLine;
107     }
108    
109     }
110    
111     #else
112     int nproc;
113     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
114     const int masterNode = 0;
115     int myNode = worldRank;
116     std::vector<int> tmpNIntObjects(nproc, 0);
117     std::vector<int> nIntObjectsInProc(nproc, 0);
118     tmpNIntObjects[myNode] = info_->getNGlobalIntegrableObjects();
119    
120     //do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups
121     MPI_Allreduce(&tmpNIntObjects[0], &nIntObjectsInProc[0], nproc, MPI_INT,
122     MPI_SUM, MPI_COMM_WORLD);
123    
124     MPI_Status ierr;
125     int intObIndex;
126     double zAngle;
127 chrisfen 2107
128 chrisfen 2101 if (masterNode == 0) {
129     std::map<int, double> zAngData;
130     for(int i = 0 ; i < nproc; ++i) {
131     if (i == masterNode) {
132     for (mol = info_->beginMolecule(mi); mol != NULL;
133     mol = info_->nextMolecule(mi)) {
134    
135     for (integrableObject = mol->beginIntegrableObject(ii);
136     integrableObject != NULL;
137     integrableObject = mol->nextIntegrableObject(ii)) {
138    
139     intObIndex = integrableObject->getGlobalIndex() ;
140     zAngle = integrableObject->getZangle();
141 chrisfen 2107 zAngData.insert(std::pair<int, double>(intObIndex, zAngle));
142 chrisfen 2101 }
143     }
144    
145     } else {
146     for(int k = 0; k < nIntObjectsInProc[i]; ++k) {
147     MPI_Recv(&intObIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD,&ierr);
148     MPI_Recv(&zAngle, 1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&ierr);
149 chrisfen 2107 zAngData.insert(std::pair<int, double>(intObIndex, zAngle));
150 chrisfen 2101 }
151     }
152    
153     }
154    
155     finalOut
156     << info_->getSnapshotManager()->getCurrentSnapshot()->getTime()
157     << " : omega values at this time\n";
158    
159     std::map<int, double>::iterator l;
160     for (l = zAngData.begin(); l != zAngData.end(); ++l) {
161     finalOut << l->second << "\n";
162     }
163    
164     } else {
165    
166     for (mol = info_->beginMolecule(mi); mol != NULL;
167     mol = info_->nextMolecule(mi)) {
168    
169     for (integrableObject = mol->beginIntegrableObject(ii);
170     integrableObject != NULL;
171     integrableObject = mol->nextIntegrableObject(ii)) {
172     intObIndex = integrableObject->getGlobalIndex();
173     zAngle = integrableObject->getZangle();
174     MPI_Send(&intObIndex, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
175     MPI_Send(&zAngle, 1, MPI_DOUBLE, masterNode, 0, MPI_COMM_WORLD);
176     }
177     }
178     }
179     #endif
180    
181     #ifdef IS_MPI
182     finalOut.close();
183     #endif
184    
185     }
186    
187     }