From: David Wells Date: Mon, 11 Dec 2017 00:19:26 +0000 (-0500) Subject: Fix a file creation check. X-Git-Tag: v9.0.0-rc1~668^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e60859bba2dc399316738aa74cc27a91b282d54b;p=dealii.git Fix a file creation check. Commit 1cdbeecc858 is broken when step-42 is run with multiple MPI processes. --- 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;