Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions benchmarks/C/aggregation.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ int benchmark_write(char *filename,
if (cfg->star_block) nvars++;
nvars *= cfg->nvars;

varid = (int*) malloc(nvars * sizeof(int));
varid = (int*) malloc(sizeof(int) * nvars);

/* initialize I/O buffer */
lenlen = cfg->len * cfg->len;
buf = (double**) malloc(nvars * sizeof(double*));
buf = (double**) malloc(sizeof(double*) * nvars);
for (i=0; i<nvars; i++) {
buf[i] = (double*) malloc(lenlen * sizeof(double));
buf[i] = (double*) malloc(sizeof(double) * lenlen);
assert(buf[i] != NULL);
for (j=0; j<lenlen; j++) buf[i][j] = (double)rank;
}
Expand Down Expand Up @@ -280,8 +280,8 @@ int benchmark_write(char *filename,
}
}
assert(v == nvars);
reqs = (int*) malloc(num_reqs * sizeof(int));
sts = (int*) malloc(num_reqs * sizeof(int));
reqs = (int*) malloc(sizeof(int) * num_reqs);
sts = (int*) malloc(sizeof(int) * num_reqs);

err = ncmpi_enddef(ncid); ERR(err)
err = ncmpi_inq_header_size(ncid, &cfg->header_size); ERR(err)
Expand Down Expand Up @@ -436,9 +436,9 @@ int benchmark_read(char *filename,
nvars *= cfg->nvars;

/* allocate I/O buffer */
buf = (double**) malloc(nvars * sizeof(double*));
buf = (double**) malloc(sizeof(double*) * nvars);
for (i=0; i<nvars; i++) {
buf[i] = (double*) malloc(lenlen * sizeof(double));
buf[i] = (double*) malloc(sizeof(double) * lenlen);
assert(buf[i] != NULL);
}
MPI_Barrier(comm);
Expand Down Expand Up @@ -499,8 +499,8 @@ int benchmark_read(char *filename,
if (cfg->star_block)
num_reqs++; /* complete in 1 nonblocking call */
}
reqs = (int*) malloc(num_reqs * sizeof(int));
sts = (int*) malloc(num_reqs * sizeof(int));
reqs = (int*) malloc(sizeof(int) * num_reqs);
sts = (int*) malloc(sizeof(int) * num_reqs);

timing[2] = timing[3] = 0;
for (n=0; n<cfg->num_records; n++) {
Expand Down
20 changes: 10 additions & 10 deletions benchmarks/C/write_block_read_column.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ int benchmark_write(char *filename,
/* initialize I/O buffer */
for (i=0; i<NVARS; i++) {
if (i % 4 == 0) {
int *int_b = (int*) malloc(len * len * sizeof(int));
int *int_b = (int*) malloc(sizeof(int) * len * len);
for (j=0; j<len*len; j++) int_b[j] = rank;
buf[i] = (void*)int_b;
}
else if (i % 4 == 1) {
float *flt_b = (float*) malloc(len * len * sizeof(float));
float *flt_b = (float*) malloc(sizeof(float) * len * len);
for (j=0; j<len*len; j++) flt_b[j] = rank;
buf[i] = (void*)flt_b;
}
else if (i % 4 == 2) {
short *shr_b = (short*) malloc(len * len * sizeof(short));
short *shr_b = (short*) malloc(sizeof(short) * len * len);
for (j=0; j<len*len; j++) shr_b[j] = rank;
buf[i] = (void*)shr_b;
}
else {
double *dbl_b = (double*) malloc(len * len * sizeof(double));
double *dbl_b = (double*) malloc(sizeof(double) * len * len);
for (j=0; j<len*len; j++) dbl_b[j] = rank;
buf[i] = (void*)dbl_b;
}
Expand Down Expand Up @@ -240,8 +240,8 @@ int benchmark_read(char *filename,
err = ncmpi_inq_dimlen(ncid, dimid[0], &gsizes[0]); ERR(err)
err = ncmpi_inq_dimlen(ncid, dimid[1], &gsizes[1]); ERR(err)

varid = (int*) malloc(nvars * sizeof(int));
buf = (void**) malloc(nvars * sizeof(void*));
varid = (int*) malloc(sizeof(int) * nvars);
buf = (void**) malloc(sizeof(void*) * nvars);

/* construct *-block partitioning pattern */
start[0] = 0;
Expand All @@ -260,13 +260,13 @@ int benchmark_read(char *filename,
for (i=0; i<nvars; i++) {
varid[i] = i;
if (i % 4 == 0)
buf[i] = malloc(len * sizeof(int));
buf[i] = malloc(sizeof(int) * len);
else if (i % 4 == 1)
buf[i] = (float*) malloc(len * sizeof(float));
buf[i] = (float*) malloc(sizeof(float) * len);
else if (i % 4 == 2)
buf[i] = (short*) malloc(len * sizeof(short));
buf[i] = (short*) malloc(sizeof(short) * len);
else
buf[i] = (double*) malloc(len * sizeof(double));
buf[i] = (double*) malloc(sizeof(double) * len);
}
end_t = MPI_Wtime();
timing[2] = end_t - start_t;
Expand Down
16 changes: 8 additions & 8 deletions examples/C/block_cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int main(int argc, char** argv) {

/* First, fill the entire array with zeros, using a blocking I/O.
Every process writes a subarray of size NY * myNX */
buf = (int**) malloc(myNX * sizeof(int*));
buf = (int**) malloc(sizeof(int*) * myNX);
buf[0] = (int*) calloc(NY * myNX, sizeof(int));
start[0] = 0; start[1] = myOff;
count[0] = NY; count[1] = myNX;
Expand All @@ -197,12 +197,12 @@ int main(int argc, char** argv) {
/* initialize the buffer with rank ID. Also make the case interesting,
by allocating buffers separately */
for (i=0; i<myNX; i++) {
buf[i] = (int*) malloc(NY * sizeof(int));
buf[i] = (int*) malloc(sizeof(int) * NY);
for (j=0; j<NY; j++) buf[i][j] = rank+10;
}

reqs = (int*) malloc(myNX * sizeof(int));
sts = (int*) malloc(myNX * sizeof(int));
reqs = (int*) malloc(sizeof(int) * myNX);
sts = (int*) malloc(sizeof(int) * myNX);

/* each proc writes myNX columns of the 2D array, block_len controls the
number of contiguous columns at a time */
Expand Down Expand Up @@ -272,15 +272,15 @@ int main(int argc, char** argv) {
ERR

/* initialize the buffer with -1, so a read error can be pinpointed */
buf = (int**) malloc(myNX * sizeof(int*));
buf[0] = (int*) malloc(global_ny * myNX * sizeof(int));
buf = (int**) malloc(sizeof(int*) * myNX);
buf[0] = (int*) malloc(sizeof(int) * global_ny * myNX);
for (i=0; i<myNX; i++) {
if (i > 0) buf[i] = buf[i-1] + global_ny;
for (j=0; j<global_ny; j++) buf[i][j] = -1;
}

reqs = (int*) malloc(myNX * sizeof(int));
sts = (int*) malloc(myNX * sizeof(int));
reqs = (int*) malloc(sizeof(int) * myNX);
sts = (int*) malloc(sizeof(int) * myNX);

/* each proc reads myNX columns of the 2D array, block_len controls the
number of contiguous columns at a time */
Expand Down
10 changes: 5 additions & 5 deletions examples/C/bput_varn_int64.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ static MPI_Offset *** calloc_3D(size_t z, size_t y, size_t x)
{
if (z*y*x == 0) return NULL;
int _j, _k;
MPI_Offset ***buf = (MPI_Offset***) malloc(z * sizeof(MPI_Offset**));
MPI_Offset **bufy = (MPI_Offset**) malloc(z*y * sizeof(MPI_Offset*));
MPI_Offset ***buf = (MPI_Offset***) malloc(sizeof(MPI_Offset**) * z);
MPI_Offset **bufy = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * z*y);
MPI_Offset *bufx = (MPI_Offset*) calloc(z*y*x, sizeof(MPI_Offset));
for (_k=0; _k<z; _k++, bufy+=y) {
buf[_k] = bufy;
Expand Down Expand Up @@ -191,7 +191,7 @@ static int check_contents(int ncid, int *varid)
3, 2, 0, 2, 3, 2, 3, 2, 1, 1,
3, 0, 2, 1, 2, 0, 2, 1, 2, 0}};

long long *r_buffer = (long long*) malloc(NY*NX*sizeof(long long));
long long *r_buffer = (long long*) malloc(sizeof(long long)*NY*NX);

for (i=0; i<4; i++) {
for (j=0; j<NY*NX; j++) r_buffer[j] = 99999;
Expand Down Expand Up @@ -388,7 +388,7 @@ int main(int argc, char** argv)
if (verbose) printf("req_lens[%d]=%d\n",i,req_lens[i]);

/* allocate I/O buffer and initialize its contents */
buffer[i] = (long long*) malloc(req_lens[i] * sizeof(long long));
buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i]);
for (j=0; j<req_lens[i]; j++) buffer[i][j] = rank;

bufsize += req_lens[i];
Expand Down Expand Up @@ -420,7 +420,7 @@ int main(int argc, char** argv)
MPI_Datatype buftype;
MPI_Type_vector(req_lens[i], 1, 2, MPI_UNSIGNED, &buftype);
MPI_Type_commit(&buftype);
buffer[i] = (long long*) malloc(req_lens[i] * 2 * sizeof(long long));
buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i] * 2);
for (j=0; j<req_lens[i]*2; j++) buffer[i][j] = rank;

err = ncmpi_bput_varn(ncid, varid[i], num_segs[i], starts[i],
Expand Down
10 changes: 5 additions & 5 deletions examples/C/bput_varn_uint.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ static MPI_Offset *** calloc_3D(size_t z, size_t y, size_t x)
{
if (z*y*x == 0) return NULL;
int _j, _k;
MPI_Offset ***buf = (MPI_Offset***) malloc(z * sizeof(MPI_Offset**));
MPI_Offset **bufy = (MPI_Offset**) malloc(z*y * sizeof(MPI_Offset*));
MPI_Offset ***buf = (MPI_Offset***) malloc(sizeof(MPI_Offset**) * z);
MPI_Offset **bufy = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * z*y);
MPI_Offset *bufx = (MPI_Offset*) calloc(z*y*x, sizeof(MPI_Offset));
for (_k=0; _k<z; _k++, bufy+=y) {
buf[_k] = bufy;
Expand Down Expand Up @@ -167,7 +167,7 @@ static int check_contents(int ncid, int *varid)
2, 2, 1, 0, 0, 0, 3, 3, 2, 2,
3, 3, 3, 1, 2, 2, 2, 0, 0, 0}};

unsigned int *r_buffer = (unsigned int*) malloc(NY*NX*sizeof(unsigned int));
unsigned int *r_buffer = (unsigned int*) malloc(sizeof(unsigned int)*NY*NX);

for (i=0; i<4; i++) {
for (j=0; j<NY*NX; j++) r_buffer[j] = 99999;
Expand Down Expand Up @@ -322,7 +322,7 @@ int main(int argc, char** argv)
if (verbose) printf("req_lens[%d]=%d\n",i,req_lens[i]);

/* allocate I/O buffer and initialize its contents */
buffer[i] = (unsigned int*) malloc(req_lens[i] * sizeof(unsigned int));
buffer[i] = (unsigned int*) malloc(sizeof(unsigned int) * req_lens[i]);
for (j=0; j<req_lens[i]; j++) buffer[i][j] = rank;

bufsize += req_lens[i];
Expand Down Expand Up @@ -354,7 +354,7 @@ int main(int argc, char** argv)
MPI_Datatype buftype;
MPI_Type_vector(req_lens[i], 1, 2, MPI_UNSIGNED, &buftype);
MPI_Type_commit(&buftype);
buffer[i] = (unsigned int*) malloc(req_lens[i] * 2 * sizeof(unsigned int));
buffer[i] = (unsigned int*) malloc(sizeof(unsigned int) * req_lens[i] * 2);
for (j=0; j<req_lens[i]*2; j++) buffer[i][j] = rank;

err = ncmpi_bput_varn(ncid, varid[i], num_segs[i], starts[i],
Expand Down
2 changes: 1 addition & 1 deletion examples/C/collective_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)

/* allocate buffer and initialize with non-zero numbers */
for (i=0; i<NUM_VARS; i++) {
buf[i] = (int *) malloc(bufsize * sizeof(int));
buf[i] = (int *) malloc(sizeof(int) * bufsize);
for (j=0; j<bufsize; j++) buf[i][j] = rank * i + 123 + j;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/C/column_wise.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char** argv)

/* First, fill the entire array with zeros, using a blocking I/O.
Every process writes a subarray of size NY * myNX */
buf = (int**) malloc(myNX * sizeof(int*));
buf = (int**) malloc(sizeof(int*) * myNX);
buf[0] = (int*) calloc(NY * myNX, sizeof(int));
start[0] = 0; start[1] = myOff;
count[0] = NY; count[1] = myNX;
Expand All @@ -187,12 +187,12 @@ int main(int argc, char** argv)
/* initialize the buffer with rank ID. Also make the case interesting,
by allocating buffers separately */
for (i=0; i<myNX; i++) {
buf[i] = (int*) malloc(NY * sizeof(int));
buf[i] = (int*) malloc(sizeof(int) * NY);
for (j=0; j<NY; j++) buf[i][j] = rank;
}

reqs = (int*) malloc(myNX * sizeof(int));
sts = (int*) malloc(myNX * sizeof(int));
reqs = (int*) malloc(sizeof(int) * myNX);
sts = (int*) malloc(sizeof(int) * myNX);

/* each proc writes myNX single columns of the 2D array */
start[0] = 0; start[1] = rank;
Expand Down
4 changes: 2 additions & 2 deletions examples/C/flexible_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int main(int argc, char** argv)
MPI_Type_commit(&subarray);

int buffer_len = (NZ+2*ghost_len) * (NY+2*ghost_len);
buf_zy = (int*) malloc(buffer_len * sizeof(int));
buf_zy = (int*) malloc(sizeof(int) * buffer_len);
for (i=0; i<buffer_len; i++) buf_zy[i] = rank;

start[0] = NZ * rank; start[1] = 0;
Expand Down Expand Up @@ -243,7 +243,7 @@ int main(int argc, char** argv)
MPI_Type_commit(&subarray);

buffer_len = (NY+2*ghost_len) * (NX+2*ghost_len);
buf_yx = (double*) malloc(buffer_len * sizeof(double));
buf_yx = (double*) malloc(sizeof(double) * buffer_len);
for (i=0; i<buffer_len; i++) buf_yx[i] = rank;

start[0] = 0; start[1] = NX * rank;
Expand Down
4 changes: 2 additions & 2 deletions examples/C/get_vara.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ pnetcdf_io(MPI_Comm comm, char *filename)
err = ncmpi_inq_attlen(ncid, varid, "float_att_name", &len); ERR

/* get attribute contents */
float_att = (float*) malloc(len * sizeof(float));
float_att = (float*) malloc(sizeof(float) * len);
err = ncmpi_get_att_float(ncid, varid, "float_att_name", float_att); ERR
free(float_att);

/* the local array size */
local_ny = global_ny;
local_nx = global_nx / nprocs;
buf = (int*) malloc(local_nx * local_ny * sizeof(int));
buf = (int*) malloc(sizeof(int) * local_nx * local_ny);

/* prepare reading subarray */
start[0] = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/C/ghost_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
/* allocate and initialize buffer with ghost cells on both ends of each dim */
nghosts = 2;
bufsize = (counts[0] + 2 * nghosts) * (counts[1] + 2 * nghosts);
buf = (int *) malloc(bufsize * sizeof(int));
buf = (int *) malloc(sizeof(int) * bufsize);
for (i=0; i<counts[0]+2*nghosts; i++)
for (j=0; j<counts[1]+2*nghosts; j++) {
if (nghosts <= i && i < counts[0]+nghosts &&
Expand Down
4 changes: 2 additions & 2 deletions examples/C/hints.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ int main(int argc, char** argv)
err = ncmpi_enddef(ncid); ERR

/* var_zy is partitioned along Z dimension */
buf_zy = (int*) malloc(NZ * (NY * nprocs) * sizeof(int));
buf_zy = (int*) malloc(sizeof(int) * NZ * (NY * nprocs));
for (i=0; i<NZ*(NY*nprocs); i++) buf_zy[i] = i;

start[0] = NZ * rank; start[1] = 0;
count[0] = NZ; count[1] = NY * nprocs;
err = ncmpi_put_vara_int_all(ncid, varid0, start, count, buf_zy); ERR

/* var_yx is partitioned along X dimension */
buf_yx = (float*) malloc((NY * nprocs) * NX * sizeof(float));
buf_yx = (float*) malloc(sizeof(float) * (NY * nprocs) * NX);
for (i=0; i<(NY*nprocs)*NX; i++) buf_yx[i] = i;

start[0] = 0; start[1] = NX * rank;
Expand Down
10 changes: 5 additions & 5 deletions examples/C/i_varn_int64.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ static MPI_Offset *** calloc_3D(size_t z, size_t y, size_t x)
{
if (z*y*x == 0) return NULL;
int _j, _k;
MPI_Offset ***buf = (MPI_Offset***) malloc(z * sizeof(MPI_Offset**));
MPI_Offset **bufy = (MPI_Offset**) malloc(z*y * sizeof(MPI_Offset*));
MPI_Offset ***buf = (MPI_Offset***) malloc(sizeof(MPI_Offset**) * z);
MPI_Offset **bufy = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * z*y);
MPI_Offset *bufx = (MPI_Offset*) calloc(z*y*x, sizeof(MPI_Offset));
for (_k=0; _k<z; _k++, bufy+=y) {
buf[_k] = bufy;
Expand Down Expand Up @@ -168,7 +168,7 @@ static int check_contents(int ncid, int *varid)
2, 2, 1, 0, 0, 0, 3, 3, 2, 2,
3, 3, 3, 1, 2, 2, 2, 0, 0, 0}};

long long *r_buffer = (long long*) malloc(NY*NX * sizeof(long long));
long long *r_buffer = (long long*) malloc(sizeof(long long) * NY*NX);

for (i=0; i<4; i++) {
for (j=0; j<NY*NX; j++) r_buffer[j] = -1;
Expand Down Expand Up @@ -322,7 +322,7 @@ int main(int argc, char** argv)
if (verbose) printf("req_lens[%d]=%d\n",i,req_lens[i]);

/* allocate I/O buffer and initialize its contents */
buffer[i] = (long long*) malloc(req_lens[i] * sizeof(long long));
buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i]);
for (j=0; j<req_lens[i]; j++) buffer[i][j] = rank;
}

Expand Down Expand Up @@ -366,7 +366,7 @@ int main(int argc, char** argv)
MPI_Datatype buftype;
MPI_Type_vector(req_lens[i], 1, 2, MPI_LONG_LONG, &buftype);
MPI_Type_commit(&buftype);
buffer[i] = (long long*) malloc(req_lens[i] * 2 * sizeof(long long));
buffer[i] = (long long*) malloc(sizeof(long long) * req_lens[i] * 2);
for (j=0; j<req_lens[i]*2; j++) buffer[i][j] = rank;

err = ncmpi_iput_varn(ncid, varid[i], num_segs[i], starts[i],
Expand Down
14 changes: 7 additions & 7 deletions examples/C/mput.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ int main(int argc, char** argv)
else if (rank == 3) num_reqs = 4;

if (num_reqs > 0) {
starts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*));
counts = (MPI_Offset**) malloc(num_reqs* sizeof(MPI_Offset*));
starts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs);
counts = (MPI_Offset**) malloc(sizeof(MPI_Offset*) * num_reqs);
starts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset));
counts[0] = (MPI_Offset*) calloc(num_reqs*NDIMS, sizeof(MPI_Offset));
for (i=1; i<num_reqs; i++) {
Expand Down Expand Up @@ -226,9 +226,9 @@ int main(int argc, char** argv)
*/
}

nvarids = (int*) malloc(num_reqs * sizeof(int));
bufcounts = (MPI_Offset*) malloc(num_reqs * sizeof(MPI_Offset));
datatypes = (MPI_Datatype*) malloc(num_reqs * sizeof(MPI_Datatype));
nvarids = (int*) malloc(sizeof(int) * num_reqs);
bufcounts = (MPI_Offset*) malloc(sizeof(MPI_Offset) * num_reqs);
datatypes = (MPI_Datatype*) malloc(sizeof(MPI_Datatype) * num_reqs);
w_len = 0;
for (i=0; i<num_reqs; i++) {
nvarids[i] = varid;
Expand All @@ -238,11 +238,11 @@ int main(int argc, char** argv)
}

/* allocate I/O buffer and initialize its contents */
buffer = (int*) malloc(w_len * sizeof(int));
buffer = (int*) malloc(sizeof(int) * w_len);
for (i=0; i<w_len; i++) buffer[i] = rank;

/* set the buffer pointers to different offsets to the I/O buffer */
bufs = (int**) malloc(num_reqs * sizeof(int*));
bufs = (int**) malloc(sizeof(int*) * num_reqs);
if (num_reqs > 0) bufs[0] = buffer;
for (i=1; i<num_reqs; i++) bufs[i] = bufs[i-1] + bufcounts[i-1];

Expand Down
Loading