35 #include "tools/wroot/file"
36 #include "tools/wroot/mpi_ntuple_row_wise"
37 #include "tools/wroot/mpi_ntuple_column_wise"
39 using namespace G4Analysis;
48 tools::impi* impi,
G4int mpiSize)
54 for (
G4int rank = 0; rank < mpiSize; rank++ ) {
77 std::vector<tools::wroot::branch*> mainBranches;
78 ntuple->get_branches(mainBranches);
79 std::vector<tools::uint32> basketSizes;
80 tools_vforcit(tools::wroot::branch*, mainBranches,
it) {
81 basketSizes.push_back((*it)->basket_size());
85 tools::uint32 basketSize =
fFileManager->GetBasketSize();
86 unsigned int basketEntries =
fFileManager->GetBasketEntries();
89 G4cout <<
"Going to send main ntuple data to slave rank " << slaveRank <<
G4endl;
92 if ( !
fImpi->pack(
id)) {
102 if ( !
fImpi->bpack(ntupleFile->byte_swap())) {
107 if ( !
fImpi->pack(ntupleFile->compression()) ) {
112 if ( !
fImpi->pack(ntupleFile->dir().seek_directory())) {
119 if ( !
fImpi->pack(basketSize) ) {
128 if ( !
fImpi->vpack(basketSizes) ) {
132 if ( !
fImpi->pack(basketEntries) ) {
144 G4cout <<
"Sent ntuple description to slave on rank " << slaveRank <<
G4endl;
156 auto finalResult =
true;
164 auto result =
Send(counter++, ntupleDescription->fNtuple);
165 finalResult = finalResult && result;
179 unsigned long numberOfEndFill = 0;
190 G4cerr <<
"!!! wait_buffer() failed." << std::endl;
194 tools::uint32 protocol;
195 if ( !
fImpi->unpack(protocol)) {
200 if ( protocol == tools::wroot::mpi_protocol_basket() ) {
205 tools::uint32 ntupleId;
206 if ( !
fImpi->unpack(ntupleId) ) {
207 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
212 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
220 if ( ! mainNtuple->mpi_add_basket(*
fImpi)) {
221 std::cerr <<
"mainNtuple->mpi_add_basket() failed." << std::endl;
225 else if ( protocol == tools::wroot::mpi_protocol_baskets() ) {
231 tools::uint32 ntupleId;
232 if ( !
fImpi->unpack(ntupleId) ) {
233 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
238 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
246 if ( ! mainNtuple->mpi_add_baskets(*
fImpi)) {
247 std::cerr <<
"mainNtuple->mpi_add_baskets() failed." << std::endl;
251 else if ( protocol==tools::wroot::mpi_protocol_end_fill() ) {
256 tools::uint32 ntupleId;
257 if ( !
fImpi->unpack(ntupleId) ) {
258 G4cerr <<
"unpack(ntuple_id) failed."<< std::endl;
263 std::cerr <<
"!!! unknown ntupleId " << ntupleId << std::endl;
271 if ( ! mainNtuple->mpi_end_fill(*
fImpi) ) {
272 G4cerr <<
"main_ntuple->mpi_end_fill() failed." << std::endl;
278 if ( numberOfEndFill ==
fSlaveRanks.size() )
break;
317 auto finalResult =
true;
325 ntupleDescription->fNtuple->merge_number_of_entries();