Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Parallel STL #165

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/hypre/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int test(const Alien::Hypre::OptionTypes::eSolver& solv, const Alien::Hypre::Opt

for (int i = 0; i < NB_RUNS; i++) {
Alien::Hypre::Options options;
options.numIterationsMax(500);
options.numIterationsMax(10000);
options.stopCriteriaValue(1e-8);
options.preconditioner(prec); // Jacobi, NoPC
options.solver(solv); //CG, GMRES, BICG, BICGSTAB
Expand Down
44 changes: 26 additions & 18 deletions plugins/hypre/src/hypre_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,26 @@ bool InternalLinearSolver::solve(const Matrix& A, const Vector& b, Vector& x)
precond_setup_function = HYPRE_BoomerAMGSetup;
precond_destroy_function = HYPRE_BoomerAMGDestroy;

#ifdef ALIEN_HYPRE_DEVICE
// Important, set these parameters for running BoomerAMG as a preconditioner
HYPRE_BoomerAMGSetMaxIter(preconditioner, 1);
HYPRE_BoomerAMGSetTol(preconditioner, 0.0);

HYPRE_BoomerAMGSetStrongThreshold(preconditioner, 0.5); // Better for 3d ?

// HYPRE_BoomerAMGSetPrintLevel(preconditioner, 1); /* print amg solution info */

//#ifdef ALIEN_HYPRE_DEVICE
// GPU only support a subset of paramater values.
// see https://hypre.readthedocs.io/en/latest/solvers-boomeramg.html#gpu-supported-options
HYPRE_BoomerAMGSetRelaxType(preconditioner, 3); /* 3, 4, 6, 7, 18, 11, 12 */
HYPRE_BoomerAMGSetRelaxType(preconditioner, 18); /* 3, 4, 6, 7, 18, 11, 12 */
HYPRE_BoomerAMGSetRelaxOrder(preconditioner, false); /* must be false */
HYPRE_BoomerAMGSetCoarsenType(preconditioner, 8); /* 8 */
// FIXME: understand why 3 and 15 do not work with unit tests on CPUs.
HYPRE_BoomerAMGSetInterpType(preconditioner, 14); /* 3, 15, 6, 14, 18 */
HYPRE_BoomerAMGSetAggInterpType(preconditioner, 5); /* 5 or 7 */
HYPRE_BoomerAMGSetInterpType(preconditioner, 18); /* 3, 15, 6, 14, 18 */
HYPRE_BoomerAMGSetAggInterpType(preconditioner, 7); /* 5 or 7 */
HYPRE_BoomerAMGSetAggNumLevels(preconditioner, 5);
HYPRE_BoomerAMGSetKeepTranspose(preconditioner, true); /* keep transpose to avoid SpMTV */
HYPRE_BoomerAMGSetRAP2(preconditioner, false); /* RAP in two multiplications (default: FALSE) */
#endif // ALIEN_HYPRE_DEVICE
//#endif // ALIEN_HYPRE_DEVICE
break;
case OptionTypes::ParaSailsPC:
precond_name = "parasails";
Expand Down Expand Up @@ -271,18 +279,18 @@ bool InternalLinearSolver::solve(const Matrix& A, const Vector& b, Vector& x)
error = (*solver_solve_function)(solver, par_a, par_rhs, par_x);
m_status.succeeded = (error == 0);

if (m_status.succeeded) {
checkError("Hypre " + solver_name + " solver GetNumIterations",
(*solver_get_num_iterations_function)(solver, &m_status.iteration_count));
checkError("Hypre " + solver_name + " solver GetFinalResidual",
(*solver_get_final_relative_residual_function)(solver, &m_status.residual));

m_status.succeeded = (m_status.iteration_count < max_it) || (m_status.succeeded == max_it && m_status.residual <= rtol);
}
else {
// Solver is not converged. Clear Hypre errors for subsequent calls.
HYPRE_ClearAllErrors();
}
//if (m_status.succeeded) {
checkError("Hypre " + solver_name + " solver GetNumIterations",
(*solver_get_num_iterations_function)(solver, &m_status.iteration_count));
checkError("Hypre " + solver_name + " solver GetFinalResidual",
(*solver_get_final_relative_residual_function)(solver, &m_status.residual));

m_status.succeeded = (m_status.iteration_count < max_it) || (m_status.succeeded == max_it && m_status.residual <= rtol);
// }
// else {
// // Solver is not converged. Clear Hypre errors for subsequent calls.
// HYPRE_ClearAllErrors();
// }

checkError(
"Hypre " + solver_name + " solver Destroy", (*solver_destroy_function)(solver));
Expand Down
63 changes: 33 additions & 30 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ add_subdirectory(alien/kernels/redistributor)
add_subdirectory(alien/kernels/simple_csr)
add_subdirectory(alien/index_manager)

IF(ALIEN_USE_SYCL)
find_package(hipSYCL CONFIG REQUIRED)
add_subdirectory(alien/kernels/sycl)
endif()
IF (ALIEN_USE_SYCL)
find_package(hipSYCL CONFIG REQUIRED)
add_subdirectory(alien/kernels/sycl)
endif ()


add_library(alien_core
Expand Down Expand Up @@ -120,44 +120,47 @@ add_library(alien_core

target_link_libraries(alien_core PUBLIC alien_utils alien_data)
target_link_libraries(alien_core PUBLIC
alien_kernel_dok
alien_kernel_composite
alien_kernel_redistributor
alien_kernel_simplecsr)

alien_kernel_dok
alien_kernel_composite
alien_kernel_redistributor
alien_kernel_simplecsr)

target_link_libraries(alien_core PUBLIC alien_index_manager)

set_property(TARGET alien_core PROPERTY CXX_STANDARD 17)

# For parallel STL
find_package(TBB REQUIRED)
target_link_libraries(alien_core PRIVATE TBB::tbb)

message(STATUS "Using AVX Simd instructions ? -> ${ALIEN_WANT_AVX}")
message(STATUS "Using AVX2 Simd instructions ? -> ${ALIEN_WANT_AVX2}")
message(STATUS "Using AVX512 Simd instructions ? -> ${ALIEN_WANT_AVX512}")

if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang))
if(ALIEN_WANT_AVX)
target_compile_options(alien_core INTERFACE -mavx)
endif()
if(ALIEN_WANT_AVX2)
target_compile_options(alien_core INTERFACE -mavx -mfma)
endif()
if(ALIEN_WANT_AVX512)
target_compile_options(alien_core INTERFACE -mavx512f -mavx512cd)
endif()
endif()

IF(ALIEN_USE_SYCL)
target_link_libraries(alien_core PUBLIC alien_kernel_sycl)
target_compile_options(alien_core PRIVATE "--gcc-toolchain=${GCCCORE_ROOT}")
add_sycl_to_target(TARGET alien_core)
ENDIF()
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL Clang))
if (ALIEN_WANT_AVX)
target_compile_options(alien_core INTERFACE -mavx)
endif ()
if (ALIEN_WANT_AVX2)
target_compile_options(alien_core INTERFACE -mavx -mfma)
endif ()
if (ALIEN_WANT_AVX512)
target_compile_options(alien_core INTERFACE -mavx512f -mavx512cd)
endif ()
endif ()

IF (ALIEN_USE_SYCL)
target_link_libraries(alien_core PUBLIC alien_kernel_sycl)
target_compile_options(alien_core PRIVATE "--gcc-toolchain=${GCCCORE_ROOT}")
add_sycl_to_target(TARGET alien_core)
ENDIF ()


target_link_libraries(alien_core PUBLIC
Arccore::arccore_trace
Arccore::arccore_collections
Arccore::arccore_base
Arccore::arccore_message_passing_mpi)
Arccore::arccore_trace
Arccore::arccore_collections
Arccore::arccore_base
Arccore::arccore_message_passing_mpi)

find_package(Boost COMPONENTS program_options REQUIRED)

Expand Down
5 changes: 3 additions & 2 deletions src/core/alien/kernels/dok/DoKDistributor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DoKDistributor.h"

#include <vector>
#include <execution>

#include "DoKBackEnd.h"
#include "DoKMatrixT.h"
Expand All @@ -30,7 +31,7 @@ namespace Alien
{

DoKDistributor::DoKDistributor(const RedistributorCommPlan* commPlan)
: m_distributor(new DoKDistributorComm(commPlan))
: m_distributor(std::make_unique<DoKDistributorComm>(commPlan))
{}

void DoKDistributor::distribute(const DoKMatrix& src, DoKMatrix& dst)
Expand All @@ -41,7 +42,7 @@ void DoKDistributor::distribute(const DoKMatrix& src, DoKMatrix& dst)
void DoKDistributor::distribute(const DoKVector& src, DoKVector& dst)
{
std::vector<std::pair<Arccore::Int32, DoKVector::ValueType>> pair_values(src.m_data.begin(), src.m_data.end());
std::sort(pair_values.begin(), pair_values.end());
std::sort(std::execution::par_unseq, pair_values.begin(), pair_values.end());

Arccore::UniqueArray<Int32> snd_keys(src.m_data.size());
Arccore::UniqueArray<DoKVector::ValueType> snd_values(src.m_data.size());
Expand Down
7 changes: 4 additions & 3 deletions src/core/alien/kernels/dok/DoKLocalMatrixIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <algorithm>
#include <stdexcept>
#include <vector>
#include <execution>

#include "DoKReverseIndexer.h"

Expand Down Expand Up @@ -75,8 +76,8 @@ namespace
class KeyCompare
{
public:
typedef typename Map::iterator Iterator;
typedef typename Map::key_type Key;
using Iterator = typename Map::iterator;
using Key = typename Map::key_type;

public:
bool operator()(const Iterator& a, const Iterator& b)
Expand All @@ -99,7 +100,7 @@ DoKLocalMatrixIndexer::sort(Arccore::Array<DoKLocalMatrixIndexer::Renumbering>&
}

KeyCompare<HashTable> compare;
std::sort(src.begin(), src.end(), compare);
std::sort(std::execution::par_unseq, src.begin(), src.end(), compare);

auto* indexer = new DoKReverseIndexer();
auto size = static_cast<Arccore::Integer>(m_data.size());
Expand Down
Loading