Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, 21/11/2018 (ivana 28 29 #include "G4RootMpiNtupleFileManager.hh" 30 31 #include "G4AnalysisUtilities.hh" 32 #include "G4RootMpiNtupleManager.hh" 33 #include "G4RootMpiPNtupleManager.hh" 34 35 #include <tools/impi> 36 37 using namespace G4Analysis; 38 using std::make_shared; 39 40 //____________________________________________ 41 G4RootMpiNtupleFileManager::G4RootMpiNtupleFil 42 : G4RootNtupleFileManager(state), 43 fImpi(nullptr), 44 fMpiRank(-1), 45 fMpiSize(0), 46 fMpiSlaveNtupleManager(nullptr), 47 fNtupleBooked(false) 48 {} 49 50 //____________________________________________ 51 G4RootMpiNtupleFileManager::~G4RootMpiNtupleFi 52 53 // 54 // private methods 55 // 56 57 //____________________________________________ 58 void G4RootMpiNtupleFileManager::SetMpiNtupleM 59 { 60 Message(kVL2, "set", "mpi ntuple merging mod 61 62 auto canMerge = true; 63 64 // Illegal situations 65 if (fMpiSize < 2) { 66 G4ExceptionDescription description; 67 description << "Merging ntuples is not app 68 << "Setting was ignored."; 69 G4Exception("G4RootMpiNtupleFileManager::S 70 JustWarning, description); 71 canMerge = false; 72 } 73 74 G4String mergingMode; 75 if (!canMerge) { 76 fNtupleMergeMode = G4NtupleMergeMode::kNon 77 mergingMode = "G4NtupleMergeMode::kNone"; 78 } 79 else { 80 // Set the number of reduced ntuple files 81 // (multiple output files are not yet supp 82 fNofNtupleFiles = nofNtupleFiles; 83 84 // Forced merging mode 85 // MPI 86 if (fMpiRank >= fMpiSize) { 87 // the extra worker 88 fNtupleMergeMode = G4NtupleMergeMode::kM 89 mergingMode = "G4NtupleMergeMode::kMain" 90 } 91 else { 92 // processing worker 93 fNtupleMergeMode = G4NtupleMergeMode::kS 94 mergingMode = "G4NtupleMergeMode::kSlave 95 } 96 } 97 98 Message(kVL1, "set", "mpi ntuple merging mod 99 } 100 101 // 102 // public methods 103 // 104 105 //____________________________________________ 106 void G4RootMpiNtupleFileManager::SetMpiNtupleM 107 108 { 109 if (fIsInitialized) { 110 G4ExceptionDescription description; 111 description << "Cannot change merging mode 112 << "The function must be calle 113 G4Exception("G4RootMpiNtupleFileManager::S 114 description); 115 return; 116 } 117 118 // Save MPI merging parameters 119 fImpi = impi; 120 fMpiRank = mpiRank; 121 fMpiSize = mpiSize; 122 123 // Set ntuple merging mode 124 SetMpiNtupleMergingMode(nofNtupleFiles); 125 } 126 127 //____________________________________________ 128 std::shared_ptr<G4VNtupleManager> G4RootMpiNtu 129 { 130 Message(kVL4, "create", "mpi ntuple manager" 131 132 std::shared_ptr<G4VNtupleManager> activeNtup 133 switch (fNtupleMergeMode) { 134 case G4NtupleMergeMode::kNone: 135 fNtupleManager = make_shared<G4RootNtupl 136 137 fNtupleManager->SetFileManager(fFileMana 138 activeNtupleManager = fNtupleManager; 139 break; 140 141 case G4NtupleMergeMode::kMain: { 142 fNtupleManager = make_shared<G4RootMpiNt 143 144 fNtupleManager->SetFileManager(fFileMana 145 activeNtupleManager = fNtupleManager; 146 break; 147 } 148 149 case G4NtupleMergeMode::kSlave: { 150 auto destinationRank = fMpiSize; 151 fMpiSlaveNtupleManager = 152 make_shared<G4RootMpiPNtupleManager>(f 153 activeNtupleManager = fMpiSlaveNtupleMan 154 break; 155 } 156 } 157 158 G4String mergeMode; 159 switch (fNtupleMergeMode) { 160 case G4NtupleMergeMode::kNone: 161 mergeMode = ""; 162 break; 163 case G4NtupleMergeMode::kMain: 164 mergeMode = "main "; 165 break; 166 case G4NtupleMergeMode::kSlave: 167 mergeMode = "slave "; 168 break; 169 } 170 Message(kVL3, "create", mergeMode + "mpi ntu 171 172 fIsInitialized = true; 173 174 return activeNtupleManager; 175 } 176 177 //____________________________________________ 178 G4bool G4RootMpiNtupleFileManager::ActionAtOpe 179 { 180 // No MPI merging, call base class 181 if (fNtupleMergeMode == G4NtupleMergeMode::k 182 return G4RootNtupleFileManager::ActionAtOp 183 } 184 185 if (!fNtupleBooked) { 186 G4String objectType = "analysis file"; 187 if (fNtupleMergeMode == G4NtupleMergeMode: 188 objectType = "main analysis file"; 189 } 190 Message(kVL4, "open", objectType, fileName 191 192 if (fNtupleMergeMode == G4NtupleMergeMode: 193 // Creating files is triggered from Crea 194 fNtupleManager->CreateNtuplesFromBooking 195 } 196 197 if (fNtupleMergeMode == G4NtupleMergeMode: 198 // G4cout << "Slave: Go to create ntuple 199 // No file is open by Slave manager 200 fMpiSlaveNtupleManager->CreateNtuplesFro 201 } 202 203 Message(kVL1, "open", objectType, fileName 204 205 fNtupleBooked = true; 206 } 207 208 return true; 209 } 210 211 //____________________________________________ 212 G4bool G4RootMpiNtupleFileManager::ActionAtWri 213 { 214 // No MPI merging, call base class 215 if (fNtupleMergeMode == G4NtupleMergeMode::k 216 return G4RootNtupleFileManager::ActionAtWr 217 } 218 219 auto result = true; 220 221 G4String ntupleType; 222 if (fNtupleMergeMode == G4NtupleMergeMode::k 223 if (fNtupleMergeMode == G4NtupleMergeMode::k 224 225 Message(kVL4, "merge", ntupleType); 226 227 if (fNtupleMergeMode == G4NtupleMergeMode::k 228 result &= fNtupleManager->Merge(); 229 } 230 231 if (fNtupleMergeMode == G4NtupleMergeMode::k 232 result &= fMpiSlaveNtupleManager->Merge(); 233 } 234 235 Message(kVL1, "merge", ntupleType, "", resul 236 237 return result; 238 } 239 240 //____________________________________________ 241 G4bool G4RootMpiNtupleFileManager::ActionAtClo 242 { 243 // No MPI merging, call base class 244 if (fNtupleMergeMode == G4NtupleMergeMode::k 245 return G4RootNtupleFileManager::ActionAtCl 246 } 247 248 if (fNtupleMergeMode == G4NtupleMergeMode::k 249 fMpiSlaveNtupleManager->SetNewCycle(false) 250 return true; 251 } 252 253 return CloseNtupleFiles(); 254 } 255 256 //____________________________________________ 257 G4bool G4RootMpiNtupleFileManager::Reset() 258 { 259 // Reset ntuples 260 261 // No MPI merging, call base class 262 if (fNtupleMergeMode == G4NtupleMergeMode::k 263 return G4RootNtupleFileManager::Reset(); 264 } 265 266 auto result = true; 267 268 if (fNtupleMergeMode == G4NtupleMergeMode::k 269 result &= fNtupleManager->Reset(); 270 } 271 272 if (fNtupleMergeMode == G4NtupleMergeMode::k 273 result &= fMpiSlaveNtupleManager->Reset(); 274 } 275 276 return result; 277 } 278