Why my job be hang in a simple pnetcdf-writing case?
Jun Xiong
jun.xiong1981 at gmail.com
Thu Apr 3 18:21:24 CDT 2014
Hi Guys:
My code
can be compiled successfully but hang when I tried to run it.
Any idea?
/********** pnetcdf-array-writing-case.c ***********/
#include <stdlib.h>
#include <mpi.h>
#include <pnetcdf.h>
#include <stdio.h>
#define TIMES 253
#define SAMPLES 99
static void handle_error(int status, int lineno)
{
fprintf(stderr, "Error at line %d: %s\n", lineno,
ncmpi_strerror(status));
MPI_Abort(MPI_COMM_WORLD, 1);
}
int main(int argc, char **argv) {
int ret, nprocs, rank, ncid, i, j;
int vid; /* variable ID */
int time_dim, sample_dim; /* variable shape */
int dims[2]; /* variable shape */
double var[TIMES*SAMPLES]; /* array to hold values */
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
ret = ncmpi_create(MPI_COMM_WORLD, argv[1], NC_CLOBBER|NC_64BIT_OFFSET,
MPI_INFO_NULL, &ncid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
ret = ncmpi_def_dim(ncid, "time", TIMES, &time_dim);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
ret = ncmpi_def_dim(ncid, "sample", TIMES, &sample_dim);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
dims[0] = time_dim;
dims[1] = sample_dim;
ret = ncmpi_def_var(ncid, "var", NC_SHORT, 2, dims, &vid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
ret = ncmpi_enddef(ncid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
for (i = 0; i < TIMES; i++)
for (j = 0; j < SAMPLES; j++)
var[i*253+j] = 9999;
ret = ncmpi_begin_indep_data(ncid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
/* write values into netCDF variable */
ret = ncmpi_put_var_double(ncid, vid, var);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
ret = ncmpi_end_indep_data(ncid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
ret = ncmpi_close(ncid);
if (ret != NC_NOERR) handle_error(ret, __LINE__);
MPI_Finalize();
return 0;
}
--
Jun Xiong, Ph.D.
U.S. Geological Survey
2255 North Gemini Drive, Flagstaff, Arizona - 86001, USA.
Office: 928-556-7215
Fax: 928-556-7169
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/parallel-netcdf/attachments/20140403/538cf4d3/attachment.html>
More information about the parallel-netcdf
mailing list