Initial import

This commit is contained in:
Guilhem Lavaux 2023-05-29 10:41:03 +02:00
commit 56a50eead3
820 changed files with 192077 additions and 0 deletions

View file

@ -0,0 +1,84 @@
include(${CMAKE_SOURCE_DIR}/cmake_modules/test_macros.cmake)
SET(LIBS
${COSMOTOOL_LIB}
${BOOST_LIBRARIES} ${HDF5_CXX_LIBRARIES}
${HEALPIX_LIBRARIES} ${HDF5_LIBRARIES}
${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${FFTW_LIBRARIES}
${ZLIB_LIBRARY}
${DL_LIBRARY}
${EXTRA_LIB})
IF(RT_LIBRARY)
SET(LIBS ${LIBS} ${RT_LIBRARY} ${FFTW_LIBRARIES})
ENDIF(RT_LIBRARY)
SET(TEST_LIBRARY_SRCS)
SET(TEST_targets)
SET(TEST_base_LIST
console has_member proj
messenger messenger2 messenger3 schechter
rgen window3d
slice_sweep slice_sweep_double cic mngp uninit fused_array
supersampling gradient_supersampling array auto_interpolator
gig fuse_wrapper tuple fused_cond cic_adjoint cg
cpu_feature
r3d hdf5_buffered
overload class_interface
)
macro(ares_add_test_targets)
list(APPEND TEST_targets ${ARGN})
endmacro()
IF (BUILD_TESTING)
add_executable(test_stl_container test_stl_container.cpp)
foreach(module IN LISTS ARES_MODULES ITEMS base)
add_liblss_test_module(${module})
foreach(test_name IN ITEMS ${TEST_${module}_LIST})
if (${module} STREQUAL base)
set(_src ${CMAKE_SOURCE_DIR}/libLSS/tests)
else()
set(_src ${CMAKE_SOURCE_DIR}/extra/${module}/libLSS/tests)
endif()
add_executable(test_${test_name} ${_src}/test_${test_name}.cpp)
SET(test_lib ${LIBS})
if (TEST_${test_name}_LIBS)
SET(test_lib ${test_lib} ${TEST_${test_name}_LIBS})
endif()
target_link_libraries(test_${test_name} test_library_LSS LSS ${test_lib})
add_dependencies(test_${test_name} ${ares_DEPS})
ares_add_test_targets(test_${test_name})
endforeach(test_name)
endforeach()
add_library(test_library_LSS dummy_file.cpp testFramework.cpp ${TEST_LIBRARY_SOURCES})
add_dependencies(test_library_LSS ${ares_DEPS})
macro(list_join listname separator output)
set(${output})
foreach(X IN LISTS ${listname})
set(${output} "${${output}}${separator}${X}")
endforeach()
endmacro()
list_join(TEST_targets " " _TEST_targets)
add_custom_target(all_tests)
cmessage(STATUS "Meta deps : ${_TEST_targets}")
add_dependencies(all_tests ${TEST_targets})
add_direct_test(test_cosmo_expansion ${CMAKE_CURRENT_SOURCE_DIR}/test_cosmo_expansion.cpp)
add_check_output_test(test_auto_interpolator ${CMAKE_CURRENT_SOURCE_DIR}/test_auto_interpolator.cpp "")
add_test_to_run(test_overload test_overload)
#add_test(NAME adam COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_adam)
add_test(NAME cg COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_cg)
endif()

View file

@ -0,0 +1,17 @@
#+
# ARES/HADES/BORG Package -- ./libLSS/tests/data/gen_reference_data.py
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
#
# Additional contributions from:
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
#
#+
import h5py as h5
import numpy as np
with h5.File("reference_data.h5", mode="w") as f:
for N in [32]:
numbers = np.random.normal(size=(N,N,N))
f[f'/f_size_{N}'] = numbers
f[f'/c_size_{N}'] = np.fft.rfftn(numbers)

Binary file not shown.

View file

@ -0,0 +1,10 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/dummy_file.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
/* empty file just to quiet CMake */

70
libLSS/tests/plot_grav.py Normal file
View file

@ -0,0 +1,70 @@
#+
# ARES/HADES/BORG Package -- ./libLSS/tests/plot_grav.py
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
#
# Additional contributions from:
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
#
#+
import h5py as h5
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
H100=100.e3
h=0.68
L=100.
N=128
G=6.67e-11
omega_m=0.30
Mpc_in_m=3.08567758e22
udistance=1.*Mpc_in_m
dmean = 1.0/(float(N)**3)
with h5.File("gravity.h5") as f:
g = f['gravity'][...]
p = f['position'][...]
pot = f['potential'][...]
ud = f['unit_density'][0]
up = f['unit_potential'][0]
ud *= Mpc_in_m**3
g = g[:(g.shape[0]/2),:]
p = p[:(p.shape[0]/2),:]
pot = pot[:(pot.shape[0]/2)]
ref = np.array([L/2,0,L/2])
plt.clf()
#plt.plot(-g[:,0])
plt.plot(p[:,1],-g[:,1])
yy = p[:,1]
aa = 6.67e-11 * ud * (L/N)**3 * yy/yy**3
plt.plot(yy, aa)
plt.gca().set_yscale('log')
plt.gca().set_xscale('log')
#plt.plot(g[:,2])
plt.gcf().savefig("grav.png")
xx=np.arange(N/2)*L/N
mass = 3*(H100*h/Mpc_in_m)**2/(8*np.pi*G) * omega_m * (Mpc_in_m)**3
real_pot = 6.67e-11 * mass / (udistance*xx)
plt.clf()
plt.plot(xx,pot*up)
plt.plot(xx,real_pot)
plt.gca().set_yscale('log')
plt.gca().set_xscale('log')
plt.gcf().savefig("pot.png")

BIN
libLSS/tests/ref_pm.h5 Normal file

Binary file not shown.

View file

@ -0,0 +1,14 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/testFramework.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <string>
#include "libLSS/tests/testFramework.hpp"
#include "libLSS/cconfig.h"
std::string LibLSS_tests::reference_path = __LIBLSS_TEST_REFERENCE_PATH;

View file

@ -0,0 +1,47 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/testFramework.hpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#ifndef __LIBLSS_TESTS_TESTFRAMEWORK_HPP
#define __LIBLSS_TESTS_TESTFRAMEWORK_HPP
#include <H5Cpp.h>
#include <boost/format.hpp>
#include <CosmoTool/hdf5_array.hpp>
namespace LibLSS_tests {
extern std::string reference_path;
namespace {
namespace prefix {
namespace details {
std::string prefix_type(float a) { return "f"; }
std::string prefix_type(double a) { return "f"; }
std::string prefix_type(int a) { return "i"; }
std::string prefix_type(std::complex<float> a) { return "c"; }
std::string prefix_type(std::complex<double> a) { return "c"; }
} // namespace details
template <typename T>
std::string get() {
return details::prefix_type(T());
}
} // namespace prefix
} // namespace
template <typename T>
void loadReferenceInput(size_t N, boost::multi_array_ref<T, 3> &data) {
H5::H5File f(reference_path, H5F_ACC_RDONLY);
CosmoTool::hdf5_read_array(
f, boost::str(boost::format("%s_size_%d") % prefix::get<T>() % N), data,
false, true);
}
} // namespace LibLSS_tests
#endif

View file

@ -0,0 +1,73 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_array.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <boost/config.hpp>
#ifdef BOOST_NO_CXX11_AUTO_DECLARATIONS
#error This test needs C++11 features to compile.
#else
#include <boost/multi_array.hpp>
#include "libLSS/tools/array_tools.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/log_traits.hpp"
#include "libLSS/tools/fused_assign.hpp"
#include "libLSS/tools/fused_array.hpp"
#include <boost/lambda/lambda.hpp>
#include <boost/bind/bind.hpp>
using boost::placeholders::_1;
using namespace LibLSS;
static
void aSwapper(boost::multi_array<double,1>& a, long i, long j)
{
std::swap(a[i], a[j]);
}
int main(int argc, char **argv)
{
using boost::extents;
setupMPI(argc, argv);
LibLSS::StaticInit::execute();
boost::multi_array<double,1> a(extents[10]);
boost::multi_array<long,1> idx(extents[10]);
copy_array(a, b_fused_idx<double, 1>(10.0-boost::lambda::_1));
copy_array(idx, b_fused_idx<long, 1>(9-boost::lambda::_1));
for (int i = 0; i < 100; i++) {
int j = drand48()*a.shape()[0];
int k = drand48()*a.shape()[0];
std::swap(a[j],a[k]);
std::swap(idx[j],idx[k]);
}
std::cout << "Before sorting" << std::endl;
for (auto r : a) {
std::cout << r << std::endl;
}
array::reorder(idx, boost::bind(aSwapper, boost::ref(a), boost::placeholders::_1, boost::placeholders::_2));
std::cout << "After sorting" << std::endl;
for (auto r : a) {
std::cout << r << std::endl;
}
doneMPI();
return 0;
}
#endif

View file

@ -0,0 +1,30 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_auto_interpolator.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/tools/auto_interpolator.hpp"
#include <boost/lambda/lambda.hpp>
#include <CosmoTool/algo.hpp>
using namespace LibLSS;
int main()
{
using boost::lambda::_1;
auto a = build_auto_interpolator(CosmoTool::square<double>, 0., 4., 0.1, 0., 16.);
for (double i = -2; i < 7; i+=0.01)
std::cout << i << " " << a(i) << " " << (i*i) << std::endl;
auto_interpolator<double> b;
b = a;
return 0;
}

View file

@ -0,0 +1,901 @@
-2 0 4
-1.99 0 3.9601
-1.98 0 3.9204
-1.97 0 3.8809
-1.96 0 3.8416
-1.95 0 3.8025
-1.94 0 3.7636
-1.93 0 3.7249
-1.92 0 3.6864
-1.91 0 3.6481
-1.9 0 3.61
-1.89 0 3.5721
-1.88 0 3.5344
-1.87 0 3.4969
-1.86 0 3.4596
-1.85 0 3.4225
-1.84 0 3.3856
-1.83 0 3.3489
-1.82 0 3.3124
-1.81 0 3.2761
-1.8 0 3.24
-1.79 0 3.2041
-1.78 0 3.1684
-1.77 0 3.1329
-1.76 0 3.0976
-1.75 0 3.0625
-1.74 0 3.0276
-1.73 0 2.9929
-1.72 0 2.9584
-1.71 0 2.9241
-1.7 0 2.89
-1.69 0 2.8561
-1.68 0 2.8224
-1.67 0 2.7889
-1.66 0 2.7556
-1.65 0 2.7225
-1.64 0 2.6896
-1.63 0 2.6569
-1.62 0 2.6244
-1.61 0 2.5921
-1.6 0 2.56
-1.59 0 2.5281
-1.58 0 2.4964
-1.57 0 2.4649
-1.56 0 2.4336
-1.55 0 2.4025
-1.54 0 2.3716
-1.53 0 2.3409
-1.52 0 2.3104
-1.51 0 2.2801
-1.5 0 2.25
-1.49 0 2.2201
-1.48 0 2.1904
-1.47 0 2.1609
-1.46 0 2.1316
-1.45 0 2.1025
-1.44 0 2.0736
-1.43 0 2.0449
-1.42 0 2.0164
-1.41 0 1.9881
-1.4 0 1.96
-1.39 0 1.9321
-1.38 0 1.9044
-1.37 0 1.8769
-1.36 0 1.8496
-1.35 0 1.8225
-1.34 0 1.7956
-1.33 0 1.7689
-1.32 0 1.7424
-1.31 0 1.7161
-1.3 0 1.69
-1.29 0 1.6641
-1.28 0 1.6384
-1.27 0 1.6129
-1.26 0 1.5876
-1.25 0 1.5625
-1.24 0 1.5376
-1.23 0 1.5129
-1.22 0 1.4884
-1.21 0 1.4641
-1.2 0 1.44
-1.19 0 1.4161
-1.18 0 1.3924
-1.17 0 1.3689
-1.16 0 1.3456
-1.15 0 1.3225
-1.14 0 1.2996
-1.13 0 1.2769
-1.12 0 1.2544
-1.11 0 1.2321
-1.1 0 1.21
-1.09 0 1.1881
-1.08 0 1.1664
-1.07 0 1.1449
-1.06 0 1.1236
-1.05 0 1.1025
-1.04 0 1.0816
-1.03 0 1.0609
-1.02 0 1.0404
-1.01 0 1.0201
-1 0 1
-0.99 0 0.9801
-0.98 0 0.9604
-0.97 0 0.9409
-0.96 0 0.9216
-0.95 0 0.9025
-0.94 0 0.8836
-0.93 0 0.8649
-0.92 0 0.8464
-0.91 0 0.8281
-0.9 0 0.81
-0.89 0 0.7921
-0.88 0 0.7744
-0.87 0 0.7569
-0.86 0 0.7396
-0.85 0 0.7225
-0.84 0 0.7056
-0.83 0 0.6889
-0.82 0 0.6724
-0.81 0 0.6561
-0.8 0 0.64
-0.79 0 0.6241
-0.78 0 0.6084
-0.77 0 0.5929
-0.76 0 0.5776
-0.75 0 0.5625
-0.74 0 0.5476
-0.73 0 0.5329
-0.72 0 0.5184
-0.71 0 0.5041
-0.7 0 0.49
-0.69 0 0.4761
-0.68 0 0.4624
-0.67 0 0.4489
-0.66 0 0.4356
-0.65 0 0.4225
-0.64 0 0.4096
-0.63 0 0.3969
-0.62 0 0.3844
-0.61 0 0.3721
-0.6 0 0.36
-0.59 0 0.3481
-0.58 0 0.3364
-0.57 0 0.3249
-0.56 0 0.3136
-0.55 0 0.3025
-0.54 0 0.2916
-0.53 0 0.2809
-0.52 0 0.2704
-0.51 0 0.2601
-0.5 0 0.25
-0.49 0 0.2401
-0.48 0 0.2304
-0.47 0 0.2209
-0.46 0 0.2116
-0.45 0 0.2025
-0.44 0 0.1936
-0.43 0 0.1849
-0.42 0 0.1764
-0.41 0 0.1681
-0.4 0 0.16
-0.39 0 0.1521
-0.38 0 0.1444
-0.37 0 0.1369
-0.36 0 0.1296
-0.35 0 0.1225
-0.34 0 0.1156
-0.33 0 0.1089
-0.32 0 0.1024
-0.31 0 0.0961
-0.3 0 0.09
-0.29 0 0.0841
-0.28 0 0.0784
-0.27 0 0.0729
-0.26 0 0.0676
-0.25 0 0.0625
-0.24 0 0.0576
-0.23 0 0.0529
-0.22 0 0.0484
-0.21 0 0.0441
-0.2 0 0.04
-0.19 0 0.0361
-0.18 0 0.0324
-0.17 0 0.0289
-0.16 0 0.0256
-0.15 0 0.0225
-0.14 0 0.0196
-0.13 0 0.0169
-0.12 0 0.0144
-0.11 0 0.0121
-0.1 0 0.01
-0.09 0 0.0081
-0.08 0 0.0064
-0.07 0 0.0049
-0.06 0 0.0036
-0.05 0 0.0025
-0.04 0 0.0016
-0.03 0 0.0009
-0.02 0 0.0004
-0.01 0 0.0001
1.64105e-15 1.64105e-16 2.69304e-30
0.01 0.001 0.0001
0.02 0.002 0.0004
0.03 0.003 0.0009
0.04 0.004 0.0016
0.05 0.005 0.0025
0.06 0.006 0.0036
0.07 0.007 0.0049
0.08 0.008 0.0064
0.09 0.009 0.0081
0.1 0.01 0.01
0.11 0.013 0.0121
0.12 0.016 0.0144
0.13 0.019 0.0169
0.14 0.022 0.0196
0.15 0.025 0.0225
0.16 0.028 0.0256
0.17 0.031 0.0289
0.18 0.034 0.0324
0.19 0.037 0.0361
0.2 0.04 0.04
0.21 0.045 0.0441
0.22 0.05 0.0484
0.23 0.055 0.0529
0.24 0.06 0.0576
0.25 0.065 0.0625
0.26 0.07 0.0676
0.27 0.075 0.0729
0.28 0.08 0.0784
0.29 0.085 0.0841
0.3 0.09 0.09
0.31 0.097 0.0961
0.32 0.104 0.1024
0.33 0.111 0.1089
0.34 0.118 0.1156
0.35 0.125 0.1225
0.36 0.132 0.1296
0.37 0.139 0.1369
0.38 0.146 0.1444
0.39 0.153 0.1521
0.4 0.16 0.16
0.41 0.169 0.1681
0.42 0.178 0.1764
0.43 0.187 0.1849
0.44 0.196 0.1936
0.45 0.205 0.2025
0.46 0.214 0.2116
0.47 0.223 0.2209
0.48 0.232 0.2304
0.49 0.241 0.2401
0.5 0.25 0.25
0.51 0.261 0.2601
0.52 0.272 0.2704
0.53 0.283 0.2809
0.54 0.294 0.2916
0.55 0.305 0.3025
0.56 0.316 0.3136
0.57 0.327 0.3249
0.58 0.338 0.3364
0.59 0.349 0.3481
0.6 0.36 0.36
0.61 0.373 0.3721
0.62 0.386 0.3844
0.63 0.399 0.3969
0.64 0.412 0.4096
0.65 0.425 0.4225
0.66 0.438 0.4356
0.67 0.451 0.4489
0.68 0.464 0.4624
0.69 0.477 0.4761
0.7 0.49 0.49
0.71 0.505 0.5041
0.72 0.52 0.5184
0.73 0.535 0.5329
0.74 0.55 0.5476
0.75 0.565 0.5625
0.76 0.58 0.5776
0.77 0.595 0.5929
0.78 0.61 0.6084
0.79 0.625 0.6241
0.8 0.64 0.64
0.81 0.657 0.6561
0.82 0.674 0.6724
0.83 0.691 0.6889
0.84 0.708 0.7056
0.85 0.725 0.7225
0.86 0.742 0.7396
0.87 0.759 0.7569
0.88 0.776 0.7744
0.89 0.793 0.7921
0.9 0.81 0.81
0.91 0.829 0.8281
0.92 0.848 0.8464
0.93 0.867 0.8649
0.94 0.886 0.8836
0.95 0.905 0.9025
0.96 0.924 0.9216
0.97 0.943 0.9409
0.98 0.962 0.9604
0.99 0.981 0.9801
1 1 1
1.01 1.021 1.0201
1.02 1.042 1.0404
1.03 1.063 1.0609
1.04 1.084 1.0816
1.05 1.105 1.1025
1.06 1.126 1.1236
1.07 1.147 1.1449
1.08 1.168 1.1664
1.09 1.189 1.1881
1.1 1.21 1.21
1.11 1.233 1.2321
1.12 1.256 1.2544
1.13 1.279 1.2769
1.14 1.302 1.2996
1.15 1.325 1.3225
1.16 1.348 1.3456
1.17 1.371 1.3689
1.18 1.394 1.3924
1.19 1.417 1.4161
1.2 1.44 1.44
1.21 1.465 1.4641
1.22 1.49 1.4884
1.23 1.515 1.5129
1.24 1.54 1.5376
1.25 1.565 1.5625
1.26 1.59 1.5876
1.27 1.615 1.6129
1.28 1.64 1.6384
1.29 1.665 1.6641
1.3 1.69 1.69
1.31 1.717 1.7161
1.32 1.744 1.7424
1.33 1.771 1.7689
1.34 1.798 1.7956
1.35 1.825 1.8225
1.36 1.852 1.8496
1.37 1.879 1.8769
1.38 1.906 1.9044
1.39 1.933 1.9321
1.4 1.96 1.96
1.41 1.989 1.9881
1.42 2.018 2.0164
1.43 2.047 2.0449
1.44 2.076 2.0736
1.45 2.105 2.1025
1.46 2.134 2.1316
1.47 2.163 2.1609
1.48 2.192 2.1904
1.49 2.221 2.2201
1.5 2.25 2.25
1.51 2.281 2.2801
1.52 2.312 2.3104
1.53 2.343 2.3409
1.54 2.374 2.3716
1.55 2.405 2.4025
1.56 2.436 2.4336
1.57 2.467 2.4649
1.58 2.498 2.4964
1.59 2.529 2.5281
1.6 2.56 2.56
1.61 2.593 2.5921
1.62 2.626 2.6244
1.63 2.659 2.6569
1.64 2.692 2.6896
1.65 2.725 2.7225
1.66 2.758 2.7556
1.67 2.791 2.7889
1.68 2.824 2.8224
1.69 2.857 2.8561
1.7 2.89 2.89
1.71 2.925 2.9241
1.72 2.96 2.9584
1.73 2.995 2.9929
1.74 3.03 3.0276
1.75 3.065 3.0625
1.76 3.1 3.0976
1.77 3.135 3.1329
1.78 3.17 3.1684
1.79 3.205 3.2041
1.8 3.24 3.24
1.81 3.277 3.2761
1.82 3.314 3.3124
1.83 3.351 3.3489
1.84 3.388 3.3856
1.85 3.425 3.4225
1.86 3.462 3.4596
1.87 3.499 3.4969
1.88 3.536 3.5344
1.89 3.573 3.5721
1.9 3.61 3.61
1.91 3.649 3.6481
1.92 3.688 3.6864
1.93 3.727 3.7249
1.94 3.766 3.7636
1.95 3.805 3.8025
1.96 3.844 3.8416
1.97 3.883 3.8809
1.98 3.922 3.9204
1.99 3.961 3.9601
2 4 4
2.01 4.041 4.0401
2.02 4.082 4.0804
2.03 4.123 4.1209
2.04 4.164 4.1616
2.05 4.205 4.2025
2.06 4.246 4.2436
2.07 4.287 4.2849
2.08 4.328 4.3264
2.09 4.369 4.3681
2.1 4.41 4.41
2.11 4.453 4.4521
2.12 4.496 4.4944
2.13 4.539 4.5369
2.14 4.582 4.5796
2.15 4.625 4.6225
2.16 4.668 4.6656
2.17 4.711 4.7089
2.18 4.754 4.7524
2.19 4.797 4.7961
2.2 4.84 4.84
2.21 4.885 4.8841
2.22 4.93 4.9284
2.23 4.975 4.9729
2.24 5.02 5.0176
2.25 5.065 5.0625
2.26 5.11 5.1076
2.27 5.155 5.1529
2.28 5.2 5.1984
2.29 5.245 5.2441
2.3 5.29 5.29
2.31 5.337 5.3361
2.32 5.384 5.3824
2.33 5.431 5.4289
2.34 5.478 5.4756
2.35 5.525 5.5225
2.36 5.572 5.5696
2.37 5.619 5.6169
2.38 5.666 5.6644
2.39 5.713 5.7121
2.4 5.76 5.76
2.41 5.809 5.8081
2.42 5.858 5.8564
2.43 5.907 5.9049
2.44 5.956 5.9536
2.45 6.005 6.0025
2.46 6.054 6.0516
2.47 6.103 6.1009
2.48 6.152 6.1504
2.49 6.201 6.2001
2.5 6.25 6.25
2.51 6.301 6.3001
2.52 6.352 6.3504
2.53 6.403 6.4009
2.54 6.454 6.4516
2.55 6.505 6.5025
2.56 6.556 6.5536
2.57 6.607 6.6049
2.58 6.658 6.6564
2.59 6.709 6.7081
2.6 6.76 6.76
2.61 6.813 6.8121
2.62 6.866 6.8644
2.63 6.919 6.9169
2.64 6.972 6.9696
2.65 7.025 7.0225
2.66 7.078 7.0756
2.67 7.131 7.1289
2.68 7.184 7.1824
2.69 7.237 7.2361
2.7 7.29 7.29
2.71 7.345 7.3441
2.72 7.4 7.3984
2.73 7.455 7.4529
2.74 7.51 7.5076
2.75 7.565 7.5625
2.76 7.62 7.6176
2.77 7.675 7.6729
2.78 7.73 7.7284
2.79 7.785 7.7841
2.8 7.84 7.84
2.81 7.897 7.8961
2.82 7.954 7.9524
2.83 8.011 8.0089
2.84 8.068 8.0656
2.85 8.125 8.1225
2.86 8.182 8.1796
2.87 8.239 8.2369
2.88 8.296 8.2944
2.89 8.353 8.3521
2.9 8.41 8.41
2.91 8.469 8.4681
2.92 8.528 8.5264
2.93 8.587 8.5849
2.94 8.646 8.6436
2.95 8.705 8.7025
2.96 8.764 8.7616
2.97 8.823 8.8209
2.98 8.882 8.8804
2.99 8.941 8.9401
3 9 9
3.01 9.061 9.0601
3.02 9.122 9.1204
3.03 9.183 9.1809
3.04 9.244 9.2416
3.05 9.305 9.3025
3.06 9.366 9.3636
3.07 9.427 9.4249
3.08 9.488 9.4864
3.09 9.549 9.5481
3.1 9.61 9.61
3.11 9.673 9.6721
3.12 9.736 9.7344
3.13 9.799 9.7969
3.14 9.862 9.8596
3.15 9.925 9.9225
3.16 9.988 9.9856
3.17 10.051 10.0489
3.18 10.114 10.1124
3.19 10.177 10.1761
3.2 10.24 10.24
3.21 10.305 10.3041
3.22 10.37 10.3684
3.23 10.435 10.4329
3.24 10.5 10.4976
3.25 10.565 10.5625
3.26 10.63 10.6276
3.27 10.695 10.6929
3.28 10.76 10.7584
3.29 10.825 10.8241
3.3 10.89 10.89
3.31 10.957 10.9561
3.32 11.024 11.0224
3.33 11.091 11.0889
3.34 11.158 11.1556
3.35 11.225 11.2225
3.36 11.292 11.2896
3.37 11.359 11.3569
3.38 11.426 11.4244
3.39 11.493 11.4921
3.4 11.56 11.56
3.41 11.629 11.6281
3.42 11.698 11.6964
3.43 11.767 11.7649
3.44 11.836 11.8336
3.45 11.905 11.9025
3.46 11.974 11.9716
3.47 12.043 12.0409
3.48 12.112 12.1104
3.49 12.181 12.1801
3.5 12.25 12.25
3.51 12.321 12.3201
3.52 12.392 12.3904
3.53 12.463 12.4609
3.54 12.534 12.5316
3.55 12.605 12.6025
3.56 12.676 12.6736
3.57 12.747 12.7449
3.58 12.818 12.8164
3.59 12.889 12.8881
3.6 12.96 12.96
3.61 13.033 13.0321
3.62 13.106 13.1044
3.63 13.179 13.1769
3.64 13.252 13.2496
3.65 13.325 13.3225
3.66 13.398 13.3956
3.67 13.471 13.4689
3.68 13.544 13.5424
3.69 13.617 13.6161
3.7 13.69 13.69
3.71 13.765 13.7641
3.72 13.84 13.8384
3.73 13.915 13.9129
3.74 13.99 13.9876
3.75 14.065 14.0625
3.76 14.14 14.1376
3.77 14.215 14.2129
3.78 14.29 14.2884
3.79 14.365 14.3641
3.8 14.44 14.44
3.81 14.517 14.5161
3.82 14.594 14.5924
3.83 14.671 14.6689
3.84 14.748 14.7456
3.85 14.825 14.8225
3.86 14.902 14.8996
3.87 14.979 14.9769
3.88 15.056 15.0544
3.89 15.133 15.1321
3.9 15.21 15.21
3.91 16 15.2881
3.92 16 15.3664
3.93 16 15.4449
3.94 16 15.5236
3.95 16 15.6025
3.96 16 15.6816
3.97 16 15.7609
3.98 16 15.8404
3.99 16 15.9201
4 16 16
4.01 16 16.0801
4.02 16 16.1604
4.03 16 16.2409
4.04 16 16.3216
4.05 16 16.4025
4.06 16 16.4836
4.07 16 16.5649
4.08 16 16.6464
4.09 16 16.7281
4.1 16 16.81
4.11 16 16.8921
4.12 16 16.9744
4.13 16 17.0569
4.14 16 17.1396
4.15 16 17.2225
4.16 16 17.3056
4.17 16 17.3889
4.18 16 17.4724
4.19 16 17.5561
4.2 16 17.64
4.21 16 17.7241
4.22 16 17.8084
4.23 16 17.8929
4.24 16 17.9776
4.25 16 18.0625
4.26 16 18.1476
4.27 16 18.2329
4.28 16 18.3184
4.29 16 18.4041
4.3 16 18.49
4.31 16 18.5761
4.32 16 18.6624
4.33 16 18.7489
4.34 16 18.8356
4.35 16 18.9225
4.36 16 19.0096
4.37 16 19.0969
4.38 16 19.1844
4.39 16 19.2721
4.4 16 19.36
4.41 16 19.4481
4.42 16 19.5364
4.43 16 19.6249
4.44 16 19.7136
4.45 16 19.8025
4.46 16 19.8916
4.47 16 19.9809
4.48 16 20.0704
4.49 16 20.1601
4.5 16 20.25
4.51 16 20.3401
4.52 16 20.4304
4.53 16 20.5209
4.54 16 20.6116
4.55 16 20.7025
4.56 16 20.7936
4.57 16 20.8849
4.58 16 20.9764
4.59 16 21.0681
4.6 16 21.16
4.61 16 21.2521
4.62 16 21.3444
4.63 16 21.4369
4.64 16 21.5296
4.65 16 21.6225
4.66 16 21.7156
4.67 16 21.8089
4.68 16 21.9024
4.69 16 21.9961
4.7 16 22.09
4.71 16 22.1841
4.72 16 22.2784
4.73 16 22.3729
4.74 16 22.4676
4.75 16 22.5625
4.76 16 22.6576
4.77 16 22.7529
4.78 16 22.8484
4.79 16 22.9441
4.8 16 23.04
4.81 16 23.1361
4.82 16 23.2324
4.83 16 23.3289
4.84 16 23.4256
4.85 16 23.5225
4.86 16 23.6196
4.87 16 23.7169
4.88 16 23.8144
4.89 16 23.9121
4.9 16 24.01
4.91 16 24.1081
4.92 16 24.2064
4.93 16 24.3049
4.94 16 24.4036
4.95 16 24.5025
4.96 16 24.6016
4.97 16 24.7009
4.98 16 24.8004
4.99 16 24.9001
5 16 25
5.01 16 25.1001
5.02 16 25.2004
5.03 16 25.3009
5.04 16 25.4016
5.05 16 25.5025
5.06 16 25.6036
5.07 16 25.7049
5.08 16 25.8064
5.09 16 25.9081
5.1 16 26.01
5.11 16 26.1121
5.12 16 26.2144
5.13 16 26.3169
5.14 16 26.4196
5.15 16 26.5225
5.16 16 26.6256
5.17 16 26.7289
5.18 16 26.8324
5.19 16 26.9361
5.2 16 27.04
5.21 16 27.1441
5.22 16 27.2484
5.23 16 27.3529
5.24 16 27.4576
5.25 16 27.5625
5.26 16 27.6676
5.27 16 27.7729
5.28 16 27.8784
5.29 16 27.9841
5.3 16 28.09
5.31 16 28.1961
5.32 16 28.3024
5.33 16 28.4089
5.34 16 28.5156
5.35 16 28.6225
5.36 16 28.7296
5.37 16 28.8369
5.38 16 28.9444
5.39 16 29.0521
5.4 16 29.16
5.41 16 29.2681
5.42 16 29.3764
5.43 16 29.4849
5.44 16 29.5936
5.45 16 29.7025
5.46 16 29.8116
5.47 16 29.9209
5.48 16 30.0304
5.49 16 30.1401
5.5 16 30.25
5.51 16 30.3601
5.52 16 30.4704
5.53 16 30.5809
5.54 16 30.6916
5.55 16 30.8025
5.56 16 30.9136
5.57 16 31.0249
5.58 16 31.1364
5.59 16 31.2481
5.6 16 31.36
5.61 16 31.4721
5.62 16 31.5844
5.63 16 31.6969
5.64 16 31.8096
5.65 16 31.9225
5.66 16 32.0356
5.67 16 32.1489
5.68 16 32.2624
5.69 16 32.3761
5.7 16 32.49
5.71 16 32.6041
5.72 16 32.7184
5.73 16 32.8329
5.74 16 32.9476
5.75 16 33.0625
5.76 16 33.1776
5.77 16 33.2929
5.78 16 33.4084
5.79 16 33.5241
5.8 16 33.64
5.81 16 33.7561
5.82 16 33.8724
5.83 16 33.9889
5.84 16 34.1056
5.85 16 34.2225
5.86 16 34.3396
5.87 16 34.4569
5.88 16 34.5744
5.89 16 34.6921
5.9 16 34.81
5.91 16 34.9281
5.92 16 35.0464
5.93 16 35.1649
5.94 16 35.2836
5.95 16 35.4025
5.96 16 35.5216
5.97 16 35.6409
5.98 16 35.7604
5.99 16 35.8801
6 16 36
6.01 16 36.1201
6.02 16 36.2404
6.03 16 36.3609
6.04 16 36.4816
6.05 16 36.6025
6.06 16 36.7236
6.07 16 36.8449
6.08 16 36.9664
6.09 16 37.0881
6.1 16 37.21
6.11 16 37.3321
6.12 16 37.4544
6.13 16 37.5769
6.14 16 37.6996
6.15 16 37.8225
6.16 16 37.9456
6.17 16 38.0689
6.18 16 38.1924
6.19 16 38.3161
6.2 16 38.44
6.21 16 38.5641
6.22 16 38.6884
6.23 16 38.8129
6.24 16 38.9376
6.25 16 39.0625
6.26 16 39.1876
6.27 16 39.3129
6.28 16 39.4384
6.29 16 39.5641
6.3 16 39.69
6.31 16 39.8161
6.32 16 39.9424
6.33 16 40.0689
6.34 16 40.1956
6.35 16 40.3225
6.36 16 40.4496
6.37 16 40.5769
6.38 16 40.7044
6.39 16 40.8321
6.4 16 40.96
6.41 16 41.0881
6.42 16 41.2164
6.43 16 41.3449
6.44 16 41.4736
6.45 16 41.6025
6.46 16 41.7316
6.47 16 41.8609
6.48 16 41.9904
6.49 16 42.1201
6.5 16 42.25
6.51 16 42.3801
6.52 16 42.5104
6.53 16 42.6409
6.54 16 42.7716
6.55 16 42.9025
6.56 16 43.0336
6.57 16 43.1649
6.58 16 43.2964
6.59 16 43.4281
6.6 16 43.56
6.61 16 43.6921
6.62 16 43.8244
6.63 16 43.9569
6.64 16 44.0896
6.65 16 44.2225
6.66 16 44.3556
6.67 16 44.4889
6.68 16 44.6224
6.69 16 44.7561
6.7 16 44.89
6.71 16 45.0241
6.72 16 45.1584
6.73 16 45.2929
6.74 16 45.4276
6.75 16 45.5625
6.76 16 45.6976
6.77 16 45.8329
6.78 16 45.9684
6.79 16 46.1041
6.8 16 46.24
6.81 16 46.3761
6.82 16 46.5124
6.83 16 46.6489
6.84 16 46.7856
6.85 16 46.9225
6.86 16 47.0596
6.87 16 47.1969
6.88 16 47.3344
6.89 16 47.4721
6.9 16 47.61
6.91 16 47.7481
6.92 16 47.8864
6.93 16 48.0249
6.94 16 48.1636
6.95 16 48.3025
6.96 16 48.4416
6.97 16 48.5809
6.98 16 48.7204
6.99 16 48.8601
7 16 49

90
libLSS/tests/test_cg.cpp Normal file
View file

@ -0,0 +1,90 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_cg.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <boost/multi_array.hpp>
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/optimization/cg.hpp"
#include <CosmoTool/algo.hpp>
#include <CosmoTool/hdf5_array.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <algorithm>
#include "libLSS/tools/optimization/array_helper.hpp"
using namespace LibLSS;
using boost::extents;
using namespace CosmoTool;
using namespace std;
typedef Optimization::BoostArrayAllocator<double, 1> allocator_t;
typedef allocator_t::array_t Array;
void A(Array &out, Array const &in) {
int N = in.shape()[0];
//initialize values
for (int i = 0; i < N; i++) {
out[i] = 0;
for (int j = 0; j < N; j++) {
//test with simple correlation function
double Mij = 0.5 * exp(-0.5 * (i - j) * (i - j));
out[i] += Mij * in[j];
}
}
}
int main(int argc, char **argv) {
setupMPI(argc, argv);
LibLSS::Console &console = LibLSS::Console::instance();
LibLSS::StaticInit::execute();
allocator_t allocator;
CG<allocator_t> cg(allocator);
int N = 2000;
boost::multi_array<double, 1> b(boost::extents[N]);
boost::multi_array<double, 1> x0(boost::extents[N]);
boost::multi_array<double, 1> x(boost::extents[N]);
fwrap(b) = 1;
fwrap(x) = 0;
for (int i = 0; i < b.size(); i++)
x0[i] = i;
A(b, x0);
cg.run(A, b, x);
double max = 0;
int imax = 0;
double eps = 0.;
for (int i = 0; i < b.size(); i++) {
double diff = fabs(x[i] - x0[i]);
if (max < diff)
max = diff;
imax = i;
eps += diff * diff;
}
if (eps < 1e-5)
std::cout << std::endl << "CG matrix inversion test passed!" << std::endl;
else
std::cout << "CG matrix inversion test failed!" << std::endl << std::endl;
std::cout << "Distance between truth and solution = " << eps << std::endl;
std::cout << "Largest deviation = " << max << " at element imax =" << imax
<< std::endl;
LibLSS::StaticInit::finalize();
doneMPI();
return 0;
}

128
libLSS/tests/test_cic.cpp Normal file
View file

@ -0,0 +1,128 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_cic.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <cmath>
#include <CosmoTool/algo.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/uninitialized_type.hpp"
#include "libLSS/tools/array_tools.hpp"
#include "libLSS/physics/classic_cic.hpp"
#include "libLSS/physics/openmp_cic.hpp"
#include "libLSS/physics/cosmo.hpp"
#include <H5Cpp.h>
#include <CosmoTool/hdf5_array.hpp>
#include "libLSS/tools/hdf5_error.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include <boost/chrono.hpp>
#undef RANDOM_ACCESS
//#define RANDOM_ACCESS
using namespace LibLSS;
using CosmoTool::cube;
typedef ClassicCloudInCell<double> CIC;
#ifdef _OPENMP
typedef OpenMPCloudInCell<double> CIC_MP;
#endif
int main(int argc, char **argv) {
MPI_Communication *world = setupMPI(argc, argv);
StaticInit::execute();
CosmologicalParameters cosmo;
cosmo.omega_m = 0.30;
cosmo.omega_b = 0.045;
cosmo.omega_q = 0.70;
cosmo.w = -1;
cosmo.n_s = 0.97;
cosmo.sigma8 = 0.8;
cosmo.h = 0.68;
cosmo.a0 = 1.0;
Console::instance().setVerboseLevel<LOG_DEBUG>();
double L = 1.0;
int N = 64;
int Np_g = 128;
int Np = cube(Np_g);
typedef UninitializedArray<boost::multi_array<double, 3>> U_Density;
typedef UninitializedArray<boost::multi_array<double, 2>> U_Particles;
U_Density density_p(boost::extents[N][N][N]);
U_Density density_mp_p(boost::extents[N][N][N]);
U_Particles particles_p(boost::extents[Np][3]);
U_Density::array_type &density = density_p.get_array();
U_Density::array_type &density_mp = density_mp_p.get_array();
U_Particles::array_type &particles = particles_p.get_array();
CIC cic;
#ifdef _OPENMP
CIC_MP cic_mp;
#endif
#ifdef RANDOM_ACCESS
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
particles[i][0] = L * rgen.uniform();
particles[i][1] = L * rgen.uniform();
particles[i][2] = L * rgen.uniform();
}
#else
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
int iz = (i % Np_g);
int iy = ((i / Np_g) % Np_g);
int ix = ((i / Np_g / Np_g));
particles[i][0] = L / Np_g * ix;
particles[i][1] = L / Np_g * iy;
particles[i][2] = L / Np_g * iz;
}
#endif
Console::instance().print<LOG_INFO>("Clearing and projecting");
array::fill(density, 0);
array::fill(density_mp, 0);
using namespace boost::chrono;
system_clock::time_point start_classic, end_classic, start_mp, end_mp;
start_classic = system_clock::now();
cic.projection(particles, density, L, L, L, N, N, N);
end_classic = system_clock::now();
start_mp = system_clock::now();
#ifdef _OPENMP
cic_mp.projection(particles, density_mp, L, L, L, N, N, N);
#endif
end_mp = system_clock::now();
duration<double> elapsed_classic = end_classic - start_classic;
duration<double> elapsed_mp = end_mp - start_mp;
std::cout << "OpenMP: " << elapsed_mp << " Classic: " << elapsed_classic
<< std::endl;
try {
H5::H5File f("cic.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "density", density);
CosmoTool::hdf5_write_array(f, "density_mp", density_mp);
} catch (const H5::FileIException &) {
Console::instance().print<LOG_ERROR>(
"Failed to load ref_pm.h5 in the current directory. Check in the "
"source directory libLSS/tests/");
return 1;
}
return 0;
}

View file

@ -0,0 +1,158 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_cic_adjoint.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <cmath>
#include <CosmoTool/algo.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/uninitialized_type.hpp"
#include "libLSS/tools/array_tools.hpp"
#include "libLSS/physics/classic_cic.hpp"
//#include "libLSS/tools/mpi_fftw_helper.hpp"
#include "libLSS/physics/modified_ngp.hpp"
#include "libLSS/physics/modified_ngp_smooth.hpp"
#include "libLSS/physics/cosmo.hpp"
#include <H5Cpp.h>
#include <CosmoTool/hdf5_array.hpp>
#include "libLSS/tools/hdf5_error.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include <boost/chrono.hpp>
//#undef RANDOM_ACCESS
#define RANDOM_ACCESS
using namespace LibLSS;
using CosmoTool::cube;
typedef ClassicCloudInCell<double> CIC;
typedef ModifiedNGP<double, NGPGrid::CIC> MNGP;
int main(int argc, char **argv) {
StaticInit::execute();
MPI_Communication *world = setupMPI(argc, argv);
CosmologicalParameters cosmo;
cosmo.omega_m = 0.30;
cosmo.omega_b = 0.045;
cosmo.omega_q = 0.70;
cosmo.w = -1;
cosmo.n_s = 0.97;
cosmo.sigma8 = 0.8;
cosmo.h = 0.68;
cosmo.a0 = 1.0;
Console::instance().setVerboseLevel<LOG_DEBUG>();
double L = 1.0;
int N = 64;
int Np_g = 64;
int Np = cube(Np_g);
typedef UninitializedArray<boost::multi_array<double, 3>> U_Density;
typedef UninitializedArray<boost::multi_array<double, 4>> U_Velocity;
typedef UninitializedArray<boost::multi_array<double, 2>> U_Particles;
U_Density density_p(boost::extents[N][N][N]);
U_Velocity velocity_p(boost::extents[3][N][N][N]);
U_Density density_mngp_p(boost::extents[N][N][N]);
U_Particles particles_p(boost::extents[Np][3]);
U_Particles velocities_p(boost::extents[Np][3]);
U_Particles adjoint_p(boost::extents[Np][3]);
U_Particles adjoint_mngp_p(boost::extents[Np][3]);
U_Density::array_type &density = density_p.get_array();
U_Velocity::array_type &velocity = velocity_p.get_array();
U_Density::array_type &density_mngp = density_mngp_p.get_array();
U_Particles::array_type &particles = particles_p.get_array();
U_Particles::array_type &velocities = velocities_p.get_array();
U_Particles::array_type &adjoint = adjoint_p.get_array();
U_Particles::array_type &adjoint_mngp = adjoint_mngp_p.get_array();
CIC cic;
MNGP mngp;
#ifdef RANDOM_ACCESS
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
particles[i][0] = L * rgen.uniform();
particles[i][1] = L * rgen.uniform();
particles[i][2] = L * rgen.uniform();
velocities[i][0] = 100. * rgen.uniform();
velocities[i][1] = 100. * rgen.uniform();
velocities[i][2] = 100. * rgen.uniform();
}
#else
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
int iz = (i % Np_g);
int iy = ((i / Np_g) % Np_g);
int ix = ((i / Np_g / Np_g));
particles[i][0] = L / Np_g * ix;
particles[i][1] = L / Np_g * iy;
particles[i][2] = L / Np_g * iz;
velocities[i][0] = 100.;
velocities[i][1] = 100.;
velocities[i][2] = 100.;
}
#endif
Console::instance().print<LOG_INFO>("Clearing and projecting");
array::fill(density, 0);
array::fill(density_mngp, 0);
using namespace boost::chrono;
system_clock::time_point start_classic, end_classic, start_mp, end_mp,
start_mp2, end_mp2;
start_classic = system_clock::now();
CIC::projection(particles, density, L, L, L, N, N, N);
end_classic = system_clock::now();
CIC::adjoint(particles, density, adjoint, L, L, L, N, N, N, 1.0);
//test velocity binning
//start_classic = system_clock::now();
//CIC::projection(particles,velocity,velocities,L, L, L, N, N, N);
//end_classic = system_clock::now();
//CIC::adjoint(particles, density, adjoint, L, L, L, N, N, N, 1.0);
start_mp = system_clock::now();
MNGP::projection(particles, density_mngp, L, L, L, N, N, N);
end_mp = system_clock::now();
MNGP::adjoint(particles, density_mngp, adjoint_mngp, L, L, L, N, N, N, 1.0);
duration<double> elapsed_classic = end_classic - start_classic;
duration<double> elapsed_mp = end_mp - start_mp;
duration<double> elapsed_mps = end_mp2 - start_mp2;
std::cout << "MNGP: " << elapsed_mp << " Classic: " << elapsed_classic
<< std::endl;
try {
H5::H5File f("cic.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "density", density);
CosmoTool::hdf5_write_array(f, "density_mngp", density_mngp);
CosmoTool::hdf5_write_array(f, "adjoint", adjoint);
CosmoTool::hdf5_write_array(f, "adjoint_mngp", adjoint_mngp);
} catch (const H5::FileIException &) {
Console::instance().print<LOG_ERROR>(
"Failed to load ref_pm.h5 in the current directory. Check in the "
"source directory libLSS/tests/");
return 1;
}
return 0;
}

View file

@ -0,0 +1,61 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_class_interface.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/physics/class_cosmo.hpp"
using namespace LibLSS;
int main(int argc, char **argv) {
setupMPI(argc, argv);
StaticInit::execute();
CosmologicalParameters params;
params.omega_r = 0.0;
params.omega_k = 0.0;
params.omega_m = 0.30;
params.omega_q = 0.70;
params.omega_b = 0.049;
params.w = -1;
params.n_s = 1.0;
params.fnl = 0;
params.wprime = 0;
params.sigma8 = 0.8;
params.h = 0.8;
params.a0 = 1.0;
params.sum_mnu = 0.1; // in eV
ClassCosmo cc(params);
// here we output the primordial power-spectrum
int Nbin = 100;
double kmin = -6;
double kmax = 0.;
double dk = (kmax - kmin) / (Nbin - 1);
std::ofstream f("interpolate_Tk.txt");
for (int i = 0; i < Nbin; i++) {
double k = std::pow(10.0, kmin + dk * i);
double Pk = cc.primordial_Pk(k);
double Tk = cc.get_Tk(k);
f << k << " " << Pk << " " << Tk << std::endl;
}
StaticInit::finalize();
doneMPI();
return 0;
}

View file

@ -0,0 +1,77 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_console.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/timing_db.hpp"
#include "libLSS/tools/hdf5_error.hpp"
using namespace std;
using LibLSS::LOG_STD;
using LibLSS::LOG_WARNING;
using LibLSS::LOG_ERROR;
using boost::format;
static void funInit()
{
cout << "Dummy static init test" << endl;
}
LibLSS::RegisterStaticInit test_reg(funInit);
int main(int argc, char **argv)
{
LibLSS::MPI_Communication *mpi_world = LibLSS::setupMPI(argc, argv);
LibLSS::StaticInit::execute();
LibLSS::Console& console = LibLSS::Console::instance();
unlink("timings.h5");
{
H5::H5File f("timings.h5", H5F_ACC_TRUNC);
LibLSS::timings::load(f);
}
console.print<LOG_STD>("Test console");
console.print<LOG_WARNING>("Test warning console");
console.print<LOG_ERROR>("Test error console");
LibLSS::Progress<LOG_STD>& p = console.start_progress<LOG_STD>("Test progress", 10);
console.indent();
console.print<LOG_STD>("test indent");
for (int j = 0; j < 10; j++)
{
p.update(j);
console.print<LOG_STD>("indented");
console.indent();
}
p.destroy();
console.print<LOG_STD>(format("This is a formatter test %d, %g") % -2 % 4.3);
console.format<LOG_STD>("This is a formatter test2 %d, %g", -2, 4.3);
{
LIBLSS_AUTO_CONTEXT(LOG_STD, ctx);
ctx.print("Now in context");
}
{
H5::H5File f("timings.h5", H5F_ACC_TRUNC);
LibLSS::timings::save(f);
}
console.print_stack_trace();
LibLSS::StaticInit::finalize();
return 0;
}

View file

@ -0,0 +1,75 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_cosmo_expansion.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/physics/cosmo.hpp"
using namespace LibLSS;
int main(int argc, char **argv) {
setupMPI(argc, argv);
StaticInit::execute();
CosmologicalParameters params;
params.omega_r = 0;
params.omega_k = 0;
params.omega_m = 0.10;
params.omega_b = 0.049;
params.omega_q = 0.90;
params.w = -1;
params.wprime = 0;
params.n_s = 1;
params.sigma8 = 0.8;
params.rsmooth = 0;
params.h = 0.7;
params.beta = 0;
params.z0 = 0;
params.a0 = 1;
Cosmology cosmo(params);
Cosmology cosmo2(params);
cosmo.precompute_com2a();
for (int i = 0; i <= 100; i++) {
double z = i / 100., znew;
double d;
bool pass;
d = cosmo.com2comph(cosmo.a2com(cosmo.z2a(z)));
znew = cosmo.a2z(cosmo.com2a(cosmo.comph2com(d)));
pass = std::abs(z - znew) < 1e-5;
std::cout << z << " " << znew << " " << d << " " << pass << std::endl;
if (pass == 0)
return 1;
}
cosmo.precompute_d_plus();
{
double Dtest = cosmo.d_plus(0.7);
double Dtest2 = cosmo2.d_plus(0.7);
std::cout << Dtest << Dtest2 << std::endl;
}
for (int i = 0; i <= 100; i++) {
double z = i / 100.;
double D = cosmo.d_plus(cosmo.z2a(z));
double D2 = cosmo2.d_plus(cosmo2.z2a(z));
bool pass = std::abs(D - D2) < 1e-5;
std::cout << z << " " << D << " " << D2 << " " << pass << std::endl;
if (pass == 0)
return 1;
}
StaticInit::finalize();
doneMPI();
return 0;
}

View file

@ -0,0 +1,101 @@
0 -0 1
0.01 29.9566 1
0.02 59.8676 1
0.03 89.7322 1
0.04 119.55 1
0.05 149.32 1
0.06 179.041 1
0.07 208.713 1
0.08 238.336 1
0.09 267.908 1
0.1 297.429 1
0.11 326.898 1
0.12 356.314 1
0.13 385.678 1
0.14 414.987 1
0.15 444.243 1
0.16 473.443 1
0.17 502.587 1
0.18 531.675 1
0.19 560.706 1
0.2 589.679 1
0.21 618.594 1
0.22 647.45 1
0.23 676.246 1
0.24 704.983 1
0.25 733.659 1
0.26 762.273 1
0.27 790.826 1
0.28 819.316 1
0.29 847.743 1
0.3 876.106 1
0.31 904.406 1
0.32 932.64 1
0.33 960.81 1
0.34 988.913 1
0.35 1016.95 1
0.36 1044.92 1
0.37 1072.82 1
0.38 1100.66 1
0.39 1128.43 1
0.4 1156.13 1
0.41 1183.75 1
0.42 1211.31 1
0.43 1238.8 1
0.44 1266.22 1
0.45 1293.57 1
0.46 1320.85 1
0.47 1348.05 1
0.48 1375.18 1
0.49 1402.24 1
0.5 1429.23 1
0.51 1456.14 1
0.52 1482.98 1
0.53 1509.74 1
0.54 1536.43 1
0.55 1563.05 1
0.56 1589.59 1
0.57 1616.05 1
0.58 1642.44 1
0.59 1668.75 1
0.6 1694.99 1
0.61 1721.14 1
0.62 1747.23 1
0.63 1773.23 1
0.64 1799.16 1
0.65 1825.01 1
0.66 1850.78 1
0.67 1876.47 1
0.68 1902.08 1
0.69 1927.62 1
0.7 1953.07 1
0.71 1978.45 1
0.72 2003.75 1
0.73 2028.96 1
0.74 2054.1 1
0.75 2079.16 1
0.76 2104.14 1
0.77 2129.04 1
0.78 2153.85 1
0.79 2178.59 1
0.8 2203.25 1
0.81 2227.82 1
0.82 2252.32 1
0.83 2276.73 1
0.84 2301.06 1
0.85 2325.32 1
0.86 2349.49 1
0.87 2373.58 1
0.88 2397.59 1
0.89 2421.51 1
0.9 2445.36 1
0.91 2469.13 1
0.92 2492.81 1
0.93 2516.41 1
0.94 2539.93 1
0.95 2563.37 1
0.96 2586.73 1
0.97 2610.01 1
0.98 2633.21 1
0.99 2656.32 1
1 2679.35 1

View file

@ -0,0 +1,11 @@
#include <string>
#include <iostream>
#include "libLSS/tools/cpu/feature_check.hpp"
int main()
{
std::string s;
LibLSS::check_compatibility(s);
std::cout << s << std::endl;
return 0;
}

View file

@ -0,0 +1,146 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_fuse_wrapper.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include <boost/multi_array.hpp>
#include <boost/timer/timer.hpp>
#include "libLSS/tools/fused_array.hpp"
#include "libLSS/tools/fusewrapper.hpp"
#include "libLSS/tools/static_init.hpp"
double fun() {
static int i = 0;
i++;
return i;
}
using namespace boost::timer;
int main() {
LibLSS::StaticInit::execute();
using boost::extents;
using boost::multi_array;
using LibLSS::_p1;
using LibLSS::_p2;
using LibLSS::b_fused_idx;
using LibLSS::b_va_fused;
using LibLSS::fwrap;
size_t N = 256;
multi_array<double, 3> A(extents[N][N][N]);
multi_array<double, 3> B(extents[N][N][N]);
auto fA = fwrap(A);
auto fC = fwrap(fA.fautowrap(fun));
auto fD = LibLSS::b_fused<double>(A, 2.0 * M_PI * _p1);
// Initialize A with some linear space.
fA = b_fused_idx<double, 3>([N](int i, int j, int k) -> double {
return double(i) / N + double(j) / N + double(k) / N;
});
std::cout << "Reference: " << LibLSS::reduce_sum<double>(A) << std::endl;
{
double r = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
r += A[i][j][k];
std::cout << "Manual: " << r << std::endl;
}
{
cpu_timer timer;
double r = 0;
for (int i = 0; i < 10; i++)
r += ((fA * 2. + 5.) / 7).sum();
std::cout << "10 composite multiply, sum and reduce:" << timer.format()
<< " " << r << std::endl;
}
// Create a lazy expression.
auto fB = std::cos(fA * (2 * M_PI)); //std::cos(fA*2*M_PI);
// WORKS PARTIALLY: shapeness must be better computed
auto fB2 = std::cos((2 * M_PI) * fA); //std::cos(fA*2*M_PI);
std::cout << fwrap(fD).sum() << std::endl;
// This does a full collapse of the expression, including the squaring
{
cpu_timer timer;
std::cout << (LibLSS::ipow<2>(fB)).sum() / LibLSS::ipow<3>(N) << std::endl;
std::cout << "Composite multiply, cos, square and reduce:" << timer.format()
<< std::endl;
std::cout << (LibLSS::ipow<2>(fB2)).sum() / LibLSS::ipow<3>(N) << std::endl;
}
{
cpu_timer timer;
std::cout << std::abs(fB).sum() / LibLSS::ipow<3>(N) << std::endl;
std::cout << "Composite multiply, cos, abs and reduce:" << timer.format()
<< std::endl;
}
//std::cout << fB->shape()[0] << std::endl;
// Assign the cos part
auto fE = fwrap(B);
{
cpu_timer timer;
fE = fB;
std::cout << "Composite multiply, cos and assign:" << timer.format()
<< std::endl;
}
{
cpu_timer timer;
std::cout << (fE * fE).sum() << std::endl;
std::cout << "Composite square and reduce:" << timer.format() << std::endl;
}
std::cout << std::pow(std::abs(fE), 2.5).sum()
<< std::endl; ////std::pow(std::abs(fE), 2.5).sum() << std::endl;
std::cout << (std::abs(fE)).min()
<< std::endl; ////std::pow(std::abs(fE), 2.5).sum() << std::endl;
std::cout << (std::abs(fE)).max()
<< std::endl; ////std::pow(std::abs(fE), 2.5).sum() << std::endl;
double r = std::numeric_limits<double>::infinity();
for (size_t i = 0; i < N; i++)
for (size_t j = 0; j < N; j++)
for (size_t k = 0; k < N; k++)
r = std::min(r, std::abs((*fE)[i][j][k]));
std::cout << r << std::endl;
fwrap(B) = fwrap(A);
fwrap(B) = -fwrap(A);
std::cout << fwrap(B).sum() << " " << fwrap(A).sum() << std::endl;
std::cout << fwrap(B).no_parallel().sum() << std::endl;
multi_array<std::complex<double>, 3> c_B(extents[N][N][N]);
auto f_c_B = fwrap(c_B);
double x = std::real(f_c_B).sum();
std::cout << x << std::endl;
auto c_a = LibLSS::make_complex(fwrap(A), fwrap(B));
//double sB;
//auto scalar_A = fwrap(1.0);
//auto scalar_B = fwrap(sB);
//scalar_B = scalar_A + 2;
return 0; //fA.sum();
}

View file

@ -0,0 +1,234 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_fused_array.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/tools/phoenix_vars.hpp"
#include <boost/phoenix/operator.hpp>
#include <boost/format.hpp>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/fused_array.hpp"
#include "libLSS/tools/fused_masked_assign.hpp"
#include "libLSS/tools/fused_reduce.hpp"
#include "libLSS/tools/array_tools.hpp"
#include "libLSS/tools/static_init.hpp"
#include <boost/chrono.hpp>
using namespace std;
using namespace LibLSS;
class TimeContext {
protected:
std::string code;
boost::chrono::system_clock::time_point start_context;
public:
TimeContext(const std::string& code_name) {
start_context = boost::chrono::system_clock::now();
code = code_name;
}
~TimeContext() {
boost::chrono::duration<double> ctx_time = boost::chrono::system_clock::now() - start_context;
cout << boost::format("Done %s in %s") % code % ctx_time << endl;;
}
};
template<typename A>
void printer(const A& a)
{
for (int i = 0; i < a.num_elements(); i++)
cout << a[i] << endl;
}
struct MulOp {
int operator()(const int& a) const {
return 2*a;
}
};
template<typename T, typename T2, typename Operation>
void hand_coded(T& a, const T2& b, Operation op)
{
size_t e1 = a.shape()[0], e2 = a.shape()[1], e3 = a.shape()[2];
#pragma omp parallel for collapse(3)
for (size_t i = 0; i < e1; i++) {
for (size_t j = 0; j < e2; j++)
for (size_t k = 0; k < e3; k++)
{
a[i][j][k] = op(b[i][j][k]);
}
}
}
template<typename T, typename T2>
void hand_constant(T& a, T2 value)
{
#pragma omp parallel for
for (size_t i = 0; i < a.shape()[0]; i++) {
for (size_t j = 0; j < a.shape()[1]; j++)
for (size_t k = 0; k < a.shape()[2]; k++) {
a[i][j][k] = value;
}
}
}
double op0(int a, int b, int c)
{
return a + 10*b + 100*c;
}
int main(int argc, char **argv)
{
setupMPI(argc, argv);
StaticInit::execute();
using boost::lambda::_1;
using boost::lambda::_2;
using boost::lambda::constant;
namespace Larray = ::LibLSS::array;
const std::size_t N = 128;
typedef boost::multi_array<double,3> Array;
Array::index_gen indices;
typedef boost::multi_array<double,3> DArray;
Array a(boost::extents[N][N][N]),
b(boost::extents[N][N][N]),
c(boost::extents[N][N][N]);
DArray d(boost::extents[N][N][N]);
for (size_t i = 0; i < a.num_elements(); i++) {
a.data()[i] = i;
b.data()[i] = i*i;
}
#if 0
{
TimeContext ctx("Constant");
for (int j = 0; j < 100; j++)
copy_array(c, b_fused<int,3>(constant(2)));
}
{
TimeContext ctx("Hand coded Constant");
for (int j = 0; j < 100; j++)
hand_constant(c, 2);
}
{
TimeContext ctx("MulOp");
for (int j = 0; j < 10000; j++)
copy_array(c, b_fused<int>(b,MulOp()));
}
#endif
{
TimeContext ctx("Lambda");
for (int j = 0; j < 1000; j++)
copy_array(c, b_fused<int>(b,2*_p1));
}
{
TimeContext ctx("Lambda va");
for (int j = 0; j < 1000; j++)
copy_array(c, b_va_fused<int>(2*_p1, b));
}
{
TimeContext ctx("Lambda va on sliced array");
auto slicer = indices[Array::index_range(1,N/2)][Array::index_range(1,N/2)][Array::index_range(1,N/2)];
for (int j = 0; j < 1000; j++) {
auto va = b_va_fused<int>(2*_1, b[slicer]);
copy_array_rv(c[slicer], va);
}
}
{
TimeContext ctx("Float Lambda");
for (int j = 0; j < 1000; j++)
copy_array(d, b_va_fused<double>(2*_p1,b), true);
}
Larray::fill(b, 103);
for (size_t i = 0; i < b.num_elements(); i++)
if (b.data()[i] != 103) {
cout << "At element " << i << " b = " << b.data()[i] << endl;
abort();
}
{
TimeContext ctx("hand coded lambda");
for (int j = 0; j < 1000; j++)
hand_coded(c, b, 2*_p1);
}
Larray::copyArray3d(a, b);
Larray::scaleArray3d(a, 2);
for (size_t i = 0; i < a.num_elements(); i++)
if (a.data()[i] != c.data()[i]) {
cout << "At element " << i << " a = " << a.data()[i] << " c = " << c.data()[i] << endl;
abort();
}
{
Array d(boost::extents[2][N][N]);
copy_array_rv(d[0], b[0]);
copy_array_rv(b[0], d[0]);
copy_array(b, b_fused_idx<double, 3>(op0));
for (size_t i = 0; i < N; i++)
for (size_t j = 0; j < N; j++)
for (size_t k = 0; k < N; k++)
if (size_t(b[i][j][k]) != (i+10*j+100*k)) {
cout << "Problem at (" << i << "," << j << "," << k << ")" << endl;
cout << "Value in b is " << b[i][j][k] << endl;
abort();
}
copy_array_rv(
d[indices[Array::index_range()][Array::index_range(1,3)][Array::index_range(1,3)]],
b[indices[Array::index_range(1,3)][Array::index_range(1,3)][Array::index_range(1,3)]]
);
for (long i = 0; i < 2; i++) {
for (long j = 1; j < 3; j++) {
for (long k = 1; k < 3; k++) {
if (d[i][j][k] != (i+1) + 10*j + 100*k) {
cout << "Problem(2) at " << i << "," << j << "," << k << endl;
abort();
}
}
}
}
}
{
copy_array(b, b_fused_idx<int, 3>([N](int i, int j, int k)->double {
return 4*i/N;
}));
copy_array_masked(a, b, b_va_fused<int>(2*_p1, b), b_va_fused<bool>(_p1 > 2, b));
std::cout << reduce_sum<int>(a) << " " << reduce_sum<int>(b) << std::endl;
double s= 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
if (b[i][j][k] > 2)
s += b[i][j][k];
else
s += 2*b[i][j][k];
std::cout << s << std::endl;
}
{
long s = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
if (b[i][j][k] > 2) s += a[i][j][k];
std::cout << s << " " << reduce_sum<int>(a, b_va_fused<bool>(_p1 > 2, b)) << std::endl;
}
return 0;
}

View file

@ -0,0 +1,130 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_fused_cond.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/tools/phoenix_vars.hpp"
#include <boost/phoenix/operator.hpp>
#include <boost/format.hpp>
//#include "libLSS/mpi/generic_mpi.hpp"
//#include "libLSS/tools/console.hpp"
#include "libLSS/tools/fused_array.hpp"
#include "libLSS/tools/fused_reduce.hpp"
#include "libLSS/tools/fused_cond.hpp"
#include "libLSS/tools/array_tools.hpp"
#include <boost/chrono.hpp>
using namespace std;
using namespace LibLSS;
class TimeContext {
protected:
std::string code;
boost::chrono::system_clock::time_point start_context;
public:
TimeContext(const std::string& code_name) {
start_context = boost::chrono::system_clock::now();
code = code_name;
}
~TimeContext() {
boost::chrono::duration<double> ctx_time = boost::chrono::system_clock::now() - start_context;
cout << boost::format("Done %s in %s") % code % ctx_time << endl;;
}
};
int main()
{
static constexpr int N = 8192;
boost::multi_array<bool, 1> amask(boost::extents[N]);
boost::multi_array<double, 1> A(boost::extents[N]);
boost::multi_array<double, 1> B(boost::extents[N]);
boost::multi_array<double, 1> C(boost::extents[N]);
auto mask = b_fused_idx<bool, 1>([](int i)->bool { return (i%2)==0; }, boost::extents[N]);
auto a0 = b_fused_idx<double, 1>(
[](int i)->int { return -2*i; },
boost::extents[N]
);
auto b0 = b_fused_idx<double, 1>(
[](int i)->int { return 3*i; },
boost::extents[N]
);
LibLSS::copy_array(A, a0);
LibLSS::copy_array(B, b0);
LibLSS::copy_array(amask, mask);
auto c = b_cond_fused<double>(
amask,
A,
B
);
{
TimeContext t("Automatic");
for (int j = 0; j < 1000000; j++)
LibLSS::copy_array(C, c);
}
{
TimeContext t("Hand written");
for (int j = 0; j < 1000000; j++)
#pragma omp parallel for
for (int i = 0; i < N; i++)
{
if (amask[i])
C[i] = A[i];
else
C[i] = B[i];
}
}
auto e = b_cond_fused<double>(mask,
a0, b0
);
{
TimeContext t("Inline");
for (int j = 0; j < 1000000; j++)
LibLSS::copy_array(C, e);
}
auto f = b_cond_fused<double>(
b_fused_idx<bool, 1>(
[](int i)->bool { return (i%2)==0; }, boost::extents[N]
),
b_fused_idx<double, 1>(
[](int i)->int { return -2*i; },
boost::extents[N]
),
b_fused_idx<double, 1>(
[](int i)->int { return 3*i; },
boost::extents[N]
)
);
{
TimeContext t("Inline 2");
for (int j = 0; j < 1000000; j++)
LibLSS::copy_array(C, f);
}
/*
for (int i = 0; i < 16; i++)
std::cout << C[i] << std::endl;
for (int i = 0; i < 16; i++)
std::cout << e[i] << std::endl;
*/
std::cout << reduce_sum<double>(e) << std::endl;
return 0;
}

35
libLSS/tests/test_gig.cpp Normal file
View file

@ -0,0 +1,35 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_gig.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/samplers/core/random_number.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/samplers/core/gig_sampler.hpp"
using std::cout;
using std::endl;
using namespace LibLSS;
int main()
{
double a = 10.;
double b = 5.;
double p = 1 - 30.;
GSL_RandomNumber rgen;
for (int i = 0; i < 100000; i++) {
cout << GIG_sampler_3params(a, b, p, rgen) << endl;
}
return 0;
}

View file

@ -0,0 +1,262 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_gradient_supersampling.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include <CosmoTool/hdf5_array.hpp>
#include <boost/bind/bind.hpp>
#include <complex>
#include <boost/lambda/lambda.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/tools/fused_array.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/sigcatcher.hpp"
#include "libLSS/tools/mpi_fftw_helper.hpp"
#include <CosmoTool/algo.hpp>
using namespace LibLSS;
using CosmoTool::square;
using namespace std;
using boost::bind;
using boost::c_storage_order;
using boost::ref;
using CosmoTool::hdf5_write_array;
using boost::lambda::constant;
using boost::placeholders::_1;
typedef FFTW_Manager_3d<double> Manager;
typedef Manager::ArrayFourier F_Array;
typedef Manager::ArrayReal R_Array;
typedef UninitializedArray<R_Array, Manager::AllocReal> UR_Array;
typedef UninitializedArray<F_Array, Manager::AllocComplex> UF_Array;
static const double epsilon = 1e-9;
namespace {
#if defined(ARES_MPI_FFTW)
RegisterStaticInit reg0(fftw_mpi_init, fftw_mpi_cleanup, 9, "MPI/FFTW");
#endif
// WISDOM must come at the end. Otherwise it is reset
RegisterStaticInit reg1(CosmoTool::init_fftw_wisdom, CosmoTool::save_fftw_wisdom, 12, "FFTW/WISDOM");
}
template<typename RGen>
double rand_init(RGen& rgen, double fac)
{
return rgen.gaussian_ratio();// * fac;
}
static
double filler()
{
static long counter = 0;
return 1;
}
template<typename Array>
typename Array::element chi2_sum(Manager& mgr, const Array& a)
{
typename Array::element chi2 = 0;
for (long i = mgr.startN0; i < mgr.startN0+mgr.localN0; i++)
for (long j = 0; j < a.shape()[1]; j++)
for (long k = 0; k < a.shape()[2]; k++)
chi2 += CosmoTool::square(a[i][j][k]);
return chi2;
}
template<typename A,typename B>
double forward_chi2(MPI_Communication *comm, Manager& mgr, Manager& mgr2, Manager::plan_type& plan, const A& a, const B& mu)
{
using boost::lambda::_1;
using boost::lambda::_2;
UF_Array tmp_hi(mgr2.extents_complex(), mgr2.allocator_complex);
UR_Array r_hi_array(mgr2.extents_real(), mgr2.allocator_real);
LibLSS::array::fill(tmp_hi.get_array(), 0);
mgr2.upgrade_complex(mgr, a, tmp_hi.get_array());
copy_array(tmp_hi.get_array(), b_fused<std::complex<double> >(tmp_hi.get_array(),mu,_1+_2));
mgr2.execute_c2r(plan, tmp_hi.get_array().data(), r_hi_array.get_array().data());
double chi2 = chi2_sum(mgr2, r_hi_array.get_array());
comm->all_reduce_t(MPI_IN_PLACE, &chi2, 1, MPI_SUM);
return chi2;
}
template<typename A, typename B>
void gradient_chi2(Manager& mgr, Manager& mgr2, Manager::plan_type& plan, const A& a, B& mu, A& c, B& d)
{
using boost::lambda::_1;
using boost::lambda::_2;
UF_Array mu_lo(mgr.extents_complex(), mgr.allocator_complex);
UF_Array sum_hi(mgr2.extents_complex(), mgr2.allocator_complex);
long N = mgr2.N0 * mgr2.N1 * mgr2.N2;
LibLSS::array::fill(sum_hi.get_array(), 0);
mgr2.upgrade_complex(mgr, a, sum_hi.get_array());
copy_array(sum_hi.get_array(), b_fused<std::complex<double> >(sum_hi.get_array(), mu, _1+_2));
mgr.degrade_complex(mgr2, sum_hi.get_array(), c);
LibLSS::array::copyArray3d(d, sum_hi.get_array());
LibLSS::array::scaleArray3d(c, 4*N);
if (mgr.on_core(0)) {
c[0][0][0] /= 2;
c[0][mgr.N1/2][0] /= 2;
c[0][0][mgr.N2/2] /= 2;
c[0][mgr.N1/2][mgr.N2/2] /= 2;
}
if (mgr.on_core(mgr.N0/2)) {
c[mgr.N0/2][0][0] /= 2;
c[mgr.N0/2][mgr.N1/2][0] /= 2;
c[mgr.N0/2][0][mgr.N2/2] /= 2;
c[mgr.N0/2][mgr.N1/2][mgr.N2/2] /= 2;
}
}
int main(int argc, char **argv)
{
using boost::format;
using boost::str;
MPI_Communication *world = setupMPI(argc, argv);
typedef RandomNumberMPI<GSL_RandomNumber> RGen;
StaticInit::execute();
Console& cons = Console::instance();
cons.outputToFile(str(format("log_test_supersampling.txt.%d") % world->rank()));
cons.setVerboseLevel<LOG_DEBUG>();
Manager mgr(16,16,16, world);
Manager mgr2(32,32,32, world);
{
RGen rgen(world, -1);
rgen.seed(97249);
F_Array f_lo_array(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
F_Array tmp_f_array(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
F_Array gradient_ref(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
F_Array gradient(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
R_Array r_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array tmp_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array r_hi_array(mgr2.extents_real(), c_storage_order(), mgr2.allocator_real);
F_Array f_hi_array(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array tmp_gradient(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array mu(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
Manager::plan_type plan_r2c = mgr.create_r2c_plan(r_array.data(), f_lo_array.data());
Manager::plan_type plan_r2c_hi = mgr2.create_r2c_plan(r_hi_array.data(), f_hi_array.data());
Manager::plan_type plan_c2r_hi = mgr2.create_c2r_plan(f_hi_array.data(), r_hi_array.data());
double fac = 1/double(r_array.num_elements());
copy_array(r_hi_array, b_fused<double, 3>( bind(rand_init<RGen>, boost::ref(rgen), 1) ) );
mgr2.execute_r2c(plan_r2c_hi, r_hi_array.data(), mu.data());
LibLSS::array::scaleArray3d(mu, 1.0/r_hi_array.num_elements());
// Generate random numbers
copy_array(r_array, b_fused<double, 3>( bind(rand_init<RGen>, boost::ref(rgen), fac) ) );
// Save them
LibLSS::array::copyArray3d(tmp_array, r_array);
mgr.execute_r2c(plan_r2c, tmp_array.data(), f_lo_array.data());
LibLSS::array::scaleArray3d(f_lo_array, 1.0/r_array.num_elements());
LibLSS::array::fill(gradient_ref, 0);
double chi2 = forward_chi2(world, mgr, mgr2, plan_c2r_hi, f_lo_array, mu);
for (long i = 0; i < mgr.N0; i++) {
for (long j = 0; j < mgr.N1; j++) {
for (long k = 0; k < mgr.N2_HC; k++) {
std::complex<double> delta(0,0);
cons.print<LOG_DEBUG>(format("doing %d,%d,%d") % i % j % k);
LibLSS::array::copyArray3d(tmp_f_array, f_lo_array);
if (mgr.on_core(i))
tmp_f_array[i][j][k] = f_lo_array[i][j][k] + std::complex<double>(epsilon,0);
if (k==mgr.N2/2 || k == 0) {
long plane = (mgr.N0-i)%mgr.N0;
F_Array::element value = 0;
if (mgr.on_core(plane)) {
if (world->size() > 1 && !mgr.on_core(i))
world->recv(&value, 1, translateMPIType<F_Array::element>(), mgr.get_peer(i), i);
else
value = tmp_f_array[i][j][k];
tmp_f_array[plane][(mgr.N1-j)%mgr.N1][k] = std::conj(value);
} else if (mgr.on_core(i)) {
world->send(&tmp_f_array[i][j][k], 1, translateMPIType<F_Array::element>(), mgr.get_peer(plane), i);
}
}
delta.real((forward_chi2(world, mgr, mgr2, plan_c2r_hi, tmp_f_array, mu) - chi2)/epsilon);
if (mgr.on_core(i))
tmp_f_array[i][j][k] = f_lo_array[i][j][k] + std::complex<double>(0,epsilon);
if (k==mgr.N2/2 || k == 0) {
long plane = (mgr.N0-i)%mgr.N0;
F_Array::element value = 0;
if (mgr.on_core(i) && plane == i && (mgr.N1-j)%mgr.N1 == j) {
tmp_f_array[i][j][k].imag(0);
}
if (mgr.on_core(plane)) {
if (world->size() > 1 && !mgr.on_core(i))
world->recv(&value, 1, translateMPIType<F_Array::element>(), mgr.get_peer(i), i);
else
value = tmp_f_array[i][j][k];
tmp_f_array[plane][(mgr.N1-j)%mgr.N1][k] = std::conj(value);
} else if (mgr.on_core(i)) {
world->send(&tmp_f_array[i][j][k], 1, translateMPIType<F_Array::element>(), mgr.get_peer(plane), i);
}
}
delta.imag((forward_chi2(world, mgr, mgr2, plan_c2r_hi, tmp_f_array, mu) - chi2)/epsilon);
if (mgr.on_core(i))
gradient_ref[i][j][k] = delta;
}
}
}
world->barrier();
LibLSS::array::fill(gradient, 0);
gradient_chi2(mgr, mgr2, plan_c2r_hi, f_lo_array, mu, gradient, tmp_gradient);
// Now we have our modes
{
string s = boost::str(boost::format("test_grad_degrade.h5_%d") % world->rank());
H5::H5File f(s, H5F_ACC_TRUNC);
hdf5_write_array(f, "gradient_ref", gradient_ref);
hdf5_write_array(f, "gradient", gradient);
hdf5_write_array(f, "gradient_hi", tmp_gradient);
hdf5_write_array(f, "mu", mu);
hdf5_write_array(f, "lo", f_lo_array);
mgr2.upgrade_complex(mgr, f_lo_array, f_hi_array);
hdf5_write_array(f, "hi", f_hi_array);
}
}
world->barrier();
StaticInit::finalize();
return 0;
}

View file

@ -0,0 +1,59 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_has_member.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <typeinfo>
#include <boost/utility/enable_if.hpp>
#include <iostream>
#include "libLSS/tools/checkmem.hpp"
using namespace std;
HAS_MEM_FUNC(checkMember, has_check_member);
struct NoStruct
{
int a;
};
struct YesStruct
{
double c;
void checkMember() { cout << "Cool" << endl; }
};
template<typename T>
typename boost::enable_if<has_check_member<T, void (T::*)()> >::type
exec_fun() {
cout << typeid(T).name() << " has the member" << endl;
T a;
a.checkMember();
}
template<typename T>
typename boost::disable_if<has_check_member<T, void (T::*)()> >::type
exec_fun() {
cout << typeid(T).name() << " does not have the member" << endl;
}
int main()
{
cout << "has_check_member<NoStruct>::value = " << has_check_member<NoStruct, void (NoStruct::*)()>::value << endl;
cout << "has_check_member<YesStruct>::value = " << has_check_member<YesStruct, void (YesStruct::*)()>::value << endl;
exec_fun<NoStruct>();
exec_fun<YesStruct>();
return 0;
}

View file

@ -0,0 +1,33 @@
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/hdf5_error.hpp"
#include <H5Cpp.h>
#include "libLSS/tools/hdf5_buffered_write.hpp"
#include "libLSS/tools/fusewrapper.hpp"
using namespace LibLSS;
int main(int argc, char **argv)
{
LibLSS::MPI_Communication *mpi_world = LibLSS::setupMPI(argc, argv);
StaticInit::execute();
H5::H5File f("test.h5", H5F_ACC_TRUNC);
auto& cons = Console::instance();
boost::multi_array<double, 3> a(boost::extents[1000][2][3]);
fwrap(a) = fwrap(b_fused_idx<double,3>([](int q, int r, int s) { return q+2*s; }));
cons.format<LOG_VERBOSE>("a[5][0] = %g", a[5][0][0]);
hdf5_write_buffered_array(f, "test", a, true, true, [&](size_t p) {
cons.format<LOG_STD>("Wrote %d", p);
});
CosmoTool::hdf5_write_array(f, "test2", a);
StaticInit::finalize();
return 0;
}

View file

@ -0,0 +1,45 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_los_projector.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/physics/projector.hpp"
using namespace LibLSS;
int main()
{
// number of pixels
double N[3] = {10,10,10};
// size pixels
double dl[3]={2,2,2};
//lower left corner
double min[3]={-1,-1,-1};
//observer position
double origin[3]={0,0,0};
// shooting direction (normalized)
double pointing[3]={1./sqrt(2.),1./sqrt(2.),0};
//double pointing[3]={1./2.,sqrt(3.)/2.,0};
//double pointing[3]={1.,0.,0.};
//double pointing[3]={1./sqrt(3.),1./sqrt(3.),1./sqrt(3.)};
LOSContainer data;
ray_tracer(origin, pointing, min, dl, N, data);
std::cout << "L:" << N[0]*dl[0] << "," << N[1]*dl[1] << "," << N[2]*dl[2] << std::endl;
std::cout << "corner:" << min[0] << "," << min[1] << "," << min[2] << std::endl;
std::cout << "origin:" << origin[0] << "," << origin[1] << "," << origin[2] << std::endl;
std::cout << "direction:" << pointing[0] << "," << pointing[1] << "," << pointing[2] << std::endl;
std::cout << "voxel_id, los:" << std::endl;
for(int i=0; i<10; i++)
{
std::cout << data.voxel_id[i][0] << data.voxel_id[i][1] << data.voxel_id[i][2] << " , " << data.dlos[i] << std::endl;
}
return 0;
}

View file

@ -0,0 +1,90 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_messenger.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include "libLSS/tools/static_init.hpp"
#include "libLSS/samplers/core/types_samplers.hpp"
#include "libLSS/mcmc/global_state.hpp"
#include "libLSS/samplers/ares/gibbs_messenger.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/hdf5_error.hpp"
using namespace LibLSS;
typedef GSL_RandomNumber RGenType;
int main(int argc, char **argv)
{
MPI_Communication *comm = setupMPI(argc, argv);
StaticInit::execute();
Console::instance().setVerboseLevel<LOG_DEBUG>();
MarkovState state;
SLong *N0, *N1, *N2;
SDouble *L0, *L1, *L2;
RGenType randgen;
state.newElement("random_generator", new RandomStateElement<RandomNumber>(&randgen));
state.newElement("N0", N0 = new SLong());
state.newElement("N1", N1 = new SLong());
state.newElement("N2", N2 = new SLong());
state.newElement("L0", L0 = new SDouble());
state.newElement("L1", L1 = new SDouble());
state.newElement("L2", L2 = new SDouble());
state.newElement("s_field", new ArrayType(boost::extents[32][32][32]), true);
N0->value = 32;
N1->value = 32;
N2->value = 32;
state.newSyScalar<long>("localN0", N0->value);
state.newSyScalar<long>("startN0", 0);
state.newSyScalar<long>("NUM_MODES", 100);
MessengerSampler s(comm);
// Initialize (data,s)->t sampler
s.init_markov(state);
// Build some mock field
ArrayType *field = state.get<ArrayType>("data_field");
field->eigen().fill(0);
(*field->array)[16][16][16] = 1;
// Build some s field
ArrayType *s_field = state.get<ArrayType>("s_field");
s_field->eigen().fill(0);
(*s_field->array)[16][16][16] = 1;
// Setup messenger parameters
ArrayType *mmask = state.get<ArrayType>("messenger_mask");
mmask->eigen().fill(0);
state.get<SDouble>("messenger_tau")->value = 0.0;
s.sample(state);
{
H5::H5File f("dump.h5", H5F_ACC_TRUNC);
state.saveState(f);
auto f2 = std::make_shared<H5::H5File>("dump_snap.h5", H5F_ACC_TRUNC);
state.mpiSaveState(f2, comm, true /* We do not do reassembly but there is only one node */, true);
}
StaticInit::finalize();
return 0;
}

View file

@ -0,0 +1,113 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_messenger2.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include "libLSS/tools/static_init.hpp"
#include "libLSS/samplers/core/types_samplers.hpp"
#include "libLSS/mcmc/global_state.hpp"
#include "libLSS/samplers/ares/gibbs_messenger.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/samplers/core/powerspec_tools.hpp"
using namespace LibLSS;
typedef GSL_RandomNumber RGenType;
int main(int argc, char **argv)
{
StaticInit::execute();
MPI_Communication *mpi_world = setupMPI(argc, argv);
Console::instance().setVerboseLevel<LOG_DEBUG>();
MarkovState state;
SLong *N0, *N1, *N2;
SDouble *L0, *L1, *L2;
RGenType randgen;
ArrayType1d *ps;
IArrayType *k_keys;
state.newElement("random_generator", new RandomStateElement<RandomNumber>(&randgen));
state.newElement("N0", N0 = new SLong());
state.newElement("N1", N1 = new SLong());
state.newElement("N2", N2 = new SLong());
state.newElement("L0", L0 = new SDouble());
state.newElement("L1", L1 = new SDouble());
state.newElement("L2", L2 = new SDouble());
state.newSyScalar<bool>("messenger_signal_blocked", false);
state.newSyScalar<long>("NUM_MODES", 100);
double dk = 2*M_PI/200. * 16 * 2 /100.;
boost::array<int, 3> N;
boost::array<double, 3> L;
N[0] = N[1] = N[2] = 32;
L[0] = L[1] = L[2] = 200.;
state.newElement("powerspectrum", ps = new ArrayType1d(boost::extents[100]), true);
state.newElement("k_keys", k_keys = new IArrayType(boost::extents[32][32][17]));
for (int ix = 0; ix < 32; ix++) {
for (int iy = 0; iy < 32; iy++) {
for (int iz = 0; iz < 17; iz++) {
boost::array<int, 3> ik;
ik[0] = ix;
ik[1] = iy;
ik[2] = iz;
(*k_keys->array)[ix][iy][iz] = power_key(N, ik, L, 0, dk, 100);
}
}
}
ps->eigen().fill(0.00001);
N0->value = 32;
N1->value = 32;
N2->value = 32;
L0->value = 200;
L1->value = 200;
L2->value = 200;
MessengerSampler s(mpi_world);
MessengerSignalSampler s2(mpi_world);
// Initialize (data,s)->t sampler
s.init_markov(state);
s2.init_markov(state);
// Build some mock field
ArrayType *field = state.get<ArrayType>("data_field");
field->eigen().fill(0);
(*field->array)[16][16][16] = 1;
// Setup messenger parameters
ArrayType *mmask = state.get<ArrayType>("messenger_mask");
mmask->eigen().fill(0);
state.get<SDouble>("messenger_tau")->value = 1;
s.sample(state);
s2.sample(state);
{
H5::H5File f("dump.h5", H5F_ACC_TRUNC);
state.saveState(f);
}
StaticInit::finalize();
doneMPI();
return 0;
}

View file

@ -0,0 +1,135 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_messenger3.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/mcmc/global_state.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/samplers/core/types_samplers.hpp"
#include "libLSS/samplers/ares/gibbs_messenger.hpp"
#include "libLSS/samplers/core/powerspec_tools.hpp"
#include "libLSS/samplers/ares/powerspectrum_a_sampler.hpp"
using namespace LibLSS;
typedef GSL_RandomNumber RGenType;
int main(int argc, char **argv)
{
StaticInit::execute();
MPI_Communication *mpi_world = setupMPI(argc, argv);
Console::instance().setVerboseLevel<LOG_DEBUG>();
MarkovState state;
SLong *N0, *N1, *N2, *N2_HC, *NUM_MODES, *localN0, *startN0, *fourierLocalSize;
SDouble *L0, *L1, *L2, *K_MIN, *K_MAX;
RGenType randgen;
ArrayType1d *ps;
IArrayType *k_keys;
state.newElement("random_generator", new RandomGen(&randgen));
state.newElement("fourierLocalSize", fourierLocalSize = new SLong());
state.newElement("localN0", localN0 = new SLong());
state.newElement("startN0", startN0 = new SLong());
state.newElement("N0", N0 = new SLong());
state.newElement("N1", N1 = new SLong());
state.newElement("N2", N2 = new SLong());
state.newElement("N2_HC", N2_HC = new SLong());
state.newSyScalar("messenger_signal_blocked", false);
state.newSyScalar("power_sampler_a_blocked", false);
state.newSyScalar("power_sampler_b_blocked", false);
state.newElement("NUM_MODES", NUM_MODES = new SLong());
state.newElement("K_MIN", K_MIN = new SDouble());
state.newElement("K_MAX", K_MAX = new SDouble());
NUM_MODES->value = 100;
K_MIN->value = 0;
K_MAX->value = 2.;
state.newElement("L0", L0 = new SDouble());
state.newElement("L1", L1 = new SDouble());
state.newElement("L2", L2 = new SDouble());
localN0->value = 64;
startN0->value = 0;
N0->value = 64;
N1->value = 64;
N2->value = 64;
N2_HC->value = 33;
fourierLocalSize->value = 64*64*33;
L0->value = 200;
L1->value = 200;
L2->value = 200;
MessengerSampler s(mpi_world);
MessengerSignalSampler s2(mpi_world);
PowerSpectrumSampler_a p(mpi_world);
// Initialize (data,s)->t sampler
s.init_markov(state);
s2.init_markov(state);
p.init_markov(state);
ArrayType1d::ArrayType& k_val = *state.get<ArrayType1d>("k_modes")->array;
int Nk = NUM_MODES->value;
s2.setMockGeneration(true);
// Fill up powerspectrum
ps = state.get<ArrayType1d>("powerspectrum");
for (int k = 1; k < Nk; k++) {
(*ps->array)[k] = pow(k_val[k], -2);
}
// Build some mock field
ArrayType *field = state.get<ArrayType>("data_field");
field->eigen().fill(0);
// Setup messenger parameters
ArrayType *mmask = state.get<ArrayType>("messenger_mask");
mmask->eigen().fill(-1);
(*mmask->array)[16][16][16] = 0;
state.get<SDouble>("messenger_tau")->value = 1.; // Remove any sign of data. I should add a mechanism to generate unconstrained realizations
// First round is unconstrained
s2.sample(state);
s2.setMockGeneration(false);
field->eigen() = state.get<ArrayType>("s_field")->eigen();
s.sample(state);
s2.sample(state);
p.sample(state);
s.sample(state);
s2.sample(state);
p.sample(state);
s.sample(state);
s2.sample(state);
p.sample(state);
{
H5::H5File f("dump.h5", H5F_ACC_TRUNC);
state.saveState(f);
}
StaticInit::finalize();
doneMPI();
return 0;
}

151
libLSS/tests/test_mngp.cpp Normal file
View file

@ -0,0 +1,151 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_mngp.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <cmath>
#include <CosmoTool/algo.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/uninitialized_type.hpp"
#include "libLSS/tools/array_tools.hpp"
#include "libLSS/physics/classic_cic.hpp"
//#include "libLSS/tools/mpi_fftw_helper.hpp"
#include "libLSS/physics/modified_ngp.hpp"
#include "libLSS/physics/modified_ngp_smooth.hpp"
#include "libLSS/physics/cosmo.hpp"
#include <H5Cpp.h>
#include <CosmoTool/hdf5_array.hpp>
#include "libLSS/tools/hdf5_error.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include <boost/chrono.hpp>
//#undef RANDOM_ACCESS
#define RANDOM_ACCESS
using namespace LibLSS;
using CosmoTool::cube;
typedef ClassicCloudInCell<double> CIC;
//typedef ModifiedNGP<double> MNGP;
typedef ModifiedNGP<double, NGPGrid::Quad> MNGP;
typedef SmoothModifiedNGP<double, SmoothNGPGrid::Quad> MNGPS;
//typedef ModifiedNGP<double, NGPGrid::CIC> MNGP;
int main(int argc, char **argv) {
StaticInit::execute();
MPI_Communication *world = setupMPI(argc, argv);
CosmologicalParameters cosmo;
cosmo.omega_m = 0.30;
cosmo.omega_b = 0.045;
cosmo.omega_q = 0.70;
cosmo.w = -1;
cosmo.n_s = 0.97;
cosmo.sigma8 = 0.8;
cosmo.h = 0.68;
cosmo.a0 = 1.0;
Console::instance().setVerboseLevel<LOG_DEBUG>();
double L = 1.0;
int N = 64;
int Np_g = 128;
int Np = cube(Np_g);
typedef UninitializedArray<boost::multi_array<double, 3>> U_Density;
typedef UninitializedArray<boost::multi_array<double, 2>> U_Particles;
U_Density density_p(boost::extents[N][N][N]);
U_Density density_mngp_p(boost::extents[N][N][N]);
U_Density density_mngps_p(boost::extents[N][N][N]);
U_Particles particles_p(boost::extents[Np][3]);
U_Particles adjoint_p(boost::extents[Np][3]);
U_Particles adjoint_mngp_p(boost::extents[Np][3]);
U_Particles adjoint_mngps_p(boost::extents[Np][3]);
U_Density::array_type &density = density_p.get_array();
U_Density::array_type &density_mngp = density_mngp_p.get_array();
U_Density::array_type &density_mngps = density_mngps_p.get_array();
U_Particles::array_type &particles = particles_p.get_array();
U_Particles::array_type &adjoint = adjoint_p.get_array();
U_Particles::array_type &adjoint_mngp = adjoint_mngp_p.get_array();
U_Particles::array_type &adjoint_mngps = adjoint_mngps_p.get_array();
CIC cic;
MNGP mngp;
#ifdef RANDOM_ACCESS
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
particles[i][0] = L * rgen.uniform();
particles[i][1] = L * rgen.uniform();
particles[i][2] = L * rgen.uniform();
}
#else
# pragma omp parallel for schedule(static)
for (long i = 0; i < Np; i++) {
int iz = (i % Np_g);
int iy = ((i / Np_g) % Np_g);
int ix = ((i / Np_g / Np_g));
particles[i][0] = L / Np_g * ix;
particles[i][1] = L / Np_g * iy;
particles[i][2] = L / Np_g * iz;
}
#endif
Console::instance().print<LOG_INFO>("Clearing and projecting");
array::fill(density, 0);
array::fill(density_mngp, 0);
array::fill(density_mngps, 0);
using namespace boost::chrono;
system_clock::time_point start_classic, end_classic, start_mp, end_mp,
start_mp2, end_mp2;
start_classic = system_clock::now();
CIC::projection(particles, density, L, L, L, N, N, N);
end_classic = system_clock::now();
CIC::adjoint(particles, density, adjoint, L, L, L, N, N, N, 1.0);
start_mp = system_clock::now();
MNGP::projection(particles, density_mngp, L, L, L, N, N, N);
end_mp = system_clock::now();
start_mp2 = system_clock::now();
MNGPS::projection(particles, density_mngps, L, L, L, N, N, N);
end_mp2 = system_clock::now();
MNGP::adjoint(particles, density_mngp, adjoint_mngp, L, L, L, N, N, N, 1.0);
MNGPS::adjoint(
particles, density_mngps, adjoint_mngps, L, L, L, N, N, N, 1.0);
duration<double> elapsed_classic = end_classic - start_classic;
duration<double> elapsed_mp = end_mp - start_mp;
duration<double> elapsed_mps = end_mp2 - start_mp2;
std::cout << "MNGP: " << elapsed_mp << " MNPS:" << elapsed_mps
<< " Classic: " << elapsed_classic << std::endl;
try {
H5::H5File f("cic.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "density", density);
CosmoTool::hdf5_write_array(f, "density_mngp", density_mngp);
CosmoTool::hdf5_write_array(f, "density_mngps", density_mngps);
CosmoTool::hdf5_write_array(f, "adjoint", adjoint);
CosmoTool::hdf5_write_array(f, "adjoint_mngp", adjoint_mngp);
CosmoTool::hdf5_write_array(f, "adjoint_mngps", adjoint_mngps);
} catch (const H5::FileIException &) {
Console::instance().print<LOG_ERROR>(
"Failed to load ref_pm.h5 in the current directory. Check in the "
"source directory libLSS/tests/");
return 1;
}
return 0;
}

View file

@ -0,0 +1,43 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_overload.cpp
Copyright (C) 2019-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#define BOOST_TEST_MODULE overload
#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/variant.hpp>
#include "libLSS/tools/overload.hpp"
using namespace LibLSS;
BOOST_AUTO_TEST_CASE(basic) {
boost::variant<int> a(2);
{
int value = boost::apply_visitor([](int b) { return b; }, a);
BOOST_CHECK_EQUAL(value, 2);
}
{
int value = boost::apply_visitor(overload([](int b) { return b; }), a);
BOOST_CHECK_EQUAL(value, 2);
}
}
BOOST_AUTO_TEST_CASE(multiple) {
boost::variant<int, std::string> a(2);
{
int value = boost::apply_visitor(
overload([](int b) { return b; }, [](std::string s) { return -1; }), a);
BOOST_CHECK_EQUAL(value, 2);
}
}
// ARES TAG: authors_num = 1
// ARES TAG: name(0) = Guilhem Lavaux
// ARES TAG: email(0) = guilhem.lavaux@iap.fr
// ARES TAG: year(0) = 2019-2020

View file

@ -0,0 +1,39 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_proj.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include "libLSS/mpi/generic_mpi.hpp"
#include "libLSS/data/spectro_gals.hpp"
#include "libLSS/data/projection.hpp"
#include "libLSS/data/galaxies.hpp"
using namespace LibLSS;
int main(int argc, char **argv)
{
MPI_Communication *comm = setupMPI(argc, argv);
H5::H5File f("toto.h5", H5F_ACC_TRUNC);
typedef GalaxySurvey<NoSelection, BaseGalaxyDescriptor> SurveyType;
SurveyType survey;
SurveyType::GalaxyType galaxy;
galaxy.id = 0;
galaxy.phi = 1.0;
galaxy.theta = 0.1;
galaxy.r = 10.;
galaxy.zo = 1000;
survey.addGalaxy(galaxy);
survey.save(f);
survey.restoreMain(f);
return 0;
}

37
libLSS/tests/test_r3d.cpp Normal file
View file

@ -0,0 +1,37 @@
#include <cstdio>
#include <iostream>
#include <healpix_cxx/healpix_base.h>
extern "C" {
#include "r3d.h"
}
int main(int argc, char **argv)
{
Healpix_Base hpx(8, RING, SET_NSIDE);
std::vector<vec3> out;
int step = 1;
out.resize(4*step);
for (int pix = 0; pix < hpx.Npix(); pix++) {
r3d_poly p[4];
r3d_rvec3 v[4];
double L = 1.0;
hpx.boundaries(pix, step, out);
v[0].x = 0;
v[0].x = 0;
v[0].z = 0;
// v[1].x = out[q].x * L;
// v[1].y = out[q].y * L;
// v[1].z = out[q].z * L;
// v[1].x = out[q].x * L;
// v[1].y = out[q].y * L;
// v[1].z = out[q].z * L;
// r3d_init_tet(&poly[p], verts);
}
return 0;
}

View file

@ -0,0 +1,71 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_rgen.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include <stdlib.h>
#include <boost/chrono.hpp>
#include <boost/format.hpp>
#include "libLSS/tools/static_init.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
using namespace LibLSS;
using boost::chrono::system_clock;
using boost::chrono::duration;
using boost::format;
using boost::str;
static const long int LOOP_NO = 100000000;
int main()
{
StaticInit::execute();
Console::instance().setVerboseLevel<LOG_DEBUG>();
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
system_clock::time_point start = system_clock::now();
#pragma omp parallel for schedule(static)
for (long l = 0; l < LOOP_NO; l++)
rgen.get();
duration<double> perf = system_clock::now() - start;
Console::instance().print<LOG_INFO>(format("Number / sec = %lg Mint / sec") % (LOOP_NO/perf.count()/1000000) );
{
H5::H5File f("PRNG.state", H5F_ACC_TRUNC);
rgen.save(f);
}
try {
RandomNumberThreaded<GSL_RandomNumber> rgen2(2*smp_get_max_threads());
H5::H5File f("PRNG.state", 0);
rgen2.restore(f);
abort();
Console::instance().print<LOG_ERROR>("Did not get any error. Bad");
}
catch (const ErrorBadState& s) {
Console::instance().print<LOG_INFO>("Got error. Exact");
}
try {
RandomNumberThreaded<GSL_RandomNumber> rgen2(-1);
H5::H5File f("PRNG.state", 0);
rgen2.restore(f);
}
catch (const ErrorBase& s) {
Console::instance().print<LOG_ERROR>("Got an error. Bad");
abort();
}
return 0;
}

View file

@ -0,0 +1,58 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_schechter.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include <boost/format.hpp>
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/physics/cosmo.hpp"
#include "libLSS/data/schechter_completeness.hpp"
using std::cout;
using std::endl;
using namespace LibLSS;
int main() {
StaticInit::execute();
Console::instance().setVerboseLevel<LOG_STD>();
CosmologicalParameters cosmo_params;
cosmo_params.omega_m = 0.30;
cosmo_params.omega_b = 0.045;
cosmo_params.omega_q = 0.70;
cosmo_params.w = -1;
cosmo_params.n_s = 0.97;
cosmo_params.sigma8 = 0.8;
cosmo_params.h = 0.68;
cosmo_params.a0 = 1.0;
Cosmology cosmo(cosmo_params);
GalaxySampleSelection selection;
SchechterParameters params;
params.Mstar = -23.17;
params.alpha = -0.9;
selection.bright_apparent_magnitude_cut = -100;
selection.faint_apparent_magnitude_cut = 11.5;
selection.bright_absolute_magnitude_cut = -26;
selection.faint_absolute_magnitude_cut = -20;
double zlist[] = {0.001, 0.005, 0.01, 0.02, 0.03};
double E[] = {1, 0.929577, 0.455884, 0.0966858, 0.013993};
for (int i = 0; i < sizeof(zlist) / sizeof(zlist[0]); i++) {
double d_comoving;
d_comoving = cosmo.a2com(cosmo.z2a(zlist[i]));
cout << "C = "
<< details::computeSchechterCompleteness(
cosmo, zlist[i], d_comoving, selection, params)
<< " expect = " << E[i] << endl;
}
return 0;
}

View file

@ -0,0 +1,58 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_slice_sweep.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include <stdlib.h>
#include <boost/chrono.hpp>
#include <boost/format.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/tools/static_init.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/samplers/rgen/slice_sweep.hpp"
#include "libLSS/mpi/generic_mpi.hpp"
using boost::multi_array;
using boost::extents;
using namespace LibLSS;
static const int Ntry=200000;
double likelihood1(double x)
{
return std::log(std::exp(-(x-1)*(x-1)/2) + std::exp(-(x-6)*(x-6)/2));
}
int main(int argc, char **argv)
{
MPI_Communication *comm = LibLSS::setupMPI(argc, argv);
StaticInit::execute();
Console::instance().setVerboseLevel<LOG_DEBUG>();
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
multi_array<double, 1> a(extents[Ntry]);
double v = 0;
for (int i = 0; i < Ntry; i++)
{
a[i] = v = LibLSS::slice_sweep(comm, rgen, [](double x) -> double { return likelihood1(x/2);}, v*2, 1)/2;
}
{
H5::H5File f("test_sweep.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "lh1", a);
}
return 0;
}

View file

@ -0,0 +1,63 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_slice_sweep_double.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include <stdlib.h>
#include <boost/chrono.hpp>
#include <boost/format.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/tools/static_init.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/samplers/rgen/slice_sweep.hpp"
#include "libLSS/mpi/generic_mpi.hpp"
using boost::multi_array;
using boost::extents;
using namespace LibLSS;
static const int Ntry=100;
double likelihood1(double x)
{
return std::log(std::exp(-(x-1)*(x-1)/2) + std::exp(-(x-6)*(x-6)/2));
}
int main(int argc, char **argv)
{
MPI_Communication *comm = LibLSS::setupMPI(argc, argv);
StaticInit::execute();
Console::instance().setVerboseLevel<LOG_DEBUG>();
RandomNumberThreaded<GSL_RandomNumber> rgen(-1);
multi_array<double, 1> a(extents[2*Ntry]);
double v = 0;
for (int i = 0; i < Ntry; i++)
{
a[i] = v = LibLSS::slice_sweep_double(comm, rgen, likelihood1, v, 1e-2);
}
for (int i = 0; i < Ntry; i++)
{
a[Ntry+i] = v = LibLSS::slice_sweep_double(comm, rgen, likelihood1, v, 1e4);
}
{
H5::H5File f("test_sweep.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "lh1", a);
}
return 0;
}

View file

@ -0,0 +1,22 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_stl_container.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include <vector>
#include <set>
#include "libLSS/tools/is_stl_container.hpp"
using namespace LibLSS;
int main()
{
//std::cout << is_stl_container_like<std::vector<double>>::value << std::endl;
std::cout << is_stl_container_like<std::set<double>>::value << std::endl;
return 0;
}

View file

@ -0,0 +1,170 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_supersampling.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <H5Cpp.h>
#include <CosmoTool/hdf5_array.hpp>
#include <boost/bind/bind.hpp>
#include <complex>
#include <boost/lambda/lambda.hpp>
#include <boost/multi_array.hpp>
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include "libLSS/tools/fused_array.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/mpi_fftw_helper.hpp"
using namespace LibLSS;
using namespace std;
using boost::bind;
using boost::c_storage_order;
using boost::ref;
using CosmoTool::hdf5_write_array;
using boost::lambda::constant;
using boost::placeholders::_1;
typedef FFTW_Manager_3d<double> Manager;
typedef Manager::ArrayFourier F_Array;
typedef Manager::ArrayReal R_Array;
namespace {
#if defined(ARES_MPI_FFTW)
RegisterStaticInit reg0(fftw_mpi_init, fftw_mpi_cleanup, 9, "MPI/FFTW");
#endif
// WISDOM must come at the end. Otherwise it is reset
RegisterStaticInit reg1(CosmoTool::init_fftw_wisdom, CosmoTool::save_fftw_wisdom, 12, "FFTW/WISDOM");
/*#if defined(_OPENMP) // Do not use MPI and Threaded FFTW at the same time for the moment.
RegisterStaticInit reg2(fftw_init_threads, fftw_cleanup_threads, 11, "FFTW/THREADS");
#endif*/
}
template<typename RGen>
double rand_init(RGen *rgen, double fac)
{
return rgen->gaussian_ratio() * fac;
}
static
double filler()
{
static long counter = 0;
return 1;
}
int main(int argc, char **argv)
{
using boost::format;
using boost::str;
namespace Larray = LibLSS::array;
MPI_Communication *world = setupMPI(argc, argv);
StaticInit::execute();
Console::instance().outputToFile(str(format("log_test_supersampling.txt.%d") % world->rank()));
Console::instance().setVerboseLevel<LOG_DEBUG>();
Manager mgr(16,16,16, world);
Manager mgr2(32,32,32, world);
{
F_Array f_array(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
F_Array f2_array(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array f3_array(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array f4_array(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
R_Array r0_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array r_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array r2_array(mgr2.extents_real(), c_storage_order(), mgr2.allocator_real);
R_Array r3_array(mgr2.extents_real(), c_storage_order(), mgr2.allocator_real);
R_Array r4_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array r5_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
R_Array r_hi_array(mgr2.extents_real(), c_storage_order(), mgr2.allocator_real);
R_Array tmp_hi(mgr2.extents_real(), c_storage_order(), mgr2.allocator_real);
R_Array r_lo_array(mgr.extents_real(), c_storage_order(), mgr.allocator_real);
F_Array f_hi_array(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array f_hi2_array(mgr2.extents_complex(), c_storage_order(), mgr2.allocator_complex);
F_Array tmp_f_lo(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
F_Array f_lo_array(mgr.extents_complex(), c_storage_order(), mgr.allocator_complex);
Manager::plan_type plan_r2c = mgr.create_r2c_plan(r_array.data(), f_array.data());
Manager::plan_type plan_c2r_lo = mgr.create_c2r_plan(f_array.data(), r_array.data());
Manager::plan_type plan_r2c_hi = mgr2.create_r2c_plan(r_hi_array.data(), f_hi_array.data());
Manager::plan_type plan_c2r = mgr2.create_c2r_plan(f3_array.data(), r2_array.data());
typedef RandomNumberMPI<GSL_RandomNumber> RGen;
{
RGen rgen(world, -1);
double fac = 1.0/(mgr.N0*mgr.N1*mgr.N2);
boost::function0<double> ff = bind(rand_init<RGen>, &rgen, fac);
rgen.seed(2012145);
Console::instance().print<LOG_DEBUG>(format("ff = %lg") % ff());
copy_array(r_array, b_fused<double, 3>(bind(rand_init<RGen>, &rgen, fac)));
r0_array = r_array;
mgr.execute_r2c(plan_r2c, r_array.data(), f_array.data());
mgr2.upgrade_complex(mgr, f_array, f2_array);
mgr.degrade_complex(mgr2, f2_array, f4_array);
Larray::copyArray3d(f3_array, f2_array);
mgr2.execute_c2r(plan_c2r, f3_array.data(), r2_array.data());
Larray::scaleArray3d(r2_array, 1./16./16./16.);
/// mgr.degrade_real(mgr2, r2_array, r_array);
Larray::fill(r3_array, 1);
//// mgr.degrade_real(mgr2, r3_array, r4_array);
//// r3_array[2][2][2] = 0;
//// mgr.degrade_real(mgr2, r3_array, r5_array);
copy_array(r_hi_array, b_fused<double, 3>( ff ) );
Larray::copyArray3d(tmp_hi, r_hi_array);
mgr2.execute_r2c(plan_r2c_hi, tmp_hi.data(), f_hi_array.data());
Larray::scaleArray3d(f_hi_array, 1./(mgr.N0*mgr.N1*mgr.N2));
mgr.degrade_complex(mgr2, f_hi_array, f_lo_array);
mgr2.upgrade_complex(mgr, f_lo_array, f_hi2_array);
Larray::copyArray3d(tmp_f_lo, f_lo_array);
mgr.execute_c2r(plan_c2r_lo, tmp_f_lo.data(), r_lo_array.data());
{
string s = boost::str(boost::format("test_upgrade.h5_%d") % world->rank());
H5::H5File f(s, H5F_ACC_TRUNC);
hdf5_write_array(f, "ref", f_array);
hdf5_write_array(f, "upgrade", f2_array);
hdf5_write_array(f, "degrade_complex", f4_array);
hdf5_write_array(f, "ref0", r0_array);
hdf5_write_array(f, "upgrade_real", r2_array);
hdf5_write_array(f, "updowngrade", r_array);
hdf5_write_array(f, "down_a", r4_array);
hdf5_write_array(f, "down_b", r5_array);
hdf5_write_array(f, "hi__r_hi", r_hi_array);
hdf5_write_array(f, "hi__f_hi", f_hi_array);
hdf5_write_array(f, "hi__f_hi2", f_hi2_array);
hdf5_write_array(f, "hi__f_lo", f_lo_array);
hdf5_write_array(f, "hi__r_lo", r_lo_array);
}
}
}
world->barrier();
StaticInit::finalize();
doneMPI();
return 0;
}

View file

@ -0,0 +1,33 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_tuple.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include "libLSS/tools/tuple_helper.hpp"
int main()
{
auto t = std::make_tuple(0, 1, 2, 3);
auto u0 = LibLSS::last_of_tuple<0>(t);
auto u = LibLSS::last_of_tuple<1>(t);
auto u2 = LibLSS::last_of_tuple<2>(t);
auto u3 = LibLSS::last_of_tuple<3>(t);
int a, b , c,d;
std::tie(a,b,c,d) = u0;
std::cout << a << " " << b << " " << c << " " << d << std::endl;
std::tie(a,b,c) = u;
std::cout << a << " " << b << " " << c << std::endl;
std::tie(b,c) = u2;
std::cout << b << " " << c << std::endl;
std::tie(c) = u3;
std::cout << c << std::endl;
return 0;
}

View file

@ -0,0 +1,110 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_uninit.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <iostream>
#include <boost/multi_array.hpp>
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/uninitialized_type.hpp"
#include "libLSS/tools/static_init.hpp"
using std::cout;
using std::endl;
using namespace LibLSS;
#pragma GCC push_options
#pragma GCC optimize ("O0")
template<typename T>
void f(T& a)
{
a[0][0] = 1;
}
#pragma GCC pop_options
#pragma GCC push_options
#pragma GCC optimize ("O0")
template<typename T>
void g(T& a)
{
a[0] = 1;
}
#pragma GCC pop_options
int main()
{
typedef boost::multi_array_ref<double, 2> Array;
StaticInit::execute();
int iteration = 1000;
{
ConsoleContext<LOG_STD> ctx("multi_array uninit ");
for (int j = 0; j < iteration; j++) {
UninitializedArray<Array> a0(boost::extents[128][128*128]);
Array& a = a0.get_array();
for (int i = 0; i < a.shape()[0]; i++) {
for (int j = 0; j < a.shape()[1]; j++) {
a[i][j] = i;
}
}
f(a);
}
}
{
boost::multi_array<double, 2> a(boost::extents[128][128*128]);
ConsoleContext<LOG_STD> ctx("multi_array prealloc");
for (int j = 0; j < iteration; j++) {
for (int i = 0; i < a.shape()[0]; i++) {
for (int j = 0; j < a.shape()[1]; j++) {
a[i][j] = i;
}
}
f(a);
}
}
{
ConsoleContext<LOG_STD> ctx("multi_array init");
for (int j = 0; j < iteration; j++) {
boost::multi_array<double, 2> a(boost::extents[128][128*128]);
for (int i = 0; i < a.shape()[0]; i++) {
for (int j = 0; j < a.shape()[1]; j++) {
a[i][j] = i;
}
}
f(a);
}
}
{
ConsoleContext<LOG_STD> ctx("native uninit");
for (int j = 0; j < iteration; j++) {
double *a = new double[128*128*128];
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 128*128; j++) {
a[i*128*128+j] = i;
}
}
g(a);
delete[] a;
}
}
return 0;
}

View file

@ -0,0 +1,75 @@
/*+
ARES/HADES/BORG Package -- ./libLSS/tests/test_window3d.cpp
Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
Additional contributions from:
Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
+*/
#include <string>
#include "libLSS/mpi/generic_mpi.hpp"
#include <cmath>
#include <healpix_cxx/healpix_map.h>
#include <boost/multi_array.hpp>
#include <boost/array.hpp>
#include "libLSS/tools/console.hpp"
#include "libLSS/tools/static_init.hpp"
#include "libLSS/data/window3d.hpp"
#include "libLSS/samplers/core/random_number.hpp"
#include "libLSS/samplers/rgen/gsl_random_number.hpp"
#include <CosmoTool/hdf5_array.hpp>
static const int N0 = 128;
struct BasicSelFunction
{
Healpix_Map<double> C;
double getRadialSelection(double r, int i) const {
return std::exp(-0.5*(r*r/400.));
}
int getNumRadial() const { return 1; }
double get_sky_completeness(double x, double y, double z) const {
return C[C.vec2pix(vec3(x,y,z))];
}
double get_sky_completeness(double ra, double dec) const {
return C[C.ang2pix(pointing(0.5*M_PI-dec, ra))];
}
};
using namespace LibLSS;
int main(int argc, char **argv)
{
Console& console = Console::instance();
MPI_Communication *comm = LibLSS::setupMPI(argc, argv);
boost::multi_array<double, 3> selFuncData(boost::extents[N0][N0][N0]);
double L[3] = {200.,200.,200.};
double xmin[3] = {-100,-100,-100};
double delta[3] = {200./N0, 200./N0, 200./N0 };
StaticInit::execute();
RandomNumberThreaded<GSL_RandomNumber> rng(-1);
console.setVerboseLevel<LOG_INFO>();
LibLSS::smp_set_nested(true);
BasicSelFunction sel;
sel.C.SetNside(1, RING);
sel.C.fill(0);
sel.C[0] = 1.0;
compute_window_value_elem(comm, rng, sel, selFuncData, L, delta, xmin, 0.001);
H5::H5File f("test_window.h5", H5F_ACC_TRUNC);
CosmoTool::hdf5_write_array(f, "selData", selFuncData);
return 0;
}