--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: paralution.h 32926 2014-05-16 17:12:16Z turcksin $
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+#ifndef __deal2__paralution_h
+#define __deal2__paralution_h
+
+#include <deal.II/base/config.h>
+
+#ifdef DEAL_II_WITH_PARALUTION
+
+#include <deal.II/base/multithread_info.h>
+
+#include <paralution.hpp>
+
+DEAL_II_NAMESPACE_OPEN
+
+
+namespace Utilities
+{
+ /**
+ * A namespace for utility functions that abstract certain operations using
+ * the Paralution library.
+ */
+ namespace Paralution
+ {
+ /**
+ * A class that is used to initialize and to stop Paralution. If a program
+ * uses Paralution one would typically just create an object of this type at
+ * the beginninh of <code>main()</code>. The constructor of this class then
+ * runs <code>paralution::init_paralution()</code>. At the end of the
+ * program, the compiler will invoke the destructor of this object which in
+ * turns calls <code>paralution::stop_paralution()</code>.
+ */
+ class Paralution_InitFinalize
+ {
+ public :
+ /**
+ * Constructor. Initialize Paralution by calling <tt>paralution::init_paralution</tt>
+ * and set the number of threads used by Paralution to the given parameters.
+ */
+ Paralution_InitFinalize(const unsigned int max_num_threads);
+
+ /**
+ * Destructor. Calls <tt>paralution::stop_paralution</tt>.
+ */
+ ~Paralution_InitFinalize();
+
+ /**
+ * Set a device.
+ */
+ void set_device(const unsigned int device) const;
+
+ /**
+ * Set a specific gpu.
+ */
+ void set_gpu_cuda(const unsigned int gpu) const;
+
+ /**
+ * Set OpenCL compute units.
+ */
+ void set_ocl_compute_units(const unsigned int compute_unit) const;
+
+ /**
+ * Set a specific OpenCL platform.
+ */
+ void set_ocl_platform(const unsigned int platform) const;
+
+ /**
+ * Set a specific OpenCL platform and device.
+ */
+ void set_ocl(const unsigned int platform, const unsigned int device) const;
+
+ /**
+ * Set the number of OpenMP thread.
+ */
+ void set_omp_threads(const unsigned int n_threads) const;
+
+ /**
+ * Print information about the platform.
+ */
+ void info() const;
+ };
+
+
+
+// ------------------- inline functions --------------
+ inline Paralution_InitFinalize::Paralution_InitFinalize(const unsigned int max_num_threads)
+ {
+ // Initialize paralution
+ paralution::init_paralution();
+
+ // Set the number of OpenMP threads
+ set_omp_threads(max_num_threads);
+
+ // Set the number of TBB threads
+ multithread_info.set_thread_limit(max_num_threads);
+ }
+
+
+ inline Paralution_InitFinalize::~Paralution_InitFinalize()
+ {
+ paralution::stop_paralution();
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_device(const unsigned int device) const
+ {
+ paralution::set_device_paralution(device);
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_gpu_cuda(const unsigned int gpu) const
+ {
+ paralution::set_gpu_cuda_paralution(gpu);
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_ocl_compute_units(const unsigned int compute_unit) const
+ {
+ paralution::set_ocl_compute_units_paralution(compute_unit);
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_ocl_platform(const unsigned int platform) const
+ {
+ paralution::set_ocl_platform_paralution(platform);
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_ocl(const unsigned int platform,
+ const unsigned int device) const
+ {
+ paralution::set_ocl_paralution(platform, device);
+ }
+
+
+
+ inline void Paralution_InitFinalize::set_omp_threads(const unsigned int n_threads) const
+ {
+ paralution::set_omp_threads_paralution(n_threads);
+ }
+
+
+
+ inline void Paralution_InitFinalize::info() const
+ {
+ paralution::info_paralution();
+ }
+ }
+}
+
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif // DEAL_II_WITH_PARALUTION
+
+#endif
#include <deal.II/base/exceptions.h>
#include <deal.II/base/subscriptor.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <algorithm>
#include <paralution.hpp>
*/
void sync();
+ /**
+ * Convert the paralution matrix to a different format. This function should
+ * only be called after convert_to_paralution_csr.
+ */
+ void convert_format(matrix_format format);
+
/**
* Return a constant reference to the underlying dealii::SparseMatrix.
*/
else
local_matrix.CopyFromAsync(sparse_matrix.paralution_matrix());
}
+
+ template <typename Number>
+ void SparseMatrix<Number>::convert_format(matrix_format format)
+ {
+ if (is_local_matrix==false)
+ {
+ switch (format)
+ {
+ case DENSE :
+ {
+ local_matrix.ConvertToDense();
+ break;
+ }
+ case CSR :
+ {
+ local_matrix.ConvertToCSR();
+ break;
+ }
+ case MCSR :
+ {
+ local_matrix.ConvertToMCSR();
+ break;
+ }
+ case BCSR :
+ {
+ local_matrix.ConvertToBCSR();
+ break;
+ }
+ case COO :
+ {
+ local_matrix.ConvertToDIA();
+ break;
+ }
+ case ELL :
+ {
+ local_matrix.ConvertToELL();
+ break;
+ }
+ case HYB :
+ {
+ local_matrix.ConvertToHYB();
+ break;
+ }
+ default :
+ {
+ AssertThrow(false,ExcMessage("Wrong format of Paralution matrix."));
+ }
+ }
+ }
+ }
}
// Explicit instantiations
#include <fstream>
#include <iomanip>
#include <deal.II/base/logstream.h>
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_sparse_matrix.h>
#include <deal.II/lac/paralution_vector.h>
#include <deal.II/lac/paralution_solver.h>
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
}
solver.solve(A,u,f,p);
}
-
- paralution::stop_paralution();
}
#include <fstream>
#include <iomanip>
#include <deal.II/base/logstream.h>
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_sparse_matrix.h>
#include <deal.II/lac/paralution_vector.h>
#include <deal.II/lac/paralution_solver.h>
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
}
solver.solve(A,u,f,p);
}
-
- paralution::stop_paralution();
}
// Test ParalutionWrappers::SparseMatrix
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/sparsity_pattern.h>
#include <deal.II/lac/paralution_sparse_matrix.h>
-#include "paralution.hpp"
template <typename Number>
void check()
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
check<float>();
check<double>();
-
- paralution::stop_paralution();
}
// Test ParalutionWrappers::Vector constructor
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
template <typename Number>
void check()
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
check<int>();
check<float>();
check<double>();
-
- paralution::stop_paralution();
}
// Test copy constructor and access elements of ParalutionWrappers::Vector
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
void check()
{
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
deallog.threshold_double(1.e-10);
check();
-
- paralution::stop_paralution();
}
// Test ParalutionWrappers::Vector iterator
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
void check()
{
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
deallog.threshold_double(1.e-10);
check();
-
- paralution::stop_paralution();
}
// Test reinit for ParalutionWrappers::Vector
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
void check()
{
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
deallog.threshold_double(1.e-10);
check();
-
- paralution::stop_paralution();
}
// operator-=
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
void check_1()
{
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
check_1();
check_2();
-
- paralution::stop_paralution();
}
#include "../tests.h"
+#include <deal.II/base/paralution.h>
#include <deal.II/lac/paralution_vector.h>
-#include "paralution.hpp"
void check()
{
int main()
{
- paralution::init_paralution();
+ Utilities::Paralution::Paralution_InitFinalize paralution(1);
std::ofstream logfile("output");
deallog << std::fixed;
deallog.threshold_double(1.e-10);
check();
-
- paralution::stop_paralution();
}
* Note that we can't do this if we run in MPI mode because then
* MPI_InitFinalize already calls this function. Since every test
* calls MPI_InitFinalize itself, we can't adjust the thread count
- * for this here.
+ * for this here. The same is true for Paralution, Paralution_InitFinalize
+ * calls set_thread_limit.
*/
-#ifndef DEAL_II_WITH_MPI
+#if !(defined DEAL_II_WITH_MPI) && !(defined DEAL_II_WITH_PARALUTION)
struct LimitConcurrency
{
LimitConcurrency ()