コード例 #1
0
ファイル: contractions_io_3d.c プロジェクト: etmc/cvc
/****************************************************
 * write_binary_contraction_data
 ****************************************************/
int write_binary_contraction_data_3d(double * const s, LimeWriter * limewriter, const int prec, const int N, DML_Checksum * ans) {
#ifdef MPI
  fprintf(stderr, "[write_binary_contraction_data_3d] No mpi version.\n");
  return(1);
#else
  int x, y, z, i=0, mu, status=0;
  double *tmp;
  float  *tmp2;
  int proc_coords[4], tloc,xloc,yloc,zloc, proc_id;
  n_uint64_t bytes;
  DML_SiteRank rank;
  int words_bigendian = big_endian();
  unsigned int VOL3 = LX*LY*LZ;
  DML_checksum_init(ans);

  tmp = (double*)malloc(2*N*sizeof(double));
  tmp2 = (float*)malloc(2*N*sizeof(float));

  if(prec == 32) bytes = (n_uint64_t)2*N*sizeof(float);
  else bytes = (n_uint64_t)2*N*sizeof(double);

  if(g_cart_id==0) {
      for(x = 0; x < LX; x++) {
      for(y = 0; y < LY; y++) {
      for(z = 0; z < LZ; z++) {
        /* Rank should be computed by proc 0 only */
        rank = (DML_SiteRank) (( x * LY + y)*LZ + z);
        for(mu=0; mu<N; mu++) {
          i = _GWI(mu, g_ipt[0][x][y][z], VOL3);
          if(!words_bigendian) {
            if(prec == 32) {
              byte_swap_assign_double2single( (tmp2+2*mu), (s + i), 2);
            } else {
              byte_swap_assign( (tmp+2*mu), (s + i), 2);
            }
          } else {
            if(prec == 32) {
              double2single((float*)(tmp2+2*mu), (s + i), 2);
            } else {
              tmp[2*mu  ] = s[i  ];
              tmp[2*mu+1] = s[i+1];
            }
          }
        }
        if(prec == 32) {
          DML_checksum_accum(ans,rank,(char *) tmp2,2*N*sizeof(float));
          status = limeWriteRecordData((void*)tmp2, &bytes, limewriter);
        }
        else {
          status = limeWriteRecordData((void*)tmp, &bytes, limewriter);
          DML_checksum_accum(ans,rank,(char *) tmp, 2*N*sizeof(double));
        }
      }}}
  }
  free(tmp2);
  free(tmp);
  return(0);
#endif
}
コード例 #2
0
ファイル: io.c プロジェクト: robfre21/tmLQCD
int read_lime_gauge_field_doubleprec(double * config, char * filename,
                                     const int T, const int LX, const int LY, const int LZ) {
    FILE * ifs;
    int t, x, y, z, status, p=0;
    n_uint64_t bytes;
    char * header_type;
    LimeReader * limereader;
    double tmp[72];
    int words_bigendian;

    words_bigendian = big_endian();
    ifs = fopen(filename, "r");
    if(ifs == (FILE *)NULL) {
        fprintf(stderr, "Could not open file %s\n Aborting...\n", filename);
        exit(500);
    }
    limereader = limeCreateReader( ifs );
    if( limereader == (LimeReader *)NULL ) {
        fprintf(stderr, "Unable to open LimeReader\n");
        exit(500);
    }
    while( (status = limeReaderNextRecord(limereader)) != LIME_EOF ) {
        if(status != LIME_SUCCESS ) {
            fprintf(stderr, "limeReaderNextRecord returned error with status = %d!\n", status);
            status = LIME_EOF;
            break;
        }
        header_type = limeReaderType(limereader);
        if(!strcmp("ildg-binary-data",header_type)) break;
    }
    if(status == LIME_EOF) {
        fprintf(stderr, "no ildg-binary-data record found in file %s\n",filename);
        limeDestroyReader(limereader);
        fclose(ifs);
        exit(-2);
    }
    bytes = limeReaderBytes(limereader);
    if((int)bytes != LX*LY*LZ*T*72*sizeof(double)) {
        fprintf(stderr, "Probably wrong lattice size or precision (bytes=%d) in file %s\n", (int)bytes, filename);
        fprintf(stderr, "Aborting...!\n");
        fflush( stdout );
        exit(501);
    }

    bytes = (n_uint64_t)72*sizeof(double);

    for(t = 0; t < T; t++) {
        for(z = 0; z < LZ; z++) {
            for(y = 0; y < LY; y++) {
                for(x = 0; x < LX; x++) {
                    p = (((t*LZ+z)*LY+y)*LX+x)*72;
                    if(!words_bigendian) {
                        status = limeReaderReadData(tmp, &bytes, limereader);
                        byte_swap_assign(&config[p], tmp, 72);
                    }
                    else {
                        status = limeReaderReadData(&config[p], &bytes, limereader);
                    }
                    if(status < 0 && status != LIME_EOR) {
                        fprintf(stderr, "LIME read error occured with status = %d while reading file %s!\n Aborting...\n",
                                status, filename);
                        exit(500);
                    }
                }
            }
        }
    }
    limeDestroyReader(limereader);
    fclose(ifs);
    return(0);
}
コード例 #3
0
ファイル: GaugeField.cpp プロジェクト: maowerner/cntr.v0.1
// Read in the gaugefield, deprecated tmLqcd routine
void GaugeField::read_lime_gauge_field_doubleprec_timeslices(double *gaugefield,
                                                             const char *filename,
                                                             const ssize_t slice_i,
                                                             const ssize_t slice_f) {
  try {
    // const int slice_i = 0;
    // const int slice_f = Lt+1;

    FILE *ifs;
    ssize_t t, x, y, z;
    int status;
    n_uint64_t bytes;
    char *header_type;
    LimeReader *limereader;
    double tmp[72], tmp2[72];
    int words_bigendian;

    printf("reading gauge fields from files:\n");
    //    if(verbose){
    //      printf("reading gauge fields from files:\n");
    //    }
    //    else{
    //      printf("\treading gauge fields:\n");
    //    }

    words_bigendian = big_endian();
    ifs = fopen(filename, "r");
    if (ifs == (FILE *)NULL) {
      fprintf(stderr, "Could not open file %s\n Aborting...\n", filename);
      exit(500);
    }
    limereader = limeCreateReader(ifs);
    if (limereader == (LimeReader *)NULL) {
      throw std::runtime_error("Unable to open LimeReader!");
    }
    while ((status = limeReaderNextRecord(limereader)) != LIME_EOF) {
      if (status != LIME_SUCCESS) {
        fprintf(
            stderr, "limeReaderNextRecord returned error with status = %d!\n", status);
        status = LIME_EOF;
        break;
      }
      header_type = limeReaderType(limereader);
      if (strcmp("ildg-binary-data", header_type) == 0)
        break;
    }
    if (status == LIME_EOF) {
      fprintf(stderr, "no ildg-binary-data record found in file %s\n", filename);
      limeDestroyReader(limereader);
      fclose(ifs);
      exit(-2);
    }
    bytes = limeReaderBytes(limereader);
    if (bytes != (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double)) {
      if (bytes != (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double) / 2) {
        fprintf(stderr,
                "Probably wrong lattice size or precision (bytes=%lu) in file %s "
                "expected %lu\n",
                (n_uint64_t)bytes,
                filename,
                (n_uint64_t)Lx * Ly * Lz * Lt * 72 * (n_uint64_t)sizeof(double));
        fprintf(stderr, "Aborting...!\n");
        fflush(stdout);
        exit(501);
      } else {
        fclose(ifs);
        throw std::runtime_error("Single precision read!");
      }
    }

    bytes = (n_uint64_t)72 * sizeof(double);

    for (t = 0; t < Lt; t++) {
      for (z = 0; z < Lz; z++) {
        for (y = 0; y < Ly; y++) {
          for (x = 0; x < Lx; x++) {
            // check for endianess and reading in data
            // the pointer limereader is internally increased by bytes
            // in the limeReaderReadData function
            if (!words_bigendian) {
              status = limeReaderReadData(tmp, &bytes, limereader);
              byte_swap_assign(tmp2, tmp, 72);
            } else
              status = limeReaderReadData(tmp2, &bytes, limereader);
            // check if reading was successfull
            if (status < 0 && status != LIME_EOR) {
              fprintf(stderr,
                      "LIME read error occured with status = %d while reading file %s!\n "
                      "Aborting...\n",
                      status,
                      filename);
              exit(500);
            }

            // we just want to read in data in the specific range of timeslices
            // must be here because the limereader pointer must be increased
            // correctly
            // could be done with much more performance but might be tricky to
            // do correctly
            if (t < slice_i || t > slice_f)
              continue;

            // copy of link variables from tmp2 into config
            // ILDG has mu-order: x,y,z,t so it is changed here to: t,x,y,z !
            const ssize_t p =
                (ssize_t)(((t - slice_i) * Lx * Lz * Lz + x * Ly * Lz + y * Lz + z) *
                          72);  // position in config
            ssize_t k = 0;
            for (ssize_t mu = 1; mu <= 4; mu++) {  // mu=4 is for the shift of U_t
              ssize_t index;
              if (mu != 4)
                index = p + mu * 18;  // for U_x, U_y and U_z
              else
                index = p;  // U_t is copied into the beginning of
              // the (config+p) array

              for (ssize_t i = 0; i < 3; i++) {
                for (ssize_t j = 0; j < 3; j++) {
                  gaugefield[index + 6 * i + 2 * j] = tmp2[2 * k];
                  gaugefield[index + 6 * i + 2 * j + 1] = tmp2[2 * k + 1];
                  k++;
                }
              }

            }  // loop over mu ends here

          }  // loop over position space ends here
        }
      }
    }
    if (status < 0 && status != LIME_EOR) {
      fprintf(stderr,
              "LIME read error occured with status = %d while reading file %s!\n "
              "Aborting...\n",
              status,
              filename);
      exit(500);
    }
    limeDestroyReader(limereader);
    fclose(ifs);
    return;

  } catch (std::exception &e) {
    std::cout << e.what()
              << "in: ReadWrite::read_lime_gauge_field_doubleprec_timeslices\n";
    throw e;
  }
}
コード例 #4
0
ファイル: contractions_io_3d.c プロジェクト: etmc/cvc
int read_binary_contraction_data_3d(double * const s, LimeReader * limereader, const int prec, const int N, DML_Checksum *ans) {
#ifdef MPI
  fprintf(stderr, "[read_binary_contraction_data_3d] No mpi version.\n");
  return(1);
#else
  int status=0, mu;
  n_uint64_t bytes, ix;
  double *tmp;
  DML_SiteRank rank;
  float *tmp2;
  int x, y, z;
  int words_bigendian = big_endian();
  unsigned int VOL3 = LX * LY * LZ;

  DML_checksum_init(ans);
  rank = (DML_SiteRank) 0;
 
  if( (tmp = (double*)malloc(2*N*sizeof(double))) == (double*)NULL ) {
    exit(500);
  }
  if( (tmp2 = (float*)malloc(2*N*sizeof(float))) == (float*)NULL ) {
    exit(501);
  }
 
 
  if(prec == 32) bytes = 2*N*sizeof(float);
  else bytes = 2*N*sizeof(double);
  for(x = 0; x < LX; x++){
  for(y = 0; y < LY; y++){
  for(z = 0; z < LZ; z++){
    ix = g_ipt[0][x][y][z];
    rank = (DML_SiteRank) (( LXstart + x)*(LY*g_nproc_y) + LYstart + y)*LZ + z;
    if(prec == 32) {
      status = limeReaderReadData(tmp2, &bytes, limereader);
      DML_checksum_accum(ans,rank,(char *) tmp2, bytes);	    
    }
    else {
      status = limeReaderReadData(tmp, &bytes, limereader);
      DML_checksum_accum(ans,rank,(char *) tmp, bytes);
    }
 
    for(mu=0; mu<N; mu++) {
      if(!words_bigendian) {
        if(prec == 32) {
          byte_swap_assign_single2double(s + _GWI(mu,ix,VOL3), (float*)(tmp2+2*mu), 2);
        } else {
          byte_swap_assign(s + _GWI(mu,ix,VOL3), (float*)(tmp+2*mu), 2);
        }
      } else {  // words_bigendian true
        if(prec == 32) {
          single2double(s + _GWI(mu,ix,VOL3), (float*)(tmp2+2*mu), 2);
        }
        else {
          s[_GWI(mu, ix,VOL3)  ] = tmp[2*mu  ];
          s[_GWI(mu, ix,VOL3)+1] = tmp[2*mu+1];
        }
      }
    }

    if(status < 0 && status != LIME_EOR) {
      return(-1);
    }
  }}}
  if(g_cart_id == 0) printf("\n# [read_binary_contraction_data] The final checksum is %#lx %#lx\n", (*ans).suma, (*ans).sumb);

  free(tmp2); free(tmp);
  return(0);
#endif
}
コード例 #5
0
ファイル: swapendian.c プロジェクト: Finkenrath/tmLQCD
int main(int argc,char *argv[]) {

  int c;
  FILE *ifs, *ofs;
  char * ifilename = NULL;
  char * ofilename = NULL;
  int single = 0;
  double tmpd, swapd;
  float tmps, swaps;
  int cnt = 0;

  while ((c = getopt(argc, argv, "h?i:o:e")) != -1) {
    switch (c) {
    case 'i': 
      ifilename = (char*)calloc(200, sizeof(char));
      strcpy(ifilename,optarg);
      break;
    case 'o':
      ofilename = (char*)calloc(200, sizeof(char));
      strcpy(ofilename,optarg);
      break;
    case 'e':
      single = 1;
      break;
    case 'h':
    case '?':
    default:
      usage();
      break;
    }
  }
  if(ifilename == NULL){
    fprintf(stderr, "input filename missing! Aborting...\n");
    exit(-1);
  }
  ifs = fopen(ifilename, "r");
  if(ifs == (FILE *)NULL) {
    fprintf(stderr, "Could not open file %s\n Aborting...\n", ifilename);
    exit(500);
  }

  if(ofilename == NULL){
    fprintf(stderr, "output filename missing! Aborting...\n");
    exit(-2);
  } 
  ofs = fopen(ofilename, "w");
  if(ofs == (FILE *)NULL) {
    fprintf(stderr, "Could not open file %s\n Aborting...\n", ofilename);
    exit(500);
  }

  while(!feof(ifs)) {
    if(!single) {
      fread(&tmpd, sizeof(double), 1, ifs);
      if(!feof(ifs)) {
	cnt++;
	byte_swap_assign(&swapd, &tmpd, 1);
	fwrite(&swapd, sizeof(double), 1, ofs);
      }
    }
    else {
      fread(&tmps, sizeof(float), 1, ifs);
      if(!feof(ifs)) {
	cnt++;
	byte_swap_assign_singleprec(&swaps, &tmps, 1);
	fwrite(&swaps, sizeof(float), 1, ofs);
      }
    }
  }

  printf("Swapped endian for %d words\n", cnt);
  if(single) {
    printf("in- and output file in single precision\n");
  }
  else {
    printf("in- and output file in double precision\n");
  }

  fclose(ofs);
  fclose(ifs);

  return(0);
}