From e60859bba2dc399316738aa74cc27a91b282d54b Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 10 Dec 2017 19:19:26 -0500 Subject: [PATCH] Fix a file creation check. Commit 1cdbeecc858 is broken when step-42 is run with multiple MPI processes. --- examples/step-42/step-42.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/step-42/step-42.cc b/examples/step-42/step-42.cc index 03b74f5b7b..da6eded48b 100644 --- a/examples/step-42/step-42.cc +++ b/examples/step-42/step-42.cc @@ -74,9 +74,11 @@ #include #include -// This final include file provides the mkdir function -// that we will use to create a directory for output files, if necessary: +// Finally, we include two system headers that let us create a directory for +// output files. The first header provides the mkdir function and +// the second lets us determine what happened if mkdir fails. #include +#include namespace Step42 { @@ -876,8 +878,13 @@ namespace Step42 output_dir = prm.get("output directory"); if (output_dir != "" && *(output_dir.rbegin()) != '/') output_dir += "/"; - const int ierr = mkdir(output_dir.c_str(), 0777); - AssertThrow(ierr == 0, ExcIO()); + + // If necessary, create a new directory for the output. + if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0) + { + const int ierr = mkdir(output_dir.c_str(), 0777); + AssertThrow(ierr == 0 || errno == EEXIST, ExcIO()); + } pcout << " Using output directory '" << output_dir << "'" << std::endl; pcout << " FE degree " << fe_degree << std::endl; -- 2.39.5