Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[obsolete?] Fractal reconstruction #480

Draft
wants to merge 70 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c5a37c0
sgs_fra solver declaration
pdziekan Feb 28, 2022
f915875
wip on fractal refinement
pdziekan Mar 1, 2022
c1b497d
working allocation of refined arrays
pdziekan Mar 2, 2022
487b356
refined grid size dependant on the number of fractal reconstructions
pdziekan Mar 2, 2022
1ad25f3
fix refine_grid_size()
pdziekan Mar 2, 2022
f3885aa
mem_factory function
pdziekan Mar 2, 2022
47348d7
consitional choice of shmem / shmem_refined
pdziekan Mar 2, 2022
a6e8b43
consitional choice of shmem / shmem_refined - upgraded
pdziekan Mar 3, 2022
be93f45
working shmem / shmem_recon stuff? (openmp and 3d only for now)
pdziekan Mar 3, 2022
963be45
solver_family protected again + solver doesnt inherit from family tag
pdziekan Mar 3, 2022
d361919
use mem_factory in all concurr types
pdziekan Mar 3, 2022
2d956d1
second ctor for shmem_refined in mem_t in each concurr type
pdziekan Mar 3, 2022
7d54514
alloc tmp with custom grid size in 1d and 2d
pdziekan Mar 3, 2022
3f81179
hdf5: store refined data
pdziekan Mar 7, 2022
71f4d70
xmf: record refined aux
pdziekan Mar 7, 2022
0fe0730
hdf5: store refined X,Y,Z TODO: make it conditional
pdziekan Mar 7, 2022
caaffb4
xmf writer: add reference writing
pdziekan Mar 7, 2022
1beeef1
xmf: write refined data using separate xmf_writer
pdziekan Mar 7, 2022
cb7d541
Merge branch 'master' of github.com:igfuw/libmpdataxx into fractal
pdziekan Mar 15, 2022
54e392b
fix grid size refinement strategy
pdziekan Mar 16, 2022
fb08f52
wip on refinement: fixed positions in output, added refined ijk
pdziekan Mar 16, 2022
e9984b5
refined fields without halos
pdziekan Mar 17, 2022
3f540a9
refined grid: halo of n_ref/2
pdziekan Mar 17, 2022
87df456
Revert "refined grid: halo of n_ref/2"
pdziekan Mar 17, 2022
aba74b3
wip on refined interpolation
pdziekan Mar 17, 2022
6aab97c
wip on interpolation
pdziekan Mar 18, 2022
e622df1
interpolation: hardocode two iterations, still no interpolation at sh…
pdziekan Mar 18, 2022
669194a
wip on interpolation at edges
pdziekan Mar 21, 2022
fe9d8f8
shmem_ref: require grid size that makes fractal reconstruction easier
pdziekan Mar 31, 2022
275789c
refinement: wip
pdziekan Mar 31, 2022
e5213f1
refinement: fix interpolation for distmem!
pdziekan Apr 1, 2022
5225da2
working interpolation of scalars
pdziekan Apr 19, 2022
c7eb23a
pbl: refine u too
pdziekan Apr 19, 2022
b0fa3f3
fra rec wip
pdziekan Apr 20, 2022
94af7cb
fra rec in 3 steps:
pdziekan Apr 20, 2022
2701722
fra rec wip
pdziekan Apr 20, 2022
93294f2
fra rec wip
pdziekan Apr 21, 2022
9866e7c
fra rec wip
pdziekan Apr 25, 2022
ab01ef0
new ref ranges working interpolation
pdziekan Apr 25, 2022
c620de4
cleanup
pdziekan Apr 25, 2022
eeaba3f
cleanup + wip on reconstruction
pdziekan Apr 25, 2022
34337eb
working reconstruction? at least for 1 iteration
pdziekan Apr 26, 2022
6c06aed
working recon, at least 1 iter
pdziekan Apr 26, 2022
42c26ac
working recon
pdziekan Apr 27, 2022
72ead36
reconstruction and interpolation: move similar code to functions
pdziekan Apr 27, 2022
12766ed
random stretching parameter
pdziekan Apr 28, 2022
549a592
move fractal reconstruction formulas to formulae/
pdziekan Apr 29, 2022
0fd42ec
Revert "move fractal reconstruction formulas to formulae/"
pdziekan Apr 29, 2022
59b3bab
Revert "Revert "move fractal reconstruction formulas to formulae/""
pdziekan Apr 29, 2022
a788a4d
pbl smg: set fra iter
pdziekan Apr 29, 2022
34ad9a5
pbl smg: fra iter 4
pdziekan Apr 29, 2022
be4a6a3
alloc refined arrays only for required advectees
pdziekan May 4, 2022
6e5ba14
grid refinement: refined boundary in the middle between mpi domains
pdziekan May 9, 2022
4275cea
cleanup
pdziekan May 9, 2022
079a75e
comments
pdziekan Jun 6, 2022
36452f9
include <random> in fractal reconstruction
pdziekan Sep 27, 2022
10a335d
stop on first compilation error in Debug mode
pdziekan Sep 27, 2022
60cd21f
sgs fra make typdefs public
pdziekan Sep 27, 2022
e5e4879
hdf5 output: handle sgs_fra family tag
pdziekan Sep 28, 2022
2c532ec
domain decmposition functions static
pdziekan Sep 28, 2022
eee8135
add hook_ante_record_all
pdziekan Sep 28, 2022
5015952
hook_pre_record_all -> hook_ante_record_all
pdziekan Sep 28, 2022
0194299
barrier in output common
pdziekan Sep 28, 2022
bbe52f9
interpolate ref: dont calc stretchin params
pdziekan Sep 30, 2022
c9b3b62
record prof refined
pdziekan Oct 3, 2022
be08975
comment
pdziekan Oct 5, 2022
815377c
formulae for averaging from refined to regular grid
pdziekan Oct 5, 2022
a7e4a9f
formulae for averaging from refined to regular grid: working but with…
pdziekan Oct 5, 2022
9217fd4
averaging from refined to regular: fixes for edge cells
pdziekan Oct 18, 2022
04ce94d
hdf output: record_aux_refined
pdziekan Oct 19, 2022
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
6 changes: 3 additions & 3 deletions libmpdata++-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(libmpdataxx_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../include/")

############################################################################################
# debug mode compiler flags
set(libmpdataxx_CXX_FLAGS_DEBUG "${libmpdataxx_CXX_FLAGS_DEBUG} -std=c++14 -DBZ_DEBUG -g -Wno-enum-compare") #TODO: -Og if compiler supports it?
set(libmpdataxx_CXX_FLAGS_DEBUG "${libmpdataxx_CXX_FLAGS_DEBUG} -std=c++17 -DBZ_DEBUG -g -Wno-enum-compare -Wfatal-errors") #TODO: -Og if compiler supports it?


############################################################################################
Expand All @@ -42,7 +42,7 @@ if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
)
set(libmpdataxx_CXX_FLAGS_RELEASE "${libmpdataxx_CXX_FLAGS_RELEASE} -std=c++14 -DNDEBUG -Ofast -march=native -Wno-enum-compare")
set(libmpdataxx_CXX_FLAGS_RELEASE "${libmpdataxx_CXX_FLAGS_RELEASE} -std=c++17 -DNDEBUG -Ofast -march=native -Wno-enum-compare")

# preventing Kahan summation from being optimised out
if (
Expand All @@ -58,7 +58,7 @@ if(
CMAKE_CXX_COMPILER_ID STREQUAL "Intel"
)
# flags taken from -fast but without -static
set(libmpdataxx_CXX_FLAGS_RELEASE "${libmpdataxx_CXX_FLAGS_RELEASE} -std=gnu++14 -DNDEBUG -xHOST -O3 -ipo -no-prec-div -fp-model fast=2")
set(libmpdataxx_CXX_FLAGS_RELEASE "${libmpdataxx_CXX_FLAGS_RELEASE} -std=gnu++17 -DNDEBUG -xHOST -O3 -ipo -no-prec-div -fp-model fast=2")
endif()


Expand Down
1 change: 1 addition & 0 deletions libmpdata++/blitz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
namespace libmpdataxx
{
template <int n_dims> using idx_t = blitz::RectDomain<n_dims>;
template <int n_dims> using idxs_t = blitz::StridedDomain<n_dims>;
using rng_t = blitz::Range;

// non-int ix_t means either rng_t or idx_t
Expand Down
8 changes: 3 additions & 5 deletions libmpdata++/concurr/boost_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ namespace libmpdataxx


// ctor
mem_t(const std::array<int, solver_t::n_dims> &grid_size) :
b(size(grid_size[0])),
parent_t::mem_t(grid_size, size(grid_size[0]))
{};
mem_t(const std::array<int, solver_t::n_dims> &grid_size, const int n_ref) : b(size(grid_size[0])), parent_t::mem_t(grid_size, size(grid_size[0]), n_ref) {};
mem_t(const std::array<int, solver_t::n_dims> &grid_size) : b(size(grid_size[0])), parent_t::mem_t(grid_size, size(grid_size[0])) {};

void barrier()
{
Expand All @@ -81,7 +79,7 @@ namespace libmpdataxx

// ctor
boost_thread(const typename solver_t::rt_params_t &p) :
parent_t(p, new mem_t(p.grid_size), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
parent_t(p, detail::mem_factory<mem_t, solver_t>(p), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
{}

};
Expand Down
8 changes: 3 additions & 5 deletions libmpdata++/concurr/cxx11_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ namespace libmpdataxx
}

// ctor
mem_t(const std::array<int, solver_t::n_dims> &grid_size) :
b(size(grid_size[0])),
parent_t::mem_t(grid_size, size(grid_size[0]))
{};
mem_t(const std::array<int, solver_t::n_dims> &grid_size, const int n_ref) : b(size(grid_size[0])), parent_t::mem_t(grid_size, size(grid_size[0]), n_ref) {};
mem_t(const std::array<int, solver_t::n_dims> &grid_size) : b(size(grid_size[0])), parent_t::mem_t(grid_size, size(grid_size[0])) {};

void barrier()
{
Expand All @@ -119,7 +117,7 @@ namespace libmpdataxx

// ctor
cxx11_thread(const typename solver_t::rt_params_t &p) :
parent_t(p, new mem_t(p.grid_size), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
parent_t(p, detail::mem_factory<mem_t, solver_t>(p), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
{}

};
Expand Down
20 changes: 13 additions & 7 deletions libmpdata++/concurr/detail/concurr_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <boost/ptr_container/ptr_vector.hpp>
#include <libmpdata++/blitz.hpp>

#include <libmpdata++/concurr/detail/sharedmem.hpp>
#include <libmpdata++/concurr/detail/sharedmem_refined.hpp>
#include <libmpdata++/concurr/detail/timer.hpp>
#include <libmpdata++/concurr/any.hpp>

Expand All @@ -34,6 +34,8 @@
#include <libmpdata++/bcond/remote_3d.hpp>
#include <libmpdata++/bcond/gndsky_3d.hpp>

#include <libmpdata++/solvers/detail/solver_type_traits.hpp>

namespace libmpdataxx
{
namespace concurr
Expand Down Expand Up @@ -149,12 +151,7 @@ namespace libmpdataxx

protected:

// (cannot be nested due to templates)
typedef sharedmem<
typename solver_t::real_t,
solver_t::n_dims,
solver_t::n_tlev
> mem_t;
using mem_t = typename solver_t::mem_t;

// member fields
boost::ptr_vector<solver_t> algos;
Expand Down Expand Up @@ -452,6 +449,15 @@ namespace libmpdataxx
return mem->max(mem->advectee(e));
}
};

template< class mem_t, class solver_t>
mem_t* mem_factory(const typename solver_t::rt_params_t &p)
{
if constexpr (solvers::detail::slvr_with_frac_recn<typename solver_t::ct_params_t_>())
return new mem_t(p.grid_size, pow(2, p.n_fra_iter));
else
return new mem_t(p.grid_size);
}
} // namespace detail
} // namespace concurr
} // namespace libmpdataxx
1 change: 1 addition & 0 deletions libmpdata++/concurr/detail/distmem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace libmpdataxx
public:

std::array<int, n_dims> grid_size;
std::array<int, n_dims> grid_size_ref;

int rank()
{
Expand Down
7 changes: 4 additions & 3 deletions libmpdata++/concurr/detail/sharedmem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ namespace libmpdataxx
rng_t(0, grid_size[d]-1),
d == 0 ? distmem.rank() : 0, // decomposition along x, because that's MPI decomposition
d == 0 ? distmem.size() : 1
// d == shmem_decomp_dim ? distmem.rank() : 0,
// d == shmem_decomp_dim ? distmem.size() : 1
);
origin[d] = this->grid_size[d].first();
}
Expand Down Expand Up @@ -294,6 +292,7 @@ namespace libmpdataxx
}

virtual arr_t advectee(int e = 0) = 0;
virtual const arr_t advectee_global(int e = 0) = 0;

void advectee_global_set(const arr_t arr, int e = 0)
{
Expand Down Expand Up @@ -507,9 +506,11 @@ namespace libmpdataxx
class sharedmem<real_t, 3, n_tlev> : public sharedmem_common<real_t, 3, n_tlev>
{
using parent_t = sharedmem_common<real_t, 3, n_tlev>;
using arr_t = typename parent_t::arr_t;
using parent_t::parent_t; // inheriting ctors

protected:
using arr_t = typename parent_t::arr_t;

public:

virtual arr_t *never_delete(arr_t *arg) override
Expand Down
122 changes: 122 additions & 0 deletions libmpdata++/concurr/detail/sharedmem_refined.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/** @file
* @copyright University of Warsaw
* @section LICENSE
* GPLv3+ (see the COPYING file or http://www.gnu.org/licenses/)
*/

// memory management with (fractal) grid refinement

#pragma once

#include "sharedmem.hpp"

namespace libmpdataxx
{
namespace concurr
{
namespace detail
{
template <
typename real_t,
int n_dims,
int n_tlev
>
class sharedmem_refined_common : public sharedmem<real_t, n_dims, n_tlev>
{
using parent_t = sharedmem<real_t, n_dims, n_tlev>;

protected:

using arr_t = typename parent_t::arr_t;

blitz::TinyVector<int, n_dims> origin_ref;

public:

const int n_ref; // number of equal divisions of the large cell (in each direction), refined resolution is dx / n_ref;
// every n_ref scalar of the refined grid is at the same position as a scalar of the normal grid
// no refinement done in the halo, because there are no SD in the halo (it's not real space)
// what about MPI boundaries? there are refined points exactly at the boundary (since n_ref has to be even)
// note: if there is a refined cell that is divided by the MPI boundary, o we need to add contributions from microphysics to both processes on both sides?
// maybe not, because microphysics contrbutions will affect the large cells, which are not divided by the MPI boundary...

std::array<rng_t, n_dims> grid_size_ref;
// TODO: these are public because used from outside in alloc - could friendship help?
//arrvec_t<arr_t> GC_ref, psi_ref;
arrvec_t<arr_t> psi_ref;

// ctors
sharedmem_refined_common(const std::array<int, n_dims> &grid_size, const int &size, const int &n_ref)
: parent_t(grid_size, size), n_ref(n_ref)
{
assert(n_ref % 2 == 0); // only division into even number of cells, because we assume that one of the refined scalar points is at the MPI boundary, which is in the middle between normal grid scalars

// for now, require a grid_size that is convenient for fractal reconstruction (which calculates 2 points based on 3 points)
// NOTE: fix this with proper halos (cyclic is easy, but what about rigid?)
// NOTE2: this is actually a requirement for fractal reconstruction, not for any grid refinement, so move this somewhere else
for (int d = 0; d < n_dims; ++d)
if((grid_size[d] - 3) % 2 != 0) throw std::runtime_error("Fractal grid refinement requires nx/ny/nz = 3 + 2 * i, where i = 0,1,2,3,...");

for (int d = 0; d < n_dims; ++d)
{
grid_size_ref[d] = refine_grid_size(
this->grid_size[d],
n_ref,
d == 0 ? this->distmem.rank() : 0,
d == 0 ? this->distmem.size() : 1
);
origin_ref[d] = grid_size_ref[d].first();

this->distmem.grid_size_ref[d] = refine_grid_size(rng_t(0,grid_size[d]-1), n_ref, 0, 1).length();
}
}

// NOTE: not all advectees are refined, so e (numbering) in refinee is different than in advectee
virtual arr_t refinee(int e = 0) = 0;
// virtual const arr_t refinee_global_ref(int e = 0) = 0;

public:
static rng_t refine_grid_size(
const rng_t &grid_size,
const int &n_ref,
const int &mpi_rank,
const int &mpi_size
) {
assert(n_ref % 2 == 0);
// NOTE: overlapping points inbetween MPI domains
return rng_t(
mpi_rank == 0 ? grid_size.first() * n_ref : grid_size.first() * n_ref - n_ref / 2,
mpi_rank == mpi_size-1 ? grid_size.last() * n_ref : grid_size.last() * n_ref + n_ref / 2 // refined points between MPI domains are evenly divided between MPI processes
);
}
};



template<typename real_t, int n_dims, int n_tlev>
class sharedmem_refined
{};

template<typename real_t, int n_tlev>
class sharedmem_refined<real_t, 3, n_tlev> : public sharedmem_refined_common<real_t, 3, n_tlev>
{
using parent_t = sharedmem_refined_common<real_t, 3, n_tlev>;
using parent_t::parent_t; // inheriting ctors

protected:
using arr_t = typename parent_t::arr_t;

public:
arr_t refinee(int e = 0) override
{
return this->psi_ref[e](
this->grid_size_ref[0],
this->grid_size_ref[1],
this->grid_size_ref[2]
).reindex(this->origin_ref);
}
};

} // namespace detail
} // namespace concurr
} // namespace libmpdataxx
7 changes: 3 additions & 4 deletions libmpdata++/concurr/openmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace libmpdataxx
{
using parent_t = detail::concurr_common<solver_t, bcxl, bcxr, bcyl, bcyr, bczl, bczr>;


struct mem_t : parent_t::mem_t
{
static int size(const unsigned max_threads = std::numeric_limits<unsigned>::max())
Expand All @@ -58,7 +57,8 @@ namespace libmpdataxx
}

// ctors
mem_t(const std::array<int, solver_t::n_dims> &grid_size) : parent_t::mem_t(grid_size, size(grid_size[0])) {};
mem_t(const std::array<int, solver_t::n_dims> &grid_size, const int n_ref) : parent_t::mem_t(grid_size, size(grid_size[0]), n_ref) {};
mem_t(const std::array<int, solver_t::n_dims> &grid_size) : parent_t::mem_t(grid_size, size(grid_size[0])) {};
};

void solve(typename parent_t::advance_arg_t nt)
Expand All @@ -75,9 +75,8 @@ namespace libmpdataxx

public:

// ctor
openmp(const typename solver_t::rt_params_t &p) :
parent_t(p, new mem_t(p.grid_size), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
parent_t(p, detail::mem_factory<mem_t, solver_t>(p), mem_t::size(p.grid_size[solver_t::n_dims < 3 ? 0 : 1])) // note 3D domain decomposition in y direction
{}

};
Expand Down
7 changes: 3 additions & 4 deletions libmpdata++/concurr/serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ namespace libmpdataxx
void barrier() { }

// ctors
mem_t(const std::array<int, solver_t::n_dims> &grid_size)
: parent_t::mem_t(grid_size, size())
{};
mem_t(const std::array<int, solver_t::n_dims> &grid_size, const int n_ref) : parent_t::mem_t(grid_size, size(grid_size[0]), n_ref) {};
mem_t(const std::array<int, solver_t::n_dims> &grid_size) : parent_t::mem_t(grid_size, size(grid_size[0])) {};
};

void solve(typename parent_t::advance_arg_t nt)
Expand All @@ -47,7 +46,7 @@ namespace libmpdataxx

// ctor
serial(const typename solver_t::rt_params_t &p) :
parent_t(p, new mem_t(p.grid_size), mem_t::size())
parent_t(p, detail::mem_factory<mem_t, solver_t>(p), mem_t::size())
{}

};
Expand Down
Loading