void polyphase_seg(float* data) { int i,n; static fftw_plan planfwd; float *p; if (!planfwd) { planfwd=fftw_create_plan(P_FFT_LEN, FFTW_FORWARD, FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM ); } for (i=0;i<P_FFT_LEN;i++) { f_data[2*i] = 0; f_data[2*i+1] = 0; for (n=0;n<N_WINDOWS;n++) { f_data[2*i] += data[2*i+2*n*P_FFT_LEN]*filter_r[P_FFT_LEN*n + i]; f_data[2*i+1] += data[2*i+2*n*P_FFT_LEN+1]*filter_i[P_FFT_LEN*n + i]; } } fftw_one(planfwd, (fftw_complex *)f_data, (fftw_complex *)NULL); /*for (i=0;i<P_FFT_LEN;i++) { fprintf( stderr, "%f %f\n", f_data[2*i], f_data[2*i+1]); }*/ //fprintf( stderr, "%f %f ", f_data[2*3], f_data[2*3+1] ); p = f_data; for (i=0; i<P_FFT_LEN; i++) { output_samples(p, i, obuf_pos); p += IFFT_LEN*2; } obuf_pos+=IFFT_LEN*2/CHAR_BIT; }
static void fft_4k( fft_complex *in, fft_complex *out ) { // Zero the unused parts of the array memset(&m_fft_in[M4KS/4],0,sizeof(fft_complex)*M4KS/2); // Copy the data into the correct bins //memcpy(&m_fft_in[M4KS*3/4], &in[0], sizeof(fft_complex)*M2KS/2); //memcpy(&m_fft_in[0], &in[M2KS/2], sizeof(fft_complex)*M2KS/2); int i,m; m = (M4KS/2)+(M4KS/4); for( i = 0; i < (M2KS); i++ ) { m_fft_in[m].re = in[i].re*m_c[i]; m_fft_in[m].im = in[i].im*m_c[i]; m = (m+1)%(M2KS*2); } #ifdef USE_AVFFT av_fft_permute( m_avfft_4k_context, m_fft_in ); av_fft_calc( m_avfft_4k_context, m_fft_in ); #else fftw_one( m_fftw_4k_plan, m_fft_in, out ); #endif return; }
int gmx_fft_1d(gmx_fft_t fft, enum gmx_fft_direction dir, void * in_data, void * out_data) { int inplace = (in_data == out_data); int isforward = (dir == GMX_FFT_FORWARD); if((fft->ndim != 1) || ((dir != GMX_FFT_FORWARD) && (dir != GMX_FFT_BACKWARD))) { gmx_fatal(FARGS,"FFT plan mismatch - bad plan or direction."); return EINVAL; } fftw_one(fft->single[inplace][isforward],(fftw_complex *)in_data,(fftw_complex *)out_data); return 0; }
static void fft_8k( fft_complex *in, fft_complex *out ) { // Copy the data into the correct bins // memcpy(&m_fft_in[M8KS/2], &in[0], sizeof(fft_complex)*M8KS/2); // memcpy(&m_fft_in[0], &in[M8KS/2], sizeof(fft_complex)*M8KS/2); int i,m; m = (M8KS/2); for( i = 0; i < (M8KS); i++ ) { m_fft_in[m].re = in[i].re*m_c[i]; m_fft_in[m].im = in[i].im*m_c[i]; m = (m+1)%M8KS; } #ifdef USE_AVFFT av_fft_permute( m_avfft_8k_context, m_fft_in ); av_fft_calc( m_avfft_8k_context, m_fft_in ); #else fftw_one( m_fftw_8k_plan, m_fft_in, out ); #endif }
int fourier(double *jr, double *ji, int n, int iflag) { int i; int plan_flags; fftw_plan plan; FFTW_COMPLEX *cbuf; init_wisdom(); plan_flags = using_wisdom ? (FFTW_USE_WISDOM | FFTW_MEASURE):FFTW_ESTIMATE; plan_flags |= FFTW_IN_PLACE; plan = fftw_create_plan(n, iflag ? FFTW_BACKWARD:FFTW_FORWARD, plan_flags); cbuf = xcalloc(n, sizeof(FFTW_COMPLEX)); if (!cbuf) { return RETURN_FAILURE; } for (i = 0; i < n; i++) { cbuf[i].re = jr[i]; cbuf[i].im = ji[i]; } fftw_one(plan, cbuf, NULL); fftw_destroy_plan(plan); for (i = 0; i < n; i++) { jr[i] = cbuf[i].re; ji[i] = cbuf[i].im; } xfree(cbuf); return RETURN_SUCCESS; }
void process_seg(float* data) { int i; float* p = data; static float dbuff[FFT_LEN*2]; static fftw_plan planfwd,planinverse; if (!planfwd) { planfwd=fftw_create_plan(FFT_LEN, FFTW_BACKWARD, FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM ); planinverse=fftw_create_plan(IFFT_LEN, FFTW_FORWARD, FFTW_MEASURE | FFTW_IN_PLACE | FFTW_USE_WISDOM ); } fftw_one(planfwd, (fftw_complex *)data, (fftw_complex *)NULL); data[0]=0; data[1]=0; fftw(planinverse, NSTRIPS, (fftw_complex *)data, 1, IFFT_LEN, (fftw_complex *)NULL, 1, IFFT_LEN); for (i=0; i<NSTRIPS; i++) { output_samples(p, i, obuf_pos); p += IFFT_LEN*2; } obuf_pos+=IFFT_LEN*2/CHAR_BIT; }
int line_model_monitor_line_spectrum_update(const int16_t amp[], int len) { int i; int x; for (i = 0; i < len; i++) audio_meter->sample(amp[i]/32768.0); if (in_ptr + len < 512) { /* Just add this fragment to the buffer. */ for (i = 0; i < len; i++) #if defined(HAVE_FFTW3_H) in[in_ptr + i][0] = amp[i]; #else in[in_ptr + i].re = amp[i]; #endif in_ptr += len; return 0; } if (len >= 512) { /* We have enough for a whole block. Use the last 512 samples we have. */ x = len - 512; for (i = 0; i < 512; i++) #if defined(HAVE_FFTW3_H) in[i][0] = amp[x + i]; #else in[i].re = amp[x + i]; #endif } else { /* We want the last 512 samples. */ x = 512 - len; for (i = 0; i < x; i++) #if defined(HAVE_FFTW3_H) in[i][0] = in[in_ptr - x + i][0]; #else in[i].re = in[in_ptr - x + i].re; #endif for (i = x; i < 512; i++) #if defined(HAVE_FFTW3_H) in[i][0] = amp[i - x]; #else in[i].re = amp[i - x]; #endif } in_ptr = 0; #if defined(HAVE_FFTW3_H) fftw_execute(p); #else fftw_one(p, in, out); #endif if (spec_re) delete spec_re; canvas_spec->current(canvas_spec); for (i = 0; i < 512; i++) { spec_re_plot[2*i] = i*4000.0/512.0; #if defined(HAVE_FFTW3_H) spec_re_plot[2*i + 1] = 20.0*log10(sqrt(out[i][0]*out[i][0] + out[i][1]*out[i][1])/(256.0*32768)) + 3.14; #else spec_re_plot[2*i + 1] = 20.0*log10(sqrt(out[i].re*out[i].re + out[i].im*out[i].im)/(256.0*32768)) + 3.14; #endif } spec_re = new Ca_Line(512, spec_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); Fl::check(); return 0; }
int main(int argc, char **argv) { int c, mu, status; int filename_set = 0; int mode = 0; int l_LX_at, l_LXstart_at; int x0, x1, x2, x3, ix, iix, iiy, gid; int Thp1, nclass; int *oh_count=(int*)NULL, *oh_id=(int*)NULL, oh_nc; int *picount; double *conn = (double*)NULL; double *conn2 = (double*)NULL; double **oh_val=(double**)NULL; double q[4], qsqr; int verbose = 0; char filename[800]; double ratime, retime; FILE *ofs; fftw_complex *corrt=NULL; fftw_complex *pi00=(fftw_complex*)NULL, *pijj=(fftw_complex*)NULL, *piavg=(fftw_complex*)NULL; fftw_plan plan_m; while ((c = getopt(argc, argv, "h?vf:m:")) != -1) { switch (c) { case 'v': verbose = 1; break; case 'f': strcpy(filename, optarg); filename_set=1; break; case 'm': mode = atoi(optarg); break; case 'h': case '?': default: usage(); break; } } /* set the default values */ if(filename_set==0) strcpy(filename, "cvc.input"); fprintf(stdout, "# Reading input from file %s\n", filename); read_input_parser(filename); /* some checks on the input data */ if((T_global == 0) || (LX==0) || (LY==0) || (LZ==0)) { if(g_proc_id==0) fprintf(stdout, "T and L's must be set\n"); usage(); } /* initialize MPI parameters */ mpi_init(argc, argv); /* initialize fftw, create plan with FFTW_FORWARD --- in contrast to * FFTW_BACKWARD in e.g. avc_exact */ plan_m = fftw_create_plan(T_global, FFTW_FORWARD, FFTW_MEASURE | FFTW_IN_PLACE); if(plan_m==NULL) { fprintf(stderr, "Error, could not create fftw plan\n"); return(1); } T = T_global; Thp1 = T/2 + 1; Tstart = 0; l_LX_at = LX; l_LXstart_at = 0; FFTW_LOC_VOLUME = T*LX*LY*LZ; fprintf(stdout, "# [%2d] fftw parameters:\n"\ "# [%2d] T = %3d\n"\ "# [%2d] Tstart = %3d\n"\ "# [%2d] l_LX_at = %3d\n"\ "# [%2d] l_LXstart_at = %3d\n"\ "# [%2d] FFTW_LOC_VOLUME = %3d\n", g_cart_id, g_cart_id, T, g_cart_id, Tstart, g_cart_id, l_LX_at, g_cart_id, l_LXstart_at, g_cart_id, FFTW_LOC_VOLUME); if(init_geometry() != 0) { fprintf(stderr, "ERROR from init_geometry\n"); exit(1); } geometry(); /**************************************** * allocate memory for the contractions * ****************************************/ conn = (double*)calloc(32*VOLUME, sizeof(double)); if( (conn==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for contr. fields\n"); exit(3); } /* conn2 = (double*)calloc(32*VOLUME, sizeof(double)); if( (conn2==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for contr. fields\n"); exit(4); } pi00 = (fftw_complex*)malloc(VOLUME*sizeof(fftw_complex)); if( (pi00==(fftw_complex*)NULL) ) { fprintf(stderr, "could not allocate memory for pi00\n"); exit(2); } pijj = (fftw_complex*)fftw_malloc(VOLUME*sizeof(fftw_complex)); if( (pijj==(fftw_complex*)NULL) ) { fprintf(stderr, "could not allocate memory for pijj\n"); exit(2); } */ corrt = fftw_malloc(T*sizeof(fftw_complex)); for(gid=g_gaugeid; gid<=g_gaugeid2; gid++) { // for(ix=0; ix<VOLUME; ix++) {pi00[ix].re = 0.; pi00[ix].im = 0.;} // for(ix=0; ix<VOLUME; ix++) {pijj[ix].re = 0.; pijj[ix].im = 0.;} /*********************** * read contractions * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "%s", filename_prefix); fprintf(stdout, "# Reading data from file %s\n", filename); status = read_lime_contraction(conn, filename, 16, 0); if(status == 106) { fprintf(stderr, "Error: could not read from file %s; status was %d\n", filename, status); continue; } /* sprintf(filename, "%s.%.4d.%.4d", filename_prefix2, gid); fprintf(stdout, "# Reading data from file %s\n", filename); status = read_lime_contraction(conn2, filename, 16, 0); if(status == 106) { fprintf(stderr, "Error: could not read from file %s; status was %d\n", filename, status); continue; } */ retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time to read contractions %e seconds\n", retime-ratime); /*********************** * fill the correlator * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; /* for(x1=0; x1<LX; x1++) { for(x2=0; x2<LY; x2++) { for(x3=0; x3<LZ; x3++) { for(x0=0; x0<T; x0++) { iix = g_ipt[0][x1][x2][x3]*T+x0; for(mu=1; mu<4; mu++) { ix = _GWI(5*mu,g_ipt[x0][x1][x2][x3],VOLUME); pijj[iix].re += ( conn[ix ] - conn2[ix ] ) * (double)Nsave / (double)(Nsave-1); pijj[iix].im += ( conn[ix+1] - conn2[ix+1] ) * (double)Nsave / (double)(Nsave-1); } ix = 2*g_ipt[x0][x1][x2][x3]; pi00[iix].re += ( conn[ix ] - conn2[ix ] ) * (double)Nsave / (double)(Nsave-1); pi00[iix].im += ( conn[ix+1] - conn2[ix+1] ) * (double)Nsave / (double)(Nsave-1); } }}} */ for(x0=0; x0<T; x0++) { ix = g_ipt[x0][0][0][0]; corrt[x0].re = conn[_GWI(5,ix,VOLUME) ] + conn[_GWI(10,ix,VOLUME) ] + conn[_GWI(15,ix,VOLUME) ]; corrt[x0].im = conn[_GWI(5,ix,VOLUME)+1] + conn[_GWI(10,ix,VOLUME)+1] + conn[_GWI(15,ix,VOLUME)+1]; corrt[x0].re /= (double)T; corrt[x0].im /= (double)T; } /* fftw(plan_m, 1, corrt, 1, T, (fftw_complex*)NULL, 0, 0); */ fftw_one(plan_m, corrt, NULL); sprintf(filename, "rho.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing VKVK data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, 0, corrt[0].re, 0., gid); for(x0=1; x0<(T/2); x0++) { fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, x0, corrt[x0].re, corrt[T-x0].re, gid); } fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, (T/2), corrt[T/2].re, 0., gid); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time to fill correlator %e seconds\n", retime-ratime); #ifdef _UNDEF free(conn); /* free(conn2); */ /******************************** * test: print correl to stdout * ********************************/ /* fprintf(stdout, "\n\n# ***************** pijj *****************\n"); for(ix=0; ix<LX*LY*LZ; ix++) { iix = ix*T; for(x0=0; x0<T; x0++) { fprintf(stdout, "%6d%3d%25.16e%25.16e\n", ix, x0, pijj[iix+x0].re, pijj[iix+x0].im); } } fprintf(stdout, "\n\n# ***************** pi00 *****************\n"); for(ix=0; ix<LX*LY*LZ; ix++) { iix = ix*T; for(x0=0; x0<T; x0++) { fprintf(stdout, "%6d%3d%25.16e%25.16e\n", ix, x0, pi00[iix+x0].re, pi00[iix+x0].im); } } */ /***************************************** * do the reverse Fourier transformation * *****************************************/ ratime = (double)clock() / CLOCKS_PER_SEC; fftw(plan_m, LX*LY*LZ, pi00, 1, T, (fftw_complex*)NULL, 0, 0); fftw(plan_m, LX*LY*LZ, pijj, 1, T, (fftw_complex*)NULL, 0, 0); for(ix=0; ix<VOLUME; ix++) { pi00[ix].re /= (double)T; pi00[ix].im /= (double)T; pijj[ix].re /= 3.*(double)T; pijj[ix].im /= 3.*(double)T; } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time for Fourier transform %e seconds\n", retime-ratime); /***************************************** * write to file *****************************************/ ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "pi00.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing pi00-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(x1=0; x1<LX; x1++) { for(x2=0; x2<LY; x2++) { for(x3=0; x3<LZ; x3++) { ix = g_ipt[0][x1][x2][x3]*T; /* fprintf(ofs, "# px=%3d, py=%3d, pz=%3d\n", x1, x2, x3); */ for(x0=0; x0<T; x0++) { /* fprintf(ofs, "%3d%25.16e%25.16e\n", x0, pi00[ix+x0].re, pi00[ix+x0].im); */ fprintf(ofs, "%3d%3d%3d%3d%25.16e%25.16e\n", x1, x2, x3, x0, pi00[ix+x0].re, pi00[ix+x0].im); } }}} fclose(ofs); sprintf(filename, "pijj.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing pijj-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(x1=0; x1<LX; x1++) { for(x2=0; x2<LY; x2++) { for(x3=0; x3<LZ; x3++) { ix = g_ipt[0][x1][x2][x3]*T; /* fprintf(ofs, "# px=%3d, py=%3d, pz=%3d\n", x1, x2, x3); */ for(x0=0; x0<T; x0++) { /* fprintf(ofs, "%3d%25.16e%25.16e\n", x0, pijj[ix+x0].re, pijj[ix+x0].im); */ fprintf(ofs, "%3d%3d%3d%3d%25.16e%25.16e\n", x1, x2, x3, x0, pijj[ix+x0].re, pijj[ix+x0].im); } }}} fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time to write correlator %e seconds\n", retime-ratime); /* if(mode==0) { ratime = (double)clock() / CLOCKS_PER_SEC; if( (picount = (int*)malloc(VOLUME*sizeof(int))) == (int*)NULL) exit(110); sprintf(filename, "corr.00.mom"); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } for(ix=0; ix<VOLUME; ix++) picount[ix] = 0; for(x1=0; x1<LX; x1++) { q[1] = 2. * sin(M_PI * (double)x1 / (double)LX); for(x2=0; x2<LY; x2++) { q[2] = 2. * sin(M_PI * (double)x2 / (double)LY); for(x3=0; x3<LZ; x3++) { q[3] = 2. * sin(M_PI * (double)x3 / (double)LZ); qsqr = q[1]*q[1] + q[2]*q[2] + q[3]*q[3]; if( qsqr>=g_qhatsqr_min-_Q2EPS && qsqr<= g_qhatsqr_max+_Q2EPS ) { ix = g_ipt[0][x1][x2][x3]; picount[ix] = 1; fprintf(ofs, "%3d%3d%3d%6d%25.16e\n", x1, x2, x3, ix, qsqr); } }}} fclose(ofs); sprintf(filename, "corr_00.00.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr_00-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(ix=0; ix<VOLUME; ix++) { if(picount[ix]>0) { for(x0=0; x0<T; x0++) { fprintf(ofs, "%3d%3d%25.16e%25.16e\n", ix, x0, pi00[ix*T+x0].re, pi00[ix*T+x0].im); } } } fclose(ofs); sprintf(filename, "corr_jj.00.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr_jj-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(ix=0; ix<VOLUME; ix++) { if(picount[ix]>0) { for(x0=0; x0<T; x0++) { fprintf(ofs, "%3d%3d%25.16e%25.16e\n", ix, x0, pijj[ix*T+x0].re, pijj[ix*T+x0].im); } } } fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time for O_h averaging %e seconds\n", retime-ratime); free(picount); } else if(mode==1) { ratime = (double)clock() / CLOCKS_PER_SEC; if( (picount = (int*)malloc(VOLUME*sizeof(int))) == (int*)NULL) exit(110); sprintf(filename, "corr.01.mom"); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } if( (picount = (int*)malloc(VOLUME*sizeof(int))) == (int*)NULL) exit(110); for(ix=0; ix<VOLUME; ix++) picount[ix] = 0; for(x1=0; x1<LX; x1++) { q[1] = 2. * M_PI * (double)x1 / (double)LX; for(x2=0; x2<LY; x2++) { q[2] = 2. * M_PI * (double)x2 / (double)LY; for(x3=0; x3<LZ; x3++) { q[3] = 2. * M_PI * (double)x3 / (double)LZ; qsqr = q[1]*q[1] + q[2]*q[2] + q[3]*q[3]; if( qsqr>=g_qhatsqr_min-_Q2EPS && qsqr<= g_qhatsqr_max+_Q2EPS ) { ix = g_ipt[0][x1][x2][x3]; picount[ix] = 1; fprintf(ofs, "%3d%3d%3d%6d%25.16e\n", x1, x2, x3, ix, qsqr); } }}} fclose(ofs); sprintf(filename, "corr_00.01.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr_01-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(ix=0; ix<VOLUME; ix++) { if(picount[ix]>0) { for(x0=0; x0<T; x0++) { fprintf(ofs, "%3d%3d%25.16e%25.16e\n", ix, x0, pi00[ix*T+x0].re, pi00[ix*T+x0].im); } } } fclose(ofs); sprintf(filename, "corr_jj.01.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr_jj-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(ix=0; ix<VOLUME; ix++) { if(picount[ix]>0) { for(x0=0; x0<T; x0++) { fprintf(ofs, "%3d%3d%25.16e%25.16e\n", ix, x0, pijj[ix*T+x0].re, pijj[ix*T+x0].im); } } } fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time for writing: %e seconds\n", retime-ratime); free(picount); } else if(mode==2) { if(make_H3orbits(&oh_id, &oh_count, &oh_val, &oh_nc) != 0) return(123); ratime = (double)clock() / CLOCKS_PER_SEC; nclass = oh_nc / Thp1; if( (piavg = (fftw_complex*)malloc(oh_nc*sizeof(fftw_complex))) == (fftw_complex*)NULL) exit(110); if( (picount = (int*)malloc(oh_nc*sizeof(int))) == (int*)NULL) exit(110); for(ix=0; ix<oh_nc; ix++) { piavg[ix].re = 0.; piavg[ix].im = 0.; picount[ix] = 0; } for(ix=0; ix<LX*LY*LZ; ix++) { for(x0=0; x0<Thp1; x0++) { iix = ix*T+x0; iiy = oh_id[ix]*Thp1+x0; piavg[iiy].re += pi00[iix].re; piavg[iiy].im += pi00[iix].im; if(x0>0 && x0<T/2) { iix = ix*T+(T-x0); piavg[iiy].re += pi00[iix].re; piavg[iiy].im += pi00[iix].im; } } picount[oh_id[ix]]++; } for(ix=0; ix<nclass; ix++) { for(x0=0; x0<Thp1; x0++) { iix = ix*Thp1+x0; if(picount[ix]>0) { piavg[iix].re /= (double)picount[ix]; piavg[iix].im /= (double)picount[ix]; if(x0>0 && x0<T/2) { piavg[iix].re /= 2.; piavg[iix].im /= 2.; } } } } sprintf(filename, "corr02_00.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr-00-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(x1=0; x1<nclass; x1++) { if(oh_val[0][x1]>=g_qhatsqr_min-_Q2EPS && oh_val[0][x1]<=g_qhatsqr_max+_Q2EPS) { ix = x1*Thp1; for(x0=0; x0<Thp1; x0++) { fprintf(ofs, "%25.16e%3d%25.16e%25.16e%5d\n", oh_val[0][x1], x0, piavg[ix+x0].re, piavg[ix+x0].im, picount[x1]); } } } fclose(ofs); for(ix=0; ix<oh_nc; ix++) { piavg[ix].re = 0.; piavg[ix].im = 0.; picount[ix] = 0; } for(ix=0; ix<LX*LY*LZ; ix++) { for(x0=0; x0<Thp1; x0++) { iix = ix*T+x0; iiy = oh_id[ix]*Thp1+x0; piavg[iiy].re += pijj[iix].re; piavg[iiy].im += pijj[iix].im; if(x0>0 && x0<T/2) { iix = ix*T+(T-x0); piavg[iiy].re += pijj[iix].re; piavg[iiy].im += pijj[iix].im; } } picount[oh_id[ix]]++; } for(ix=0; ix<nclass; ix++) { for(x0=0; x0<Thp1; x0++) { iix = ix*Thp1+x0; if(picount[ix]>0) { piavg[iix].re /= (double)picount[ix]; piavg[iix].im /= (double)picount[ix]; if(x0>0 && x0<T/2) { piavg[iix].re /= 2.; piavg[iix].im /= 2.; } } }} sprintf(filename, "corr02_jj.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing corr-jj-data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu); for(x1=0; x1<nclass; x1++) { ix = x1*Thp1; for(x0=0; x0<Thp1; x0++) { fprintf(ofs, "%25.16e%3d%25.16e%25.16e%5d\n", oh_val[0][x1], x0, piavg[ix+x0].re, piavg[ix+x0].im, picount[x1]); } } fclose(ofs); sprintf(filename, "corr.02.mom"); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } for(ix=0; ix<VOLUME; ix++) fprintf(ofs, "%5d%25.16e%5d", ix, oh_val[0][ix], picount[ix]); fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time for O_h averaging %e seconds\n", retime-ratime); free(piavg); free(picount); } */ #endif } /*************************************** * free the allocated memory, finalize * ***************************************/ free(corrt); free_geometry(); /* free(pi00); free(pijj); */ fftw_destroy_plan(plan_m); return(0); }
void F77_FUNC_(fftw_f77_one,FFTW_F77_ONE) (fftw_plan *p, fftw_complex *in, fftw_complex *out) { fftw_one(*p,in,out); }
int main(int argc, char **argv) { int c, mu; int filename_set = 0; int l_LX_at, l_LXstart_at; int source_location, have_source_flag = 0; int x0, ix; int sx0, sx1, sx2, sx3; int check_WI=0; double *conn = (double*)NULL; double *conn2 = (double*)NULL; int verbose = 0; char filename[800]; double ratime, retime; FILE *ofs; /************************** * variables for WI check */ int x1, x2, x3, nu; double wre, wim, q[4]; /**************************/ fftw_complex *in=(fftw_complex*)NULL, *out=(fftw_complex*)NULL; fftw_plan plan_m; while ((c = getopt(argc, argv, "wh?vf:")) != -1) { switch (c) { case 'v': verbose = 1; break; case 'f': strcpy(filename, optarg); filename_set=1; break; case 'w': check_WI = 1; fprintf(stdout, "# [get_rho_corr] check WI in momentum space\n"); break; case 'h': case '?': default: usage(); break; } } /* set the default values */ set_default_input_values(); if(filename_set==0) strcpy(filename, "cvc.input"); // set the default values set_default_input_values(); if(filename_set==0) strcpy(filename, "cvc.input"); fprintf(stdout, "# [get_rho_corr] reading input parameters from file %s\n", filename); read_input_parser(filename); /* some checks on the input data */ if((T_global == 0) || (LX==0) || (LY==0) || (LZ==0)) { if(g_proc_id==0) fprintf(stdout, "T and L's must be set\n"); usage(); } if(g_kappa == 0.) { if(g_proc_id==0) fprintf(stdout, "kappa should be > 0.n"); usage(); } /* initialize MPI parameters */ mpi_init(argc, argv); /* initialize fftw, create plan with FFTW_FORWARD --- in contrast to * FFTW_BACKWARD in e.g. avc_exact */ plan_m = fftw_create_plan(T_global, FFTW_FORWARD, FFTW_MEASURE); T = T_global; Tstart = 0; l_LX_at = LX; l_LXstart_at = 0; FFTW_LOC_VOLUME = T*LX*LY*LZ; fprintf(stdout, "# [%2d] fftw parameters:\n"\ "# [%2d] T = %3d\n"\ "# [%2d] Tstart = %3d\n"\ "# [%2d] l_LX_at = %3d\n"\ "# [%2d] l_LXstart_at = %3d\n"\ "# [%2d] FFTW_LOC_VOLUME = %3d\n", g_cart_id, g_cart_id, T, g_cart_id, Tstart, g_cart_id, l_LX_at, g_cart_id, l_LXstart_at, g_cart_id, FFTW_LOC_VOLUME); if(init_geometry() != 0) { fprintf(stderr, "ERROR from init_geometry\n"); exit(1); } geometry(); /**************************************** * allocate memory for the contractions * ****************************************/ conn = (double*)calloc(2 * 16 * VOLUME, sizeof(double)); if( (conn==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for contr. fields\n"); exit(3); } for(ix=0; ix<32*VOLUME; ix++) conn[ix] = 0.; conn2= (double*)calloc(2 * T, sizeof(double)); if( (conn2==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for corr.\n"); exit(2); } for(ix=0; ix<2*T; ix++) conn2[ix] = 0.; /***************************************** * prepare Fourier transformation arrays * *****************************************/ in = (fftw_complex*)malloc(T*sizeof(fftw_complex)); out = (fftw_complex*)malloc(T*sizeof(fftw_complex)); if( (in==(fftw_complex*)NULL) || (out==(fftw_complex*)NULL) ) exit(4); /******************************** * determine source coordinates * ********************************/ have_source_flag = (int)(g_source_location/(LX*LY*LZ)>=Tstart && g_source_location/(LX*LY*LZ)<(Tstart+T)); if(have_source_flag==1) fprintf(stdout, "process %2d has source location\n", g_cart_id); sx0 = g_source_location/(LX*LY*LZ)-Tstart; sx1 = (g_source_location%(LX*LY*LZ)) / (LY*LZ); sx2 = (g_source_location%(LY*LZ)) / LZ; sx3 = (g_source_location%LZ); if(have_source_flag==1) { fprintf(stdout, "local source coordinates: (%3d,%3d,%3d,%3d)\n", sx0, sx1, sx2, sx3); source_location = g_ipt[sx0][sx1][sx2][sx3]; } have_source_flag = 0; /*********************** * read contractions * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; // read_contraction(conn, (int*)NULL, filename_prefix, 16); read_lime_contraction(conn, filename_prefix, 16, 0); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "time to read contractions %e seconds\n", retime-ratime); // TEST Ward Identity if(check_WI) { fprintf(stdout, "# [get_corr_v5] Ward identity\n"); sprintf(filename, "WI.%.4d", Nconf); ofs = fopen(filename, "w"); if(ofs == NULL) exit(32); for(x0=0; x0<T; x0++) { q[0] = 2. * sin(M_PI * (double)x0 / (double)T); for(x1=0; x1<LX; x1++) { q[1] = 2. * sin(M_PI * (double)x1 / (double)LX); for(x2=0; x2<LY; x2++) { q[2] = 2. * sin(M_PI * (double)x2 / (double)LY); for(x3=0; x3<LZ; x3++) { q[3] = 2. * sin(M_PI * (double)x3 / (double)LZ); ix = g_ipt[x0][x1][x2][x3]; for(nu=0;nu<4;nu++) { wre = q[0] * conn[_GWI(4*0+nu,ix,VOLUME)] + q[1] * conn[_GWI(4*1+nu,ix,VOLUME)] \ + q[2] * conn[_GWI(4*2+nu,ix,VOLUME)] + q[3] * conn[_GWI(4*3+nu,ix,VOLUME)]; wim = q[0] * conn[_GWI(4*0+nu,ix,VOLUME)+1] + q[1] * conn[_GWI(4*1+nu,ix,VOLUME)+1] \ + q[2] * conn[_GWI(4*2+nu,ix,VOLUME)+1] + q[3] * conn[_GWI(4*3+nu,ix,VOLUME)+1]; fprintf(ofs, "\t%3d%3d%3d%3d%3d%16.7e%16.7e\n", nu, x0, x1, x2, x3, wre, wim); } }}}} fclose(ofs); } /*********************** * fill the correlator * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; for(x0=0; x0<T; x0++) { for(mu=1; mu<4; mu++) { ix = get_indexf(x0,0,0,0,mu,mu); fprintf(stdout, "x0=%3d, mu=%3d\tix=%8d\n", x0, mu, ix); conn2[2*x0 ] += conn[ix ]; conn2[2*x0+1] += conn[ix+1]; } } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "time to fill correlator %e seconds\n", retime-ratime); /******************************** * test: print correl to stdout * ********************************/ for(x0=0; x0<T; x0++) { fprintf(stdout, "%3d%25.16e%25.16e\n", x0, conn2[2*x0], conn[2*x0+1]); } /***************************************** * do the reverse Fourier transformation * *****************************************/ ratime = (double)clock() / CLOCKS_PER_SEC; memcpy((void*)in, (void*)conn2, 2*T*sizeof(double)); fftw_one(plan_m, in, out); for(ix=0; ix<T; ix++) { conn2[2*ix ] = out[ix].re / (double)T; conn2[2*ix+1] = out[ix].im / (double)T; } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "time for Fourier transform %e seconds\n", retime-ratime); ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "rho_corr.%.4d", Nconf); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "could not open file %s for writing\n", filename); exit(5); } //for(x0=0; x0<T; x0++) { // fprintf(ofs, "%3d%25.16e%25.16e\n", x0, conn2[2*x0], conn2[2*x0+1]); //} x0 = 0; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], 0., Nconf); for(x0=1; x0<T/2; x0++) { fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], conn2[2*(T-x0)], Nconf); } x0 = T/2; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], 0., Nconf); fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "time to write correlator %e seconds\n", retime-ratime); /*************************************** * free the allocated memory, finalize * ***************************************/ free_geometry(); fftw_free(in); fftw_free(out); free(conn); free(conn2); fftw_destroy_plan(plan_m); return(0); }
int main(int argc, char **argv) { int c, mu, nu, status, gid; int filename_set = 0; int l_LX_at, l_LXstart_at; int source_location, have_source_flag = 0; int x0, x1, x2, x3, ix; int sx0, sx1, sx2, sx3; int tsize = 0; double *conn = NULL; double *conn2 = (double*)NULL; int verbose = 0; char filename[800]; double ratime, retime; FILE *ofs; int ivec[4], idx[4], imu; double q[4], wre, wim; fftw_complex *inT=NULL, *outT=NULL, *inL=NULL, *outL=NULL; fftw_plan plan_m_T, plan_m_L; while ((c = getopt(argc, argv, "h?vf:")) != -1) { switch (c) { case 'v': verbose = 1; break; case 'f': strcpy(filename, optarg); filename_set=1; break; case 'h': case '?': default: usage(); break; } } // set the default values set_default_input_values(); if(filename_set==0) strcpy(filename, "cvc.input"); fprintf(stdout, "# [get_corr_v2] reading input parameters from file %s\n", filename); read_input_parser(filename); // some checks on the input data if((T_global == 0) || (LX==0) || (LY==0) || (LZ==0)) { fprintf(stdout, "# [get_corr_v2] T=%d, LX=%d, LY=%d, LZ=%d\n", T_global, LX, LY, LZ); if(g_proc_id==0) fprintf(stderr, "[get_corr_v2] Error, T and L's must be set\n"); usage(); } // initialize MPI parameters mpi_init(argc, argv); /* initialize fftw, create plan with FFTW_FORWARD --- in contrast to * FFTW_BACKWARD in e.g. avc_exact */ plan_m_T = fftw_create_plan(T_global, FFTW_FORWARD, FFTW_MEASURE); plan_m_L = fftw_create_plan(LX, FFTW_FORWARD, FFTW_MEASURE); T = T_global; Tstart = 0; l_LX_at = LX; l_LXstart_at = 0; FFTW_LOC_VOLUME = T*LX*LY*LZ; fprintf(stdout, "# [%2d] fftw parameters:\n"\ "# [%2d] T = %3d\n"\ "# [%2d] Tstart = %3d\n"\ "# [%2d] l_LX_at = %3d\n"\ "# [%2d] l_LXstart_at = %3d\n"\ "# [%2d] FFTW_LOC_VOLUME = %3d\n", g_cart_id, g_cart_id, T, g_cart_id, Tstart, g_cart_id, l_LX_at, g_cart_id, l_LXstart_at, g_cart_id, FFTW_LOC_VOLUME); if(init_geometry() != 0) { fprintf(stderr, "[get_corr_v2] Error from init_geometry\n"); EXIT(1); } geometry(); /**************************************** * allocate memory for the contractions * ****************************************/ conn = (double*)calloc(32 * VOLUME, sizeof(double)); if( (conn==NULL) ) { fprintf(stderr, "[get_corr_v2] Error, could not allocate memory for contr. fields\n"); EXIT(2); } conn2= (double*)calloc(8 * T, sizeof(double)); if( (conn2==NULL) ) { fprintf(stderr, "[get_corr_v2] Error, could not allocate memory for corr.\n"); EXIT(3); } /***************************************** * prepare Fourier transformation arrays * *****************************************/ inT = (fftw_complex*)malloc(T * sizeof(fftw_complex)); inL = (fftw_complex*)malloc(LX * sizeof(fftw_complex)); outT = (fftw_complex*)malloc(T * sizeof(fftw_complex)); outL = (fftw_complex*)malloc(LX * sizeof(fftw_complex)); if( inT==NULL || inL==NULL || outT==NULL || outL==NULL ) { fprintf(stderr, "[get_corr_v2] Error, could not allocate fftw fields\n"); EXIT(4); } /******************************** * determine source coordinates * ********************************/ /* have_source_flag = (int)(g_source_location/(LX*LY*LZ)>=Tstart && g_source_location/(LX*LY*LZ)<(Tstart+T)); if(have_source_flag==1) fprintf(stdout, "# [get_corr_v2] process %2d has source location\n", g_cart_id); sx0 = g_source_location/(LX*LY*LZ)-Tstart; sx1 = (g_source_location%(LX*LY*LZ)) / (LY*LZ); sx2 = (g_source_location%(LY*LZ)) / LZ; sx3 = (g_source_location%LZ); if(have_source_flag==1) { fprintf(stdout, "# [get_corr_v2] local source coordinates: (%3d,%3d,%3d,%3d)\n", sx0, sx1, sx2, sx3); source_location = g_ipt[sx0][sx1][sx2][sx3]; } have_source_flag = 0; */ for(gid=g_gaugeid; gid<=g_gaugeid2; gid+=g_gauge_step) { memset(conn, 0, 32*VOLUME*sizeof(double)); memset(conn2, 0, 8*T*sizeof(double)); /*********************** * read contractions * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "%s.%.4d", filename_prefix, gid); if(format==2 || format==3) { status = read_contraction(conn, NULL, filename, 16); } else if( format==0) { status = read_lime_contraction(conn, filename, 16, 0); } if(status != 0) { // fprintf(stderr, "[get_corr_v2] Error from read_contractions, status was %d\n", status); // EXIT(5); fprintf(stderr, "[get_corr_v2] Warning, could not read contractions for gid %d, status was %d\n", gid, status); continue; } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# [get_corr_v2] time to read contractions %e seconds\n", retime-ratime); // TEST Pi_mm /* fprintf(stdout, "# [get_corr_v2] Pi_mm\n"); for(x0=0; x0<T; x0++) { for(x1=0; x1<LX; x1++) { for(x2=0; x2<LY; x2++) { for(x3=0; x3<LZ; x3++) { ix = g_ipt[x0][x1][x2][x3]; for(nu=0;nu<4;nu++) { wre = conn[_GWI(5*nu,ix,VOLUME)]; wim = conn[_GWI(5*nu,ix,VOLUME)+1]; fprintf(stdout, "\t%3d%3d%3d%3d%3d%16.7e%16.7e\n", nu, x0, x1, x2, x3, wre, wim); } }}}} */ // TEST Ward Identity /* fprintf(stdout, "# [get_corr_v2] Ward identity\n"); for(x0=0; x0<T; x0++) { q[0] = 2. * sin(M_PI * (double)x0 / (double)T); for(x1=0; x1<LX; x1++) { q[1] = 2. * sin(M_PI * (double)x1 / (double)LX); for(x2=0; x2<LY; x2++) { q[2] = 2. * sin(M_PI * (double)x2 / (double)LY); for(x3=0; x3<LZ; x3++) { q[3] = 2. * sin(M_PI * (double)x3 / (double)LZ); ix = g_ipt[x0][x1][x2][x3]; for(nu=0;nu<4;nu++) { wre = q[0] * conn[_GWI(4*0+nu,ix,VOLUME)] + q[1] * conn[_GWI(4*1+nu,ix,VOLUME)] \ + q[2] * conn[_GWI(4*2+nu,ix,VOLUME)] + q[3] * conn[_GWI(4*3+nu,ix,VOLUME)]; wim = q[0] * conn[_GWI(4*0+nu,ix,VOLUME)+1] + q[1] * conn[_GWI(4*1+nu,ix,VOLUME)+1] \ + q[2] * conn[_GWI(4*2+nu,ix,VOLUME)+1] + q[3] * conn[_GWI(4*3+nu,ix,VOLUME)+1]; fprintf(stdout, "\t%3d%3d%3d%3d%3d%16.7e%16.7e\n", nu, x0, x1, x2, x3, wre, wim); } }}}} */ /*********************** * fill the correlator * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; for(mu=0; mu<4; mu++) { ivec[0] = (0 + mu)%4; ivec[1] = (1 + mu)%4; ivec[2] = (2 + mu)%4; ivec[3] = (3 + mu)%4; idx[ivec[1]] = 0; idx[ivec[2]] = 0; idx[ivec[3]] = 0; tsize = (mu==0) ? T : LX; for(x0=0; x0<tsize; x0++) { idx[ivec[0]] = x0; for(nu=1; nu<4; nu++) { imu = (mu+nu) % 4; // ix = get_indexf(idx[0],idx[1],idx[2],idx[3],imu,imu); ix = _GWI(5*imu, g_ipt[idx[0]][idx[1]][idx[2]][idx[3]], VOLUME); // TEST //fprintf(stdout, "\tPi_%d_%d x0=%3d mu=%3d\tix=%8d\n", mu, mu, x0, imu, ix); conn2[2*(mu*T+x0) ] += conn[ix ]; conn2[2*(mu*T+x0)+1] += conn[ix+1]; } } } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# [get_corr_v2] time to fill correlator %e seconds\n", retime-ratime); // TEST /* fprintf(stdout, "# [get_corr_v2] correlators\n"); for(mu=0;mu<4;mu++) { for(x0=0; x0<T; x0++) { fprintf(stdout, "\t%3d%3d%25.16e%25.16e\n", mu, x0, conn2[2*(mu*T+x0)], conn2[2*(mu*T+x0)+1]); }} */ /***************************************** * reverse Fourier transformation *****************************************/ ratime = (double)clock() / CLOCKS_PER_SEC; memcpy((void*)inT, (void*)conn2, 2*T*sizeof(double)); fftw_one(plan_m_T, inT, outT); for(ix=0; ix<T; ix++) { conn2[2*ix ] = outT[ix].re / (double)T; conn2[2*ix+1] = outT[ix].im / (double)T; } for(mu=1; mu<4; mu++) { memcpy((void*)inL, (void*)(conn2+2*mu*T), 2*LX*sizeof(double)); fftw_one(plan_m_L, inL, outL); for(ix=0; ix<LX; ix++) { conn2[2*(mu*T+ix) ] = outL[ix].re / (double)LX; conn2[2*(mu*T+ix)+1] = outL[ix].im / (double)LX; } } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# [get_corr_v2] time for Fourier transform %e seconds\n", retime-ratime); ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "v0v0_corr.%.4d", gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "[get_corr_v2] Error, could not open file %s for writing\n", filename); EXIT(6); } x0 = 0; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], 0., gid); for(x0=1; x0<T/2; x0++) { fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], conn2[2*(T-x0)], gid); } x0 = T / 2; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*x0], 0., gid); fclose(ofs); for(mu=1; mu<4; mu++) { sprintf(filename, "v%dv%d_corr.%.4d", mu, mu, gid); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "[get_corr_v2] Error, could not open file %s for writing\n", filename); EXIT(7); } x0 = 0; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*(mu*T+x0)], 0., gid); for(x0=1; x0<LX/2; x0++) { fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*(mu*T+x0)], conn2[2*(mu*T+ LX-x0)], gid); } x0 = LX / 2; fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 5, 1, x0, conn2[2*(mu*T+x0)], 0., gid); fclose(ofs); } retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# [get_corr_v2] time to write correlator %e seconds\n", retime-ratime); } // of loop on gid /*************************************** * free the allocated memory, finalize * ***************************************/ free_geometry(); fftw_free(inT); fftw_free(outT); fftw_free(inL); fftw_free(outL); free(conn); free(conn2); fftw_destroy_plan(plan_m_T); fftw_destroy_plan(plan_m_L); fprintf(stdout, "# [get_corr_v2] %s# [get_corr_v2] end of run\n", ctime(&g_the_time)); fflush(stdout); fprintf(stderr, "[get_corr_v2] %s[get_corr_v2] end of run\n", ctime(&g_the_time)); fflush(stderr); return(0); }
void zfft1(dcomplex *data, /* size n_in */ int n_in, dcomplex *dataout, /* output */ int isign0) { fftw_complex *in, *out; fftw_plan p; int i; double scale; int isign; if (isign0>0) { isign=-1; } else { isign=1; } #ifdef fftw2 in = (fftw_complex*)malloc(sizeof(fftw_complex)*n_in); out = (fftw_complex*)malloc(sizeof(fftw_complex)*n_in); #else in = fftw_malloc(sizeof(fftw_complex)*n_in); out = fftw_malloc(sizeof(fftw_complex)*n_in); #endif for (i=0;i<n_in;i++) { #ifdef fftw2 c_re(in[i]) = data[i].r; c_im(in[i]) = data[i].i; #else in[i][0]=data[i].r; in[i][1]=data[i].i; #endif } #ifdef fftw2 p = fftw_create_plan(n_in, isign, FFTW_ESTIMATE); fftw_one(p,in,out); #else p = fftw_plan_dft_1d(n_in,in,out,isign,FFTW_ESTIMATE); fftw_execute(p); #endif if (isign==-1) { scale = 1.0/( (double)n_in); for (i=0;i<n_in;i++) { #ifdef fftw2 dataout[i].r=c_re(out[i])*scale; dataout[i].i=c_im(out[i])*scale; #else dataout[i].r=out[i][0]*scale; dataout[i].i=out[i][1]*scale; #endif } } else { for (i=0;i<n_in;i++) { #ifdef fftw2 dataout[i].r=c_re(out[i]); dataout[i].i=c_im(out[i]); #else dataout[i].r=out[i][0]; dataout[i].i=out[i][1]; #endif } } fftw_destroy_plan(p); #ifdef fftw2 free(out); free(in); #else fftw_free(out); fftw_free(in); #endif }
void test_in_place(int n, int istride, int howmany, fftw_direction dir, fftw_plan validated_plan, int specific) { fftw_complex *in1, *in2, *out2; fftw_plan plan; int i, j; int flags = measure_flag | wisdom_flag | FFTW_IN_PLACE; if (coinflip()) flags |= FFTW_THREADSAFE; in1 = (fftw_complex *) fftw_malloc(istride * n * sizeof(fftw_complex) * howmany); in2 = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex) * howmany); out2 = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex) * howmany); if (!specific) plan = fftw_create_plan(n, dir, flags); else plan = fftw_create_plan_specific(n, dir, flags, in1, istride, (fftw_complex *) NULL, 0); /* generate random inputs */ for (i = 0; i < n * howmany; ++i) { c_re(in1[i * istride]) = c_re(in2[i]) = DRAND(); c_im(in1[i * istride]) = c_im(in2[i]) = DRAND(); } /* * fill in other positions of the array, to make sure that * fftw doesn't overwrite them */ for (j = 1; j < istride; ++j) for (i = 0; i < n * howmany; ++i) { c_re(in1[i * istride + j]) = i * istride + j; c_im(in1[i * istride + j]) = i * istride - j; } CHECK(plan != NULL, "can't create plan"); WHEN_VERBOSE(2, fftw_print_plan(plan)); /* fft-ize */ if (howmany != 1 || istride != 1 || coinflip()) fftw(plan, howmany, in1, istride, n * istride, (fftw_complex *) NULL, 0, 0); else fftw_one(plan, in1, NULL); fftw_destroy_plan(plan); /* check for overwriting */ for (j = 1; j < istride; ++j) for (i = 0; i < n * howmany; ++i) CHECK(c_re(in1[i * istride + j]) == i * istride + j && c_im(in1[i * istride + j]) == i * istride - j, "input has been overwritten"); for (i = 0; i < howmany; ++i) { fftw(validated_plan, 1, in2 + n * i, 1, n, out2 + n * i, 1, n); } CHECK(compute_error_complex(in1, istride, out2, 1, n * howmany) < TOLERANCE, "test_in_place: wrong answer"); WHEN_VERBOSE(2, printf("OK\n")); fftw_free(in1); fftw_free(in2); fftw_free(out2); }
static void generate_proakis(void) { float f; float f1; float offset; float amp; float phase; float delay; float pw; int index; int i; int l; #if defined(HAVE_FFTW3_H) double in[FFT_SIZE][2]; double out[FFT_SIZE][2]; #else fftw_complex in[FFT_SIZE]; fftw_complex out[FFT_SIZE]; #endif fftw_plan p; #if defined(HAVE_FFTW3_H) p = fftw_plan_dft_1d(FFT_SIZE, in, out, FFTW_BACKWARD, FFTW_ESTIMATE); #else p = fftw_create_plan(FFT_SIZE, FFTW_BACKWARD, FFTW_ESTIMATE); #endif for (i = 0; i < FFT_SIZE; i++) { #if defined(HAVE_FFTW3_H) in[i][0] = in[i][1] = 0.0f; #else in[i].re = in[i].im = 0.0f; #endif } for (i = 1; i < FFT_SIZE/2; i++) { f = (float) i*SAMPLE_RATE/FFT_SIZE; f1 = f/200.0f; offset = f1 - floor(f1); index = (int) floor(f1); /* Linear interpolation */ amp = ((1.0f - offset)*proakis[index].amp + offset*proakis[index + 1].amp)/2.3f; delay = (1.0f - offset)*proakis[index].delay + offset*proakis[index + 1].delay; phase = 2.0f*M_PI*f*delay*0.001f; #if defined(HAVE_FFTW3_H) in[i][0] = amp*cosf(phase); in[i][1] = amp*sinf(phase); in[FFT_SIZE - i][0] = in[i][0]; in[FFT_SIZE - i][1] = -in[i][1]; #else in[i].re = amp*cosf(phase); in[i].im = amp*sinf(phase); in[FFT_SIZE - i].re = in[i].re; in[FFT_SIZE - i].im = -in[i].im; #endif } #if defined(HAVE_FFTW3_H) fftw_execute(p); #else fftw_one(p, in, out); #endif fprintf(outfile, "/* Medium range telephone line response\n"); fprintf(outfile, " (from p 537, Digital Communication, John G. Proakis */\n"); fprintf(outfile, "float proakis_line_model[] =\n"); fprintf(outfile, "{\n"); /* Normalise the filter's gain */ pw = 0.0f; l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2; for (i = 0; i < LINE_FILTER_SIZE; i++) { #if defined(HAVE_FFTW3_H) pw += out[l][0]*out[l][0]; #else pw += out[l].re*out[l].re; #endif if (++l == FFT_SIZE) l = 0; } pw = sqrt(pw); l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2; for (i = 0; i < LINE_FILTER_SIZE; i++) { #if defined(HAVE_FFTW3_H) impulse_responses[filter_sets][i] = out[l][0]/pw; #else impulse_responses[filter_sets][i] = out[l].re/pw; #endif fprintf(outfile, "%15.5f,\n", impulse_responses[filter_sets][i]); if (++l == FFT_SIZE) l = 0; } fprintf(outfile, "};\n\n"); filter_sets++; }
static void generate_ad_edd(void) { float f; float offset; float amp; float phase; float delay; float pw; #if defined(HAVE_FFTW3_H) double in[FFT_SIZE][2]; double out[FFT_SIZE][2]; #else fftw_complex in[FFT_SIZE]; fftw_complex out[FFT_SIZE]; #endif fftw_plan p; int i; int j; int k; int l; #if defined(HAVE_FFTW3_H) p = fftw_plan_dft_1d(FFT_SIZE, in, out, FFTW_BACKWARD, FFTW_ESTIMATE); #else p = fftw_create_plan(FFT_SIZE, FFTW_BACKWARD, FFTW_ESTIMATE); #endif for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { for (i = 0; i < FFT_SIZE; i++) { #if defined(HAVE_FFTW3_H) in[i][0] = in[i][1] = 0.0f; #else in[i].re = in[i].im = 0.0f; #endif } for (i = 1; i < FFT_SIZE/2; i++) { f = (float) i*SAMPLE_RATE/FFT_SIZE; amp = 0.0f; for (l = 0; l < (int) (sizeof(ad)/sizeof(ad[0])); l++) { if (f < ad[l].freq) break; } if (l < (int) (sizeof(ad)/sizeof(ad[0]))) { offset = (f - ad[l - 1].freq)/(ad[l].freq - ad[l - 1].freq); amp = (1.0 - offset)*ad[l - 1].ad[j] + offset*ad[l].ad[j]; amp = pow(10.0, -amp/20.0); } delay = 0.0f; for (l = 0; l < (int) (sizeof(edd)/sizeof(edd[0])); l++) { if (f < edd[l].freq) break; } if (l < (int) (sizeof(edd)/sizeof(edd[0]))) { offset = (f - edd[l - 1].freq)/(edd[l].freq - edd[l - 1].freq); delay = (1.0f - offset)*edd[l - 1].edd[k] + offset*edd[l].edd[k]; } phase = 2.0f*M_PI*f*delay*0.001f; #if defined(HAVE_FFTW3_H) in[i][0] = amp*cosf(phase); in[i][1] = amp*sinf(phase); in[FFT_SIZE - i][0] = in[i][0]; in[FFT_SIZE - i][1] = -in[i][1]; #else in[i].re = amp*cosf(phase); in[i].im = amp*sinf(phase); in[FFT_SIZE - i].re = in[i].re; in[FFT_SIZE - i].im = -in[i].im; #endif } #if 0 for (i = 0; i < FFT_SIZE; i++) fprintf(outfile, "%5d %15.5f,%15.5f\n", i, in[i].re, in[i].im); #endif #if defined(HAVE_FFTW3_H) fftw_execute(p); #else fftw_one(p, in, out); #endif fprintf(outfile, "/* V.56bis AD-%d, EDD%d */\n", (j == 0) ? 1 : j + 4, k + 1); fprintf(outfile, "float ad_%d_edd_%d_model[] =\n", (j == 0) ? 1 : j + 4, k + 1); fprintf(outfile, "{\n"); /* Normalise the filter's gain */ pw = 0.0f; l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2; for (i = 0; i < LINE_FILTER_SIZE; i++) { #if defined(HAVE_FFTW3_H) pw += out[l][0]*out[l][0]; #else pw += out[l].re*out[l].re; #endif if (++l == FFT_SIZE) l = 0; } pw = sqrt(pw); l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2; for (i = 0; i < LINE_FILTER_SIZE; i++) { #if defined(HAVE_FFTW3_H) impulse_responses[filter_sets][i] = out[l][0]/pw; #else impulse_responses[filter_sets][i] = out[l].re/pw; #endif fprintf(outfile, "%15.5f,\n", impulse_responses[filter_sets][i]); if (++l == FFT_SIZE) l = 0; } fprintf(outfile, "};\n\n"); filter_sets++; } } }
int main(int argc, char **argv) { int c, mu, status; int filename_set = 0; int mode = 0; int l_LX_at, l_LXstart_at; int x0, x1, x2, x3, ix, iix, iiy, gid, iclass; int Thp1, nclass; int *picount; double *conn = (double*)NULL; double *conn2 = (double*)NULL; double q[4], qsqr; int verbose = 0; char filename[800]; double ratime, retime; int *qid=NULL, *qcount=NULL, **qrep=NULL, **qmap=NULL; double **qlist=NULL, qmax=0.; int VOL3; FILE *ofs; fftw_complex *corrt=NULL; fftw_complex *pi00=(fftw_complex*)NULL, *pijj=(fftw_complex*)NULL, *piavg=(fftw_complex*)NULL; fftw_plan plan_m; while ((c = getopt(argc, argv, "h?vf:m:q:")) != -1) { switch (c) { case 'v': verbose = 1; break; case 'f': strcpy(filename, optarg); filename_set=1; break; case 'm': mode = atoi(optarg); break; case 'q': qmax = atof(optarg); fprintf(stdout, "\n# [] qmax set to %e\n", qmax); break; case 'h': case '?': default: usage(); break; } } /* set the default values */ if(filename_set==0) strcpy(filename, "cvc.input"); fprintf(stdout, "# Reading input from file %s\n", filename); read_input_parser(filename); /* some checks on the input data */ if((T_global == 0) || (LX==0) || (LY==0) || (LZ==0)) { if(g_proc_id==0) fprintf(stdout, "T and L's must be set\n"); usage(); } /* initialize MPI parameters */ mpi_init(argc, argv); /* initialize fftw, create plan with FFTW_FORWARD --- in contrast to * FFTW_BACKWARD in e.g. avc_exact */ plan_m = fftw_create_plan(T_global, FFTW_FORWARD, FFTW_MEASURE | FFTW_IN_PLACE); if(plan_m==NULL) { fprintf(stderr, "Error, could not create fftw plan\n"); return(1); } T = T_global; Thp1 = T/2 + 1; Tstart = 0; l_LX_at = LX; l_LXstart_at = 0; FFTW_LOC_VOLUME = T*LX*LY*LZ; fprintf(stdout, "# [%2d] fftw parameters:\n"\ "# [%2d] T = %3d\n"\ "# [%2d] Tstart = %3d\n"\ "# [%2d] l_LX_at = %3d\n"\ "# [%2d] l_LXstart_at = %3d\n"\ "# [%2d] FFTW_LOC_VOLUME = %3d\n", g_cart_id, g_cart_id, T, g_cart_id, Tstart, g_cart_id, l_LX_at, g_cart_id, l_LXstart_at, g_cart_id, FFTW_LOC_VOLUME); if(init_geometry() != 0) { fprintf(stderr, "ERROR from init_geometry\n"); exit(1); } geometry(); VOL3 = LX*LY*LZ; status = make_qlatt_orbits_3d_parity_avg(&qid, &qcount, &qlist, &nclass, &qrep, &qmap); if(status != 0) { fprintf(stderr, "\n[] Error while creating h4-lists\n"); exit(4); } fprintf(stdout, "# [] number of classes = %d\n", nclass); // exit(255); /**************************************** * allocate memory for the contractions * ****************************************/ conn = (double*)calloc(32*VOLUME, sizeof(double)); if( (conn==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for contr. fields\n"); exit(3); } /* conn2 = (double*)calloc(32*VOLUME, sizeof(double)); if( (conn2==(double*)NULL) ) { fprintf(stderr, "could not allocate memory for contr. fields\n"); exit(4); } pi00 = (fftw_complex*)malloc(VOLUME*sizeof(fftw_complex)); if( (pi00==(fftw_complex*)NULL) ) { fprintf(stderr, "could not allocate memory for pi00\n"); exit(2); } pijj = (fftw_complex*)fftw_malloc(VOLUME*sizeof(fftw_complex)); if( (pijj==(fftw_complex*)NULL) ) { fprintf(stderr, "could not allocate memory for pijj\n"); exit(2); } */ corrt = fftw_malloc(T*sizeof(fftw_complex)); if(corrt == NULL) { fprintf(stderr, "\nError, could not alloc corrt\n"); exit(3); } for(gid=g_gaugeid; gid<=g_gaugeid2; gid+=g_gauge_step) { // for(ix=0; ix<VOLUME; ix++) {pi00[ix].re = 0.; pi00[ix].im = 0.;} // for(ix=0; ix<VOLUME; ix++) {pijj[ix].re = 0.; pijj[ix].im = 0.;} /*********************** * read contractions * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; sprintf(filename, "%s.%.4d", filename_prefix, gid); fprintf(stdout, "# Reading data from file %s\n", filename); if(format==2) { status = read_contraction(conn, NULL, filename, 16); } else { status = read_lime_contraction(conn, filename, 16, 0); } if(status != 0) { fprintf(stderr, "Error: could not read from file %s; status was %d\n", filename, status); continue; } /* sprintf(filename, "%s.%.4d.%.4d", filename_prefix2, gid); fprintf(stdout, "# Reading data from file %s\n", filename); status = read_lime_contraction(conn2, filename, 16, 0); if(status == 106) { fprintf(stderr, "Error: could not read from file %s; status was %d\n", filename, status); continue; } */ retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time to read contractions %e seconds\n", retime-ratime); /*********************** * fill the correlator * ***********************/ ratime = (double)clock() / CLOCKS_PER_SEC; /* for(x1=0; x1<LX; x1++) { for(x2=0; x2<LY; x2++) { for(x3=0; x3<LZ; x3++) { for(x0=0; x0<T; x0++) { iix = g_ipt[0][x1][x2][x3]*T+x0; for(mu=1; mu<4; mu++) { ix = _GWI(5*mu,g_ipt[x0][x1][x2][x3],VOLUME); pijj[iix].re += ( conn[ix ] - conn2[ix ] ) * (double)Nsave / (double)(Nsave-1); pijj[iix].im += ( conn[ix+1] - conn2[ix+1] ) * (double)Nsave / (double)(Nsave-1); } ix = 2*g_ipt[x0][x1][x2][x3]; pi00[iix].re += ( conn[ix ] - conn2[ix ] ) * (double)Nsave / (double)(Nsave-1); pi00[iix].im += ( conn[ix+1] - conn2[ix+1] ) * (double)Nsave / (double)(Nsave-1); } }}} */ for(iclass=0;iclass<nclass;iclass++) { if(qlist[iclass][0] >= qmax) { // fprintf(stdout, "\n# [] will skip class %d, momentum squared = %f is too large\n", iclass, qlist[iclass][0]); continue; // } else { // fprintf(stdout, "\n# [] processing class %d, momentum squared = %f\n", iclass, qlist[iclass][0]); } for(x0=0; x0<T; x0++) { corrt[x0].re = 0.; corrt[x0].im = 0.; } /* for(x1=0;x1<VOL3;x1++) { if(qid[x1]==iclass) { fprintf(stdout, "# using mom %d ---> (%d, %d, %d)\n", x1, qrep[iclass][1], qrep[iclass][2], qrep[iclass][3]); for(x0=0; x0<T; x0++) { ix = x0*VOL3 + x1; corrt[x0].re += conn[_GWI(5,ix,VOLUME) ] + conn[_GWI(10,ix,VOLUME) ] + conn[_GWI(15,ix,VOLUME) ]; corrt[x0].im += conn[_GWI(5,ix,VOLUME)+1] + conn[_GWI(10,ix,VOLUME)+1] + conn[_GWI(15,ix,VOLUME)+1]; } } } */ for(x0=0; x0<T; x0++) { for(x1=0;x1<qcount[iclass];x1++) { x2 = qmap[iclass][x1]; // if(x0==0) fprintf(stdout, "# using mom %d ---> (%d, %d, %d)\n", x2, qrep[iclass][1], qrep[iclass][2], qrep[iclass][3]); ix = x0*VOL3 + x2; corrt[x0].re += conn[_GWI(5,ix,VOLUME) ] + conn[_GWI(10,ix,VOLUME) ] + conn[_GWI(15,ix,VOLUME) ]; corrt[x0].im += conn[_GWI(5,ix,VOLUME)+1] + conn[_GWI(10,ix,VOLUME)+1] + conn[_GWI(15,ix,VOLUME)+1]; } } // fprintf(stdout, "\n\n# ------------------------------\n"); for(x0=0; x0<T; x0++) { corrt[x0].re /= (double)T * qcount[iclass]; corrt[x0].im /= (double)T * qcount[iclass]; } /* fftw(plan_m, 1, corrt, 1, T, (fftw_complex*)NULL, 0, 0); */ fftw_one(plan_m, corrt, NULL); sprintf(filename, "rho.%.4d.x%.2dy%.2dz%.2d", gid, qrep[iclass][1], qrep[iclass][2], qrep[iclass][3]); if( (ofs=fopen(filename, "w")) == (FILE*)NULL ) { fprintf(stderr, "Error: could not open file %s for writing\n", filename); exit(5); } fprintf(stdout, "# writing VKVK data to file %s\n", filename); fprintf(ofs, "# %6d%3d%3d%3d%3d%12.7f%12.7f%21.12f\n", gid, T_global, LX, LY, LZ, g_kappa, g_mu, qlist[iclass][0]); fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, 0, corrt[0].re, 0., gid); for(x0=1; x0<(T/2); x0++) { fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, x0, corrt[x0].re, corrt[T-x0].re, gid); } fprintf(ofs, "%3d%3d%3d%25.16e%25.16e%6d\n", 0, 0, (T/2), corrt[T/2].re, 0., gid); fflush(ofs); fclose(ofs); retime = (double)clock() / CLOCKS_PER_SEC; fprintf(stdout, "# time to fill correlator %e seconds\n", retime-ratime); } // of loop on classes } // end of loop on gauge id /*************************************** * free the allocated memory, finalize * ***************************************/ if(corrt != NULL) free(corrt); free_geometry(); if(pi00 != NULL) free(pi00); if(pijj != NULL) free(pijj); fftw_destroy_plan(plan_m); finalize_q_orbits(&qid, &qcount, &qlist, &qrep); if(qmap != NULL) { free(qmap[0]); free(qmap); } if(g_cart_id == 0) { g_the_time = time(NULL); fprintf(stdout, "\n# [] %s# [] end of run\n", ctime(&g_the_time)); fprintf(stderr, "\n# [] %s# [] end of run\n", ctime(&g_the_time)); } return(0); }