Skip to content

Commit ceebf9c

Browse files
authored
Merge pull request #104 from ajnonaka/heFFTe
MPI-Distributed heFFTe tutorials
2 parents 6a315b5 + 8712177 commit ceebf9c

File tree

15 files changed

+1003
-16
lines changed

15 files changed

+1003
-16
lines changed

Docs/source/ML_Tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Located in the directory ``amrex-tutorials/ExampleCodes/ML/PYTORCH``, this examp
1010
Here we use a 1-input, 2-output model to illustrate the interface between the PyTorch model and a MultiFab.
1111

1212
**Beta Decay Reaction**
13-
--------------
13+
-----------------------
1414

1515
In this example, the machine learning model is a regression model pre-trained to solve a two-component ODE system describing beta decay.
1616

Docs/source/heFFTe_Tutorial.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. role:: cpp(code)
2+
:language: c++
3+
4+
.. role:: fortran(code)
5+
:language: fortran
6+
7+
.. _tutorials_heffte:
8+
9+
heFFTe
10+
==========================
11+
12+
These tutorials demonstrate how to heFFTe to solve for and manipulate Fourier transform data using multiple MPI ranks/GPUs.
13+
14+
There are two heFFTe tutorials, ``Basic`` and ``Poisson``:
15+
16+
- ``Basic`` tutorial: The tutorial found in ``amrex-tutorials/ExampleCodes/heFFTe/Basic`` is
17+
useful if the objective is to simply take a forward FFT of data, and the DFT's ordering in k-space
18+
matters to the user. This tutorial initializes a 3D or 2D :cpp:`MultiFab`, takes a forward FFT,
19+
and then redistributes the data in k-space where the center cell in the domain corresponds to the k=0 mode.
20+
The results are written to a plot file.
21+
22+
- ``Poisson`` tutorial: This tutorial: ``amrex-tutorials/ExampleCodes/heFFTe/Poisson``
23+
solves a Poisson equation with periodic boundary conditions. In it, both a forward FFT and reverse FFT
24+
are called to solve the equation, however, no reordering of the DFT data in k-space is performed.
25+
26+
We note that both backends, fftw and cufft, assume a row-major ordering of data; since a :cpp:`MultiFab` is column major,
27+
the output to the spectral array is spatially-transposed.
28+
29+
.. toctree::
30+
:maxdepth: 1
31+
32+
.. _section:heffte_tutorial:heffte_basic:
33+
34+
Basic
35+
--------------------------
36+
37+
This tutorial initializes a 3D or 2D :cpp:`MultiFab`, takes a forward FFT,
38+
and then redistributes the data in k-space where the center cell in the domain corresponds to the k=0 mode.
39+
The results are written to a plot file.
40+
41+
.. _section:heffte_tutorial:heffte_pois:
42+
43+
Poisson
44+
--------------------------
45+
46+
In this test case we set up a right hand side (rhs), call the forward transform,
47+
modify the coefficients, then call the backward solver and output the solution
48+
to the discrete Poisson equation.

Docs/source/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ sorted by the following categories:
4545
Conduit Mesh Blueprint for use with the ALPINE Ascent in situ visualization
4646
and analysis tool.
4747
- :ref:`EB<tutorials_eb>` -- Examples of embedded boundaries.
48+
- :ref:`FFTW<tutorials_fftw>` -- FFTW and cuFFT single-rank tutorials.
4849
- :ref:`ForkJoin<tutorials_forkjoin>` -- Parallel execution and subgrouping of MPI ranks.
4950
- :ref:`GPU<tutorials_gpu>` -- Offload work to the GPUs using AMReX tools.
51+
- :ref:`heFFTe<tutorials_heffte>` -- heFFTe distributed tutorials.
5052
- :ref:`Linear Solvers<tutorials_linearsolvers>` -- Examples of several linear solvers.
5153
- :ref:`ML/PYTORCH<tutorials_ml>` -- Use of pytorch models to replace point-wise computational kernels.
5254
- :ref:`MUI<tutorials_mui>` -- Incorporates the MxUI/MUI (Multiscale Universal interface) frame into AMReX.
@@ -67,8 +69,10 @@ sorted by the following categories:
6769
Basic_Tutorial
6870
Blueprint_Tutorial
6971
EB_Tutorial
72+
FFTW_Tutorial
7073
ForkJoin_Tutorial
7174
GPU_Tutorial
75+
heFFTe_Tutorial
7276
LinearSolvers_Tutorial
7377
ML_Tutorial
7478
MUI_Tutorial
@@ -88,10 +92,14 @@ sorted by the following categories:
8892

8993
.. _`EB`: EB_Tutorial.html
9094

95+
.. _`FFTW`: FFTW_Tutorial.html
96+
9197
.. _`ForkJoin`: ForkJoin_Tutorial.html
9298

9399
.. _`GPU`: GPU_Tutorial.html
94100

101+
.. _`heFFTe`: heFFTe_Tutorial.html
102+
95103
.. _`Linear Solvers`: LinearSolvers_Tutorial.html
96104

97105
.. _`MUI`: MUI_Tutorial.html

ExampleCodes/FFTW/Basic/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int main (int argc, char* argv[])
108108
// INITIALIZE PHI
109109
// **********************************
110110

111-
double omega = M_PI/2.0;
111+
Real omega = M_PI/2.0;
112112

113113
// loop over boxes
114114
for (MFIter mfi(phi); mfi.isValid(); ++mfi)
@@ -128,10 +128,10 @@ int main (int argc, char* argv[])
128128
Real z = (AMREX_SPACEDIM==3) ? (k+0.5) * dx[2] : 0.;
129129
phi_ptr(i,j,k) = std::sin(4*M_PI*x/prob_hi_x + omega);
130130
if (AMREX_SPACEDIM >= 2) {
131-
phi_ptr(i,j,k) *= std::sin(124*M_PI*y/prob_hi_y + omega);
131+
phi_ptr(i,j,k) *= std::sin(6*M_PI*y/prob_hi_y + omega);
132132
}
133133
if (AMREX_SPACEDIM == 3) {
134-
phi_ptr(i,j,k) *= std::sin(2*M_PI*z/prob_hi_z + omega);
134+
phi_ptr(i,j,k) *= std::sin(8*M_PI*z/prob_hi_z + omega);
135135
}
136136
});
137137
}

ExampleCodes/FFTW/Basic/myfunc.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ void ShiftFFT(MultiFab& dft_onegrid, const Geometry& geom, const int& zero_avg)
1717

1818
MultiFab::Copy(dft_onegrid_temp,dft_onegrid,0,0,1,0);
1919

20-
// Shift DFT by N/2+1 (pi)
21-
for (MFIter mfi(dft_onegrid); mfi.isValid(); ++mfi) {
20+
// zero k=0 mode
21+
if (zero_avg == 1) {
22+
for (MFIter mfi(dft_onegrid); mfi.isValid(); ++mfi) {
2223

23-
const Box& bx = mfi.tilebox();
24+
const Box& bx = mfi.tilebox();
2425

25-
const Array4<Real>& dft_temp = dft_onegrid_temp.array(mfi);
26+
const Array4<Real>& dft_temp = dft_onegrid_temp.array(mfi);
2627

27-
if (zero_avg == 1) {
28-
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
29-
{
30-
if (i == 0 && j == 0 && k == 0) {
31-
dft_temp(i,j,k) = 0.;
32-
}
33-
});
34-
}
28+
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
29+
{
30+
if (i == 0 && j == 0 && k == 0) {
31+
dft_temp(i,j,k) = 0.;
32+
}
33+
});
34+
}
3535
}
3636

3737
// Shift DFT by N/2+1 (pi)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
AMREX_HOME ?= ../../../../amrex
2+
HEFFTE_HOME ?= ../../../../heffte/build
3+
4+
DEBUG = FALSE
5+
DIM = 3
6+
COMP = gcc
7+
TINY_PROFILE = TRUE
8+
USE_MPI = TRUE
9+
USE_CUDA = FALSE
10+
USE_HIP = FALSE
11+
12+
BL_NO_FORT = TRUE
13+
14+
include $(AMREX_HOME)/Tools/GNUMake/Make.defs
15+
include $(AMREX_HOME)/Src/Base/Make.package
16+
include Make.package
17+
18+
VPATH_LOCATIONS += $(HEFFTE_HOME)/include
19+
INCLUDE_LOCATIONS += $(HEFFTE_HOME)/include
20+
LIBRARY_LOCATIONS += $(HEFFTE_HOME)/lib
21+
22+
libraries += -lheffte
23+
24+
ifeq ($(USE_CUDA),TRUE)
25+
libraries += -lcufft
26+
else ifeq ($(USE_HIP),TRUE)
27+
# Use rocFFT. ROC_PATH is defined in amrex
28+
INCLUDE_LOCATIONS += $(ROC_PATH)/rocfft/include
29+
LIBRARY_LOCATIONS += $(ROC_PATH)/rocfft/lib
30+
LIBRARIES += -L$(ROC_PATH)/rocfft/lib -lrocfft
31+
else
32+
libraries += -lfftw3_mpi -lfftw3f -lfftw3
33+
endif
34+
35+
include $(AMREX_HOME)/Tools/GNUMake/Make.rules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CEXE_sources += main.cpp

ExampleCodes/heFFTe/Basic/README

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
heFFTe instaallation guide:
2+
https://icl-utk-edu.github.io/heffte/md_doxygen_installation.html
3+
4+
Installation
5+
6+
>> git clone [email protected]:icl-utk-edu/heffte.git
7+
OR
8+
>> git clone https://github.com/icl-utk-edu/heffte.git
9+
10+
>> cd heffte
11+
>> mkdir build
12+
>> cd build
13+
14+
HOST BUILD
15+
16+
>> cmake -DCMAKE_BUILD_TYPE=Release \
17+
-DCMAKE_CXX_STANDARD=17 \
18+
-DBUILD_SHARED_LIBS=OFF \
19+
-DCMAKE_INSTALL_PREFIX=. \ # can choose any installation /path/to/heffte
20+
-DHeffte_ENABLE_FFTW=ON \
21+
-DHeffte_ENABLE_CUDA=OFF \
22+
..
23+
24+
>> make -j4
25+
>> make install
26+
27+
>> cd /path/to/amrex-tutorials/ExampleCodes/heFFTe/Basic
28+
>> make -j4 HEFFTE_HOME=/path/to/heffte
29+
30+
NVIDIA/CUDA BUILD
31+
32+
>> cmake -DCMAKE_BUILD_TYPE=Release \
33+
-DCMAKE_CXX_STANDARD=17 \
34+
-DBUILD_SHARED_LIBS=OFF \
35+
-DCMAKE_INSTALL_PREFIX=. \ # can choose any installation /path/to/heffte
36+
-DHeffte_ENABLE_FFTW=ON \
37+
-DHeffte_ENABLE_CUDA=ON \
38+
-DHeffte_DISABLE_GPU_AWARE_MPI=ON \ # OFF is not working on perlmutter
39+
..
40+
41+
>> make -j4
42+
>> make install
43+
44+
>> cd /path/to/amrex-tutorials/ExampleCodes/heFFTe/Basic/
45+
>> make -j4 USE_CUDA=TRUE HEFFTE_HOME=/path/to/heffte

ExampleCodes/heFFTe/Basic/inputs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n_cell_x = 64
2+
n_cell_y = 64
3+
n_cell_z = 64
4+
5+
max_grid_size_x = 32
6+
max_grid_size_y = 32
7+
max_grid_size_z = 64
8+
9+
prob_lo_x = 0.
10+
prob_lo_y = 0.
11+
prob_lo_z = 0.
12+
13+
prob_hi_x = 1.
14+
prob_hi_y = 1.
15+
prob_hi_z = 1.

0 commit comments

Comments
 (0)