Skip to content
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(blade LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

file(GLOB_RECURSE sources *.cxx *.cu *.h)

Expand Down
18 changes: 16 additions & 2 deletions src/run/run.cu
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,20 @@ void Run::set_variable(char *line,char *token,System *system)
dxAtomMax=io_nextf(line)*ANGSTROM;
} else if (strcmp(token,"dxrmsinit")==0) {
dxRMSInit=io_nextf(line)*ANGSTROM;
} else if (strcmp(token, "lbfgs_m")==0){
lbfgs_m=io_nexti(line);
} else if (strcmp(token, "lbfgs_eps")==0){
lbfgs_eps=io_nextf(line);
} else if (strcmp(token,"mintype")==0) {
std::string minString=io_nexts(line);
if (strcmp(minString.c_str(),"sd")==0) {
if (strcmp(minString.c_str(), "lbfgs")==0){
minType=elbfgs;
} else if (strcmp(minString.c_str(),"sd")==0) {
minType=esd;
} else if (strcmp(minString.c_str(),"sdfd")==0) {
minType=esdfd;
} else {
fatal(__FILE__,__LINE__,"Unrecognized token %s for minimization type minType. Options are: sd or sdfd\n",minString.c_str());
fatal(__FILE__,__LINE__,"Unrecognized token %s for minimization type minType. Options are: lbfgs, sd, or sdfd\n",minString.c_str());
}
} else if (strcmp(token,"domdecheuristic")==0) {
domdecHeuristic=io_nextb(line);
Expand Down Expand Up @@ -406,6 +412,7 @@ void Run::energy(char *line,char *token,System *system)
system->potential->calc_force(0,system);
system->state->recv_energy();
print_nrg(0,system);
display_nrg(system);
dynamics_finalize(system);
}

Expand Down Expand Up @@ -501,6 +508,13 @@ void Run::minimize(char *line,char *token,System *system)
gpuCheck(cudaPeekAtLastError());
}

if(system->run->minType==elbfgs){
Run* r = system->run;
printf("L-BFGS (m=%d) did %d force evaluations in %d steps. Reset memory %d times.\n",
r->lbfgs->m, r->lbfgs_energy_evals, r->lbfgs->step_count, r->lbfgs->reset_count);
printf("U0: %f, Uf: %f, Uf - U0: %f\n", r->lbfgs->U0, r->lbfgs->Uf, r->lbfgs->Uf - r->lbfgs->U0);
}

system->state->min_dest(system);
dynamics_finalize(system);
}
Expand Down
8 changes: 8 additions & 0 deletions src/run/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "xdr/xdrfile.h"
#include "xdr/xdrfile_xtc.h"
#include "update/lbfgs.h"

// Forward delcaration
class System;
Expand All @@ -19,6 +20,7 @@ struct Cutoffs {
};

typedef enum emin {
elbfgs, // Limited memory BFGS algo
esd, // steepest descent
esdfd, // steepest descent with finite difference to choose step length
eminend} EMin;
Expand Down Expand Up @@ -56,6 +58,12 @@ class Run {
real dxRMS;
EMin minType; // minimization scheme

// L-BFGS variables
LBFGS* lbfgs;
int lbfgs_energy_evals = 0;
int lbfgs_m = 7; // gradient history length*DOF
real lbfgs_eps = 1; // gradient rms convergence criteria

real betaEwald;
real rCut;
real rSwitch;
Expand Down
2 changes: 2 additions & 0 deletions src/system/state.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ State::State(System *system) {
cudaMalloc(&(positionBackup_d),(2*nL+3*n)*sizeof(real_x));
forceBuffer=(real_f*)calloc(rootFactor*(2*nL+3*n),sizeof(real_f));
cudaMalloc(&(forceBuffer_d),rootFactor*(2*nL+3*n)*sizeof(real_f));
cudaMalloc(&(forceBufferX_d),rootFactor*(2*nL+3*n)*sizeof(real_x));
cudaMalloc(&(forceBackup_d),(2*nL+3*n)*sizeof(real_f));

if (system->idCount>0) { // OMP
Expand Down Expand Up @@ -156,6 +157,7 @@ State::~State() {
if (positionBackup_d) cudaFree(positionBackup_d);
if (forceBuffer) free(forceBuffer);
if (forceBuffer_d) cudaFree(forceBuffer_d);
if (forceBufferX_d) cudaFree(forceBufferX_d);
if (forceBackup_d) cudaFree(forceBackup_d);
// Other buffers
if (energy) free(energy);
Expand Down
1 change: 1 addition & 0 deletions src/system/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class State {
real *positionBuffer_omp;
real_f *forceBuffer;
real_f *forceBuffer_d;
real_x *forceBufferX_d;
real_f *forceBackup_d; // For NPT
real_f *forceBuffer_omp;

Expand Down
Loading