/*----------------------------------------------------------------------*/ void w_serial_finish_lattice(w_serial_site_writer *state) { /* gf = file descriptor as opened by w_serial_i */ gauge_file *gf = state->gf; fsu3_matrix *lbuf = state->lbuf; FILE *fp = gf->fp; gauge_header *gh = gf->header; off_t checksum_offset = state->checksum_offset; /* Location of checksum */ free(lbuf); printf("Saved gauge configuration serially to binary file %s\n", gf->filename); printf("Time stamp %s\n",gh->time_stamp); /* Write checksum */ /* Position file pointer */ if( g_seek(fp,checksum_offset,SEEK_SET) < 0 ) { printf("w_serial: Node %d g_seek %lld failed error %d file %s\n", this_node,(long long)checksum_offset,errno,gf->filename); fflush(stdout);terminate(1); } write_checksum(SERIAL,gf); } /* w_serial_finish_lattice */
int write_tar_entry (char* tarname, char* filename) { int size = get_file_size(filename); int modified = get_file_modified(filename); p_write_tar_entry(tarname, filename, size, modified, 0); write_checksum(tarname, 0); finalize_tar(tarname); return 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 }
int write_su3_vector(WRITER * writer, double const *eigenvalue, su3_vector * const s, const int prec, const int t0, int const nsets) { DML_Checksum checksum; uint64_t bytes; int status = 0; // general information about the configuration write_su3_vector_info(writer, 0); // eigenvalue write_eigenvalue_xml(writer, eigenvalue, t0, nsets); // data bytes = (n_uint64_t)LX * g_nproc_x * LY * g_nproc_y * LZ * g_nproc_z * (n_uint64_t)(sizeof(su3_vector) * prec / 64) * nsets; write_header(writer, 0, 0, "scidac-binary-data", bytes); status = write_binary_su3_vector_data(s, writer, &checksum, prec, t0, nsets); write_checksum(writer, &checksum, NULL); return status; }
int write_tar_entries (char* tarname, char* manifest) { char line[10000]; char unused[50]; char tentry[50]; char part[50]; char file[50]; char* entries[100]; int i = 0; FILE* f; f = fopen(manifest, "r"); while (fgets(line, sizeof(line), f)) { split(line, "\n", tentry, unused); split(tentry, ":", part, file); p_write_tar_entry(part, file, get_file_size(file), get_file_modified(file), 0); write_checksum(part, 0); strcpy(entries[i], part); i++; } fclose(f); merge_entries(tarname, entries, i); finalize_tar(tarname); return 0; }
int write_gauge_field(char * filename, const int prec, paramsXlfInfo const *xlfInfo) { WRITER * writer = NULL; uint64_t bytes; int status = 0; DML_Checksum checksum; paramsIldgFormat *ildg; bytes = (uint64_t)L * L * L * T_global * sizeof(su3) * prec / 16; /* all these functions, except for write_binary_gauge_data do their own error handling */ construct_writer(&writer, filename, 0);/* the 0 is for not appending */ write_xlf_info(writer, xlfInfo); ildg = construct_paramsIldgFormat(prec); write_ildg_format(writer, ildg); free(ildg); /* Both begin and end bit are 0, the message is begun with the format, and will end with the checksum */ write_header(writer, 0, 0, "ildg-binary-data", bytes); status = write_binary_gauge_data(writer, prec, &checksum); write_checksum(writer, &checksum, NULL); if (g_cart_id == 0 && g_debug_level > 0) { fprintf(stdout, "# Scidac checksums for gaugefield %s:\n", filename); fprintf(stdout, "# Calculated : A = %#010x B = %#010x.\n", checksum.suma, checksum.sumb); fflush(stdout); } #ifdef TM_USE_MPI MPI_Barrier(MPI_COMM_WORLD); #endif /* MPI */ destruct_writer(writer); return status; }
// ----------------------------------------------------------------- // Only node0 writes the gauge configuration to a binary file gf static void w_serial(gauge_file *gf) { register int i, j; int rank29, rank31, buf_length, tbuf_length; int x, y, z, t, currentnode, newnode; FILE *fp = NULL; gauge_header *gh = NULL; fmatrix *lbuf = NULL; fmatrix *tbuf = malloc(nx * 4 * sizeof(*tbuf)); off_t offset; // File stream pointer off_t coord_list_size; // Size of coordinate list in bytes off_t head_size; // Size of header plus coordinate list off_t checksum_offset = 0; // Location of checksum off_t gauge_check_size; // Size of checksum record // tbuf holds message buffer space for the x dimension // of the local hypercube (needs at most 4nx matrices) if (tbuf == NULL) { printf("w_serial: node%d can't malloc tbuf\n", this_node); terminate(1); } // Only allocate lbuf on node0 if (this_node == 0) { if (gf->parallel) printf("w_serial: Attempting serial write to parallel file\n"); lbuf = malloc(MAX_BUF_LENGTH * 4 * sizeof(*lbuf)); if (lbuf == NULL) { printf("w_serial: Node 0 can't malloc lbuf\n"); fflush(stdout); terminate(1); } fp = gf->fp; gh = gf->header; // No coordinate list written // Fields to be written in standard coordinate list order coord_list_size = 0; head_size = gh->header_bytes + coord_list_size; checksum_offset = head_size; gauge_check_size = sizeof(gf->check.sum29) + sizeof(gf->check.sum31); offset = head_size + gauge_check_size; if (fseeko(fp, offset, SEEK_SET) < 0) { printf("w_serial: node%d g_seek %lld failed error %d file %s\n", this_node, (long long)offset, errno, gf->filename); fflush(stdout); terminate(1); } } // Buffered algorithm for writing fields in serial (lexicographic) order // Initialize checksums gf->check.sum31 = 0; gf->check.sum29 = 0; // Count 32-bit words mod 29 and mod 31 in order of appearance on file // Here only node 0 uses these values -- both start at 0 i = 4 * sizeof(fmatrix) / sizeof(int32type) * sites_on_node * this_node; rank29 = i % 29; rank31 = i % 31; g_sync(); currentnode = 0; // The node delivering data buf_length = 0; tbuf_length = 0; for (j = 0, t = 0; t < nt; t++) { for (z = 0; z < nz; z++) { for (y = 0; y < ny; y++) { for (x = 0; x < nx; x++, j++) { // The node providing the next site newnode = node_number(x, y, z, t); if (newnode != currentnode || x == 0) { // We are switching to a new node or have exhausted a line of nx // Sweep any data in the retiring node's tbuf to the node0 lbuf if (tbuf_length > 0) { if (currentnode != 0) send_buf_to_node0(tbuf, tbuf_length, currentnode); // node0 flushes tbuf, accumulates checksum // and writes lbuf if it is full if (this_node == 0) { flush_tbuf_to_lbuf(gf, &rank29, &rank31, lbuf, &buf_length, tbuf, tbuf_length); if (buf_length > MAX_BUF_LENGTH - nx) flush_lbuf_to_file(gf, lbuf, &buf_length); } tbuf_length = 0; } // node0 sends a few bytes to newnode as a clear to send signal if (newnode != currentnode) { if (this_node == 0 && newnode != 0) send_field((char *)tbuf, 32, newnode); if (this_node == newnode && newnode != 0) get_field((char *)tbuf, 32, 0); currentnode = newnode; } } // The node with the data just appends to its tbuf if (this_node == currentnode) { i = node_index(x, y, z, t); d2f_4mat(&lattice[i].link[0], &tbuf[4 * tbuf_length]); } if (this_node == currentnode || this_node == 0) tbuf_length++; } } } } // Purge any remaining data if (tbuf_length > 0) { if (currentnode != 0) send_buf_to_node0(tbuf, tbuf_length, currentnode); } if (this_node == 0) { flush_tbuf_to_lbuf(gf, &rank29, &rank31, lbuf, &buf_length, tbuf, tbuf_length); flush_lbuf_to_file(gf, lbuf, &buf_length); } g_sync(); free(tbuf); if (this_node == 0) { free(lbuf); printf("Saved gauge configuration serially to binary file %s\n", gf->filename); printf("Time stamp %s\n", gh->time_stamp); // Write checksum // Position file pointer if (g_seek(fp, checksum_offset, SEEK_SET) < 0) { printf("w_serial: node%d g_seek %lld failed error %d file %s\n", this_node, (long long)checksum_offset, errno, gf->filename); fflush(stdout); terminate(1); } write_checksum(SERIAL, gf); } }