ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/io/ZConsWriter.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/io/ZConsWriter.cpp (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 49 | Line 49 | ZConsWriter::ZConsWriter(SimInfo* info, const std::str
49  
50  
51   namespace oopse {
52 < ZConsWriter::ZConsWriter(SimInfo* info, const std::string& filename) : info_(info) {
53 <  //use master - slave mode, only master node writes to disk
52 >  ZConsWriter::ZConsWriter(SimInfo* info, const std::string& filename) : info_(info) {
53 >    //use master - slave mode, only master node writes to disk
54   #ifdef IS_MPI
55      if(worldRank == 0){
56   #endif
57  
58 <    output_.open(filename.c_str());
58 >      output_.open(filename.c_str());
59  
60 <    if(!output_){
61 <         sprintf( painCave.errMsg,
62 <                  "Could not open %s for z constrain output_ \n", filename.c_str());
63 <         painCave.isFatal = 1;
64 <         simError();
65 <    }
60 >      if(!output_){
61 >        sprintf( painCave.errMsg,
62 >                 "Could not open %s for z constrain output_ \n", filename.c_str());
63 >        painCave.isFatal = 1;
64 >        simError();
65 >      }
66  
67 <    output_ << "//time(fs)" << std::endl;
68 <    output_ << "//number of fixed z-constrain molecules" << std::endl;
69 <    output_ << "//global Index of molecule\tzconstrain force\tcurrentZPos" << std::endl;
67 >      output_ << "//time(fs)" << std::endl;
68 >      output_ << "//number of fixed z-constrain molecules" << std::endl;
69 >      output_ << "//global Index of molecule\tzconstrain force\tcurrentZPos" << std::endl;
70  
71   #ifdef IS_MPI
72      }
73   #endif  
74  
75 < }
75 >  }
76  
77 < ZConsWriter::~ZConsWriter()
78 < {
77 >  ZConsWriter::~ZConsWriter()
78 >  {
79  
80   #ifdef IS_MPI
81 <  if(worldRank == 0 ){
81 >    if(worldRank == 0 ){
82   #endif  
83 <  output_.close();  
83 >      output_.close();  
84   #ifdef IS_MPI  
85 <  }
85 >    }
86   #endif
87 < }
87 >  }
88  
89 < void ZConsWriter::writeFZ(const std::list<ZconstraintMol>& fixedZmols){
89 >  void ZConsWriter::writeFZ(const std::list<ZconstraintMol>& fixedZmols){
90   #ifndef IS_MPI
91      output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() << std::endl;
92      output_ << fixedZmols.size() << std::endl;
93  
94      std::list<ZconstraintMol>::const_iterator i;
95      for ( i = fixedZmols.begin(); i != fixedZmols.end(); ++i) {
96 <        output_ << i->mol->getGlobalIndex() <<"\t" << i->fz << "\t" << i->zpos << "\t" << i->param.zTargetPos <<std::endl;
96 >      output_ << i->mol->getGlobalIndex() <<"\t" << i->fz << "\t" << i->zpos << "\t" << i->param.zTargetPos <<std::endl;
97      }
98   #else
99      int nproc;
# Line 114 | Line 114 | void ZConsWriter::writeFZ(const std::list<ZconstraintM
114      
115      if (masterNode == 0) {
116  
117 <        std::vector<ZconsData> zconsData;
118 <        ZconsData tmpData;      
119 <        for(int i =0 ; i < nproc; ++i) {
120 <            if (i == masterNode) {
121 <                std::list<ZconstraintMol>::const_iterator j;
122 <                for ( j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
123 <                    tmpData.zmolIndex = j->mol->getGlobalIndex() ;
124 <                    tmpData.zforce= j->fz;
125 <                    tmpData.zpos = j->zpos;
126 <                    tmpData.zconsPos = j->param.zTargetPos;
127 <                    zconsData.push_back(tmpData);
128 <                }                
117 >      std::vector<ZconsData> zconsData;
118 >      ZconsData tmpData;      
119 >      for(int i =0 ; i < nproc; ++i) {
120 >        if (i == masterNode) {
121 >          std::list<ZconstraintMol>::const_iterator j;
122 >          for ( j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
123 >            tmpData.zmolIndex = j->mol->getGlobalIndex() ;
124 >            tmpData.zforce= j->fz;
125 >            tmpData.zpos = j->zpos;
126 >            tmpData.zconsPos = j->param.zTargetPos;
127 >            zconsData.push_back(tmpData);
128 >          }                
129  
130 <            } else {
131 <                for(int k =0 ; k < nFixedZmolsInProc[i]; ++k) {
132 <                    MPI_Recv(&zmolIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD,&ierr);
133 <                    MPI_Recv(data, 3, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&ierr);
134 <                    tmpData.zmolIndex = zmolIndex;
135 <                    tmpData.zforce= data[0];
136 <                    tmpData.zpos = data[1];
137 <                    tmpData.zconsPos = data[2];
138 <                    zconsData.push_back(tmpData);                                        
139 <                }
140 <            }
130 >        } else {
131 >          for(int k =0 ; k < nFixedZmolsInProc[i]; ++k) {
132 >            MPI_Recv(&zmolIndex, 1, MPI_INT, i, 0, MPI_COMM_WORLD,&ierr);
133 >            MPI_Recv(data, 3, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,&ierr);
134 >            tmpData.zmolIndex = zmolIndex;
135 >            tmpData.zforce= data[0];
136 >            tmpData.zpos = data[1];
137 >            tmpData.zconsPos = data[2];
138 >            zconsData.push_back(tmpData);                                        
139 >          }
140 >        }
141              
142 <        }
142 >      }
143  
144  
145 <        output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() << std::endl;
146 <        output_ << zconsData.size() << std::endl;
145 >      output_ << info_->getSnapshotManager()->getCurrentSnapshot()->getTime() << std::endl;
146 >      output_ << zconsData.size() << std::endl;
147  
148 <        std::vector<ZconsData>::iterator l;
149 <        for (l = zconsData.begin(); l != zconsData.end(); ++l) {
150 <            output_ << l->zmolIndex << "\t" << l->zforce << "\t" << l->zpos << "\t" <<  l->zconsPos << std::endl;
151 <        }
148 >      std::vector<ZconsData>::iterator l;
149 >      for (l = zconsData.begin(); l != zconsData.end(); ++l) {
150 >        output_ << l->zmolIndex << "\t" << l->zforce << "\t" << l->zpos << "\t" <<  l->zconsPos << std::endl;
151 >      }
152          
153      } else {
154  
155 <        std::list<ZconstraintMol>::const_iterator j;
156 <        for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
157 <            zmolIndex = j->mol->getGlobalIndex();            
158 <            data[0] = j->fz;
159 <            data[1] = j->zpos;
160 <            data[2] = j->param.zTargetPos;
161 <            MPI_Send(&zmolIndex, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
162 <            MPI_Send(data, 3, MPI_DOUBLE, masterNode, 0, MPI_COMM_WORLD);
155 >      std::list<ZconstraintMol>::const_iterator j;
156 >      for (j = fixedZmols.begin(); j != fixedZmols.end(); ++j) {
157 >        zmolIndex = j->mol->getGlobalIndex();            
158 >        data[0] = j->fz;
159 >        data[1] = j->zpos;
160 >        data[2] = j->param.zTargetPos;
161 >        MPI_Send(&zmolIndex, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD);
162 >        MPI_Send(data, 3, MPI_DOUBLE, masterNode, 0, MPI_COMM_WORLD);
163              
164 <        }
164 >      }
165      }
166   #endif
167 < }
167 >  }
168  
169   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines