Skip to content

Commit 2ad7819

Browse files
authored
Merge pull request ComputationalRadiationPhysics#5403 from psychocoderHPC/fix-folderCreation
fix folder creation
2 parents 0c243cb + b024bcf commit 2ad7819

File tree

8 files changed

+62
-36
lines changed

8 files changed

+62
-36
lines changed

include/picongpu/plugins/PhaseSpace/PhaseSpace.x.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,6 @@ namespace picongpu
318318

319319
if(activatePlugin)
320320
{
321-
/** create dir */
322-
pmacc::Filesystem::get().createDirectoryWithPermissions("phaseSpace");
323-
324321
uint32_t const r_element = axis_element.space;
325322

326323
/* CORE + BORDER elements for spatial bins */
@@ -382,6 +379,12 @@ namespace picongpu
382379
std::lower_bound(planeReduceRootRanks.begin(), planeReduceRootRanks.end(), 0),
383380
planeReduceRootRanks.end());
384381

382+
if(static_cast<int>(gc.getGlobalRank()) == ranks.front())
383+
{
384+
/** only one rank is creating the output directory */
385+
pmacc::Filesystem::get().createDirectoryWithPermissions("phaseSpace");
386+
}
387+
385388
MPI_CHECK(MPI_Comm_group(MPI_COMM_WORLD, &world_group));
386389
MPI_CHECK(MPI_Group_incl(world_group, ranks.size(), ranks.data(), &new_group));
387390
MPI_CHECK(MPI_Comm_create(MPI_COMM_WORLD, new_group, &commFileWriter));

include/picongpu/plugins/makroParticleCounter/PerSuperCell.x.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,14 @@ namespace picongpu
185185
DataSpace<simDim> localSuperCells(subGrid.getLocalDomain().size / SuperCellSize::toRT());
186186
localResult = std::make_unique<GridBufferType>(localSuperCells);
187187

188-
/* create folder for hdf5 files*/
189-
pmacc::Filesystem::get().createDirectoryWithPermissions(foldername);
188+
GridController<simDim>& gc = Environment<simDim>::get().GridController();
189+
if(gc.getGlobalRank() == 0)
190+
{
191+
/* Only one rank is allowed to create the directory.
192+
* All ranks participate the IO therefore selecting rank zero is fine.
193+
*/
194+
pmacc::Filesystem::get().createDirectoryWithPermissions(foldername);
195+
}
190196
}
191197
}
192198

include/picongpu/plugins/openPMD/openPMDWriter.x.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,16 +1126,26 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
11261126

11271127
Environment<>::get().PluginConnector().setNotificationPeriod(this, emplaced->second.periods());
11281128

1129-
/** create output directory */
1130-
pmacc::Filesystem::get().createDirectoryWithPermissions(outputDirectory);
1129+
if(gc.getGlobalRank() == 0)
1130+
{
1131+
/* Only one rank is allowed to create the directory.
1132+
* All ranks participate the IO therefore selecting rank zero is fine.
1133+
*/
1134+
pmacc::Filesystem::get().createDirectoryWithPermissions(outputDirectory);
1135+
}
11311136
}
11321137
else if(not tomlSourcesSpecified && notifyPeriodSpecified)
11331138
{
11341139
std::string const& notifyPeriod = m_help->notifyPeriod.get(id);
11351140
Environment<>::get().PluginConnector().setNotificationPeriod(this, notifyPeriod);
11361141

1137-
/** create output directory */
1138-
pmacc::Filesystem::get().createDirectoryWithPermissions(outputDirectory);
1142+
if(gc.getGlobalRank() == 0)
1143+
{
1144+
/* Only one rank is allowed to create the directory.
1145+
* All ranks participate the IO therefore selecting rank zero is fine.
1146+
*/
1147+
pmacc::Filesystem::get().createDirectoryWithPermissions(outputDirectory);
1148+
}
11391149
}
11401150
else
11411151
{

include/picongpu/plugins/output/images/PngCreator.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ namespace picongpu
101101
}
102102

103103
private:
104+
/** Write image to disk
105+
*
106+
* @attention Only one MPI rank is allowed to call this method.
107+
*/
104108
template<typename T_DataType>
105109
void createImage(std::shared_ptr<std::vector<T_DataType>> imageBuffer, MessageHeader const header);
106110

include/picongpu/plugins/particleCalorimeter/ParticleCalorimeter.x.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,15 @@ namespace picongpu
209209

210210
void checkpoint(uint32_t currentStep, std::string const& checkpointDirectory) override
211211
{
212-
/*
213-
* Create folder for openPMD checkpoint files.
214-
* openPMD would also do it automatically, but let's keep things explicit.
215-
*/
216-
pmacc::Filesystem::get().createDirectoryWithPermissions(checkpointDirectory + "/" + this->foldername);
212+
GridController<simDim>& gc = Environment<simDim>::get().GridController();
213+
if(gc.getGlobalRank() == 0)
214+
{
215+
/*
216+
* Create folder for openPMD checkpoint files.
217+
* openPMD would also do it automatically, but let's keep things explicit.
218+
*/
219+
pmacc::Filesystem::get().createDirectoryWithPermissions(checkpointDirectory + "/" + this->foldername);
220+
}
217221
auto dataSize = this->dBufLeftParsCalorimeter->capacityND();
218222
HBufCalorimeter hBufLeftParsCalorimeter(dataSize);
219223
HBufCalorimeter hBufTotal(dataSize);
@@ -356,8 +360,12 @@ namespace picongpu
356360
this->calorimeterFrameVecY,
357361
this->calorimeterFrameVecZ);
358362

359-
/* create folder for openPMD files*/
360-
pmacc::Filesystem::get().createDirectoryWithPermissions(this->foldername);
363+
bool const isIORank = this->allGPU_reduce->hasResult(mpi::reduceMethods::Reduce());
364+
if(isIORank)
365+
{
366+
/* create folder for openPMD files*/
367+
pmacc::Filesystem::get().createDirectoryWithPermissions(this->foldername);
368+
}
361369

362370
// set how often the plugin should be executed while PIConGPU is running
363371
Environment<>::get().PluginConnector().setNotificationPeriod(this, m_help->notifyPeriod.get(m_id));

include/pmacc/mappings/simulation/Filesystem.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,9 @@ namespace pmacc
4646

4747
void Filesystem::createDirectoryWithPermissions(std::string const dir) const
4848
{
49-
auto const mpiRank = Environment<>::get().EnvironmentController().getCommunicator().getRank();
50-
bool const isRootRank = mpiRank == 0;
51-
52-
if(isRootRank)
53-
{
54-
createDirectory(dir);
55-
/* must be set by only one process to avoid races */
56-
setDirectoryPermissions(dir);
57-
}
49+
createDirectory(dir);
50+
/* must be set by only one process to avoid races */
51+
setDirectoryPermissions(dir);
5852
}
5953

6054
std::string Filesystem::basename(std::string const pathFilename) const

include/pmacc/mappings/simulation/Filesystem.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,36 @@ namespace pmacc
3434
class Filesystem
3535
{
3636
public:
37-
/**
38-
* Create directory with default permissions
37+
/** Create directory with default permissions
38+
*
39+
* @attention Only one MPI rank is allowed to call this method.
3940
*
4041
* @param dir name of directory
4142
*/
4243
void createDirectory(std::string const dir) const;
43-
/**
44-
* Set 755 permissions for a directory
44+
/** Set 755 permissions for a directory
45+
*
46+
* @attention Only one MPI rank is allowed to call this method.
4547
*
4648
* @param dir name of directory
4749
*/
4850
void setDirectoryPermissions(std::string const dir) const;
4951

50-
/**
51-
* Create directory and set 755 permissions by root rank.
52+
/** Create directory and set 755 permissions by root rank.
53+
*
54+
* @attention Only one MPI rank is allowed to call this method.
5255
*
5356
* @param dir name of directory
5457
*/
5558
void createDirectoryWithPermissions(std::string const dir) const;
5659

57-
/**
58-
* Strip path from absolute or relative paths to filenames
60+
/** Strip path from absolute or relative paths to filenames
5961
*
6062
* @param path and filename
6163
*/
6264
std::string basename(std::string const pathFilename) const;
6365

64-
/**
65-
* Returns the instance of the filesystem class.
66+
/** Returns the instance of the filesystem class.
6667
*
6768
* This class is a singleton class.
6869
*

include/pmacc/simulationControl/SimulationHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace pmacc
111111
MPI_CHECK(MPI_Barrier(gc.getCommunicator().getMPIComm()));
112112

113113
/* create directory containing checkpoints */
114-
if(numCheckpoints == 0)
114+
if(numCheckpoints == 0 && gc.getGlobalRank() == 0)
115115
{
116116
pmacc::Filesystem::get().createDirectoryWithPermissions(checkpointDirectory);
117117
}

0 commit comments

Comments
 (0)