void cfio_create_c_( char *path, int *len, int *cmode, int *ncidp, int *ierr) { debug(DEBUG_CFIO, "path = %s, cmode = %d", path, *cmode); path[*len] = 0; *ierr = cfio_create(path, *cmode, ncidp); return; }
int main(int argc, char** argv) { int ncidp; int dim1,var1,i, j, l; size_t start[2],count[2]; char fileName[100]; char var_name[16]; int *var; int valn; double compute_time = 0.0, IO_time = 0.0, communicate_time = 0.0, waitIO_time = 0.0, init_time = 0.0, final_time = 0.0, total_time = 0.0; int itr, sleep_ms_per_itr, ratio; size_t len = 10; MPI_Comm comm = MPI_COMM_WORLD; if(8 != argc) { printf("Usage : perform_test LAT_PROC LON_PROC output_dir itr sleep_ms_per_itr\n"); return -1; } LAT_PROC = atoi(argv[1]); LON_PROC = atoi(argv[2]); ratio = atoi(argv[3]); itr = atoi(argv[5]); sleep_ms_per_itr = atoi(argv[6]); valn = atoi(argv[7]); MPI_Init(&argc, &argv); MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &size); times_init(); double start_time = times_cur(); start[0] = (rank % LAT_PROC) * (LAT / LAT_PROC); start[1] = (rank / LAT_PROC) * (LON / LON_PROC); count[0] = LAT / LAT_PROC; count[1] = LON / LON_PROC; double *fp = malloc(count[0] * count[1] *sizeof(double)); for( i = 0; i< count[0] * count[1]; i++) { fp[i] = i + rank * count[0] * count[1]; } times_start(); //total_time times_start(); // init_time cfio_init( LAT_PROC, LON_PROC, ratio); init_time = times_end(); // init_time CFIO_START(); double start_time = times_cur(); var = malloc(sizeof(int) * valn); for(i = 0; i < itr; i ++) { times_start(); if( SLEEP_TIME != 0) { struct timeval sleep_begin, sleep_end; // simulate computation of sleep_ms_per_itr ms gettimeofday(&sleep_begin, NULL); do { gettimeofday(&sleep_end, NULL); } while ((sleep_end.tv_sec - sleep_begin.tv_sec) * 1000 + (sleep_end.tv_usec - sleep_begin.tv_usec) / 1000 < sleep_ms_per_itr); } compute_time += times_end(); times_start(); // communicate_time sprintf(fileName,"%s/cfio-%d.nc", argv[4], i); int dimids[2]; cfio_create(fileName, NC_64BIT_OFFSET, &ncidp); int lat = LAT; cfio_def_dim(ncidp, "lat", LAT,&dimids[0]); cfio_def_dim(ncidp, "lon", LON,&dimids[1]); //cfio_put_att(ncidp, NC_GLOBAL, "global", NC_CHAR, 6, "global"); for(j = 0; j < valn; j++) { sprintf(var_name, "time_v%d", j); cfio_def_var(ncidp,var_name, CFIO_DOUBLE, 2,dimids, start, count, &var[j]); // cfio_put_att(ncidp, var[j], "global", NC_CHAR, // strlen(var_name), var_name ); } cfio_enddef(ncidp); for(j = 0; j < valn; j++) { cfio_put_vara_double(ncidp,var[j], 2,start, count,fp); } //cfio_put_vara_float(rank,ncidp,var1, 2,start, count,fp); //cfio_put_vara_float(rank,ncidp,var1, 2,start, count,fp); cfio_close(ncidp); communicate_time += times_end(); // communicate_time times_start(); // waitIO_time cfio_io_end(); waitIO_time += times_end(); // waitIO_time } free(fp); if (var) { free(var); } CFIO_END(); times_start(); // final_time cfio_finalize(); final_time = times_end(); // final_time total_time = times_end(); if (0 == rank) { printf("%8s %8s %8s %8s %8s %8s %8s %8s %8s\n", "proc", "init", "final", "total", "compute", "communi", "waitIO", "IO", "simulate"); } printf("%8d %8d %8d %8d %8d %8d %8d %8d %8d\n", rank, (int)init_time, (int)final_time, (int)total_time, (int)compute_time, (int)communicate_time, (int)waitIO_time, (int)(communicate_time + waitIO_time), (int)(total_time - init_time - final_time)); MPI_Finalize(); times_final(); return 0; }
int main(int argc, char** argv) { int rank, size; char *path = "test"; int ncidp; int dim1,var1,i; size_t len = 10; char *test="test"; MPI_Comm comm = MPI_COMM_WORLD; MPI_Init(&argc, &argv); MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &size); //assert(size == LAT_PROC * LON_PROC); //set_debug_mask(DEBUG_IO); size_t start[2],count[2]; start[0] = (rank % LAT_PROC) * (LAT / LAT_PROC); start[1] = (rank / LAT_PROC) * (LON / LON_PROC); count[0] = LAT / LAT_PROC; count[1] = LON / LON_PROC; float *fp = malloc(count[0] * count[1] *sizeof(float)); for( i = 0; i< count[0] * count[1]; i++) { fp[i] = i + rank * count[0] * count[1]; } cfio_init( LAT_PROC, LON_PROC, ratio); CFIO_START(); char fileName[100]; memset(fileName, 0, sizeof(fileName)); sprintf(fileName,"%s.nc",path); int dimids[2]; cfio_create(fileName, 0, &ncidp); debug_mark(DEBUG_USER); int lat = LAT; cfio_def_dim(ncidp, "lat", LAT,&dimids[0]); cfio_def_dim(ncidp, "lon", LON,&dimids[1]); cfio_def_dim(ncidp, "lat", LAT,&dimids[0]); int a = 3; double b= 4.0; cfio_put_att(ncidp, NC_GLOBAL, "test", CFIO_INT, 1, &a); cfio_put_att(ncidp, NC_GLOBAL, "test", CFIO_FLOAT, 1, &b); cfio_def_var(ncidp,"time_v", CFIO_FLOAT, 2, dimids, start, count, &var1); cfio_put_att(ncidp, var1, "test", CFIO_CHAR, strlen(test), test); cfio_enddef(ncidp); cfio_put_vara_float(ncidp,var1, 2,start, count,fp); cfio_close(ncidp); cfio_io_end(); free(fp); CFIO_END(); cfio_finalize(); MPI_Finalize(); return 0; }