Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TMPIFile.h
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Amit Bashyal, August 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TMPIFile
13#define ROOT_TMPIFile
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// TMPIFile //
18// //
19// File Object derived from TMemFile. //
20// //
21// The TMPIFile class provides the ability to aggregate data across //
22// many MPI ranks on a cluster into a single file. This can be useful //
23// on HPCs or large clusters. The user must control the syncronization //
24// of the data across multiple ranks via the Sync() function. //
25// When Sync() is called, this triggers objects in the TFile space to //
26// be communicated over MPI to a master writer which combines the data //
27// before writing it to file. //
28// //
29//////////////////////////////////////////////////////////////////////////
30
31#include "TMPIClientInfo.h"
32#include "TBits.h"
33#include "TFileMerger.h"
34#include "TMemFile.h"
35
36#include <mpi.h>
37
38#include <vector>
39
40class TMPIFile : public TMemFile {
41
42private:
43 Int_t fEndProcess = 0; // collector tracks number of exited processes
44 Int_t fSplitLevel; // number of collectors to use
45 Int_t fMPIColor; // used by MPI ranks to track which collector to use
46
47 Int_t fMPIGlobalRank; // global rank number
48 Int_t fMPIGlobalSize; // total ranks
49 Int_t fMPILocalRank; // rank number in sub communicator
50 Int_t fMPILocalSize; // number of ranks in sub communicator
51
52 MPI_Comm fSubComm; // sub communicator handle
53 MPI_Request fMPIRequest; // request place holder
54
55 TString fMPIFilename; // output filename, only used by collector
56
57 char *fSendBuf = 0; // message buffer, only used by worker
58
59 struct ParallelFileMerger : public TObject {
60 private:
61 using ClientColl_t = std::vector<TMPIClientInfo>;
62
69
70 static void DeleteObject(TDirectory *dir, Bool_t withReset);
71
72 public:
73 ParallelFileMerger(const char *filename, Int_t compression_settings, Bool_t writeCache = kFALSE);
74 ~ParallelFileMerger() override;
75
76 ULong_t Hash() const override { return fFilename.Hash(); };
77 const char *GetName() const override { return fFilename; };
78
80
82 Bool_t Merge();
83 Bool_t NeedMerge(Float_t clientThreshold);
84 Bool_t NeedFinalMerge() { return fClientsContact.CountBits() > 0; };
85 void RegisterClient(UInt_t clientID, TFile *file);
86 };
87
88 void SetOutputName();
89 void CheckSplitLevel();
90 void SplitMPIComm();
91 void UpdateEndProcess();
92
94
95public:
96 TMPIFile(const char *name, char *buffer, Long64_t size = 0, Option_t *option = "", Int_t split = 1,
97 const char *ftitle = "", Int_t compress = 4);
98 TMPIFile(const char *name, Option_t *option = "", Int_t split = 1, const char *ftitle = "",
99 Int_t compress = 4); // no complete implementation
100 ~TMPIFile() override;
101
102 // some functions on MPI information
107 Int_t GetMPIColor() const { return fMPIColor; };
108 Int_t GetSplitLevel() const { return fSplitLevel; };
109
111
112 // Collector Functions
113 void RunCollector(Bool_t cache = kFALSE);
115
116 // Sender Functions
117 void CreateBufferAndSend();
118 // Empty Buffer to signal the end of job...
120 void Sync();
121
122 // Finalize work and save output in disk.
123 void Close(Option_t *option = "") final;
124
126};
127#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
char name[80]
Definition TGX11.cxx:148
Container of bits.
Definition TBits.h:26
Describe directory structure in memory.
Definition TDirectory.h:45
This class provides file copy and merging services.
Definition TFileMerger.h:30
TFile(const TFile &)=delete
void CheckSplitLevel()
Checks that the split level is more than one.
Definition TMPIFile.cxx:486
Int_t fSplitLevel
Definition TMPIFile.h:44
char * fSendBuf
Definition TMPIFile.h:57
Int_t GetSplitLevel() const
Definition TMPIFile.h:108
void CreateEmptyBufferAndSend()
For Workers: Creates an empty buffer and sends it to the Collector.
Definition TMPIFile.cxx:412
~TMPIFile() override
TMPIFile destructor.
Definition TMPIFile.cxx:93
Int_t fMPIGlobalRank
Definition TMPIFile.h:47
Int_t GetMPIGlobalRank() const
Definition TMPIFile.h:105
void CreateBufferAndSend()
Called by the Workers only: Copies the current content in memory and sends it asynchronously to the C...
Definition TMPIFile.cxx:395
Int_t fMPILocalSize
Definition TMPIFile.h:50
Bool_t IsReceived()
Checks the member MPI_REQEUST object to see if a message has been received.
Definition TMPIFile.cxx:541
Int_t GetMPIColor() const
Definition TMPIFile.h:107
void UpdateEndProcess()
As worker ranks exit, they send the collector empty messages.
Definition TMPIFile.cxx:110
Bool_t IsCollector()
return True if this is the Collector rank, otherwise False
Definition TMPIFile.cxx:385
Int_t fMPIColor
Definition TMPIFile.h:45
TString fMPIFilename
Definition TMPIFile.h:55
void SetOutputName()
Called by the Collector only: edits the input filename from the user to append the rank ID of the Col...
Definition TMPIFile.cxx:468
void RunCollector(Bool_t cache=kFALSE)
This is the core of the Collector rank which listens for incoming messages from Worker ranks.
Definition TMPIFile.cxx:119
Int_t fMPILocalRank
Definition TMPIFile.h:49
Int_t fMPIGlobalSize
Definition TMPIFile.h:48
Int_t fEndProcess
Definition TMPIFile.h:43
TMPIFile(const char *name, char *buffer, Long64_t size=0, Option_t *option="", Int_t split=1, const char *ftitle="", Int_t compress=4)
TMPIFile constructor.
Definition TMPIFile.cxx:58
void Sync()
Called by the Workers only: Called periodically by workers and triggers the sending of data to the Co...
Definition TMPIFile.cxx:430
MPI_Comm fSubComm
Definition TMPIFile.h:52
Int_t GetMPILocalSize() const
Definition TMPIFile.h:104
Int_t GetMPILocalRank() const
Definition TMPIFile.h:106
void SplitMPIComm()
Called by all ranks to create the sub communicators (if more than one rank).
Definition TMPIFile.cxx:498
Int_t GetMPIGlobalSize() const
Definition TMPIFile.h:103
MPI_Request fMPIRequest
Definition TMPIFile.h:53
TString GetMPIFilename() const
Definition TMPIFile.h:110
TMemFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Long64_t defBlockSize=0LL)
Usual Constructor.
Definition TMemFile.cxx:161
TObject()
TObject constructor.
Definition TObject.h:259
Basic string class.
Definition TString.h:138
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:45
auto filename
void file()
Definition file.C:11
s0 Close()
void dir(char *path=0)
Definition rootalias.C:42
ULong_t Hash() const override
Return hash value for this object.
Definition TMPIFile.h:76
Bool_t NeedMerge(Float_t clientThreshold)
Return true, if enough client have reported.
Definition TMPIFile.cxx:355
const char * GetName() const override
Returns name of object.
Definition TMPIFile.h:77
void RegisterClient(UInt_t clientID, TFile *file)
Register that a client has sent a file.
Definition TMPIFile.cxx:336
Bool_t Merge()
Merge the current inputs into the output file.
Definition TMPIFile.cxx:297
Bool_t InitialMerge(TFile *input)
Initial merge of the input to copy the resetable object (TTree) into the output and remove them from ...
Definition TMPIFile.cxx:281
~ParallelFileMerger() override
Deconstructor for ParallelFileMerger class.
Definition TMPIFile.cxx:213
std::vector< TMPIClientInfo > ClientColl_t
Definition TMPIFile.h:61
ParallelFileMerger(const char *filename, Int_t compression_settings, Bool_t writeCache=kFALSE)
Constructor for ParallelFileMerger class.
Definition TMPIFile.cxx:195
static void DeleteObject(TDirectory *dir, Bool_t withReset)
Definition TMPIFile.cxx:219
static Bool_t NeedInitialMerge(TDirectory *dir)
Definition TMPIFile.cxx:250