Skip to content

Commit

Permalink
Merge pull request #263 from electronic-structure/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
toxa81 authored Sep 17, 2018
2 parents 765d1ce + 9555d21 commit faf052e
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 122 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ exec_program(
ARGS "describe --all"
OUTPUT_VARIABLE GIT_BRANCHNAME
RETURN_VALUE GIT_QUERY_BRANCH)
configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_BINARY_DIR}/src/version.h")
configure_file("${PROJECT_SOURCE_DIR}/src/version.hpp.in" "${PROJECT_BINARY_DIR}/src/version.hpp")
include_directories(BEFORE ${PROJECT_BINARY_DIR}/src)

MACRO(SIRIUS_SETUP_TARGET _target)
Expand Down
6 changes: 3 additions & 3 deletions apps/tests/test_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void test_gpu(int N)

for (size_t i = 0; i < buf.size(); i++) buf(i) = char(i % 255);

DUMP("hash(buf): %llX", buf.hash());
// DUMP("hash(buf): %llX", buf.hash());

buf.allocate(memory_t::device);
buf.copy_to_device();
Expand All @@ -19,7 +19,7 @@ void test_gpu(int N)
void* ptr = cuda_malloc_host(N);
void* ptr1 = std::malloc(N);

DUMP("hash(buf): %llX", buf.hash());
// DUMP("hash(buf): %llX", buf.hash());

printf("test of GPU pointer: %i\n", cuda_check_device_ptr(buf.at<GPU>()));
printf("test of CPU pointer: %i\n", cuda_check_device_ptr(ptr));
Expand All @@ -45,7 +45,7 @@ int main(int argn, char** argv)

sirius::initialize(1);
cuda_device_info();

#ifdef __GPU
test_gpu(N);
#endif
Expand Down
12 changes: 6 additions & 6 deletions apps/tests/test_wf_redistr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void test_wf_redistr(double alat, double pw_cutoff, double wf_cutoff, int num_ba
dmatrix<double_complex> psi(gv_wf.num_gvec_, num_bands, blacs_grid, (int)spl_gv_wf.block_size(), 1);
psi.zero();

for (int i = 0; i < num_bands; i++)
for (int i = 0; i < num_bands; i++)
{
for (int ig = 0; ig < gv_wf.num_gvec_; ig++)
{
Expand Down Expand Up @@ -67,13 +67,13 @@ void test_wf_redistr(double alat, double pw_cutoff, double wf_cutoff, int num_ba
{
printf("time to swap %li Mb: %f sec.", (sizeof(double_complex) * gv_wf.num_gvec_ * num_bands) >> 20, tval);
}

psi.zero();
linalg<CPU>::gemr2d(gv_wf.num_gvec_, num_bands, psi_slab, 0, 0, psi, 0, 0, blacs_grid.context());
if (h != psi.panel().hash())
{
DUMP("wrong hash");
}
// if (h != psi.panel().hash())
// {
// DUMP("wrong hash");
// }
}

int main(int argn, char **argv)
Expand Down
4 changes: 2 additions & 2 deletions apps/unit_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ INCLUDE = -I./../../src
.cpp.o:
$(CXX) $(CXX_OPT) $(INCLUDE) $< $(LIB_SIRIUS) $(LIBS) -o $@

all: test_init test_sht test_fft_correctness test_fft_real test_spline test_rot_ylm test_linalg test_wf_ortho test_serialize
all: test_init test_sht test_fft_correctness test_fft_real test_spline test_rot_ylm test_linalg test_wf_ortho test_serialize test_mempool

%: %.cpp $(LIB_SIRIUS)
$(CXX) $(CXX_OPT) $(INCLUDE) $< $(LIB_SIRIUS) $(LIBS) -o $@

clean:
rm -rf *.o test_init test_sht test_fft_correctness test_fft_real test_spline test_rot_ylm test_linalg test_wf_ortho test_serialize *.dSYM
rm -rf *.o test_init test_sht test_fft_correctness test_fft_real test_spline test_rot_ylm test_linalg test_wf_ortho test_serialize test_mempool *.dSYM
91 changes: 91 additions & 0 deletions apps/unit_tests/test_mempool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <sirius.h>

using namespace sirius;

void test1()
{
memory_pool mp;
}

void test2()
{
memory_pool mp;
mp.allocate<double_complex, memory_t::host>(1024);
mp.reset<memory_t::host>();
}

void test3()
{
memory_pool mp;
mp.allocate<double_complex, memory_t::host>(1024);
mp.allocate<double_complex, memory_t::host>(2024);
mp.allocate<double_complex, memory_t::host>(3024);
mp.reset<memory_t::host>();
}

void test4()
{
memory_pool mp;
mp.allocate<double_complex, memory_t::host>(1024);
mp.reset<memory_t::host>();
mp.allocate<double_complex, memory_t::host>(1024);
mp.allocate<double_complex, memory_t::host>(1024);
mp.reset<memory_t::host>();
mp.allocate<double_complex, memory_t::host>(1024);
mp.allocate<double_complex, memory_t::host>(1024);
mp.allocate<double_complex, memory_t::host>(1024);
mp.reset<memory_t::host>();
}

void test5()
{
memory_pool mp;

for (int k = 0; k < 2; k++) {
std::vector<double*> vp;
for (size_t i = 1; i < 20; i++) {
size_t sz = 1 << i;
double* ptr = mp.allocate<double, memory_t::host>(sz);
ptr[0] = 0;
ptr[sz - 1] = 0;
vp.push_back(ptr);
}
for (auto& e: vp) {
mp.free<memory_t::host>(e);
}
}
}

int run_test()
{
test1();
test2();
test3();
test4();
test5();
return 0;
}

int main(int argn, char** argv)
{
cmd_args args;

args.parse_args(argn, argv);
if (args.exist("help")) {
printf("Usage: %s [options]\n", argv[0]);
args.print_help();
return 0;
}

sirius::initialize(1);
printf("%-30s", "testing memory pool: ");
int result = run_test();
if (result) {
printf("\x1b[31m" "Failed" "\x1b[0m" "\n");
} else {
printf("\x1b[32m" "OK" "\x1b[0m" "\n");
}
sirius::finalize();

return 0;
}
60 changes: 30 additions & 30 deletions apps/unit_tests/test_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void check_spline(Spline<double> const& s__, std::function<double(double)> f__,

void test_spline_1a()
{
auto f = [](double x) { return std::sin(x) / x;};
auto f = [](double x) { return std::sin(x) / x;};

double x0 = 1e-7;
double x1 = 2.0;

Radial_grid_lin_exp<double> rgrid(2000, 1e-7, 2);
Spline<double> s(rgrid, f);

Expand All @@ -39,11 +39,11 @@ void test_spline_1a()

void test_spline_1b()
{
auto f = [](double x) { return std::exp(-2*x) * x;};
auto f = [](double x) { return std::exp(-2*x) * x;};

double x0 = 1e-7;
double x1 = 2.0;

Radial_grid_lin_exp<double> rgrid(2000, 1e-7, 2);
Spline<double> s(rgrid, f);

Expand All @@ -65,7 +65,7 @@ void test_spline_3(std::vector< Spline<double> > const& s, std::function<double(
// Test vector of splines.
void test_spline_2()
{
auto f = [](double x) { return std::sin(x) / x;};
auto f = [](double x) { return std::sin(x) / x;};

double x0 = 1e-7;
double x1 = 2.0;
Expand Down Expand Up @@ -154,8 +154,8 @@ void test_spline_5()
}
}
double tval = t.stop();
DUMP("inner product time: %12.6f", tval);
DUMP("performance: %12.6f GFlops", 1e-9 * n * n * N * 85 / tval);
printf("inner product time: %12.6f", tval);
printf("performance: %12.6f GFlops", 1e-9 * n * n * N * 85 / tval);
}

void test_spline_6()
Expand All @@ -178,16 +178,16 @@ void test1(double x0, double x1, int m, double exact_result)
printf(" lower and upper boundaries: %f %f\n", x0, x1);
Radial_grid_exp<double> r(5000, x0, x1);
Spline<double> s(r);

for (int i = 0; i < 5000; i++) {
s(i) = std::sin(r[i]);
}

double d = s.interpolate().integrate(m);
double err = std::abs(1 - d / exact_result);

printf(" relative error: %18.12f", err);
if (err < 1e-10)
if (err < 1e-10)
{
printf(" OK\n");
}
Expand All @@ -206,14 +206,14 @@ void test1(double x0, double x1, int m, double exact_result)
// int N = 5000;
// Radial_grid r(grid_type, N, x0, x1);
// Spline<double> s(r, [](double x){return std::exp(x);});
//
//
// printf("grid type : %s\n", r.grid_type_name().c_str());
//
// //== std::string fname = "grid_" + r.grid_type_name() + ".txt";
// //== FILE* fout = fopen(fname.c_str(), "w");
// //== for (int i = 0; i < r.num_points(); i++) fprintf(fout,"%i %16.12e\n", i, r[i]);
// //== fclose(fout);
//
//
// printf("x = %f, true exp(x) = %f, exp(x) = %f, exp'(x)= %f, exp''(x) = %f\n", x0, s[0], s.deriv(0, 0), s.deriv(1, 0), s.deriv(2, 0));
// printf("x = %f, true exp(x) = %f, exp(x) = %f, exp'(x)= %f, exp''(x) = %f\n", x1, s[N - 1], s.deriv(0, N - 1), s.deriv(1, N - 1), s.deriv(2, N - 1));
//}
Expand All @@ -222,7 +222,7 @@ void test3(int m, double x0, double x1, double exact_val)
{
printf("\n");
printf("test3\n");

Radial_grid_exp<double> r(2000, x0, x1);
Spline<double> s1(r);
Spline<double> s2(r);
Expand Down Expand Up @@ -308,7 +308,7 @@ void test6a()
{
printf("OK\n");
}

//== int N = 4000;
//== FILE* fout = fopen("spline_test.dat", "w");
//== for (int i = 0; i < N; i++)
Expand Down Expand Up @@ -341,7 +341,7 @@ void test6()
{
printf("OK\n");
}

//== int N = 4000;
//== FILE* fout = fopen("spline_test.dat", "w");
//== for (int i = 0; i < N; i++)
Expand All @@ -368,7 +368,7 @@ void test7()
double err1{0}, err2{0};
for (int ir = 0; ir < r.num_points(); ir++) {
double x = r[ir];
double d2s = (-16*std::cos(8*x))/std::pow(0.1 + x,2) + (2*std::sin(8*x))/std::pow(0.1 + x,3) -
double d2s = (-16*std::cos(8*x))/std::pow(0.1 + x,2) + (2*std::sin(8*x))/std::pow(0.1 + x,3) -
(64*std::sin(8*x))/(0.1 + x);
err1 += std::abs(d2s - s.deriv(2, ir));
err2 += std::abs(d2s - s1.deriv(1, ir));
Expand All @@ -384,14 +384,14 @@ void test7()
// int N = 400;
// double r0 = 1e-6;
// double r1 = 3.0;
//
//
// Radial_grid r(static_cast<radial_grid_t>(rgrid_t), N, r0, r1);
//
// auto int_s0 = [](double x, T a1, T a2) {
// return (2*a2 + 2*a1*a2*x + std::pow(a1,2)*(-1 + a2*std::pow(x,2)))/(std::pow(a1,3)*std::exp(a1*x));
// };
// auto int_s2 = [](double x, T a1, T a2) {
// return (24*a2 + 24*a1*a2*x + std::pow(a1,4)*std::pow(x,2)*(-1 + a2*std::pow(x,2)) +
// return (24*a2 + 24*a1*a2*x + std::pow(a1,4)*std::pow(x,2)*(-1 + a2*std::pow(x,2)) +
// 2*std::pow(a1,2)*(-1 + 6*a2*std::pow(x,2)) + std::pow(a1,3)*(-2*x + 4*a2*std::pow(x,3)))/
// (std::pow(a1,5)*std::exp(a1*x));
// };
Expand All @@ -400,7 +400,7 @@ void test7()
// T a1 = i1;
// T a2 = i2;
// Spline<T> s(r, [a1, a2](double x){return std::exp(-a1 * x) * (1 - a2 * x * x);});
//
//
// if (std::is_same<T, long double>::value) {
// printf("test8: diff: %18.12Lf\n", std::abs(s.integrate(0) - (int_s0(r1, a1, a2) - int_s0(r0, a1, a2))));
// printf("test8: diff: %18.12Lf\n", std::abs(s.integrate(2) - (int_s2(r1, a1, a2) - int_s2(r0, a1, a2))));
Expand All @@ -419,23 +419,23 @@ void test7()
// int N = 2000;
// double r0 = 1e-7;
// double r1 = 3.0;
//
//
// Radial_grid r(static_cast<radial_grid_t>(rgrid_t), N, r0, r1);
// printf("dx(0) = %18.12f\n", r.dx(0));
//
//
// auto f = [](double x){return 1.0 / std::pow(static_cast<T>(x), 2);};
//
// Spline<T> s(r, f);
//
//
// if (rgrid_t == 1) {
// check_spline(s, f, r0, r1);
// }
//
// if (std::is_same<T, double>::value) {
// printf("test9: diff: %18.12f\n", std::abs(s.integrate(2) - (r1 - r0)));
// printf("test9: diff: %18.12f\n", std::abs(s.integrate(2) - (r1 - r0)));
// }
// if (std::is_same<T, long double>::value) {
// printf("test9: diff: %18.12Lf\n", std::abs(s.integrate(2) - (r1 - r0)));
// printf("test9: diff: %18.12Lf\n", std::abs(s.integrate(2) - (r1 - r0)));
// }
//}
//template <typename T>
Expand All @@ -458,20 +458,20 @@ void test7()
// int N = 4000;
// T r0 = 1e-7;
// T r1 = 3.0;
//
//
// sirius::experimental::Radial_grid_exp<T> rgrid(N, r0, r1);
// //auto f = [](T x){return 1.0 / std::pow(static_cast<T>(x), 1);};
// auto f = [](T x){return std::exp(-x);};
//
// sirius::experimental::Spline<T, T> s(rgrid, f);
//
//
// check_spline_1<T>(s, f, r0, r1);
//}

int main(int argn, char** argv)
{
sirius::initialize(1);

test6a();
test6();

Expand Down Expand Up @@ -507,7 +507,7 @@ int main(int argn, char** argv)
test5();

test7();

//for (int i = 0; i < 5; i++) {
// printf("grid type: %i\n", i);
// printf("testing in double\n");
Expand All @@ -525,6 +525,6 @@ int main(int argn, char** argv)
//}

sirius::finalize();

return 0;
}
Loading

0 comments on commit faf052e

Please sign in to comment.