예제 #1
0
// write global checksum, and runinfo in new file
void write_1st_msg(const char* filename, GlobalDat& dat,
                          size_t chksum){
  // open file
  FILE* fp;
  fp = fopen(filename, "w");
  LimeWriter* w;
  w = limeCreateWriter(fp);
  // first record is global checksum
  int MB_flag = 1;
  int ME_flag = 0;
  LimeRecordHeader* chk;
  n_uint64_t chk_bytes = sizeof(chksum);
  chk = limeCreateHeader(MB_flag, ME_flag, "Global Checksum", chk_bytes);
  limeWriteRecordHeader(chk, w);
  limeDestroyHeader(chk);
  limeWriteRecordData(&chksum, &chk_bytes, w);
  
  // second record is data on calculation
  MB_flag = 0; ME_flag = 1;
  
  LimeRecordHeader* run_id;
  n_uint64_t run_id_bytes = sizeof(dat);
  run_id = limeCreateHeader(MB_flag, ME_flag, "Runinfo", run_id_bytes);
  limeWriteRecordHeader(run_id,w);
  limeDestroyHeader(run_id);
  limeWriteRecordData(&dat, &run_id_bytes, w);
  limeDestroyWriter(w);
  fclose(fp);
} 
예제 #2
0
파일: lime_io.c 프로젝트: urbach/DDalphaAMG
void lime_write_info(FILE **fout, char* binary_data, n_uint64_t data_size_per_site, n_uint64_t *offset) {
  
  LimeWriter *limewriter;
  LimeRecordHeader *limeheader = NULL;
  n_uint64_t message_length;
  char tmp_string[STRINGLENGTH];
  
  ASSERT((limewriter = limeCreateWriter(*fout))!=(LimeWriter*)NULL);
  
  sprintf(tmp_string, "Vector_by_DDalphaAMG");
  message_length=(n_uint64_t) strlen(tmp_string);
  limeheader = limeCreateHeader(1, 1, "vector-type", message_length);
  
  ASSERT(limeheader != (LimeRecordHeader*)NULL);
  ASSERT(limeWriteRecordHeader(limeheader, limewriter)>=0);
  ASSERT(limeWriteRecordData(tmp_string, &message_length, limewriter)>=0);
  limeDestroyHeader(limeheader);
  
  sprintf(tmp_string, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<etmcFormat>\n\t<field>diracFermion</field>\n\t<precision>64</precision>\n\t<flavours>1</flavours>\n\t<lx>%d</lx>\n\t<ly>%d</ly>\n\t<lz>%d</lz>\n\t<lt>%d</lt>\n\t<spin>4</spin>\n\t<colour>3</colour>\n</etmcFormat>", g.global_lattice[0][X], g.global_lattice[0][Y], g.global_lattice[0][Z], g.global_lattice[0][T]);
  message_length=(n_uint64_t) strlen(tmp_string);
  limeheader = limeCreateHeader(1, 1, "etmc-propagator-format", message_length);
  
  ASSERT(limeheader != (LimeRecordHeader*)NULL);
  ASSERT(limeWriteRecordHeader(limeheader, limewriter)>=0);
  ASSERT(limeWriteRecordData(tmp_string, &message_length, limewriter)>=0);
  limeDestroyHeader(limeheader);
  message_length=(n_uint64_t) strlen(tmp_string);
  limeheader = limeCreateHeader(1, 1, "DDalphaAMG-header", message_length);
  
  ASSERT(limeheader != (LimeRecordHeader*)NULL);
  ASSERT(limeWriteRecordHeader(limeheader, limewriter)>=0);
  ASSERT(limeWriteRecordData(tmp_string, &message_length, limewriter)>=0);
  limeDestroyHeader(limeheader);
  
  int vol=1, mu;
  for ( mu=0; mu<4; mu++ ){
    vol*=g.global_lattice[0][mu];
  }
  message_length=data_size_per_site*vol;
  limeheader = limeCreateHeader(1, 1, "scidac-binary-data", message_length);
  ASSERT(limeWriteRecordHeader(limeheader, limewriter)>=0);
  limeDestroyHeader(limeheader);
  message_length=1;
  //make one fake record-write to set offset
  ASSERT(limeWriteRecordData(tmp_string, &message_length, limewriter)>=0);
  *offset = (n_uint64_t) ftell(*fout)-1;
  
  limeDestroyWriter(limewriter);
}
예제 #3
0
//append correlation functions to file
void append_msgs(const char* filename, std::vector<vec>& corr, std::vector<Tag>& tags,
              LimeWriter* w, bool be){
  // Each message contains three records:
  // 1st: Checksum for the Correlator
  // 2nd: Tag for the Correlator
  // 3rd: Correlationfunction itself
  LimeRecordHeader* corr_chk;
  LimeRecordHeader* id;
  LimeRecordHeader* corr_hd;

  boost::uint64_t corr_chksum;
  n_uint64_t tag_bytes = sizeof(tags[0]);
  n_uint64_t data_bytes = (corr[0]).size()*2*sizeof(double);
  char headername[100];  
  // Access flags for record and message: MB (Message Begin): 1 if true, ME
  // (Message End): 1 if true
  int MB_flag, ME_flag;
  for(size_t el = 0; el < corr.size(); ++el){

    // 1st record for checksum
    corr_chksum = checksum <vec> (corr[el], corr[el].size());
    if(be) corr_chksum = swap_endian<boost::uint64_t>(corr_chksum);
    n_uint64_t chk_bytes = sizeof(corr_chksum);
    ME_flag = 0; MB_flag = 1;
    corr_chk = limeCreateHeader(MB_flag, ME_flag,"Correlator checksum", chk_bytes);
    limeWriteRecordHeader( corr_chk, w );
    limeDestroyHeader( corr_chk );
    limeWriteRecordData( &corr_chksum, &chk_bytes, w );

    // 2nd record for Tag as struct of 3 2dim integer-arrays
    ME_flag = 0; MB_flag = 0;
    sprintf(headername,"Tag of Correlator with p^2 = %zd", el);
    id = limeCreateHeader( MB_flag, ME_flag, headername , tag_bytes );
    limeWriteRecordHeader( id, w );
    limeDestroyHeader( id );
    limeWriteRecordData( &tags[el], &tag_bytes, w );

    // 3rd record for correlator belonging to tag
    ME_flag = 1; MB_flag = 0; 
    sprintf(headername,"Correlator with p^2 = %zd", el);
    corr_hd = limeCreateHeader( MB_flag, ME_flag, headername, data_bytes );
    limeWriteRecordHeader( corr_hd, w );
    limeDestroyHeader( corr_hd );
    limeWriteRecordData( corr[el].data(), &data_bytes, w ); 
  }
}
예제 #4
0
/***********************************************************
 * write_lime_contraction
 ***********************************************************/
int write_lime_contraction_3d(double * const s, char * filename, const int prec, const int N, char * type, const int gid, const int sid) {
#ifdef MPI
  fprintf(stderr, "[write_lime_contraction_3d] No mpi version.\n");
  return(1);
#else

  FILE * ofs = NULL;
  LimeWriter * limewriter = NULL;
  LimeRecordHeader * limeheader = NULL;
  int status = 0;
  int ME_flag=0, MB_flag=0;
  n_uint64_t bytes;
  DML_Checksum checksum;

  write_contraction_format(filename, prec, N, type, gid, sid);

  if(g_cart_id==0) {
    ofs = fopen(filename, "a");
    if(ofs == (FILE*)NULL) {
      fprintf(stderr, "Could not open file %s for writing!\n Aborting...\n", filename);
      exit(500);
    }
  
    limewriter = limeCreateWriter( ofs );
    if(limewriter == (LimeWriter*)NULL) {
      fprintf(stderr, "LIME error in file %s for writing!\n Aborting...\n", filename);
      exit(500);
    }

    bytes = LX*g_nproc_x*LY*g_nproc_y*LZ*(n_uint64_t)2*N*sizeof(double)*prec/64;
    MB_flag=0; ME_flag=1;
    limeheader = limeCreateHeader(MB_flag, ME_flag, "scidac-binary-data", bytes);
    status = limeWriteRecordHeader( limeheader, limewriter);
    if(status < 0 ) {
      fprintf(stderr, "LIME write header (scidac-binary-data) error %d\n", status);
      exit(500);
    }
    limeDestroyHeader( limeheader );
  }
  
  status = write_binary_contraction_data_3d(s, limewriter, prec, N, &checksum);
  if(g_cart_id==0) {
    printf("# Final check sum is (%#lx  %#lx)\n", checksum.suma, checksum.sumb);
    if(ferror(ofs)) {
      fprintf(stderr, "Warning! Error while writing to file %s \n", filename);
    }
    limeDestroyWriter( limewriter );
    fflush(ofs);
    fclose(ofs);
  }
  write_checksum(filename, &checksum);
  return(0);
#endif
}
예제 #5
0
void limeDestroyReader(LimeReader *r)
{
  if (r != (LimeReader *)NULL) { 

    if ( r->curr_header != (LimeRecordHeader *)NULL ) { 
      limeDestroyHeader(r->curr_header);
      r->curr_header = (LimeRecordHeader *)NULL;
    }
    free(r);

  }
}
예제 #6
0
/* Entrance assumption to this function is that:
   i) The stream pointer is pointing to the beginning of 
      a record header.

   ii) There is a header about to come 
*/
int readAndParseHeader(LimeReader *r)
{

  unsigned int i_version;
  int i_MB, i_ME;
  n_uint32_t i_magic_no;
  n_uint64_t  i_data_length;
  unsigned char *typebuf;
  int status;
  //int msg_begin = 1;
  char myname[] = "lime::readAndParseHeader";

  /* Destroy any old header structure kicking about */
  if( r->curr_header != (LimeRecordHeader *)NULL ) { 
    //msg_begin = r->is_last;   /* Remember whether we finished a message */
    limeDestroyHeader(r->curr_header);
    r->curr_header = (LimeRecordHeader *)NULL;
  }

  /* Read the entire header */

  status = DCAP(fread)((void *)lime_header.int64, 
		 sizeof(n_uint64_t), MAX_HDR64, r->fp);
  if( status != MAX_HDR64 ) {
    if( DCAP(feof)( r->fp ) ) return LIME_EOF;
    fprintf(stderr,"%s read %d but wanted %d\n",myname,status,MAX_HDR64);
    return LIME_ERR_READ;
  }

  /* Check magic number */

  i_magic_no = big_endian_long(*lime_hdr_magic_no);
  if(i_magic_no != LIME_MAGIC_NO){
    fprintf(stderr,"%s: wrong magic number: read %x but wanted %x\n",
	    myname,i_magic_no,LIME_MAGIC_NO);
    return LIME_ERR_READ;
  }

#ifdef LIME_DEBUG
  fprintf(stderr, "%s Magic number OK: %d\n ", myname, i_magic_no);
  fflush(stderr);
#endif

  /* LIME version number */

  i_version = big_endian_short(*lime_hdr_version);

#ifdef LIME_DEBUG
  fprintf(stderr, "%s Input Version: %d\n ", myname,(int)i_version);
  fflush(stderr);
#endif

  /* MB flag */

  if ( *lime_hdr_mbme & MB_MASK ) { 
    i_MB = 1; 
  } 
  else {
    i_MB = 0;
  }

#ifdef LIME_DEBUG
  fprintf(stderr, "%s MB Flag: %d\n ", myname, (int)i_MB);
  fflush(stderr);
#endif
  
  /* ME Flag */

  if( *lime_hdr_mbme & ME_MASK ) {
    i_ME = 1;
  }
  else { 
    i_ME = 0;
  }

#ifdef LIME_DEBUG
  fprintf(stderr, "%s ME Flag: %d\n ", myname, (int)i_ME);
  fflush(stderr);
#endif

  /* Data length */

  i_data_length = big_endian_long_long(*lime_hdr_data_len);

#ifdef LIME_DEBUG
  fprintf(stderr, "%s Data Length: %llu\n ", myname, (unsigned long long)i_data_length);
  fflush(stderr);  
#endif

  /* Record type. */
  typebuf = (unsigned char *)lime_hdr_rec_type;

  /* Sanity Checking */
  /* Check Version */
  if( i_version != LIME_VERSION ) { 
    fprintf(stderr, "%s Unknown Lime Version\n",myname);
    exit(EXIT_FAILURE);
  }

#ifdef LIME_DEBUG
  printf("%s: type %s\n",myname,typebuf);
#endif

  /* If we are the first packet we MUST have MB flag set */
  /**  suppressed to allow seeking withing file without penalty
  if( msg_begin != i_MB ) { 
    fprintf(stderr, "%s MB Flag incorrect: last ME = %d but current MB=%d \n",
	    myname, msg_begin, i_MB);
    exit(EXIT_FAILURE);
  }
  **/

  r->curr_header = limeCreateHeader(i_MB, i_ME,
				    (char*)typebuf,
				    i_data_length);


  if (r->curr_header == (LimeRecordHeader *)NULL ) { 
    fprintf(stderr, "%s ERROR; Couldn't create header\n",myname);
    exit(EXIT_FAILURE);
  }

  return LIME_SUCCESS;
}