Skip to content

Commit

Permalink
mixed_cg_merge: clean up invert_doublet_eo and extend interface to be…
Browse files Browse the repository at this point in the history
… more consistent with current invert_eo interface, add control structure for calling ND version of rgmixedcg
  • Loading branch information
kostrzewa committed Feb 12, 2016
1 parent 529104d commit c092c95
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 144 deletions.
150 changes: 16 additions & 134 deletions invert_doublet_eo.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include"read_input.h"
#include"xchange/xchange.h"
#include"operator/tm_operators_nd.h"
#include"operator/tm_operators_nd_32.h"
#include"invert_doublet_eo.h"
#ifdef QUDA
# include "quda_interface.h"
Expand All @@ -68,7 +69,7 @@ int invert_doublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
spinor * const Even_s, spinor * const Odd_s,
spinor * const Even_c, spinor * const Odd_c,
const double precision, const int max_iter,
const int solver_flag, const int rel_prec,
const int solver_flag, const int rel_prec, solver_params_t solver_params,
const ExternalInverter inverter, const SloppyPrecision sloppy, const CompressionType compression) {

int iter = 0;
Expand All @@ -85,60 +86,10 @@ int invert_doublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,

#ifdef HAVE_GPU
# ifdef TEMPORALGAUGE

/* initialize temporal gauge here */
int retval;
double dret1, dret2;
double plaquette1 = 0.0;
double plaquette2 = 0.0;

if (usegpu_flag) {

/* need VOLUME here (not N=VOLUME/2)*/
if ((retval = init_temporalgauge_trafo(VOLUME, g_gauge_field)) != 0 ) { // initializes the transformation matrices
if (g_proc_id == 0) printf("Error while gauge fixing to temporal gauge. Aborting...\n"); // g_tempgauge_field as a copy of g_gauge_field
exit(200);
}

/* do trafo */
plaquette1 = measure_plaquette(g_gauge_field);
apply_gtrafo(g_gauge_field, g_trafo); // transformation of the gauge field
plaquette2 = measure_plaquette(g_gauge_field);
if (g_proc_id == 0) printf("\tPlaquette before gauge fixing: %.16e\n", plaquette1/6./VOLUME);
if (g_proc_id == 0) printf("\tPlaquette after gauge fixing: %.16e\n", plaquette2/6./VOLUME);

/* do trafo to odd_s part of source */
dret1 = square_norm(Odd_s, VOLUME/2 , 1);
apply_gtrafo_spinor_odd(Odd_s, g_trafo); // odd spinor transformation, strange
dret2 = square_norm(Odd_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to odd_c part of source */
dret1 = square_norm(Odd_c, VOLUME/2 , 1);
apply_gtrafo_spinor_odd(Odd_c, g_trafo); // odd spinor transformation, charm
dret2 = square_norm(Odd_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to even_s part of source */
dret1 = square_norm(Even_s, VOLUME/2 , 1);
apply_gtrafo_spinor_even(Even_s, g_trafo); // even spinor transformation, strange
dret2 = square_norm(Even_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to even_c part of source */
dret1 = square_norm(Even_c, VOLUME/2 , 1);
apply_gtrafo_spinor_even(Even_c, g_trafo); // even spinor transformation, charm
dret2 = square_norm(Even_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

# ifdef MPI
xchange_gauge(g_gauge_field);
# endif

gtrafo_eo_nd(Even_s, Odd_s, Even_c, Odd_c,
(spinor*const)NULL, (spinor*const)NULL, (spinor*const)NULL, (spinor*const)NULL,
GTRAFO_APPLY);
}
# endif
#endif /* HAVE_GPU*/
Expand Down Expand Up @@ -189,9 +140,14 @@ int invert_doublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
VOLUME/2, &Qtm_pm_ndpsi);
}
#else // CPU, conjugate gradient
iter = cg_her_nd(Odd_new_s, Odd_new_c, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1],
max_iter, precision, rel_prec,
VOLUME/2, &Qtm_pm_ndpsi);
if(solver_flag == RGMIXEDCG){
iter = rg_mixed_cg_her_nd(Odd_new_s, Odd_new_c, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1],
solver_params, max_iter, precision, rel_prec, VOLUME/2,
&Qtm_pm_ndpsi, &Qtm_pm_ndpsi_32);
} else {
iter = cg_her_nd(Odd_new_s, Odd_new_c, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1],
max_iter, precision, rel_prec, VOLUME/2, &Qtm_pm_ndpsi);
}
#endif


Expand All @@ -214,83 +170,9 @@ int invert_doublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
#ifdef HAVE_GPU
/* return from temporal gauge again */
# ifdef TEMPORALGAUGE

if (usegpu_flag) {

/* undo trafo */
/* apply_inv_gtrafo(g_gauge_field, g_trafo);*/
/* copy back the saved original field located in g_tempgauge_field -> update necessary*/
plaquette1 = measure_plaquette(g_gauge_field);
copy_gauge_field(g_gauge_field, g_tempgauge_field);
g_update_gauge_copy = 1;
plaquette2 = measure_plaquette(g_gauge_field);
if (g_proc_id == 0) printf("\tPlaquette before inverse gauge fixing: %.16e\n", plaquette1/6./VOLUME);
if (g_proc_id == 0) printf("\tPlaquette after inverse gauge fixing: %.16e\n", plaquette2/6./VOLUME);

/* undo trafo to source Even_s */
dret1 = square_norm(Even_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_s, g_trafo);
dret2 = square_norm(Even_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);


/* undo trafo to source Even_c */
dret1 = square_norm(Even_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_c, g_trafo);
dret2 = square_norm(Even_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* undo trafo to source Odd_s */
dret1 = square_norm(Odd_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_s, g_trafo);
dret2 = square_norm(Odd_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* undo trafo to source Odd_c */
dret1 = square_norm(Odd_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_c, g_trafo);
dret2 = square_norm(Odd_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);


// Even_new_s
dret1 = square_norm(Even_new_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_new_s, g_trafo);
dret2 = square_norm(Even_new_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Even_new_c
dret1 = square_norm(Even_new_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_new_c, g_trafo);
dret2 = square_norm(Even_new_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Odd_new_s
dret1 = square_norm(Odd_new_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_new_s, g_trafo);
dret2 = square_norm(Odd_new_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Odd_new_c
dret1 = square_norm(Odd_new_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_new_c, g_trafo);
dret2 = square_norm(Odd_new_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

finalize_temporalgauge();

# ifdef MPI
xchange_gauge(g_gauge_field);
# endif

gtrafo_eo_nd(Even_s, Odd_s, Even_c, Odd_c, Even_new_s, Odd_new_s, Even_new_c, Odd_new_c,
GTRAFO_REVERT);
}
# endif
#endif
Expand All @@ -303,7 +185,7 @@ int invert_cloverdoublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
spinor * const Even_s, spinor * const Odd_s,
spinor * const Even_c, spinor * const Odd_c,
const double precision, const int max_iter,
const int solver_flag, const int rel_prec,
const int solver_flag, const int rel_prec, solver_params_t solver_params,
const ExternalInverter inverter, const SloppyPrecision sloppy, const CompressionType compression) {

int iter = 0;
Expand Down
5 changes: 3 additions & 2 deletions invert_doublet_eo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
#define _INVERT_DOUBLET_EO_H

#include "global.h"
#include "solver/solver_params.h"

int invert_doublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
spinor * const Even_new_c, spinor * const Odd_new_c,
spinor * const Even_s, spinor * const Odd_s,
spinor * const Even_c, spinor * const Odd_c,
const double precision, const int max_iter,
const int solver_flag, const int rel_prec,
const int solver_flag, const int rel_prec, solver_params_t solver_params,
const ExternalInverter inverter, const SloppyPrecision sloppy, const CompressionType compression);


Expand All @@ -54,6 +55,6 @@ int invert_cloverdoublet_eo(spinor * const Even_new_s, spinor * const Odd_new_s,
spinor * const Even_s, spinor * const Odd_s,
spinor * const Even_c, spinor * const Odd_c,
const double precision, const int max_iter,
const int solver_flag, const int rel_prec,
const int solver_flag, const int rel_prec, solver_params_t solver_params,
const ExternalInverter inverter, const SloppyPrecision sloppy, const CompressionType compression);
#endif
4 changes: 2 additions & 2 deletions operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ void op_invert(const int op_id, const int index_start, const int write_prop) {
optr->iterations = invert_doublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3,
optr->sr0, optr->sr1, optr->sr2, optr->sr3,
optr->eps_sq, optr->maxiter,
optr->solver, optr->rel_prec,
optr->solver, optr->rel_prec, optr->solver_params,
optr->external_inverter, optr->sloppy_precision, optr->compression_type);
} else {
optr->iterations = invert_cloverdoublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3,
optr->sr0, optr->sr1, optr->sr2, optr->sr3,
optr->eps_sq, optr->maxiter,
optr->solver, optr->rel_prec,
optr->solver, optr->rel_prec, optr->solver_params,
optr->external_inverter, optr->sloppy_precision, optr->compression_type);
}
g_mu = optr->mubar;
Expand Down
134 changes: 128 additions & 6 deletions temporalgauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include "geometry_eo.h"
#include "start.h"
#include "temporalgauge.h"
#include "measure_gauge_action.h"
#include "stdio.h"
#include "stdlib.h"
#include "linalg_eo.h"
#ifdef MPI
#include<mpi.h>
#include "mpi_init.h"
Expand Down Expand Up @@ -959,10 +961,130 @@ void apply_inv_gtrafo_spinor_even (spinor * spin, su3 * trafofield) {

}







void gtrafo_eo_nd(spinor * const Even_s, spinor * const Odd_s, spinor * const Even_c, spinor * const Odd_c,
spinor * const Even_new_s, spinor * const Odd_new_s, spinor * const Even_new_c, spinor * const Odd_new_c,
GTRAFO_TYPE type){

/* initialize temporal gauge here */
int retval;
double dret1, dret2;
static double plaquette1 = 0.0;
static double plaquette2 = 0.0;

if(type==GTRAFO_APPLY){
/* need VOLUME here (not N=VOLUME/2)*/
if ((retval = init_temporalgauge_trafo(VOLUME, g_gauge_field)) != 0 ) { // initializes the transformation matrices
if (g_proc_id == 0) printf("Error while gauge fixing to temporal gauge. Aborting...\n"); // g_tempgauge_field as a copy of g_gauge_field
exit(200);
}

/* do trafo */
plaquette1 = measure_plaquette(g_gauge_field);
apply_gtrafo(g_gauge_field, g_trafo); // transformation of the gauge field
plaquette2 = measure_plaquette(g_gauge_field);
if (g_proc_id == 0) printf("\tPlaquette before gauge fixing: %.16e\n", plaquette1/6./VOLUME);
if (g_proc_id == 0) printf("\tPlaquette after gauge fixing: %.16e\n", plaquette2/6./VOLUME);

/* do trafo to odd_s part of source */
dret1 = square_norm(Odd_s, VOLUME/2 , 1);
apply_gtrafo_spinor_odd(Odd_s, g_trafo); // odd spinor transformation, strange
dret2 = square_norm(Odd_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to odd_c part of source */
dret1 = square_norm(Odd_c, VOLUME/2 , 1);
apply_gtrafo_spinor_odd(Odd_c, g_trafo); // odd spinor transformation, charm
dret2 = square_norm(Odd_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to even_s part of source */
dret1 = square_norm(Even_s, VOLUME/2 , 1);
apply_gtrafo_spinor_even(Even_s, g_trafo); // even spinor transformation, strange
dret2 = square_norm(Even_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* do trafo to even_c part of source */
dret1 = square_norm(Even_c, VOLUME/2 , 1);
apply_gtrafo_spinor_even(Even_c, g_trafo); // even spinor transformation, charm
dret2 = square_norm(Even_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);
} else {
/* undo trafo */
/* apply_inv_gtrafo(g_gauge_field, g_trafo);*/
/* copy back the saved original field located in g_tempgauge_field -> update necessary*/
plaquette1 = measure_plaquette(g_gauge_field);
copy_gauge_field(g_gauge_field, g_tempgauge_field);
g_update_gauge_copy = 1;
plaquette2 = measure_plaquette(g_gauge_field);
if (g_proc_id == 0) printf("\tPlaquette before inverse gauge fixing: %.16e\n", plaquette1/6./VOLUME);
if (g_proc_id == 0) printf("\tPlaquette after inverse gauge fixing: %.16e\n", plaquette2/6./VOLUME);

/* undo trafo to source Even_s */
dret1 = square_norm(Even_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_s, g_trafo);
dret2 = square_norm(Even_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);


/* undo trafo to source Even_c */
dret1 = square_norm(Even_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_c, g_trafo);
dret2 = square_norm(Even_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* undo trafo to source Odd_s */
dret1 = square_norm(Odd_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_s, g_trafo);
dret2 = square_norm(Odd_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

/* undo trafo to source Odd_c */
dret1 = square_norm(Odd_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_c, g_trafo);
dret2 = square_norm(Odd_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);


// Even_new_s
dret1 = square_norm(Even_new_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_new_s, g_trafo);
dret2 = square_norm(Even_new_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Even_new_c
dret1 = square_norm(Even_new_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_even(Even_new_c, g_trafo);
dret2 = square_norm(Even_new_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Odd_new_s
dret1 = square_norm(Odd_new_s, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_new_s, g_trafo);
dret2 = square_norm(Odd_new_s, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

// Odd_new_c
dret1 = square_norm(Odd_new_c, VOLUME/2 , 1);
apply_inv_gtrafo_spinor_odd(Odd_new_c, g_trafo);
dret2 = square_norm(Odd_new_c, VOLUME/2, 1);
if (g_proc_id == 0) printf("\tsquare norm before gauge fixing: %.16e\n", dret1);
if (g_proc_id == 0) printf("\tsquare norm after gauge fixing: %.16e\n", dret2);

finalize_temporalgauge();
}
# ifdef MPI
xchange_gauge(g_gauge_field);
# endif
}

Loading

0 comments on commit c092c95

Please sign in to comment.