예제 #1
0
void run_monopole_corr_neighbors(Catalog cat_dat,double *corr,
								 double *ercorr,unsigned long long *DD,
								 int nb_r, double r_max, int nthreads)
{
  //////
  // Main routine for monopole using neighbor boxes
  
  // lint n_dat;
  int nside;
  // Catalog cat_dat;
  NeighborBox *boxes;

  nside=optimal_nside(l_box,r_max,cat_dat.np);
  boxes=catalog_to_boxes(nside,cat_dat);


//  printf("*** Correlating\n");
 // timer(0);
  corr_mono_box_neighbors(nside,boxes,cat_dat.np, cat_dat.pos,DD,nb_r,r_max,nthreads);
  
 // timer(1);

  make_CF(DD,cat_dat.np,corr,ercorr,nb_r,r_max);
  // write_CF(fnameOut,corr,ercorr,DD);

  free_catalog(cat_dat);
  free_boxes(nside,boxes);

 // timer(5);
}
예제 #2
0
파일: io.c 프로젝트: flaviasobreira/CUTE
void write_CF_cuda(char *fname,unsigned long long *DD,
		   unsigned long long *DR,unsigned long long *RR,
		   int nD,int nR)
{
  //////
  // Writes correlation function to file fname
  FILE *fo;
  int ii;

  print_info("*** Writing output file ");
#ifdef _VERBOSE
  print_info("%s ",fname);
#endif
  print_info("\n");

  fo=fopen(fname,"w");
  if(fo==NULL) {
    char oname[64]="output_CUTE.dat";
    fprintf(stderr,"Error opening output file %s",fname);
    fprintf(stderr," using ./output_CUTE.dat");
    fo=fopen(oname,"w");
    if(fo==NULL) error_open_file(oname);
  }

  if(corr_type==1) {
    for(ii=0;ii<NB_HISTO_1D;ii++) {
      double th;
      double corr,ercorr;
      make_CF((histo_t)(DD[ii]),(histo_t)(DR[ii]),
	      (histo_t)(RR[ii]),(np_t)(nD),(np_t)(nD),
	      (np_t)(nR),(np_t)(nR),&corr,&ercorr);
      if(logbin)
	th=pow(10,((ii+0.5)-NB_HISTO_1D)/n_logint+log_th_max)/DTORAD;
      else
      th=(ii+0.5)/(NB_HISTO_1D*i_theta_max*DTORAD);

      fprintf(fo,"%lE %lE %lE %llu %llu %llu\n",
	      th,corr,ercorr,DD[ii],DR[ii],RR[ii]);
    }
  }
  else if(corr_type==2) {
    for(ii=0;ii<NB_HISTO_1D;ii++) {
      double rr;
      double corr,ercorr;
      make_CF((histo_t)(DD[ii]),(histo_t)(DR[ii]),
	      (histo_t)(RR[ii]),(np_t)(nD),(np_t)(nD),
	      (np_t)(nR),(np_t)(nR),&corr,&ercorr);
      if(logbin)
	rr=pow(10,((ii+0.5)-NB_HISTO_1D)/n_logint+log_r_max);
      else
	rr=(ii+0.5)/(NB_HISTO_1D*i_r_max);

      fprintf(fo,"%lE %lE %lE %llu %llu %llu\n",
	      rr,corr,ercorr,DD[ii],DR[ii],RR[ii]);
    }
  }
  else if(corr_type==3) {
    for(ii=0;ii<NB_HISTO_2D;ii++) {
      int jj;
      double rt=(ii+0.5)/(NB_HISTO_2D*i_rt_max);
      for(jj=0;jj<NB_HISTO_2D;jj++) {
	double corr,ercorr;
	double rl=(jj+0.5)/(NB_HISTO_2D*i_rl_max);
	int ind=jj+NB_HISTO_2D*ii;
	make_CF((histo_t)(DD[ind]),(histo_t)(DR[ind]),
		(histo_t)(RR[ind]),(np_t)(nD),(np_t)(nD),
		(np_t)(nR),(np_t)(nR),&corr,&ercorr);
	fprintf(fo,"%lE %lE %lE %lE %llu %llu %llu\n",
		rl,rt,corr,ercorr,DD[ind],DR[ind],RR[ind]);
      }
    }
  }
  else if(corr_type==4) {
    for(ii=0;ii<NB_HISTO_2D;ii++) {
      int jj;
      double mu=(ii+0.5)/(NB_HISTO_2D);
      for(jj=0;jj<NB_HISTO_2D;jj++) {
	double corr,ercorr;
	double rr;
	if(logbin)
	  rr=pow(10,((jj+0.5)-NB_HISTO_2D)/n_logint+log_r_max);
	else
	  rr=(jj+0.5)/(NB_HISTO_2D*i_r_max);

	int ind=jj+NB_HISTO_2D*ii;
	make_CF((histo_t)(DD[ind]),(histo_t)(DR[ind]),
		(histo_t)(RR[ind]),(np_t)(nD),(np_t)(nD),
		(np_t)(nR),(np_t)(nR),&corr,&ercorr);
	fprintf(fo,"%lE %lE %lE %lE %llu %llu %llu\n",
		mu,rr,corr,ercorr,DD[ind],DR[ind],RR[ind]);
      }
    }
  }
  fclose(fo);
  
  print_info("\n");
}
예제 #3
0
파일: io.c 프로젝트: flaviasobreira/CUTE
void write_CF(char *fname,
	      histo_t *DD,histo_t *DR,histo_t *RR,
	      np_t sum_wd,np_t sum_wd2,
	      np_t sum_wr,np_t sum_wr2)
{
  //////
  // Writes correlation function to file fname
#ifdef _HAVE_MPI
  int n_bins_all=0;

  if(corr_type==0)
    n_bins_all=nb_dz;
  else if(corr_type==1)
    n_bins_all=nb_theta;
  else if(corr_type==2)
    n_bins_all=nb_r;
  else if(corr_type==3)
    n_bins_all=nb_rt*nb_rl;
  else if(corr_type==4)
    n_bins_all=nb_r*nb_mu;
  else if(corr_type==5)
    n_bins_all=nb_red*nb_dz*nb_theta;
  else if(corr_type==6)
    n_bins_all=nb_theta*((nb_red*(nb_red+1))/2);

  if(NodeThis==0)
    MPI_Reduce(MPI_IN_PLACE,DD,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
  else
    MPI_Reduce(DD,NULL,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
  if(NodeThis==0)
    MPI_Reduce(MPI_IN_PLACE,DR,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
  else
    MPI_Reduce(DR,NULL,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
  if(NodeThis==0)
    MPI_Reduce(MPI_IN_PLACE,RR,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
  else
    MPI_Reduce(RR,NULL,n_bins_all,HISTO_T_MPI,MPI_SUM,0,MPI_COMM_WORLD);
#endif //_HAVE_MPI

  if(NodeThis==0) {
    FILE *fo;
    int ii;
    
    print_info("*** Writing output file ");
#ifdef _VERBOSE
    print_info("%s ",fname);
#endif
    print_info("\n");

    fo=fopen(fname,"w");
    if(fo==NULL) {
      char oname[64]="output_CUTE.dat";
      fprintf(stderr,"Error opening output file %s",fname);
      fprintf(stderr," using ./output_CUTE.dat");
      fo=fopen(oname,"w");
      if(fo==NULL) error_open_file(oname);
    }
    
    if(corr_type==0) {
      for(ii=0;ii<nb_dz;ii++) {
	double dz;
	double corr,ercorr;
	make_CF(DD[ii],DR[ii],RR[ii],sum_wd,sum_wd2,
		sum_wr,sum_wr2,&corr,&ercorr);
	dz=(ii+0.5)/(nb_dz*i_dz_max);
	fprintf(fo,"%lE %lE %lE ",dz,corr,ercorr);
#ifdef _WITH_WEIGHTS
	fprintf(fo,"%lE %lE %lE\n",DD[ii],DR[ii],RR[ii]);
#else //_WITH_WEIGHTS
	fprintf(fo,"%llu %llu %llu\n",DD[ii],DR[ii],RR[ii]);
#endif //_WITH_WEIGHTS
      }
    }
    else if(corr_type==1) {
      for(ii=0;ii<nb_theta;ii++) {
	double th;
	double corr,ercorr;
	make_CF(DD[ii],DR[ii],RR[ii],sum_wd,sum_wd2,
		sum_wr,sum_wr2,&corr,&ercorr);
	if(logbin)
	  th=pow(10,((ii+0.5)-nb_theta)/n_logint+log_th_max)/DTORAD;
	else
	  th=(ii+0.5)/(nb_theta*i_theta_max*DTORAD);
	
	fprintf(fo,"%lE %lE %lE ",th,corr,ercorr);
#ifdef _WITH_WEIGHTS
	fprintf(fo,"%lE %lE %lE\n",DD[ii],DR[ii],RR[ii]);
#else //_WITH_WEIGHTS
	fprintf(fo,"%llu %llu %llu\n",DD[ii],DR[ii],RR[ii]);
#endif //_WITH_WEIGHTS
      }
    }
    else if(corr_type==2) {
      for(ii=0;ii<nb_r;ii++) {
	double rr;
	double corr,ercorr;
	make_CF(DD[ii],DR[ii],RR[ii],sum_wd,sum_wd2,
		sum_wr,sum_wr2,&corr,&ercorr);
	if(logbin)
	  rr=pow(10,((ii+0.5)-nb_r)/n_logint+log_r_max);
	else
	  rr=(ii+0.5)/(nb_r*i_r_max);
	
	fprintf(fo,"%lE %lE %lE ",rr,corr,ercorr);
#ifdef _WITH_WEIGHTS
	fprintf(fo,"%lE %lE %lE\n",DD[ii],DR[ii],RR[ii]);
#else //_WITH_WEIGHTS
	fprintf(fo,"%llu %llu %llu\n",DD[ii],DR[ii],RR[ii]);
#endif //_WITH_WEIGHTS
      }
    }
    else if(corr_type==3) {
      for(ii=0;ii<nb_rt;ii++) {
	int jj;
	double rt=(ii+0.5)/(nb_rt*i_rt_max);
	for(jj=0;jj<nb_rl;jj++) {
	  double corr,ercorr;
	  double rl=(jj+0.5)/(nb_rl*i_rl_max);
	  int ind=jj+nb_rl*ii;
	  make_CF(DD[ind],DR[ind],RR[ind],sum_wd,sum_wd2,
		  sum_wr,sum_wr2,&corr,&ercorr);
	  fprintf(fo,"%lE %lE %lE %lE ",rl,rt,corr,ercorr);
#ifdef _WITH_WEIGHTS
	  fprintf(fo,"%lE %lE %lE\n",DD[ind],DR[ind],RR[ind]);
#else //_WITH_WEIGHTS
	  fprintf(fo,"%llu %llu %llu\n",DD[ind],DR[ind],RR[ind]);
#endif //_WITH_WEIGHTS
	}
      }
    }
    else if(corr_type==4) {
      for(ii=0;ii<nb_r;ii++) {
	int jj;
	double rr;
	if(logbin)
	  rr=pow(10,((ii+0.5)-nb_r)/n_logint+log_r_max);
	else
	  rr=(ii+0.5)/(nb_r*i_r_max);
	
	for(jj=0;jj<nb_mu;jj++) {
	  double corr,ercorr;
	  double mu=(jj+0.5)/(nb_mu);
	  int ind=jj+nb_mu*ii;
	  make_CF(DD[ind],DR[ind],RR[ind],sum_wd,sum_wd2,
		  sum_wr,sum_wr2,&corr,&ercorr);
	  fprintf(fo,"%lE %lE %lE %lE ",mu,rr,corr,ercorr);
#ifdef _WITH_WEIGHTS
	  fprintf(fo,"%lE %lE %lE\n",DD[ind],DR[ind],RR[ind]);
#else //_WITH_WEIGHTS
	  fprintf(fo,"%llu %llu %llu\n",DD[ind],DR[ind],RR[ind]);
#endif //_WITH_WEIGHTS
	}
      }
    }
    else if(corr_type==5) {
      for(ii=0;ii<nb_red;ii++) {
	int jj;
	double z_mean=red_0+(ii+0.5)/(i_red_interval*nb_red);
	for(jj=0;jj<nb_dz;jj++) {
	  int kk;
	  double dz=(jj+0.5)/(nb_dz*i_dz_max);
	  for(kk=0;kk<nb_theta;kk++) {
	    double theta;
	    int index=kk+nb_theta*(jj+nb_dz*ii);
	    double corr,ercorr;
	    if(logbin)
	      theta=pow(10,((kk+0.5)-nb_theta)/n_logint+log_th_max)/DTORAD;
	    else
	      theta=(kk+0.5)/(nb_theta*i_theta_max*DTORAD);
	    make_CF(DD[index],DR[index],RR[index],sum_wd,sum_wd2,
		    sum_wr,sum_wr2,&corr,&ercorr);
	    fprintf(fo,"%lE %lE %lE %lE %lE ",z_mean,dz,theta,corr,ercorr);
#ifdef _WITH_WEIGHTS
	    fprintf(fo,"%lE %lE %lE\n",DD[index],DR[index],RR[index]);
#else //_WITH_WEIGHTS
	    fprintf(fo,"%llu %llu %llu\n",DD[index],DR[index],RR[index]);
#endif //_WITH_WEIGHTS
	  }
	}
      }
    }
    else if(corr_type==6) {
      for(ii=0;ii<nb_red;ii++) {
	int jj;
	double z1=red_0+(ii+0.5)/(i_red_interval*nb_red);
	for(jj=ii;jj<nb_red;jj++) {
	  int kk;
	  double z2=red_0+(jj+0.5)/(i_red_interval*nb_red);
	  for(kk=0;kk<nb_theta;kk++) {
	    double theta;
	    //	  int index=kk+nb_theta*(jj+nb_red*ii);
	    int index=kk+nb_theta*((ii*(2*nb_red-ii-1))/2+jj);
	    double corr,ercorr;
	    if(logbin)
	      theta=pow(10,((kk+0.5)-nb_theta)/n_logint+log_th_max)/DTORAD;
	    else
	      theta=(kk+0.5)/(nb_theta*i_theta_max*DTORAD);
	    make_CF(DD[index],DR[index],RR[index],sum_wd,sum_wd2,
		    sum_wr,sum_wr2,&corr,&ercorr);
	    fprintf(fo,"%lE %lE %lE %lE %lE ",z1,z2,theta,corr,ercorr);
#ifdef _WITH_WEIGHTS
	    fprintf(fo,"%lE %lE %lE\n",DD[index],DR[index],RR[index]);
#else //_WITH_WEIGHTS
	    fprintf(fo,"%llu %llu %llu\n",DD[index],DR[index],RR[index]);
#endif //_WITH_WEIGHTS
	  }
	}
      }
    }
    fclose(fo);
    
    printf("\n");
  }
}