Skip to content

Commit

Permalink
Merge pull request #402 from toxa81/develop
Browse files Browse the repository at this point in the history
Mostly test of Davison solver
  • Loading branch information
toxa81 authored Aug 7, 2019
2 parents 7c3b1a7 + e2cc788 commit 923c020
Show file tree
Hide file tree
Showing 20 changed files with 1,013 additions and 984 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0
6.3.1
55 changes: 32 additions & 23 deletions apps/tests/test_davidson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ void init_wf(K_point* kp__, Wave_functions& phi__, int num_bands__, int num_mag_
}
}

void test_davidson(device_t pu__, double pw_cutoff__, double gk_cutoff__, int N__)
void test_davidson(cmd_args const& args__)
{
auto pu = get_device_t(args__.value<std::string>("device", "CPU"));
auto pw_cutoff = args__.value<double>("pw_cutoff", 30);
auto gk_cutoff = args__.value<double>("gk_cutoff", 10);
auto N = args__.value<int>("N", 1);
auto mpi_grid = args__.value<std::vector<int>>("mpi_grid", {1, 1});
auto solver = args__.value<std::string>("solver", "lapack");

utils::timer t1("test_davidson|setup");

/* create simulation context */
Expand Down Expand Up @@ -101,24 +108,28 @@ void test_davidson(device_t pu__, double pw_cutoff__, double gk_cutoff__, int N_
/* lattice constant */
double a{5};
/* set lattice vectors */
ctx.unit_cell().set_lattice_vectors({{a * N__, 0, 0},
{0, a * N__, 0},
{0, 0, a * N__}});
ctx.unit_cell().set_lattice_vectors({{a * N, 0, 0},
{0, a * N, 0},
{0, 0, a * N}});
/* add atoms */
double p = 1.0 / N__;
for (int i = 0; i < N__; i++) {
for (int j = 0; j < N__; j++) {
for (int k = 0; k < N__; k++) {
double p = 1.0 / N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
ctx.unit_cell().add_atom("Cu", {i * p, j * p, k * p});
}
}
}

/* initialize the context */
ctx.set_verbosity(1);
ctx.pw_cutoff(pw_cutoff__);
ctx.gk_cutoff(gk_cutoff__);
ctx.set_processing_unit(pu__);
ctx.pw_cutoff(pw_cutoff);
ctx.gk_cutoff(gk_cutoff);
ctx.set_processing_unit(pu);
ctx.set_mpi_grid_dims(mpi_grid);
ctx.gen_evp_solver_name(solver);
ctx.std_evp_solver_name(solver);

t1.stop();

ctx.set_verbosity(1);
Expand All @@ -145,8 +156,6 @@ void test_davidson(device_t pu__, double pw_cutoff__, double gk_cutoff__, int N_
}
init_wf(&kp, kp.spinor_wave_functions(), ctx.num_bands(), 0);



Hamiltonian H(ctx, pot);
H.prepare();
Band(ctx).solve_pseudo_potential<double_complex>(kp, H);
Expand All @@ -159,8 +168,13 @@ void test_davidson(device_t pu__, double pw_cutoff__, double gk_cutoff__, int N_
}
std::sort(ekin.begin(), ekin.end());

for (int i = 0; i < ctx.num_bands(); i++) {
printf("%20.16f %20.16f %20.16e\n", ekin[i], kp.band_energy(i, 0), std::abs(ekin[i] - kp.band_energy(i, 0)));
if (Communicator::world().rank() == 0) {
double max_diff = 0;
for (int i = 0; i < ctx.num_bands(); i++) {
max_diff = std::max(max_diff, std::abs(ekin[i] - kp.band_energy(i, 0)));
//printf("%20.16f %20.16f %20.16e\n", ekin[i], kp.band_energy(i, 0), std::abs(ekin[i] - kp.band_energy(i, 0)));
}
printf("maximum eigen-value difference: %20.16e\n", max_diff);
}
}

Expand Down Expand Up @@ -232,7 +246,8 @@ int main(int argn, char** argv)
{"pw_cutoff=", "(double) plane-wave cutoff for density and potential"},
{"gk_cutoff=", "(double) plane-wave cutoff for wave-functions"},
{"N=", "(int) cell multiplicity"},
{"mpi_grid=", "(int[2]) dimensions of the MPI grid for band diagonalization"}
{"mpi_grid=", "(int[2]) dimensions of the MPI grid for band diagonalization"},
{"solver=", "eigen-value solver"}
});

if (args.exist("help")) {
Expand All @@ -241,14 +256,8 @@ int main(int argn, char** argv)
return 0;
}

auto pu = get_device_t(args.value<std::string>("device", "CPU"));
auto pw_cutoff = args.value<double>("pw_cutoff", 30);
auto gk_cutoff = args.value<double>("gk_cutoff", 10);
auto N = args.value<int>("N", 1);
auto mpi_grid = args.value<std::vector<int>>("mpi_grid", {1, 1});

sirius::initialize(1);
test_davidson(pu, pw_cutoff, gk_cutoff, N);
test_davidson(args);
int rank = Communicator::world().rank();
sirius::finalize();
if (!rank) {
Expand Down
2 changes: 1 addition & 1 deletion doc/doxygen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "SIRIUS"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "6.3.0"
PROJECT_NUMBER = "6.3.1"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
21 changes: 19 additions & 2 deletions make_version_hpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import datetime
import json
import os
import datetime

now = datetime.datetime.now()

# The SIRIUS releases are tagged with `vX.Y.Z` schema, where X is a major version,
# Y is a minor version and Z is a revision.

# Use github REST API to query the tags
request_str = 'https://api.github.com/repos/electronic-structure/SIRIUS/tags'
Expand Down Expand Up @@ -91,20 +97,31 @@ def main():
fname = sys.argv[1] # path to VERSION file

version_str = ""

major_version = -1
minor_version = -1
revision = -1

# get version string from the file
try:
with open(sys.argv[1]) as vf:
version_str = vf.readline().strip()
version = version_str.split('.')
major_version = int(version[0])
minor_version = int(version[1])
revision = int(version[2])
except OSError:
pass
sha_str = get_sha(version_str, os.path.dirname(fname))
branch_name = get_branch(sha_str, version_str)

print("const char* const git_hash = \"%s\";" % sha_str)
print("const char* const git_branchname = \"%s\";" % branch_name)
# print("const char* const build_date = \"%s\";"%(now.strftime("%a, %e %b %Y %H:%M:%S")))
#print("const char* const build_date = \"%s\";"%(now.strftime("%a, %e %b %Y %H:%M:%S")))
print("const int major_version = %i;" % major_version)
print("const int minor_version = %i;" % minor_version);
print("const int revision = %i;" % revision);
print("#endif")


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions src/Band/diag_full_potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ void Band::diag_full_potential_first_variation_davidson(K_point& kp__, Hamiltoni
o_diag(j, ispn) = o_diag1[j];
}
}
if (ctx_.processing_unit() == device_t::GPU) {
o_diag.allocate(memory_t::device).copy_to(memory_t::device);
}

/* short notation for number of target wave-functions */
int num_bands = ctx_.num_fv_states();
Expand Down
8 changes: 8 additions & 0 deletions src/Band/diag_pseudo_potential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ Band::diag_pseudo_potential_davidson(K_point* kp__, Hamiltonian& H__) const
}
}

if (ctx_.processing_unit() == device_t::GPU) {
o_diag.allocate(memory_t::device).copy_to(memory_t::device);
}

if (ctx_.control().print_checksum_) {
auto cs1 = h_diag.checksum();
auto cs2 = o_diag.checksum();
Expand Down Expand Up @@ -798,6 +802,10 @@ Band::diag_S_davidson(K_point& kp__, Hamiltonian& H__) const
o_diag1(ig, ispn) = 1.0;
}
}
if (ctx_.processing_unit() == device_t::GPU) {
o_diag.allocate(memory_t::device).copy_to(memory_t::device);
o_diag1.allocate(memory_t::device).copy_to(memory_t::device);
}

auto& std_solver = ctx_.std_evp_solver();

Expand Down
3 changes: 3 additions & 0 deletions src/Band/residuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ residuals(memory_t mem_type__, linalg_t la_type__, int ispn__, int N__, int num_
}
}
} else { /* compute all residuals first */
if (is_device_memory(mem_type__)) {
eval__.allocate(memory_t::device).copy_to(memory_t::device);
}
evec_ptr = &evec__;
eval_ptr = &eval__;
n = num_bands__;
Expand Down
Loading

0 comments on commit 923c020

Please sign in to comment.