@@ -1392,25 +1392,58 @@ auto JSONIOHandlerImpl::putJsonContents(
13921392 return res;
13931393 };
13941394
1395- auto parallelImplementation =
1396- [this , &filename, &writeSingleFile, &num_digits](MPI_Comm comm) {
1397- auto path = fullPath (*filename);
1398- auto dirpath = path + " .parallel" ;
1399- if (!auxiliary::create_directories (dirpath))
1395+ auto parallelImplementation = [this ,
1396+ &filename,
1397+ &writeSingleFile,
1398+ &num_digits](MPI_Comm comm) {
1399+ auto path = fullPath (*filename);
1400+ auto dirpath = path + " .parallel" ;
1401+ if (!auxiliary::create_directories (dirpath))
1402+ {
1403+ throw std::runtime_error (
1404+ " Failed creating directory '" + dirpath +
1405+ " ' for parallel JSON output" );
1406+ }
1407+ int rank = 0 , size = 0 ;
1408+ MPI_Comm_rank (comm, &rank);
1409+ MPI_Comm_size (comm, &size);
1410+ std::stringstream subfilePath;
1411+ subfilePath << dirpath << " /mpi_rank_"
1412+ << std::setw (num_digits (size - 1 )) << std::setfill (' 0' )
1413+ << rank << " .json" ;
1414+ writeSingleFile (subfilePath.str ());
1415+ if (rank == 0 )
1416+ {
1417+ constexpr char const *readme_msg = R"(
1418+ This folder has been created by a parallel instance of the JSON backend in
1419+ openPMD. There is one JSON file for each parallel writer MPI rank.
1420+ The parallel JSON backend performs no metadata or data aggregation at all.
1421+
1422+ This functionality is intended mainly for debugging and prototyping workflows.
1423+ There is no support in the openPMD-api for reading this folder as a single
1424+ dataset. For reading purposes, either pick a single .json file and read that, or
1425+ merge the .json files somehow (no tooling provided for this (yet)).
1426+ )" ;
1427+ std::fstream readme_file;
1428+ readme_file.open (
1429+ dirpath + " /README.txt" ,
1430+ std::ios_base::out | std::ios_base::trunc);
1431+ readme_file << readme_msg + 1 ;
1432+ readme_file.close ();
1433+ if (!readme_file.good () &&
1434+ !filename.fileState ->printedReadmeWarningAlready )
14001435 {
1401- throw std::runtime_error (
1402- " Failed creating directory '" + dirpath +
1403- " ' for parallel JSON output" );
1436+ std::cerr
1437+ << " [Warning] Something went wrong in trying to create "
1438+ " README file at '"
1439+ << dirpath
1440+ << " /README.txt'. Will ignore and continue. The README "
1441+ " message would have been:\n ----------\n "
1442+ << readme_msg + 1 << " ----------" << std::endl;
1443+ filename.fileState ->printedReadmeWarningAlready = true ;
14041444 }
1405- int rank = 0 , size = 0 ;
1406- MPI_Comm_rank (comm, &rank);
1407- MPI_Comm_size (comm, &size);
1408- std::stringstream subfilePath;
1409- subfilePath << dirpath << " /mpi_rank_"
1410- << std::setw (num_digits (size - 1 ))
1411- << std::setfill (' 0' ) << rank << " .json" ;
1412- writeSingleFile (subfilePath.str ());
1413- };
1445+ }
1446+ };
14141447
14151448 std::shared_ptr<nlohmann::json> res;
14161449 if (m_communicator.has_value ())
0 commit comments