Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -27,49 +27,47 @@
|
||||
// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMpiNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
#include "tools/wroot/mpi_ntuple_column_wise"
|
||||
#include "tools/wroot/mpi_ntuple_row_wise"
|
||||
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
const int kTAG_NTUPLE = 1004; // This constant is defined in G4MPImanager
|
||||
// (should be passed from the application)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleManager::G4RootMpiNtupleManager(
|
||||
const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManager,
|
||||
G4bool rowWise, G4bool rowMode,
|
||||
tools::impi* impi, G4int mpiSize)
|
||||
: G4RootNtupleManager(state, bookingManager, 0, 0, rowWise, rowMode),
|
||||
fImpi(impi),
|
||||
fSlaveRanks(),
|
||||
fMainRank(0)
|
||||
const G4AnalysisManagerState& state, std::shared_ptr<G4NtupleBookingManager> bookingManager,
|
||||
G4bool rowWise, G4bool rowMode, tools::impi* impi, G4int mpiSize)
|
||||
: G4RootNtupleManager(state, bookingManager, 0, 0, rowWise, rowMode),
|
||||
fImpi(impi),
|
||||
fSlaveRanks(),
|
||||
fMainRank(0)
|
||||
{
|
||||
for ( G4int rank = 0; rank < mpiSize; rank++ ) {
|
||||
for (G4int rank = 0; rank < mpiSize; rank++) {
|
||||
fSlaveRanks.push_back(rank);
|
||||
}
|
||||
fMainRank = mpiSize;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMpiNtupleManager::~G4RootMpiNtupleManager()
|
||||
{}
|
||||
G4RootMpiNtupleManager::~G4RootMpiNtupleManager() {}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescription)
|
||||
{
|
||||
// Pack and send the main ntuple data to the slave ranks
|
||||
// Pack and send the main ntuple data to the slave ranks
|
||||
|
||||
// G4cout << "Going to send main ntuple data " << G4endl;
|
||||
// G4cout << "ntupleDescription: " << ntupleDescription << G4endl;
|
||||
@@ -78,11 +76,12 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
// Get ntuple
|
||||
auto ntuple = ntupleDescription->GetNtuple();
|
||||
|
||||
// Get basket sizes
|
||||
// Get basket sizes
|
||||
std::vector<tools::wroot::branch*> mainBranches;
|
||||
ntuple->get_branches(mainBranches);
|
||||
std::vector<tools::uint32> basketSizes;
|
||||
tools_vforcit(tools::wroot::branch*, mainBranches, it) {
|
||||
tools_vforcit(tools::wroot::branch*, mainBranches, it)
|
||||
{
|
||||
basketSizes.push_back((*it)->basket_size());
|
||||
}
|
||||
|
||||
@@ -92,57 +91,58 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
tools::uint32 basketSize = fFileManager->GetBasketSize();
|
||||
unsigned int basketEntries = fFileManager->GetBasketEntries();
|
||||
|
||||
for ( auto slaveRank : fSlaveRanks ) {
|
||||
for (auto slaveRank : fSlaveRanks) {
|
||||
// G4cout << "Going to send main ntuple data to slave rank " << slaveRank << G4endl;
|
||||
|
||||
fImpi->pack_reset();
|
||||
if ( ! fImpi->pack(id)) {
|
||||
G4cerr << "pack(id) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->bpack(fRowWise) ) {
|
||||
G4cerr << "bpack(fRowWise) failed."<< G4endl;
|
||||
if (!fImpi->pack(id)) {
|
||||
G4cerr << "pack(id) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->bpack(ntupleFile->byte_swap())) {
|
||||
G4cerr << "bpack(byte_swap) failed." << G4endl;
|
||||
if (!fImpi->bpack(fRowWise)) {
|
||||
G4cerr << "bpack(fRowWise) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->pack(ntupleFile->compression()) ) {
|
||||
G4cerr << "pack(compression) failed." << G4endl;
|
||||
return false;
|
||||
|
||||
if (!fImpi->bpack(ntupleFile->byte_swap())) {
|
||||
G4cerr << "bpack(byte_swap) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! fImpi->pack(ntupleFile->dir().seek_directory())) {
|
||||
|
||||
if (!fImpi->pack(ntupleFile->compression())) {
|
||||
G4cerr << "pack(compression) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fImpi->pack(ntupleFile->dir().seek_directory())) {
|
||||
// Should be used fNtupleDirectory ??
|
||||
G4cerr << "pack(seek) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( fRowWise ) {
|
||||
if ( ! fImpi->pack(basketSize) ) {
|
||||
if (fRowWise) {
|
||||
if (!fImpi->pack(basketSize)) {
|
||||
G4cerr << "pack(basketSize) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( ! fImpi->bpack(fRowMode) ) {
|
||||
}
|
||||
else {
|
||||
if (!fImpi->bpack(fRowMode)) {
|
||||
G4cerr << "bpack(fRowMode) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
if ( ! fImpi->vpack(basketSizes) ) {
|
||||
}
|
||||
if (!fImpi->vpack(basketSizes)) {
|
||||
G4cerr << "vpack(basketSizes) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
if ( ! fImpi->pack(basketEntries) ) {
|
||||
if (!fImpi->pack(basketEntries)) {
|
||||
G4cerr << "pack(basketEntries) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! fImpi->send_buffer(slaveRank, kTAG_NTUPLE )) {
|
||||
if (!fImpi->send_buffer(slaveRank, kTAG_NTUPLE)) {
|
||||
G4cerr << "send_buffer() failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ G4bool G4RootMpiNtupleManager::Send(G4int id, RootNtupleDescription* ntupleDescr
|
||||
|
||||
G4cout << "Sent ntuple description to slave on rank " << slaveRank << G4endl;
|
||||
}
|
||||
|
||||
|
||||
// G4cout << "Done: send main ntuple data " << G4endl;
|
||||
return true;
|
||||
}
|
||||
@@ -163,59 +163,57 @@ G4bool G4RootMpiNtupleManager::InitializeRanks()
|
||||
auto finalResult = true;
|
||||
|
||||
auto counter = 0;
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! ntupleDescription->GetActivation() ) ) continue;
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// Do not create ntuple if it is inactivated
|
||||
if (fState.GetIsActivation() && (!ntupleDescription->GetActivation())) continue;
|
||||
|
||||
auto result = Send(counter++, ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
{
|
||||
// Receive the pntuple data from the slave ranks
|
||||
// For the time being only one ntuple
|
||||
// Receive the pntuple data from the slave ranks
|
||||
// For the time being only one ntuple
|
||||
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer" << G4endl;
|
||||
|
||||
unsigned long numberOfEndFill = 0;
|
||||
|
||||
|
||||
G4bool verbose = IsVerbose(kVL2);
|
||||
|
||||
while ( true ) {
|
||||
while (true) {
|
||||
fImpi->pack_reset();
|
||||
|
||||
// loop until receiving end_fill from all ranks
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer entering loop" << G4endl;
|
||||
int probe_src;
|
||||
if ( ! fImpi->wait_buffer(fMainRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
if (!fImpi->wait_buffer(fMainRank, kTAG_NTUPLE, probe_src, verbose)) {
|
||||
G4cerr << "!!! wait_buffer() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
tools::uint32 protocol;
|
||||
if ( ! fImpi->unpack(protocol)) {
|
||||
G4cerr << "unpack(protocol) failed."<< G4endl;
|
||||
if (!fImpi->unpack(protocol)) {
|
||||
G4cerr << "unpack(protocol) failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( protocol == tools::wroot::mpi_protocol_basket() ) {
|
||||
|
||||
if (protocol == tools::wroot::mpi_protocol_basket()) {
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_basket" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -224,24 +222,24 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// add basket to main ntuple
|
||||
if ( ! mainNtuple->mpi_add_basket(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_basket() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
if (!mainNtuple->mpi_add_basket(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_basket() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ( protocol == tools::wroot::mpi_protocol_baskets() ) {
|
||||
//column_wise and row_mode only.
|
||||
}
|
||||
else if (protocol == tools::wroot::mpi_protocol_baskets()) {
|
||||
// column_wise and row_mode only.
|
||||
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_baskets" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -250,40 +248,39 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// add basket to main ntuple
|
||||
if ( ! mainNtuple->mpi_add_baskets(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_baskets() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
if (!mainNtuple->mpi_add_baskets(*fImpi)) {
|
||||
std::cerr << "mainNtuple->mpi_add_baskets() failed." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ( protocol==tools::wroot::mpi_protocol_end_fill() ) {
|
||||
|
||||
}
|
||||
else if (protocol == tools::wroot::mpi_protocol_end_fill()) {
|
||||
// G4cout << "G4RootMpiNtupleManager::WaitBuffer got protocol_end_fill" << G4endl;
|
||||
|
||||
|
||||
// get ntuple Id
|
||||
tools::uint32 ntupleId;
|
||||
if ( ! fImpi->unpack(ntupleId) ) {
|
||||
G4cerr << "unpack(ntuple_id) failed."<< std::endl;
|
||||
if (!fImpi->unpack(ntupleId)) {
|
||||
G4cerr << "unpack(ntuple_id) failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ntupleId >= fNtupleVector.size() ) {
|
||||
if (ntupleId >= fNtupleVector.size()) {
|
||||
std::cerr << "!!! unknown ntupleId " << ntupleId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Main ntuple
|
||||
auto mainNtuple = fNtupleVector[ntupleId];
|
||||
|
||||
// end_fill in main ntuple
|
||||
if ( ! mainNtuple->mpi_end_fill(*fImpi) ) {
|
||||
G4cerr << "main_ntuple->mpi_end_fill() failed." << std::endl;
|
||||
if (!mainNtuple->mpi_end_fill(*fImpi)) {
|
||||
G4cerr << "main_ntuple->mpi_end_fill() failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
numberOfEndFill++;
|
||||
|
||||
if ( numberOfEndFill == fSlaveRanks.size() ) break;
|
||||
}
|
||||
if (numberOfEndFill == fSlaveRanks.size()) break;
|
||||
}
|
||||
else {
|
||||
G4cerr << "unknown protocol " << protocol << G4endl;
|
||||
return false;
|
||||
@@ -293,30 +290,28 @@ G4bool G4RootMpiNtupleManager::WaitBuffer()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMpiNtupleManager::CreateNtuplesFromBooking(
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
{
|
||||
// G4cout << "G4RootMpiNtupleManager::CreateNtuplesFromBooking()" << G4endl;
|
||||
|
||||
// Call base class method
|
||||
G4TNtupleManager<tools::wroot::ntuple,G4RootFile>::CreateNtuplesFromBooking(
|
||||
ntupleBookings);
|
||||
G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::CreateNtuplesFromBooking(ntupleBookings);
|
||||
|
||||
// Initialize ranks
|
||||
if ( ! InitializeRanks() ) {
|
||||
if (!InitializeRanks()) {
|
||||
G4cerr << "InitializeRanks failed." << G4endl;
|
||||
}
|
||||
|
||||
// Go to wait buffer mode
|
||||
if ( ! WaitBuffer() ) {
|
||||
if (!WaitBuffer()) {
|
||||
G4cerr << "WaitBuffer failed." << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -326,10 +321,9 @@ G4bool G4RootMpiNtupleManager::Merge()
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! ntupleDescription->GetActivation() ) ) continue;
|
||||
for (auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
// Do not create ntuple if it is inactivated
|
||||
if (fState.GetIsActivation() && (!ntupleDescription->GetActivation())) continue;
|
||||
|
||||
// G4cout << "Go to call merge_number_of_entries" << G4endl;
|
||||
ntupleDescription->GetNtuple()->merge_number_of_entries();
|
||||
|
||||
Reference in New Issue
Block a user