So this is rude. I have a piece of code that used the C ++ Columbia Physics System library. I get segfault when I run it, most likely because the classes are: CgArg and vector f_field_in, etc. Not initialized. I used Valgrind and found that in fact, various arguments pointed to invalid memory.
It is strange that if I insert an iostream call into either of the two functions, segfault leaves. I found out when I put flags in places for debugging. It is also not segfault if I define an integer and write a simple cin →. That is why I think this is something related to iostream.
If you know why the iostream call somehow passed code snippets to the arguments, I would really appreciate it if you shared it with me.
#include <iostream> using namespace std; #include <config.h> #include <util/lattice.h> #include <util/dirac_op.h> #include <util/gjp.h> #include <interface.h> #define CLOVER_MAT_SIZE 72 USING_NAMESPACE_CPS // Same function for clover matrix and its inverse. static void interface(double *h_quda_clover, double *h_cps_clover) { h_quda_clover[0]=h_cps_clover[0]; // c00_00_re = C0.x, A0
... and much more from this material ...
h_quda_clover[35+36]=h_cps_clover[34+36]; // c32_31_im = C8.w, A5 } static void fill_h_clover_inv(Lattice &lat, int site[], double *h_quda_clover_inv_site) { double h_cps_clover_inv[72]; Vector *f_field_out, *f_field_in; CgArg *arg; CnvFrmType convert=CNV_FRM_NO; DiracOpClover dirac(lat,f_field_out,f_field_in,arg,convert); //cout << "B: " << site << endl; //cout << "B: site: " << site[0] << ' ' << site[1] << ' ' << site[2] << ' ' << site[3] << endl; dirac.SiteCloverMat(site,h_cps_clover_inv); interface(h_quda_clover_inv_site,h_cps_clover_inv); } void fill_h_clover_inv_all(Lattice &lat, double *h_quda_clover_inv, int parity) { double *ptr=h_quda_clover_inv; int nsites[4]; nsites[0]=GJP.XnodeSites(); nsites[1]=GJP.YnodeSites(); nsites[2]=GJP.ZnodeSites(); nsites[3]=GJP.TnodeSites(); int site[4]; cout << "A: " << site << endl; for (site[3] = 0; site[3] < nsites[3]; ++(site[3])) { for (site[2] = 0; site[2] < nsites[2]; ++(site[2])) { for (site[1] = 0; site[1] < nsites[1]; ++(site[1])) { site[0] = (site[3] + site[2] + site[1] + parity)%2; for (; site[0] < nsites[0]; site[0] += 2) { //cout << "A: site: " << site[0] << ' ' << site[1] << ' ' << site[2] << ' ' << site[3] << endl; fill_h_clover_inv(lat,site,ptr); ptr += CLOVER_MAT_SIZE; } } } } }
source share