int main(int argc, char **argv) { const char *fin = argv[1]; const char *fout1 = argv[2]; const char *fout2 = argv[3]; struct timeval timer1, timer2; size_t D_dims[2], E_dims[2], Q_dims[2]; double *D = read_mat(fin, "D", D_dims); double *E = read_mat(fin, "E", E_dims); double *Q; int N = (D_dims[0] > D_dims[1]) ? (int)D_dims[0] : (int)D_dims[1]; double *WORK; int *IWORK; Q_dims[0] = Q_dims[1] = (size_t)N; Q = (double *)malloc(N * N * sizeof(double)); WORK = (double *)malloc((2 * N + 2 * N * N) * sizeof(double)); IWORK = (int *)malloc((3 + 5 * N) * sizeof(int)); gettimeofday(&timer1, NULL); dlaed0(N, D, E, Q, N, WORK, IWORK); gettimeofday(&timer2, NULL); printf("Time: %.3lf s\n", GetTimerValue(timer1, timer2) / 1000.0 ); write_mat(fout1, "D", D, D_dims); write_mat(fout2, "Q", Q, Q_dims); return 0; }
int MPI_Finalize(void) { int result, MPIT_result; uint64_t * exchange_count_matrix = NULL; uint64_t * exchange_size_matrix = NULL; uint64_t * exchange_avg_size_matrix = NULL; if (0 == comm_world_rank) { exchange_count_matrix = (uint64_t *) malloc(comm_world_size * comm_world_size * sizeof(uint64_t)); exchange_size_matrix = (uint64_t *) malloc(comm_world_size * comm_world_size * sizeof(uint64_t)); exchange_avg_size_matrix = (uint64_t *) malloc(comm_world_size * comm_world_size * sizeof(uint64_t)); } stop_monitoring_result(&counts); stop_monitoring_result(&sizes); get_monitoring_result(&counts); get_monitoring_result(&sizes); PMPI_Gather(counts.vector, comm_world_size, MPI_UNSIGNED_LONG, exchange_count_matrix, comm_world_size, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); PMPI_Gather(sizes.vector, comm_world_size, MPI_UNSIGNED_LONG, exchange_size_matrix, comm_world_size, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); if (0 == comm_world_rank) { int i, j; //Get the same matrix than profile2mat.pl for (i = 0; i < comm_world_size; ++i) { for (j = i + 1; j < comm_world_size; ++j) { exchange_count_matrix[i * comm_world_size + j] = exchange_count_matrix[j * comm_world_size + i] = (exchange_count_matrix[i * comm_world_size + j] + exchange_count_matrix[j * comm_world_size + i]) / 2; exchange_size_matrix[i * comm_world_size + j] = exchange_size_matrix[j * comm_world_size + i] = (exchange_size_matrix[i * comm_world_size + j] + exchange_size_matrix[j * comm_world_size + i]) / 2; if (exchange_count_matrix[i * comm_world_size + j] != 0) exchange_avg_size_matrix[i * comm_world_size + j] = exchange_avg_size_matrix[j * comm_world_size + i] = exchange_size_matrix[i * comm_world_size + j] / exchange_count_matrix[i * comm_world_size + j]; } } write_mat("monitoring_msg.mat", exchange_count_matrix, comm_world_size); write_mat("monitoring_size.mat", exchange_size_matrix, comm_world_size); write_mat("monitoring_avg.mat", exchange_avg_size_matrix, comm_world_size); } free(exchange_count_matrix); free(exchange_size_matrix); free(exchange_avg_size_matrix); destroy_monitoring_result(&counts); destroy_monitoring_result(&sizes); MPIT_result = MPI_T_pvar_session_free(&session); if (MPIT_result != MPI_SUCCESS) { fprintf(stderr, "WARNING : failed to free MPI_T session, monitoring results may be impacted : check your OpenMPI installation\n"); } MPIT_result = MPI_T_finalize(); if (MPIT_result != MPI_SUCCESS) { fprintf(stderr, "WARNING : failed to finalize MPI_T interface, monitoring results may be impacted : check your OpenMPI installation\n"); } result = PMPI_Finalize(); return result; }
int main ( int argc, char *argv[] ) { char *prog_name = "mat2hdf"; int c; scats_mat_t *mat; SCATS_MATVAR *matvar; hid_t hdf_id; if ( argc > 1 && !strcmp(argv[1],"--version")) { printf("mat2hdf v%d.%d.%d (compiled %s, %s for %s)\n", SCATS_MAJOR_VERSION, SCATS_MINOR_VERSION, SCATS_RELEASE_LEVEL, __DATE__, __TIME__, SCATS_PLATFORM ); exit(0); } else if ( argc > 1 && !strcmp(argv[1],"--help") ) { Scats_Help(helpstr); exit(0); } else if ( argc < 3 ) Scats_Help(helpstr); Scats_LogInit(prog_name); while ((c = getopt(argc, argv, "v")) != EOF) { switch (c) { case 'v': Scats_SetVerbose(1,0); break; default: Scats_Warning("%c not a valid option\n", c); break; } } mat = Scats_MatOpen( argv[optind],SCATS_ACC_RDONLY ); if ( !mat ) Scats_Error("Error opening %s\n", argv[1]); H5open(); hdf_id = Scats_HDFOpen(argv[optind+1], SCATS_ACC_RDWR); if ( hdf_id < 0 ) { printf("Error opening HDF file %s\n", argv[2]); Scats_MatClose(mat); return 1; } while ( (matvar = Scats_MatVarReadNext(mat)) != NULL ) { write_mat(hdf_id,matvar); Scats_MatVarFree(matvar); matvar = NULL; } Scats_MatClose(mat); Scats_HDFClose(hdf_id); H5close(); return 0; }
bool Spectrum2D::_write_file(std::string dir, std::string format) const { if (format == "m") { write_m(dir + "/" + metadata_.name + ".m"); return true; } else if (format == "mat") { write_mat(dir + "/" + metadata_.name + ".mat"); return true; } else if (format == "m4b") { write_m4b(dir + "/" + metadata_.name + ".m4b"); return true; } else return false; }
// save a matrix into file "n" from matrix A // returns 0: success, 1: failure int save_matrix( matrix_t* AA, char* n ) { if ( n == NULL ) { fprintf( stderr, "output error: No output specified (-o)\n" ); return 1; // failure } int ret; enum sparse_matrix_file_format_t ext; if (( ret = _identify_format_from_extension( n, &ext, 0 ) ) != 0 ) return ret; switch(ext) { case MATRIX_MARKET: ret = writemm( n, AA, NULL, ext ); break; // NULL = ignore comments case MATLAB: ret = write_mat( n, AA ); break; case HARWELL_BOEING: ret = 100; assert(0); break; // shouldn't be able to get here } if ( ret != 0 ) fprintf( stderr, "output error: Failed to store matrix\n"); // TODO move these printouts to main... return ret; }
int genrmt(char *infile, char *outfile) { int i,j; FILE *fp; double x,t0,t1; char *cbuf,*fext; /* open file */ switch(seqmode) { case SEQ_MOLPHY: fext=fext_molphy; break; case SEQ_PAML: fext=fext_paml; break; case SEQ_PAUP: fext=fext_paup; break; case SEQ_PUZZLE: fext=fext_puzzle; break; case SEQ_PHYML: fext=fext_phyml; break; case SEQ_MT: default: fext=fext_mt; break; } if(infile) { fp=openfp(infile,fext,"r",&cbuf); printf("\n# reading %s",cbuf); } else { fp=STDIN; printf("\n# reading from stdin"); } /* read file */ mm=nn=0; switch(seqmode) { case SEQ_MOLPHY: datmat = fread_mat_lls(fp, &mm, &nn); break; case SEQ_PAML: datmat = fread_mat_lfh(fp, &mm, &nn); break; case SEQ_PAUP: datmat = fread_mat_paup(fp, &mm, &nn); break; case SEQ_PUZZLE: datmat = fread_mat_puzzle(fp, &mm, &nn); break; case SEQ_PHYML: datmat = fread_mat_phyml(fp, &mm, &nn); break; case SEQ_MT: default: datmat = fread_mat(fp, &mm, &nn); break; } if(infile) {fclose(fp); FREE(cbuf);} printf("\n# M:%d N:%d",mm,nn); /* allocating buffers */ datvec=new_vec(mm); bn=new_ivec(kk); rr1=new_vec(kk); /* calculate the log-likelihoods */ for(i=0;i<mm;i++) { x=0; for(j=0;j<nn;j++) x+=datmat[i][j]; datvec[i]=x; } /* calculate scales */ for(i=0;i<kk;i++) { bn[i]=(int)(rr[i]*nn); /* sample size for bootstrap */ rr1[i]=(double)bn[i]/nn; /* recalculate rr for integer adjustment */ } /* open out file */ if(outfile) { /* vt ascii write to file */ fp=openfp(outfile,fext_vt,"w",&cbuf); printf("\n# writing %s",cbuf); fwrite_vec(fp,datvec,mm); fclose(fp); FREE(cbuf); /* rmt binary write to file */ fp=openfp(outfile,fext_rmt,"wb",&cbuf); printf("\n# writing %s",cbuf); fwrite_bvec(fp,datvec,mm); fwrite_bvec(fp,rr1,kk); fwrite_bivec(fp,bb,kk); fwrite_bi(fp,kk); } else { /* rmt ascii write to stdout */ printf("\n# writing to stdout"); printf("\n# OBS:\n"); write_vec(datvec,mm); printf("\n# R:\n"); write_vec(rr1,kk); printf("\n# B:\n"); write_ivec(bb,kk); printf("\n# RMAT:\n"); printf("%d\n",kk); } /* generating the replicates by resampling*/ for(i=j=0;i<kk;i++) j+=bb[i]; printf("\n# start generating total %d replicates for %d items",j,mm); fflush(STDOUT); t0=get_time(); for(i=0;i<kk;i++) { repmat=new_lmat(mm,bb[i]); scaleboot(datmat,repmat,mm,nn,bn[i],bb[i]); if(outfile) { fwrite_bmat(fp,repmat,mm,bb[i]); putdot(); } else { printf("\n## RMAT[%d]:\n",i); write_mat(repmat,mm,bb[i]); } free_lmat(repmat,mm); } t1=get_time(); printf("\n# time elapsed for bootstrap t=%g sec",t1-t0); if(outfile) { fclose(fp); FREE(cbuf); } /* freeing buffers */ free_vec(bn); free_vec(rr1); free_vec(datvec); free_mat(datmat); return 0; }
int main(int argc, char *argv[]) { //int nchan=4096; //int ndat=12000; int nchan=1024; int ndat=327680; int nrep=1; if (argc>1) nchan=atoi(argv[1]); if (argc>2) ndat=atoi(argv[2]); if (argc>3) nrep=atoi(argv[3]); float **dat=matrix(nchan,ndat+nchan); float **dat2=matrix(nchan,ndat+nchan); if (1) for (int i=0;i<nchan;i++) dat[i][(int)(0.8317*i+160.2)]=1; else for (int i=0;i<nchan;i++) dat[i][ndat/2]=1; #if 0 write_mat(dat,nchan,ndat,"dat_starting.dat"); dedisperse_kernel(dat,dat2,nchan,ndat); write_mat(dat2,nchan,ndat,"dat_1pass.dat"); dedisperse_2pass(dat,dat2,nchan,ndat); write_mat(dat,nchan,ndat,"dat_2pass.dat"); #endif double t1=omp_get_wtime(); //dedisperse(dat,dat2,nchan,ndat); //dedisperse_blocked(dat,dat2,nchan,ndat); dedisperse_blocked_cached(dat,dat2,nchan,ndat); double t2=omp_get_wtime(); printf("took %12.4f seconds.\n",t2-t1); int ichan,idat; find_peak(dat,nchan,ndat,&ichan,&idat); t1=omp_get_wtime(); printf("took %12.4f seconds to find peak.\n",t1-t2); for (int i=0;i<10;i++) { t1=omp_get_wtime(); for (int j=0;j<nrep;j++) { dedisperse_blocked_cached(dat,dat2,nchan,ndat); //dedisperse(dat,dat2,nchan,ndat); } t2=omp_get_wtime(); double nops=get_npass(nchan)*(nchan+0.0)*(ndat+0.0)*(nrep+0.0); printf("took %12.6f seconds at rate %12.6f.\n",t2-t1,nops/(t2-t1)/1024/1024); //printf("took %12.4f seconds.\n",t2-t1); } //write_mat(dat,nchan,ndat,"dat_final1.dat"); //write_mat(dat2,nchan,ndat,"dat_final2.dat"); }
void test_rnw(hid_t fapl) { size_t dim0, dim1; int i, j, k; int x, y; clock_t b, e; double file_open_time, file_close_time; double dataset_open_time, dataset_close_time; double read_time, write_time; file_open_time = 0; file_close_time = 0; dataset_open_time = 0; dataset_close_time = 0; read_time = 0; write_time = 0; for (dim0 = DIM0_START; dim0 <= DIM0_LIM; dim0 *= 2) { for (dim1 = DIM1_START; dim1 <= DIM1_LIM; dim1 *= 2) { for (i = 0; i < LENGTH; i++) { // Open file b = clock(); hid_t file_id; file_id = open_file(fapl, FILE_NAME_RNW); e = clock(); file_open_time += (double) (e - b) / CLOCKS_PER_SEC; // get name of dataset char name[25]; sprintf(name, "dataset_%dx%d", dim0, dim1); // puts string into buffer // Open dataset b = clock(); hid_t dataset_id; dataset_id = open_dataset(file_id, name); e = clock(); dataset_open_time += (double) (e - b) / CLOCKS_PER_SEC; // READS AND WRITES double matrix[dim0][dim1]; for (k = 0; k < READS_AND_WRITES; k++) { b = clock(); read_mat(dataset_id, dim0, dim1, matrix); e = clock(); read_time += (double) (e - b) / CLOCKS_PER_SEC; // Modify the data at least a bit // just to eliminate any shortcuts. /* for (x = 0; x < dim0; x++) { for (y = 0; y < dim1; y++) { matrix[x][y] += 1; } } */ // NOTE: there don't seem to be any shortcuts b = clock(); write_mat(dataset_id, dim0, dim1, matrix); e = clock(); write_time += (double) (e - b) / CLOCKS_PER_SEC; } // Close dataset b = clock(); close_dataset(dataset_id); e = clock(); dataset_close_time += (double) (e - b) / CLOCKS_PER_SEC; // Close file b = clock(); close_file(file_id); e = clock(); file_close_time += (double) (e - b) / CLOCKS_PER_SEC; } } } printf("Executed an average-case read and write test with the following properties:\n"); printf("The experiment uses file: " FILE_NAME_RNW "\n"); printf("The experiment repeats %d times.\n", LENGTH); printf("Dim0 starting from %d and doubling until %d.\n", DIM0_START, DIM0_LIM); printf("Dim1 starting from %d and doubling until %d.\n", DIM1_START, DIM1_LIM); printf("Reading and writing a matrix %d times.\n", READS_AND_WRITES); double total_reads_and_writes; total_reads_and_writes = LENGTH * READS_AND_WRITES * (DIM0_LIM - DIM0_START) * (DIM1_LIM - DIM1_START); printf("This means a total of %.0lf doubles have been read and written.\n", total_reads_and_writes); printf("\n"); printf("Opening the file took a total of %f seconds.\n", file_open_time); printf("Closing the file took a total of %f seconds.\n", file_close_time); printf("Opening the dataset took a total of %f seconds.\n", dataset_open_time); printf("Closing the dataset took a total of %f seconds.\n", dataset_close_time); printf("Reading the data took a total of %f seconds.\n", read_time); printf("Writing the data took a total of %f seconds.\n", write_time); printf("This means that reading produces an average overhead of %f ns per double.\n", read_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); printf("This means that writing produces an average overhead of %f ns per double.\n\n", write_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); }