Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when using clang -Wshorten-64-to-32 #135

Merged
merged 20 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8b7ff15
Name strlen of dim/var/attr is expected < NC_MAX_INT
wkliao Mar 19, 2024
fff0ec7
File name strlen is expected < NC_MAX_INT
wkliao Mar 19, 2024
0344d07
use size_t for C functions returning integer of type size_t
wkliao Mar 19, 2024
777d607
proper type cast, as these test programs test small problem size
wkliao Mar 19, 2024
9abedd7
proper type cast and remove tab characters
wkliao Mar 19, 2024
9e48ca0
put_att consistency check: use MPI large count APIs if available
wkliao Mar 19, 2024
125d40d
check against X_INT_MAX
wkliao Mar 19, 2024
bfa3b8f
use size_t for memory buffer operations
wkliao Mar 19, 2024
63cc3be
type cast, check NC_EINTOVERFLOW, and fix MPI error checking
wkliao Mar 19, 2024
4209056
Hints nc_header_read_chunk_size and nc_num_subfiles are of type int
wkliao Mar 19, 2024
87e646b
req_size has been checked against NC_MAX_INT
wkliao Mar 19, 2024
39bc2e5
use 'chunk' instead of 'size', better describing its purpose
wkliao Mar 19, 2024
6451ff5
Update/overwrite file header in multiple runs if large
wkliao Mar 19, 2024
c476d70
use MPI_Type_create_hindexed_c for large datatype
wkliao Mar 19, 2024
29d45fb
--large-single-req has been removed in #131
wkliao Mar 19, 2024
d4f1ffd
dump memory footprint in verbose mode
wkliao Mar 19, 2024
6202203
free allocated memory before return NC_EINTOVERFLOW
wkliao Mar 19, 2024
923e7a7
wrap error code for debugging
wkliao Mar 19, 2024
eb9d70f
fix: nelems may not be = nblocks
wkliao Mar 19, 2024
3551cf8
fix typecast 64-to-32 bit int
wkliao Mar 19, 2024
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
4 changes: 2 additions & 2 deletions examples/C/block_cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int main(int argc, char** argv) {
i, start[0],start[1], count[0],count[1]);

if (i % block_len == block_len-1) {
int stride = MIN(myNX-1-i, block_len);
MPI_Offset stride = MIN(myNX-1-i, block_len);
block_start += block_len * nprocs;
start[1] = block_start + stride * rank;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ int main(int argc, char** argv) {
ERR

if (i % block_len == block_len-1) {
int stride = MIN(myNX-1-i, block_len);
MPI_Offset stride = MIN(myNX-1-i, block_len);
block_start += block_len * nprocs;
start[1] = block_start + stride * rank;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/C/ghost_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ pnetcdf_check_mem_usage(MPI_Comm comm)
static int
pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
{
int i, j, rank, nprocs, ncid, bufsize, err, nerrs=0;
int i, j, rank, nprocs, ncid, err, nerrs=0;
int psizes[2], local_rank[2], dimids[2], varid, nghosts;
int *buf, *buf_ptr;
size_t bufsize;
MPI_Offset gsizes[2], starts[2], counts[2], imap[2];

MPI_Comm_rank(comm, &rank);
Expand Down
2 changes: 1 addition & 1 deletion examples/C/global_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int main(int argc, char** argv)
sprintf(str_att, "Mon Aug 13 21:27:48 2018");

/* make sure the time string are consistent among all processes */
MPI_Bcast(str_att, strlen(str_att), MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Bcast(str_att, (int)strlen(str_att), MPI_CHAR, 0, MPI_COMM_WORLD);

err = ncmpi_put_att_text(ncid, NC_GLOBAL, "history", strlen(str_att),
&str_att[0]); ERR
Expand Down
5 changes: 3 additions & 2 deletions examples/C/transpose.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
for (j=0; j<counts[1]; j++)
for (i=0; i<counts[2]; i++)
buf[k*counts[1]*counts[2] +
j*counts[2] + i] = (starts[0]+k)*gsizes[1]*gsizes[2]
j*counts[2] + i] = (int)(
(starts[0]+k)*gsizes[1]*gsizes[2]
+ (starts[1]+j)*gsizes[2]
+ (starts[2]+i);
+ (starts[2]+i));

/* set an MPI-IO hint to disable file offset alignment for fixed-size
* variables */
Expand Down
10 changes: 5 additions & 5 deletions examples/C/transpose2D.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
char str[512];
int i, j, rank, nprocs, ncid, bufsize, err, nerrs=0;
int *buf, psizes[NDIMS], dimids[NDIMS], dimidsT[NDIMS];
int XY_id, YX_id;
int XY_id, YX_id, lower_dims;
MPI_Offset gsizes[NDIMS], start[NDIMS], count[NDIMS], imap[NDIMS];
MPI_Offset startT[NDIMS], countT[NDIMS];
MPI_Info info;
Expand All @@ -137,7 +137,7 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)

/* for each MPI rank, find its local rank IDs along each dimension in
* start[] */
int lower_dims=1;
lower_dims = 1;
for (i=NDIMS-1; i>=0; i--) {
start[i] = rank / lower_dims % psizes[i];
lower_dims *= psizes[i];
Expand All @@ -160,7 +160,7 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
buf = (int *) malloc(bufsize * sizeof(int));
for (i=0; i<count[0]; i++)
for (j=0; j<count[1]; j++)
buf[i*count[1] + j] = (start[0]+i)*gsizes[1] + (start[1]+j);
buf[i*count[1] + j] = (int)((start[0]+i)*gsizes[1] + (start[1]+j));

/* set an MPI-IO hint to disable file offset alignment for fixed-size
* variables */
Expand Down Expand Up @@ -219,12 +219,12 @@ pnetcdf_io(MPI_Comm comm, char *filename, int cmode, int len)
/* check the contents */
for (i=0; i<countT[0]; i++)
for (j=0; j<countT[1]; j++) {
int expect = (start[1]+i) + gsizes[1] * (start[0]+j);
int expect = (int)((start[1]+i) + gsizes[1] * (start[0]+j));
if (buf[i*countT[1] + j] != expect) {
printf("Error at %s:%d: expect buf[%lld]=%d but got %d\n",
__FILE__,__LINE__,i*countT[1]+j,expect,buf[i*count[1]+j]);
nerrs++;
i = count[1]; /* break loop i */
i = (int)count[1]; /* also break loop i */
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/C/vard_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ int main(int argc, char **argv) {
int i, j, err, nerrs=0, ncid, varid0, varid1, dimids[2];
int rank, nprocs, array_of_blocklengths[2], buf[NY][NX];
int array_of_sizes[2], array_of_subsizes[2], array_of_starts[2];
MPI_Offset start[2], count[2], recsize, bufcount, len;
int start[2], count[2];
MPI_Offset recsize, bufcount, len;
MPI_Aint array_of_displacements[2];
MPI_Datatype buftype, rec_filetype, fix_filetype;

Expand Down
16 changes: 7 additions & 9 deletions examples/C/vard_mvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main(int argc, char **argv)
int rank, nprocs, *buf[2];
int array_of_sizes[2], array_of_subsizes[2], array_of_starts[2];
int array_of_blocklengths[NY];
MPI_Offset recsize, start[2], count[2], offset[2];
MPI_Offset recsize, offset[2];
MPI_Aint a0, a1, array_of_displacements[NY];
MPI_Datatype buftype, vtype[2], filetype;

Expand Down Expand Up @@ -217,16 +217,14 @@ int main(int argc, char **argv)

/* specify the access pattern, a subarray for each variable of size
* NY * NX from each MPI process */
start[0] = 0; start[1] = NX*rank;
count[0] = NY; count[1] = NX;

/* create the first datatype using MPI subarray constructor */
array_of_sizes[0] = 2;
array_of_sizes[1] = NX*nprocs;
array_of_subsizes[0] = count[0];
array_of_subsizes[1] = count[1];
array_of_starts[0] = start[0];
array_of_starts[1] = start[1];
array_of_subsizes[0] = NY;
array_of_subsizes[1] = NX;
array_of_starts[0] = 0;
array_of_starts[1] = NX*rank;

/* create the first datatype using MPI subarray constructor */
MPI_Type_create_subarray(2, array_of_sizes, array_of_subsizes,
array_of_starts, MPI_ORDER_C, MPI_INT, &vtype[0]);
MPI_Type_commit(&vtype[0]);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/pnetcdf-permute.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char **argv) {
char filename[256];
int i, j, k, rank, nprocs, ret;
int ncfile, ndims=NDIMS;
MPI_Offset dim_sizes[NDIMS];
int dim_sizes[NDIMS];
MPI_Offset start[NDIMS], count[NDIMS], nitems;
int dimids[NDIMS], transposed_dims[NDIMS];
int varid1, transposed_varid, flexible_varid;
Expand Down
7 changes: 5 additions & 2 deletions examples/tutorial/pnetcdf-read-from-master.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ int main(int argc, char **argv) {
}

/*and finally all processors have the data */
err = MPI_Bcast(data, var_size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_ERR(err)
if (var_size < NC_MAX_INT) {
err = MPI_Bcast(data, (int)var_size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_ERR(err)
}
/* else: must call MPI_Bcast_c() for large count requests */

/* Here, every process can do computation on the local buffer, data,
or copy the contents to somewhere else */
Expand Down
35 changes: 31 additions & 4 deletions src/dispatchers/attr_getput.m4
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ check_consistency_put(MPI_Comm comm,
MPI_Comm_rank(comm, &rank);

/* check if attribute name is consistent among all processes */
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down Expand Up @@ -179,27 +179,54 @@ check_consistency_put(MPI_Comm comm,

/* check if nelems is consistent across all processes */
root_nelems = nelems;

#if !defined(HAVE_MPI_TYPE_SIZE_C) && !defined(HAVE_MPI_TYPE_SIZE_X)
if (root_nelems > NC_MAX_INT) {
DEBUG_ASSIGN_ERROR(err, NC_EINTOVERFLOW)
root_nelems = 0;
}
#endif

TRACE_COMM(MPI_Bcast)(&root_nelems, 1, MPI_OFFSET, 0, comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast");
if (err == NC_NOERR && root_nelems != nelems)
DEBUG_ASSIGN_ERROR(err, NC_EMULTIDEFINE_ATTR_LEN)

/* must continue to participate collective calls below, even if error */

/* check if buf contents is consistent across all processes */
if (root_nelems > 0) { /* non-scalar attribute */
/* note xsz is aligned, thus must use the exact size of buf */
int itype_size, rank, buf_size;
int rank, itype_size;
size_t buf_size;
void *root_buf;

MPI_Comm_rank(comm, &rank);

/* for attributes, itype is nc_type, so its size is small. Thus, no
* need to check against NC_MAX_INT.
*/
MPI_Type_size(itype, &itype_size);
buf_size = (int)root_nelems * itype_size;
buf_size = root_nelems * itype_size;

if (rank > 0) root_buf = (void*) NCI_Malloc(buf_size);
else root_buf = (void*)buf;

TRACE_COMM(MPI_Bcast)(root_buf, root_nelems, itype, 0, comm);
if (root_nelems > NC_MAX_INT) {
#ifdef HAVE_MPI_BCAST_C
TRACE_COMM(MPI_Bcast_c)(root_buf, root_nelems, itype, 0, comm);
#else
/* Note root_nelems has been bcast-ed, same value among all ranks */
DEBUG_ASSIGN_ERROR(err, NC_EMULTIDEFINE_ATTR_LEN)
#endif
}
else
TRACE_COMM(MPI_Bcast)(root_buf, (int)root_nelems, itype, 0, comm);

if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast");

if (err == NC_NOERR &&
(root_nelems != nelems || memcmp(root_buf, buf, buf_size)))
DEBUG_ASSIGN_ERROR(err, NC_EMULTIDEFINE_ATTR_VAL)
Expand Down
8 changes: 4 additions & 4 deletions src/dispatchers/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ncmpi_copy_att(int ncid_in,

/* check if name is consistent among all processes */
assert(name != NULL);
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp_out->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down Expand Up @@ -300,7 +300,7 @@ ncmpi_rename_att(int ncid,

/* check if name is consistent among all processes */
assert(name != NULL);
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand All @@ -318,7 +318,7 @@ ncmpi_rename_att(int ncid,

/* check if newname is consistent among all processes */
assert(newname != NULL);
root_name_len = strlen(newname) + 1;
root_name_len = (int)strlen(newname) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down Expand Up @@ -410,7 +410,7 @@ ncmpi_del_att(int ncid,

/* check if name is consistent among all processes */
assert(name != NULL);
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down
4 changes: 2 additions & 2 deletions src/dispatchers/dimension.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ncmpi_def_dim(int ncid, /* IN: file ID */

/* check if name is consistent among all processes */
assert(name != NULL);
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down Expand Up @@ -297,7 +297,7 @@ ncmpi_rename_dim(int ncid, /* IN: file ID */

/* check if name is consistent among all processes */
assert(newname != NULL);
root_name_len = strlen(newname) + 1;
root_name_len = (int)strlen(newname) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down
4 changes: 2 additions & 2 deletions src/dispatchers/variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ncmpi_def_var(int ncid, /* IN: file ID */

/* check if name is consistent among all processes */
assert(name != NULL);
root_name_len = strlen(name) + 1;
root_name_len = (int)strlen(name) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down Expand Up @@ -666,7 +666,7 @@ ncmpi_rename_var(int ncid, /* IN: file ID */

/* check if newname is consistent among all processes */
assert(newname != NULL);
root_name_len = strlen(newname) + 1;
root_name_len = (int)strlen(newname) + 1;
TRACE_COMM(MPI_Bcast)(&root_name_len, 1, MPI_INT, 0, pncp->comm);
if (mpireturn != MPI_SUCCESS)
return ncmpii_error_mpi2nc(mpireturn, "MPI_Bcast root_name_len");
Expand Down
11 changes: 8 additions & 3 deletions src/drivers/common/ncx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2120,9 +2120,14 @@ APIPrefix`x_put_off_t'(void **xpp, const off_t *lp, size_t sizeof_off_t)
#ifdef WORDS_BIGENDIAN
memcpy(*xpp, lp, 4);
#else
int xtmp, itmp = *lp;
xtmp = SWAP4(itmp);
memcpy(*xpp, &xtmp, 4);
if (*lp > X_INT_MAX)
DEBUG_RETURN_ERROR(NC_EINTOVERFLOW)
else {
int xtmp, itmp;
itmp = (int)*lp;
xtmp = SWAP4(itmp);
memcpy(*xpp, &xtmp, 4);
}
#endif
} else {
#ifdef WORDS_BIGENDIAN
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ char* ncmpii_remove_file_system_type_prefix(const char *filename)
/* check if prefix is one of recognized file system types */
int i=0;
while (fstypes[i] != NULL) {
int prefix_len = strlen(fstypes[i]);
size_t prefix_len = strlen(fstypes[i]);
if (!strncmp(filename, fstypes[i], prefix_len)) { /* found */
ret_filename += prefix_len + 1;
break;
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/ncbbio/ncbbio_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef struct NC_bb_metadataheader {
MPI_Offset max_ndims;
MPI_Offset num_entries;
MPI_Offset entry_begin;
int basenamelen;
size_t basenamelen;
char basename[1]; /* The hack to keep basename inside the structure */
} NC_bb_metadataheader;

Expand All @@ -97,7 +97,7 @@ typedef struct NC_bb_metadataptr {
typedef struct NC_bb_metadataidx {
NC_bb_metadataptr *entries;
int nused;
int nalloc;
size_t nalloc;
} NC_bb_metadataidx;

/* Buffer structure */
Expand Down Expand Up @@ -134,8 +134,8 @@ typedef struct NC_bb_put_req {
typedef struct NC_bb_put_list {
NC_bb_put_req *reqs; // Array of request object
int *ids; // Array of request ids
int nalloc; // Size of the pool
int nused; // Number of ids issued
size_t nalloc; // Size of the pool
size_t nused; // Number of ids issued
} NC_bb_put_list;

/* Shared file object */
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/ncbbio/ncbbio_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
int ncbbio_log_create(NC_bb* ncbbp,
__attribute__((unused)) MPI_Info info)
{
int i, rank, np, err, flag, masterrank, procname_len;
int rank, np, err, flag, masterrank, procname_len;
char logbase[NC_LOG_MAX_PATH], basename[NC_LOG_MAX_PATH];
char procname[MPI_MAX_PROCESSOR_NAME];
char *abspath, *fname, *path, *fdir = NULL;
Expand Down Expand Up @@ -86,7 +86,7 @@ int ncbbio_log_create(NC_bb* ncbbp,
logbasep = ncmpii_remove_file_system_type_prefix(ncbbp->logbase);
}
else {
i = strlen(path);
size_t i = strlen(path);
fdir = (char*)NCI_Malloc((i + 1) * sizeof(char));
strncpy(fdir, path, i + 1);
/* Search for first '\' from the back */
Expand Down
8 changes: 5 additions & 3 deletions src/drivers/ncbbio/ncbbio_nonblocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ int ncbbio_put_list_init(NC_bb *ncbbp) {
*/
static int ncbbio_put_list_resize(NC_bb *ncbbp)
{
int i;
ssize_t nsize;
size_t i, nsize;
void *ptr;
NC_bb_put_list *lp = &(ncbbp->putlist);

Expand All @@ -109,8 +108,11 @@ static int ncbbio_put_list_resize(NC_bb *ncbbp)
/* Initialize values of ids and reqs
* Assign increasing unique id
*/
if (nsize > NC_MAX_INT)
DEBUG_RETURN_ERROR(NC_EINTOVERFLOW)

for (i=lp->nalloc; i<nsize; i++) {
lp->ids[i] = i; // Unique ids
lp->ids[i] = (int)i; // Unique ids
lp->reqs[i].valid = 0; // Not in use
}

Expand Down
Loading