Skip to content

Commit

Permalink
tune_skin command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fweik committed Jul 21, 2015
1 parent 5a343ea commit 86bf316
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/core/tuning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "utils.hpp"
#include "communication.hpp"
#include "errorhandling.hpp"
#include "integrate.hpp"
#include "global.hpp"
#include <limits>

int timing_samples = 0;

Expand Down Expand Up @@ -61,3 +64,44 @@ double time_force_calc(int default_samples)
markTime();
return diffTime()/rds;
}

static double time_calc(int rds)
{
if (mpi_integrate(0, 0))
return -1;

/* perform force calculation test */
markTime();
if (mpi_integrate(rds, -1))
return -1;
markTime();
return diffTime()/rds;
}


void tune_skin(double min, double max, double tol) {
skin_set = true;

double a = min;
double b = max;
double time_a, time_b;

while(fabs(a - b) > tol) {
skin = a;
mpi_bcast_parameter(FIELD_SKIN);
time_a = time_calc(1000);

skin = b;
mpi_bcast_parameter(FIELD_SKIN);
time_b = time_calc(1000);

if(time_a > time_b) {
a = 0.5*(a + b);
} else {
b = 0.5*(a + b);
}
printf("a %e b %e time_a %e time_b %e delta %e\n", a, b, time_a, time_b, fabs(a - b));
}
skin = 0.5*(a+b);
mpi_bcast_parameter(FIELD_SKIN);
}
4 changes: 4 additions & 0 deletions src/core/tuning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ void markTime();
/** calculate milliseconds between last two calls to \ref markTime. */
double diffTime();

/** sets the optimal \ref skin between min and max by bisectio to tolerance tol.
*/
void tune_skin(double min, double max, double tol);

#endif
4 changes: 4 additions & 0 deletions src/tcl/initialize_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ char *get_default_scriptsdir();
/** Returns runtime of the integration loop in seconds. From tuning_tcl.cpp **/
int tclcommand_time_integration(ClientData data, Tcl_Interp *interp, int argc, char *argv[]);

/** Tunes the skin */
int tclcommand_tune_skin(ClientData data, Tcl_Interp *interp, int argc, char *argv[]);

/** Reads particles from pdb file, see \ref readpdb.cpp */
int tclcommand_readpdb(ClientData data, Tcl_Interp *interp, int argc, char *argv[]);

Expand Down Expand Up @@ -236,6 +239,7 @@ static void tcl_register_commands(Tcl_Interp* interp) {
REGISTER_COMMAND("system_CMS_velocity", tclcommand_system_CMS_velocity);
REGISTER_COMMAND("galilei_transform", tclcommand_galilei_transform);
REGISTER_COMMAND("time_integration", tclcommand_time_integration);
REGISTER_COMMAND("tune_skin", tclcommand_tune_skin);
REGISTER_COMMAND("electrokinetics", tclcommand_electrokinetics);
#if defined(SD) || defined(BD)
/* from integrate_sd_tcl.cpp */
Expand Down
23 changes: 23 additions & 0 deletions src/tcl/tuning_tcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,26 @@ int tclcommand_time_integration(ClientData data, Tcl_Interp *interp, int argc, c
Tcl_AppendResult(interp, buffer, (char *)NULL);
return TCL_OK;
}

int tclcommand_tune_skin(ClientData data, Tcl_Interp *interp, int argc, char *argv[]) {
if(argc != 4) {
puts("usage:");
return TCL_ERROR;
}

double min, max, tol;
if(!(ARG_IS_D(1, min) && ARG_IS_D(2, max) && ARG_IS_D(3, tol))) {
puts("usage:");
return TCL_ERROR;
}

tune_skin(min, max, tol);
return TCL_OK;
}







0 comments on commit 86bf316

Please sign in to comment.