<br>
(Guido Kanschat, 2011/09/26)
-<li> New: There is now a function GridTools::volume() computing the volume
-
-<li> New: The function Utilities::MPI::sum
-function can be used to compute the sum of values over a number of
+<li> New: The functions Utilities::MPI::sum and Utilities::MPI::max
+function can be used to compute the sum or maximum of values over a number of
MPI processes without having to deal with the underlying MPI functions.
<br>
(Wolfgang Bangerth, 2011/09/25)
<br>
(Patrick Sodré, 2011/09/07)
-<li> New: There is now a function GridTools::volume computing the volume
+<li> New: There is now a function GridTools::volume() computing the volume
of a triangulation.
<br>
(Wolfgang Bangerth, 2011/09/02)
*/
template <typename T>
T sum (const T &t,
+ const MPI_Comm &mpi_communicator);
+
+ /**
+ * Return the maximum over all processors of the value @p t. This function
+ * is collective over all processors given in the communicator. If
+ * deal.II is not configured for use of MPI, this function simply
+ * returns the value of @p t. This function corresponds to the
+ * <code>MPI_Allreduce</code> function, i.e. all processors receive
+ * the result of this operation.
+ *
+ * @note This function is only implemented for certain template
+ * arguments <code>T</code>, namely <code>float, double, int,
+ * unsigned int</code>.
+ */
+ template <typename T>
+ T max (const T &t,
const MPI_Comm &mpi_communicator);
/**
#endif
}
+
template <typename T>
inline
T sum (const T &t,
return t;
#endif
}
+
+
+ template <typename T>
+ inline
+ T max (const T &t,
+ const MPI_Comm &mpi_communicator)
+ {
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+ T sum;
+ MPI_Allreduce (const_cast<void*>(static_cast<const void*>(&t)),
+ &sum, 1, internal::mpi_type_id(&t), MPI_MAX,
+ mpi_communicator);
+ return sum;
+#else
+ (void)mpi_communicator;
+ return t;
+#endif
+ }
}
}
//---------------------------------------------------------------------------
-// check Utilities::System::calculate_collective_mpi_sum()
+// check Utilities::MPI::sum()
#include "../tests.h"
#include <deal.II/base/logstream.h>
--- /dev/null
+//---------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2009, 2010, 2011 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+// check Utilities::MPI::max()
+
+#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);
+
+ int int_sum, uint_sum, double_sum, float_sum;
+ int_sum
+ =
+ Utilities::MPI::max<int>(myid+1,
+ MPI_COMM_WORLD);
+ uint_sum
+ =
+ Utilities::MPI::max<unsigned int>(myid+1,
+ MPI_COMM_WORLD);
+ float_sum
+ =
+ Utilities::MPI::max<float>(myid+1,
+ MPI_COMM_WORLD);
+ double_sum
+ =
+ Utilities::MPI::max<double>(myid+1,
+ MPI_COMM_WORLD);
+
+ if (myid==0)
+ deallog << int_sum << ' ' << uint_sum << ' ' << double_sum << ' ' << float_sum << std::endl;
+}
+
+
+int main(int argc, char *argv[])
+{
+#ifdef DEAL_II_COMPILER_SUPPORTS_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_file_for_mpi("collective_03").c_str());
+ 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 1 1 1
--- /dev/null
+
+DEAL:mpi::10 10 10 10
--- /dev/null
+
+DEAL:mpi::4 4 4 4