Fix this by determining when &input=&output and in that case pass MPI_IN_PLACE.
<h3>Specific improvements</h3>
<ol>
+ <li> Fixed: The vector and array versions of Utilities::MPI::sum() and
+ Utilities::MPI::max() produced segmentation faults with some MPI implementations
+ if the input and output arguments were the same. This is now fixed.
+ <br>
+ (Wolfgang Bangerth, 2014/09/29)
+ </li>
+
<li> Fixed: Trying to have FE_Q(p) and FE_DGQ(r) elements next to each
other in an hp::DoFHandler object led to assertions saying that these two
elements don't know how to compute interface constraints where such
* array of length N. In other words, the i-th element of the results
* array is the sum over the i-th entries of the input arrays from each
* processor.
+ *
+ * Input and output arrays may be the same.
*/
template <typename T, unsigned int N>
inline
* Like the previous function, but take the sums over the elements of a
* std::vector. In other words, the i-th element of the results array is
* the sum over the i-th entries of the input arrays from each processor.
+ *
+ * Input and output vectors may be the same.
*/
template <typename T>
inline
* array of length N. In other words, the i-th element of the results
* array is the maximum of the i-th entries of the input arrays from each
* processor.
+ *
+ * Input and output arrays may be the same.
*/
template <typename T, unsigned int N>
inline
* std::vector. In other words, the i-th element of the results array is
* the maximum over the i-th entries of the input arrays from each
* processor.
+ *
+ * Input and output vectors may be the same.
*/
template <typename T>
inline
T (&sums)[N])
{
#ifdef DEAL_II_WITH_MPI
- MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
+ MPI_Allreduce ((&values[0] != &sums[0]
+ ?
+ const_cast<void *>(static_cast<const void *>(&values[0]))
+ :
+ MPI_IN_PLACE),
&sums[0], N, internal::mpi_type_id(values), MPI_SUM,
mpi_communicator);
#else
{
#ifdef DEAL_II_WITH_MPI
sums.resize (values.size());
- MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
+ MPI_Allreduce ((&values[0] != &sums[0]
+ ?
+ const_cast<void *>(static_cast<const void *>(&values[0]))
+ :
+ MPI_IN_PLACE),
&sums[0], values.size(), internal::mpi_type_id((T *)0), MPI_SUM,
mpi_communicator);
#else
T (&maxima)[N])
{
#ifdef DEAL_II_WITH_MPI
- MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
+ MPI_Allreduce ((&values[0] != &maxima[0]
+ ?
+ const_cast<void *>(static_cast<const void *>(&values[0]))
+ :
+ MPI_IN_PLACE),
&maxima[0], N, internal::mpi_type_id(values), MPI_MAX,
mpi_communicator);
#else
{
#ifdef DEAL_II_WITH_MPI
maxima.resize (values.size());
- MPI_Allreduce (const_cast<void *>(static_cast<const void *>(&values[0])),
+ MPI_Allreduce ((&values[0] != &maxima[0]
+ ?
+ const_cast<void *>(static_cast<const void *>(&values[0]))
+ :
+ MPI_IN_PLACE),
&maxima[0], values.size(), internal::mpi_type_id((T *)0), MPI_MAX,
mpi_communicator);
#else
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2009 - 2014 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check Utilities::MPI::sum() for arrays, but with input=output
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/utilities.h>
+#include <fstream>
+
+void test()
+{
+ unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+ const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+ unsigned int sums[2] = { 1, 2 };
+ Utilities::MPI::sum (sums,
+ MPI_COMM_WORLD,
+ sums);
+ Assert (sums[0] == numprocs, ExcInternalError());
+ Assert (sums[1] == 2*numprocs, ExcInternalError());
+
+ if (myid==0)
+ deallog << sums[0] << ' ' << sums[1] << std::endl;
+}
+
+
+int main(int argc, char *argv[])
+{
+#ifdef DEAL_II_WITH_MPI
+ Utilities::MPI::MPI_InitFinalize mpi (argc, argv);
+#else
+ (void)argc;
+ (void)argv;
+ compile_time_error;
+
+#endif
+
+ if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+ {
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ deallog.push("mpi");
+ test();
+ deallog.pop();
+ }
+ else
+ test();
+}
--- /dev/null
+
+DEAL:mpi::1 2
--- /dev/null
+
+DEAL:mpi::10 20
--- /dev/null
+
+DEAL:mpi::4 8
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2009 - 2014 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check Utilities::MPI::sum() for vectors
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/utilities.h>
+#include <fstream>
+
+void test()
+{
+ unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+ const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+ unsigned int values_[2] = { 1, 2 };
+ std::vector<unsigned int> values(&values_[0], &values_[2]);
+ std::vector<unsigned int> sums(2);
+ Utilities::MPI::sum (values,
+ MPI_COMM_WORLD,
+ sums);
+ Assert (sums[0] == numprocs, ExcInternalError());
+ Assert (sums[1] == 2*numprocs, ExcInternalError());
+
+ if (myid==0)
+ deallog << sums[0] << ' ' << sums[1] << std::endl;
+}
+
+
+int main(int argc, char *argv[])
+{
+#ifdef DEAL_II_WITH_MPI
+ Utilities::MPI::MPI_InitFinalize mpi (argc, argv);
+#else
+ (void)argc;
+ (void)argv;
+ compile_time_error;
+
+#endif
+
+ if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+ {
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ deallog.push("mpi");
+ test();
+ deallog.pop();
+ }
+ else
+ test();
+}
--- /dev/null
+
+DEAL:mpi::1 2
--- /dev/null
+
+DEAL:mpi::10 20
--- /dev/null
+
+DEAL:mpi::4 8
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2009 - 2014 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check Utilities::MPI::sum() for vectors, but with input=output
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/utilities.h>
+#include <fstream>
+
+void test()
+{
+ unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+ const unsigned int numprocs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+ unsigned int values_[2] = { 1, 2 };
+ std::vector<unsigned int> sums(&values_[0], &values_[2]);
+ Utilities::MPI::sum (sums,
+ MPI_COMM_WORLD,
+ sums);
+ Assert (sums[0] == numprocs, ExcInternalError());
+ Assert (sums[1] == 2*numprocs, ExcInternalError());
+
+ if (myid==0)
+ deallog << sums[0] << ' ' << sums[1] << std::endl;
+}
+
+
+int main(int argc, char *argv[])
+{
+#ifdef DEAL_II_WITH_MPI
+ Utilities::MPI::MPI_InitFinalize mpi (argc, argv);
+#else
+ (void)argc;
+ (void)argv;
+ compile_time_error;
+
+#endif
+
+ if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+ {
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ deallog.push("mpi");
+ test();
+ deallog.pop();
+ }
+ else
+ test();
+}
--- /dev/null
+
+DEAL:mpi::1 2
--- /dev/null
+
+DEAL:mpi::10 20
--- /dev/null
+
+DEAL:mpi::4 8