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