T sum (const T &t,
const MPI_Comm &mpi_communicator);
+ /**
+ * Like the previous function,
+ * but take the sums over the
+ * elements of an 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.
+ */
+ template <typename T, unsigned int N>
+ inline
+ void sum (const T (&values)[N],
+ const MPI_Comm &mpi_communicator,
+ T (&sums)[N]);
+
/**
* Return the maximum over all processors of the value @p t. This function
* is collective over all processors given in the communicator. If
T max (const T &t,
const MPI_Comm &mpi_communicator);
+ /**
+ * Like the previous function,
+ * but take the maxima over the
+ * elements of an 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.
+ */
+ template <typename T, unsigned int N>
+ inline
+ void max (const T (&values)[N],
+ const MPI_Comm &mpi_communicator,
+ T (&maxima)[N]);
+
/**
* Data structure to store the result of
* min_max_avg().
}
+ template <typename T, unsigned int N>
+ inline
+ void sum (const T (&values)[N],
+ const MPI_Comm &mpi_communicator,
+ T (&sums)[N])
+ {
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+ MPI_Allreduce (const_cast<void*>(static_cast<const void*>(&values[0])),
+ &sums[0], N, internal::mpi_type_id(values), MPI_SUM,
+ mpi_communicator);
+#else
+ (void)mpi_communicator;
+ for (unsigned int i=0; i<N; ++i)
+ sums[i] = values[i];
+#endif
+ }
+
+
template <typename T>
inline
T max (const T &t,
return t;
#endif
}
+
+
+ template <typename T, unsigned int N>
+ inline
+ void max (const T (&values)[N],
+ const MPI_Comm &mpi_communicator,
+ T (&maxima)[N])
+ {
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+ MPI_Allreduce (const_cast<void*>(static_cast<const void*>(&values[0])),
+ &maxima[0], N, internal::mpi_type_id(values), MPI_MAX,
+ mpi_communicator);
+#else
+ (void)mpi_communicator;
+ for (unsigned int i=0; i<N; ++i)
+ maxima[i] = values[i];
+#endif
+ }
}
}
--- /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::sum() for arrays
+
+#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 };
+ 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_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_02_array").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 2
--- /dev/null
+
+DEAL:mpi::10 20
--- /dev/null
+
+DEAL:mpi::4 8
--- /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() for arrays
+
+#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 };
+ unsigned int maxima[2];
+ Utilities::MPI::max (values,
+ MPI_COMM_WORLD,
+ maxima);
+ Assert (maxima[0] == 1, ExcInternalError());
+ Assert (maxima[1] == 2, ExcInternalError());
+
+ if (myid==0)
+ deallog << maxima[0] << ' ' << maxima[1] << 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_array").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 2
--- /dev/null
+
+DEAL:mpi::1 2
--- /dev/null
+
+DEAL:mpi::1 2