Skip to content

Commit

Permalink
input file infrastructure for BSM operator, operator_invert adapted, …
Browse files Browse the repository at this point in the history
…scalar field reading added
  • Loading branch information
urbach committed Sep 21, 2015
1 parent 71d528a commit 10cd47c
Show file tree
Hide file tree
Showing 12 changed files with 482 additions and 340 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SUBDIRS = ${USESUBDIRS}
# delete the default suffix rules
.SUFFIXES:

all: Makefile dep $(SUBDIRS) hmc_tm invert benchmark test_DslashBSM
all: Makefile dep $(SUBDIRS) hmc_tm invert benchmark

$(SUBDIRS):
$(MAKE) --directory=$@
Expand Down
21 changes: 6 additions & 15 deletions buffers/utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef _BUFFER_UTILS_H
#define _BUFFER_UTILS_H

#include <buffers/gauge.h>

Expand All @@ -8,18 +9,8 @@ void generic_exchange(void *field_in, int bytes_per_site);
void exchange_gauge_field(gauge_field_t target);
void exchange_gauge_field_array(gauge_field_array_t target);

inline void copy_gauge_field(gauge_field_t dest, gauge_field_t orig)
{
memmove((void*)dest.field, (void*)orig.field, sizeof(su3_tuple) * VOLUMEPLUSRAND + 1);
}

inline void exchange_gauge_field(gauge_field_t target)
{
generic_exchange((void*)target.field, sizeof(su3_tuple));
}
void copy_gauge_field(gauge_field_t dest, gauge_field_t orig);
void exchange_gauge_field(gauge_field_t target);
void exchange_gauge_field_array(gauge_field_array_t target);

inline void exchange_gauge_field_array(gauge_field_array_t target)
{
for (unsigned int idx = 0; idx < target.length; ++idx)
exchange_gauge_field(target.field_array[idx]);
}
#endif
17 changes: 17 additions & 0 deletions buffers/utils_generic_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,20 @@ void generic_exchange(void *field_in, int bytes_per_site)

#endif /* MPI */


void copy_gauge_field(gauge_field_t dest, gauge_field_t orig)
{
memmove((void*)dest.field, (void*)orig.field, sizeof(su3_tuple) * VOLUMEPLUSRAND + 1);
}

void exchange_gauge_field(gauge_field_t target)
{
generic_exchange((void*)target.field, sizeof(su3_tuple));
}

void exchange_gauge_field_array(gauge_field_array_t target)
{
for (unsigned int idx = 0; idx < target.length; ++idx)
exchange_gauge_field(target.field_array[idx]);
}

1 change: 1 addition & 0 deletions init/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "init/init_gauge_field.h"
#include "init/init_gauge_tmp.h"
#include "init/init_geometry_indices.h"
#include "init/init_scalar_field.h"
#ifdef WITHLAP
# include "init/init_jacobi_field.h"
#endif
Expand Down
39 changes: 39 additions & 0 deletions invert.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "xchange/xchange.h"
#endif
#include <io/utils.h>
#include <io/scalar.h>
#include "read_input.h"
#include "mpi_init.h"
#include "sighandler.h"
Expand Down Expand Up @@ -97,6 +98,7 @@ int main(int argc, char *argv[])
char datafilename[206];
char parameterfilename[206];
char conf_filename[50];
char scalar_filename[50];
char * input_filename = NULL;
char * filename = NULL;
double plaquette_energy;
Expand Down Expand Up @@ -217,6 +219,14 @@ int main(int argc, char *argv[])
exit(-1);
}

if(have_bsm_op) {
j = init_bispinor_field(VOLUMEPLUSRAND, 6);
if ( j!= 0) {
fprintf(stderr, "Not enough memory for bispinor fields! Aborting...\n");
exit(0);
}
}

if (g_running_phmc) {
j = init_chi_spinor_field(VOLUMEPLUSRAND / 2, 20);
if (j != 0) {
Expand Down Expand Up @@ -313,6 +323,34 @@ int main(int argc, char *argv[])
}
}

if(have_bsm_op) {
// read scalar field
if( strcmp(scalar_input_filename, "create_random_scalarfield") == 0 ) {
for( int s = 0; s < 4; s++)
ranlxd(g_scalar_field[s], VOLUME);
}
else {
sprintf(scalar_filename, "%s.%d", scalar_input_filename, nscalar);
if (g_cart_id == 0) {
printf("#\n# Trying to read scalar field from file %s in %s precision.\n",
scalar_filename, (scalar_precision_read_flag == 32 ? "single" : "double"));
fflush(stdout);
}

int i;
if( (i = read_scalar_field(scalar_filename,g_scalar_field)) !=0) {
fprintf(stderr, "Error %d while reading scalar field from %s\n Aborting...\n", i, scalar_filename);
exit(-2);
}

if (g_cart_id == 0) {
printf("# Finished reading scalar field.\n");
fflush(stdout);
}
}
}


if (reweighting_flag == 1) {
reweighting_factor(reweighting_samples, nstore);
}
Expand Down Expand Up @@ -483,6 +521,7 @@ int main(int argc, char *argv[])
free_blocks();
free_dfl_subspace();
free_gauge_field();
free_scalar_field();
free_geometry_indices();
free_spinor_field();
free_moment_field();
Expand Down
58 changes: 29 additions & 29 deletions io/scalar_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ extern int scalar_precision_read_flag;

int read_scalar_field(char * filename, scalar ** const sf) {

FILE *ptr;

int count = 4*VOLUME;
int scalarreadsize = ( scalar_precision_read_flag==64 ? sizeof(double) : sizeof(float) );

ptr = fopen(filename,"rb"); // r for read, b for binary

// read into buffer
void *buffer;
if((buffer = malloc(count*scalarreadsize)) == NULL) {
printf ("malloc errno : %d\n",errno);
errno = 0;
return(2);
}

if( count > fread(buffer,scalarreadsize,count,ptr) )
return(-1);

// copy to sf
for( int s=0; s<4; s++ ) {
for( int i=0; i<VOLUME; i++ ) {
if ( scalar_precision_read_flag==64 )
sf[s][i] = ((double*)buffer)[4*i+s];
else
sf[s][i] = ((float*)buffer)[4*i+s];
}
}

return(0);
FILE *ptr;

int count = 4*VOLUME;
int scalarreadsize = ( scalar_precision_read_flag==64 ? sizeof(double) : sizeof(float) );

ptr = fopen(filename,"rb"); // r for read, b for binary

// read into buffer
void *buffer;
if((buffer = malloc(count*scalarreadsize)) == NULL) {
printf ("malloc errno : %d\n",errno);
errno = 0;
return(2);
}

if( count > fread(buffer,scalarreadsize,count,ptr) )
return(-1);

// copy to sf
for( int s = 0; s < 4; s++ ) {
for( int i = 0; i < VOLUME; i++ ) {
if ( scalar_precision_read_flag == 64 )
sf[s][i] = ((double*)buffer)[4*i+s];
else
sf[s][i] = ((float*)buffer)[4*i+s];
}
}

return(0);
}
82 changes: 79 additions & 3 deletions operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
#include "operator/tm_operators.h"
#include "linalg_eo.h"
#include "operator/D_psi.h"
#include "operator/D_psi_BSM.h"
#include "operator/Dov_psi.h"
#include "operator/tm_operators_nd.h"
#include "operator/Hopping_Matrix.h"
#include "invert_eo.h"
#include "invert_doublet_eo.h"
#include "invert_overlap.h"
#include "invert_clover_eo.h"
#include "init/init_scalar_field.h"
#include "boundary.h"
#include "start.h"
#include "solver/eigenvalues.h"
Expand Down Expand Up @@ -129,7 +131,7 @@ int add_operator(const int type) {
optr->m = 0.;
optr->inverter = &op_invert;
}
if(optr->type == DBTMWILSON || optr->type == DBCLOVER) {
if(optr->type == DBTMWILSON || optr->type == DBCLOVER || optr->type == BSM) {
optr->no_flavours = 2;
g_running_phmc = 1;
}
Expand Down Expand Up @@ -189,8 +191,6 @@ int init_operators() {
fprintf(stderr,"Incremental EigCG solver is added only with Even-Odd preconditioning!. Forcing\n");
optr->even_odd_flag = 1;
}


}
else if(optr->type == OVERLAP) {
optr->even_odd_flag = 0;
Expand All @@ -211,6 +211,16 @@ int init_operators() {
optr->even_odd_flag = 1;
optr->applyDbQsq = &Qtm_pm_ndpsi;
}
else if(optr->type == BSM) {
optr->even_odd_flag = 0;
optr->applyQsqbi = &Q2_psi_BSM;
// generate space for 4
int j = init_scalar_field(VOLUMEPLUSRAND, 4);
if ( j!= 0) {
fprintf(stderr, "Not enough memory for scalar fields! Aborting...\n");
exit(0);
}
}
}
}
return(0);
Expand Down Expand Up @@ -425,6 +435,72 @@ void op_invert(const int op_id, const int index_start, const int write_prop) {

if(write_prop) optr->write_prop(op_id, index_start, 0);
}
else if(optr->type == BSM) {
for(i = 0; i < SourceInfo.no_flavours; i++) {

convert_eo_to_lexic(g_spinor_field[8], optr->sr0, optr->sr1);
convert_eo_to_lexic(g_spinor_field[9], optr->sr2, optr->sr3);
compact(g_bispinor_field[1], g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]);

cg_her_bi(g_bispinor_field[0], g_bispinor_field[1],
optr->maxiter, optr->eps_sq, optr->rel_prec, VOLUME, optr->applyQsqbi);

optr->applyQsqbi(g_bispinor_field[2], g_bispinor_field[0]);
assign_diff_mul((spinor*)g_bispinor_field[2], (spinor*)g_bispinor_field[1], 1.0, 2*VOLUME);
double squarenorm = square_norm((spinor*)g_bispinor_field[2], 2*VOLUME, 1);
if(g_proc_id==0) {
printf("# BSM Dirac inversion ||A*result1-b||^2 = %e\n\n", squarenorm);
fflush(stdout);
}


D_psi_dagger_BSM(g_bispinor_field[1], g_bispinor_field[0]);
decompact(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], g_bispinor_field[1]);

convert_lexic_to_eo(optr->prop0, optr->prop1, g_spinor_field[DUM_DERI]);
convert_lexic_to_eo(optr->prop2, optr->prop3, g_spinor_field[DUM_DERI+1]);

/* write propagator */
if(write_prop) optr->write_prop(op_id, index_start, 2*i);

compact(g_bispinor_field[0], g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]);

D_psi_BSM(g_bispinor_field[1], g_bispinor_field[0]);

cg_her_bi(g_bispinor_field[0], g_bispinor_field[1],
optr->maxiter, optr->eps_sq, optr->rel_prec, VOLUME, optr->applyQsqbi);

optr->applyQsqbi(g_bispinor_field[2], g_bispinor_field[0]);
assign_diff_mul((spinor*)g_bispinor_field[2], (spinor*)g_bispinor_field[1], 1.0, 2*VOLUME);
squarenorm = square_norm((spinor*)g_bispinor_field[2], 2*VOLUME, 1);
if(g_proc_id==0) {
printf("# BSM Dirac inversion ||A*result1-b||^2 = %e\n\n", squarenorm);
fflush(stdout);
}

D_psi_dagger_BSM(g_bispinor_field[1], g_bispinor_field[0]);
decompact(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], g_bispinor_field[1]);

convert_lexic_to_eo(optr->prop0, optr->prop1, g_spinor_field[DUM_DERI]);
convert_lexic_to_eo(optr->prop2, optr->prop3, g_spinor_field[DUM_DERI+1]);

/* write propagator */
if(write_prop) optr->write_prop(op_id, index_start, 2*i+1);

// mirror sources
if(i == 0 && SourceInfo.no_flavours == 2 && SourceInfo.type != 1) {
spinor * tmp;
tmp = optr->sr0;
optr->sr0 = optr->sr2;
optr->sr2 = tmp;
tmp = optr->sr1;
optr->sr1 = optr->sr3;
optr->sr3 = tmp;
}
/* volume sources need only one inversion */
else if(SourceInfo.type == 1) i++;
}
}
etime = gettime();
if (g_cart_id == 0 && g_debug_level > 0) {
fprintf(stdout, "# Inversion done in %d iterations, squared residue = %e!\n",
Expand Down
2 changes: 2 additions & 0 deletions operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define DBTMWILSON 3
#define CLOVER 4
#define DBCLOVER 5
#define BSM 6

#define max_no_operators 10

Expand Down Expand Up @@ -102,6 +103,7 @@ typedef struct {
void (*applyQp) (spinor * const, spinor * const);
void (*applyQm) (spinor * const, spinor * const);
void (*applyQsq) (spinor * const, spinor * const);
void (*applyQsqbi) (bispinor * const, bispinor * const);
void (*applyMp) (spinor * const, spinor * const);
void (*applyMm) (spinor * const, spinor * const);
void (*applyDbQsq) (spinor * const, spinor * const, spinor * const, spinor * const);
Expand Down
Loading

0 comments on commit 10cd47c

Please sign in to comment.