Skip to content

Commit ad33dde

Browse files
authored
41 cmake build with mumps (#47)
1 parent 7d752fd commit ad33dde

15 files changed

Lines changed: 176 additions & 63 deletions

CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16.3)
33
project(GMGPolar VERSION 1.0.0)
44

55
option(GMGPOLAR_BUILD_TESTS "Build GMGPolar unit tests." ON)
6+
option(GMGPOLAR_USE_MUMPS "Use MUMPS to compute matrix factorizations." OFF)
67

78
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
89
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -36,9 +37,48 @@ add_library(GMGPolar ${SOURCES_SRC})
3637

3738
add_executable(gmgpolar_simulation ./src/main.cpp)
3839

40+
configure_file(${CMAKE_SOURCE_DIR}/include/config_internal.h.in ${CMAKE_SOURCE_DIR}/include/config_internal.h)
41+
3942
target_include_directories(gmgpolar_simulation PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/test_cases )
4043
target_include_directories(GMGPolar PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/test_cases )
4144

45+
if(GMGPOLAR_USE_MUMPS)
46+
47+
set(INC_DIRS
48+
/home/kueh_mj/.spack/rev.23.05/install/linux-rocky8-zen2/gcc-10.4.0/mumps-5.4.1-fftqkl/include
49+
/sw/rev/23.05/linux-rocky8-zen2/gcc-10.4.0/metis-5.1.0-akhgsf/include
50+
)
51+
52+
set(LIB_DIRS
53+
/home/kueh_mj/.spack/rev.23.05/install/linux-rocky8-zen2/gcc-10.4.0/mumps-5.4.1-fftqkl/lib
54+
/sw/rev/23.05/linux-rocky8-zen2/gcc-10.4.0/metis-5.1.0-akhgsf/lib
55+
)
56+
57+
include_directories(
58+
${INC_DIRS}
59+
)
60+
61+
target_link_directories(
62+
GMGPolar
63+
PUBLIC
64+
${LIB_DIRS}
65+
)
66+
67+
set(LIBS
68+
mpiseq
69+
dmumps
70+
mumps_common
71+
metis
72+
)
73+
74+
target_link_libraries(
75+
GMGPolar
76+
PUBLIC
77+
${LIBS}
78+
)
79+
endif()
80+
81+
4282
find_package(OpenMP)
4383

4484
#currently works on GNU compiler
@@ -58,8 +98,10 @@ else()
5898
message(FATAL_ERROR "Please use GNU compiler or change CMakeLists manually")
5999
endif()
60100

101+
61102
target_link_libraries(gmgpolar_simulation PRIVATE GMGPolar)
62103

104+
63105
include(thirdparty/CMakeLists.txt)
64106
add_subdirectory(tests)
65107

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ Obtaining the source code
2121
The GmgPolar Solver does not require any external libraries.
2222
It is possible to link the code with the sparse direct solver ``MUMPS``.
2323

24-
* ``MUMPS`` is optionnal. To use it, compile the code with option -DUSE_MUMPS. It is
25-
recommended to use the latest version (currently 5.4.1) but any version ulterior
24+
* ``MUMPS`` is optional. However, it is absolutely recommended if large grids are considered.
25+
Otherwise, the nonoptimal backup solver will be used for factorization of the matrices and will
26+
slow down the setup phase significantly. To use it, compile the code with option -DGMGPOLAR_USE_MUMPS.
27+
It is recommended to use the latest version (currently 5.4.1) but any version ulterior
2628
to 5.1.0 should be okay. MUMPS is available freely on demand on the MUMPS consortium
2729
website "mumps-solver.org".
2830

include/config.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2019-2023 The GMGPolar Development Team
3+
*
4+
* Authors: Martin J. Kühn
5+
*
6+
* Contact:
7+
* Carola Kruse <Carola.Kruse@CERFACS.fr>
8+
* Martin J. Kuehn <Martin.Kuehn@DLR.de>
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
/**
24+
* Configuration of GMGPolar library.
25+
*/
26+
27+
#ifndef GMGPOLAR_CONFIG_H
28+
#define GMGPOLAR_CONFIG_H
29+
30+
#include "config_internal.h"
31+
32+
#endif // GMGPOLAR_CONFIG_H

include/config_internal.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2019-2023 The GMGPolar Development Team
3+
*
4+
* Authors: Martin J. Kühn
5+
*
6+
* Contact:
7+
* Carola Kruse <Carola.Kruse@CERFACS.fr>
8+
* Martin J. Kuehn <Martin.Kuehn@DLR.de>
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
/**
24+
* Configured by cmake.
25+
*/
26+
27+
#ifndef GMGPOLAR_CONFIG_INTERNAL_H
28+
#define GMGPOLAR_CONFIG_INTERNAL_H
29+
30+
#define GMGPOLAR_USE_MUMPS
31+
32+
#endif // GMGPOLAR_CONFIG_INTERNAL_H

include/config_internal.h.in

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2019-2023 The GMGPolar Development Team
3+
*
4+
* Authors: Martin J. Kühn
5+
*
6+
* Contact:
7+
* Carola Kruse <Carola.Kruse@CERFACS.fr>
8+
* Martin J. Kuehn <Martin.Kuehn@DLR.de>
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
/**
24+
* Configured by cmake.
25+
*/
26+
27+
#ifndef GMGPOLAR_CONFIG_INTERNAL_H
28+
#define GMGPOLAR_CONFIG_INTERNAL_H
29+
30+
#cmakedefine GMGPOLAR_USE_MUMPS
31+
32+
#endif // GMGPOLAR_CONFIG_INTERNAL_H

include/gmgpolar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
#include <sys/stat.h>
4242
#include <iomanip>
4343
#include <ctime>
44+
#include "config.h"
4445
#include "constants.h"
4546
#include "level.h"
4647
#include "gyro.h"
4748

4849
class gmgpolar
4950
{
5051
public:
51-
/*******************************************************************************
52+
/*******************************************************************************
5253
* Attributes
5354
******************************************************************************/
5455
/***************************************************************************

include/level.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
#include <fstream>
4545
#include <iomanip>
4646
#include <sys/stat.h>
47+
48+
#include "config.h"
4749
#include "gyro.h"
4850

49-
#ifdef USE_MUMPS
51+
#ifdef GMGPOLAR_USE_MUMPS
5052
#include "mpi.h"
5153
#include "dmumps_c.h"
5254

@@ -91,12 +93,11 @@ class level
9193
// - using in-house solver
9294
std::vector<int> row_Ac_LU, col_Ac_LU;
9395
std::vector<double> vals_Ac_LU;
94-
#ifdef USE_MUMPS
96+
#ifdef GMGPOLAR_USE_MUMPS
9597
// - using MUMPS
9698
DMUMPS_STRUC_C mumps_Ac;
9799
DMUMPS_STRUC_C mumps_across;
98100
#endif
99-
100101
/*! Beta coefficient update */
101102
std::vector<double> betaVec;
102103

@@ -154,7 +155,7 @@ class level
154155
std::vector<std::vector<int>> A_Zebra_r_LU_row[4];
155156
std::vector<std::vector<int>> A_Zebra_c_LU_row[4];
156157
std::vector<std::vector<double>> A_Zebra_v_LU_row[4];
157-
#ifdef USE_MUMPS
158+
#ifdef GMGPOLAR_USE_MUMPS
158159
// - using MUMPS
159160
DMUMPS_STRUC_C mumps_A_Zebra[4];
160161

@@ -197,7 +198,6 @@ class level
197198
/***************************************************************************
198199
* gmgpolar
199200
**************************************************************************/
200-
void build_bound();
201201
void define_coarse_nodes_onelevel(level* finer);
202202
void store_theta_n_co();
203203
// void define_colors();
@@ -287,7 +287,7 @@ class level
287287
std::vector<double>& A_vals, int m_solution);
288288
std::vector<double> solve_gaussian_elimination(std::vector<int> A_row_indices, std::vector<int> A_col_indices,
289289
std::vector<double> A_vals, std::vector<double> f);
290-
#ifdef USE_MUMPS
290+
#ifdef GMGPOLAR_USE_MUMPS
291291
void init_mumps(DMUMPS_STRUC_C& mumps);
292292
void facto_mumps(DMUMPS_STRUC_C& mumps, std::vector<int> A_row_indices, std::vector<int> A_col_indices,
293293
std::vector<double> A_vals, int m_solution);

src/RHS.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ double gyro::eval_def_rhs(double r, double theta, int verbose)
4646
else {
4747
rhs_val = functions->rho_pole(r, theta, kappa_eps, delta_e, Rmax);
4848
}
49-
if (verbose)
49+
if (verbose) {
5050
std::cout << "RHS(" << r << ", " << theta << "): " << rhs_val << "\n";
51+
}
5152
return rhs_val;
5253
} /* ----- end of gyro::eval_def_rhs ----- */
5354

@@ -71,8 +72,9 @@ std::vector<double> gyro::eval_def_rhs(double r, std::vector<double> theta, std:
7172
else {
7273
functions->rho_pole(r, theta, kappa_eps, delta_e, Rmax, rhs_val, sin_theta, cos_theta);
7374
}
74-
if (verbose)
75+
if (verbose) {
7576
for (int i = 0; i < ntheta; i++)
7677
std::cout << "RHS(" << r << ", " << theta[i] << "): " << rhs_val[i] << "\n";
78+
}
7779
return rhs_val;
7880
} /* ----- end of gyro::eval_def_rhs ----- */

src/direct_solve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
#include "level.h"
3030

31-
#ifdef USE_MUMPS
31+
#ifdef GMGPOLAR_USE_MUMPS
3232
/*!
3333
* \brief Initialization of a MUMPS structure
3434
*

src/level.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ level::level(int l_)
4343
reset_timers();
4444
delete_circles = 0;
4545

46-
#ifdef USE_MUMPS
46+
#ifdef GMGPOLAR_USE_MUMPS
4747
init_mumps(mumps_Ac);
4848
if (gyro::icntl[Param::optimized] == 0) {
4949
for (int i = 0; i < 4; i++) {
@@ -64,7 +64,7 @@ level::level(int l_)
6464
*/
6565
level::~level()
6666
{
67-
#ifdef USE_MUMPS
67+
#ifdef GMGPOLAR_USE_MUMPS
6868
finalize_mumps(mumps_Ac);
6969
if (gyro::icntl[Param::optimized] == 0) {
7070
for (int i = 0; i < 4; i++) {
@@ -124,36 +124,6 @@ void level::display_theta()
124124
gyro::disp(theta, "Coordinates theta");
125125
} /* ----- end of level::display_theta ----- */
126126

127-
/*!
128-
* \brief Defines which nodes are on the boundary
129-
*
130-
* returns ndistance to Dirichlet boundary in binary (0: o boundary, >0: not on boundary)
131-
* uses tolerance of 1e-10 to define boundary
132-
*
133-
*/
134-
void level::build_bound()
135-
{
136-
double tol_bound_check = gyro::dcntl[Param::tol_bound_check];
137-
double r0_DB = gyro::dcntl[Param::r0_DB];
138-
double R = gyro::dcntl[Param::R];
139-
140-
is_bound = std::vector<int>(m);
141-
142-
for (int j = 0; j < nr; j++) {
143-
int is_DB = fabs((r[j] - r0_DB) * (r[j] - R)) < tol_bound_check;
144-
for (int i = 0; i < ntheta_int; i++) {
145-
is_bound[j * ntheta_int + i] = is_DB;
146-
}
147-
}
148-
149-
if (gyro::icntl[Param::verbose] > 5)
150-
std::cout << "Printing for (r, theta) if the node is on the boundary.\n";
151-
for (int j = 0; j < nr; j++)
152-
for (int i = 0; i < ntheta_int; i++)
153-
std::cout << "(" << r[j] << ", " << theta[j] << "): " << is_bound[j * ntheta_int + i]
154-
<< "\n";
155-
} /* ----- end of gyro::build_bound ----- */
156-
157127
/*!
158128
* \brief Defines the number of entries in A
159129
*

0 commit comments

Comments
 (0)