Changeset 622

Show
Ignore:
Timestamp:
09/16/08 16:47:00 (5 months ago)
Author:
kgao
Message:

dimension with more than 231 elements support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CDF3/src/lib/dim.c

    r613 r622  
    332332                        return NC_EDIMSIZE; 
    333333        } else if ((ncp->flags & NC_64BIT_DATA)) { 
    334                 /* CDF3 format*/ 
    335                 if (size > X_UINT_MAX - 3 || (size < 0))  
     334                /* CDF5 format*/ 
     335                if (size < 0)  
    336336                        /* "-3" handles rounded-up size */ 
    337337                        return NC_EDIMSIZE; 
  • trunk/CDF3/src/lib/mpinetcdf.c

    r613 r622  
    845845        { 
    846846                 
    847                 if(*coord > X_INT_MAX) 
     847                if(*coord > X_INT64_T_MAX) 
    848848                        return NC_EINVALCOORDS; /* sanity check */ 
    849849                if(NC_readonly(ncp) && *coord >= ncp->numrecs) 
     
    873873        { 
    874874                /* cast needed for braindead systems with signed int64_t */ 
    875                 if( *ip >= (unsigned long)*up ) 
     875                if( *ip >= (uint64_t)*up ) 
    876876                        return NC_EINVALCOORDS; 
    877877        } 
     
    903903  { 
    904904    /* cast needed for braindead systems with signed int64_t */ 
    905     if( *edges > (unsigned long)*shp || *start + *edges > (unsigned long)*shp) 
     905    if( *edges > (uint64_t)*shp || *start + *edges > (uint64_t)*shp) 
    906906    { 
    907907      return(NC_EEDGE); 
     
    926926  if(IS_RECVAR(varp)) 
    927927  { 
    928     if ( *stride == 0 || *stride >= X_INT_MAX) 
     928    if ( *stride == 0 || *stride >= X_INT64_T_MAX) 
    929929      /* cast needed for braindead systems with signed int64_t */ 
    930930      return NC_ESTRIDE; 
     
    939939  { 
    940940    /* cast needed for braindead systems with signed int64_t */ 
    941     if( (*edges > (unsigned long)*shp) ||  
    942         (*edges > 0 && *start+1 + (*edges-1) * *stride > (unsigned long)*shp) || 
    943         (*edges == 0 && *start > (unsigned long)*shp) ) 
     941    if( (*edges > (uint64_t)*shp) ||  
     942        (*edges > 0 && *start+1 + (*edges-1) * *stride > (uint64_t)*shp) || 
     943        (*edges == 0 && *start > (uint64_t)*shp) ) 
    944944    { 
    945945      return(NC_EEDGE); 
    946946    } 
    947947 
    948     if ( *stride == 0 || *stride >= X_INT_MAX) 
     948    if ( *stride == 0 || *stride >= X_INT64_T_MAX) 
    949949      /* cast needed for braindead systems with signed int64_t */ 
    950950      return NC_ESTRIDE; 
     
    10631063  int64_t dim, ndims; 
    10641064  int *shape = NULL, *subcount = NULL, *substart = NULL; /* all in bytes */ 
     1065  int64_t *shape64 = NULL, *subcount64 = NULL, *substart64 = NULL; 
    10651066  MPI_Datatype rectype; 
    10661067  MPI_Datatype filetype; 
    10671068  int mpireturn; 
     1069  MPI_Datatype types[3]; 
     1070  MPI_Datatype type1; 
     1071  int64_t size, disps[3]; 
     1072  int blklens[3]; 
     1073  int tag = 0; 
     1074  int i; 
     1075   
    10681076 
    10691077  offset = varp->begin; 
     
    11871195 
    11881196      } else { 
    1189  
     1197         
    11901198        /* non record variable */ 
    1191  
    1192         for (dim = 0; dim < ndims-1; dim++ ) { 
    1193           shape[dim] = varp->shape[dim]; 
    1194           subcount[dim] = count[dim]; 
    1195           substart[dim] = start[dim]; 
    1196         } 
    1197  
    1198         shape[dim] = varp->xsz * varp->shape[dim]; 
    1199         subcount[dim] = varp->xsz * count[dim]; 
    1200         substart[dim] = varp->xsz * start[dim]; 
    1201  
    1202         MPI_Type_create_subarray(ndims, shape, subcount, substart,  
    1203                          MPI_ORDER_C, MPI_BYTE, &filetype);  
    1204  
    1205         MPI_Type_commit(&filetype); 
    1206       } 
     1199       tag = 0; 
     1200         for (dim=0; dim< ndims-1; dim++){ 
     1201           if  (varp->shape[dim] > 2147483647){ /* if shape > 2^31-1 */ 
     1202                tag = 1; 
     1203                break; 
     1204           } 
     1205         } 
     1206       if ((varp->shape[dim]*varp->xsz)  > 2147483647) 
     1207          tag = 1; 
     1208       if (tag == 0 ){ 
     1209          for (dim = 0; dim < ndims-1; dim++ ) { 
     1210            shape[dim] = varp->shape[dim]; 
     1211            subcount[dim] = count[dim]; 
     1212            substart[dim] = start[dim]; 
     1213          }  
     1214 
     1215          shape[dim] = varp->xsz * varp->shape[dim]; 
     1216          subcount[dim] = varp->xsz * count[dim]; 
     1217          substart[dim] = varp->xsz * start[dim]; 
     1218   
     1219          MPI_Type_create_subarray(ndims, shape, subcount, substart,  
     1220                         MPI_ORDER_C, MPI_BYTE, &filetype);  
     1221   
     1222          MPI_Type_commit(&filetype); 
     1223        } else { 
     1224shape64 = (int64_t *)malloc(sizeof(int64_t) * ndims); 
     1225          subcount64 = (int64_t *)malloc(sizeof(int64_t) * ndims); 
     1226          substart64 = (int64_t *)malloc(sizeof(int64_t) * ndims); 
     1227 
     1228          if (ndims == 1){  // for 64-bit support,  added July 23, 2008 
     1229            shape64[0] = varp->shape[0]; 
     1230            subcount64[0] = count[0]; 
     1231            substart64[0] = start[0]; 
     1232 
     1233            offset += start[0]*varp->xsz; 
     1234 
     1235            MPI_Type_contiguous(subcount64[0]*varp->xsz, MPI_BYTE, &type1); 
     1236            MPI_Type_commit(&type1); 
     1237 
     1238          #if (MPI_VERSION < 2) 
     1239            MPI_Type_hvector(subcount64[0], varp->xsz, shape64[0]*varp->xsz, 
     1240                            MPI_BYTE, &filetype); 
     1241          #else 
     1242            MPI_Type_create_hvector(1, 1, shape64[0]*varp->xsz, 
     1243                                    type1, &filetype); 
     1244          #endif 
     1245            MPI_Type_commit(&filetype); 
     1246            MPI_Type_free(&type1); 
     1247 
     1248       } else { 
     1249          for (dim = 0; dim < ndims-1; dim++ ) { 
     1250            shape64[dim] = varp->shape[dim]; 
     1251            subcount64[dim] = count[dim]; 
     1252            substart64[dim] = start[dim]; 
     1253          } 
     1254 
     1255          shape64[dim] = varp->xsz * varp->shape[dim]; 
     1256          subcount64[dim] = varp->xsz * count[dim]; 
     1257          substart64[dim] = varp->xsz * start[dim]; 
     1258          MPI_Type_hvector(subcount64[dim-1], 
     1259                             subcount64[dim], 
     1260                             varp->xsz * varp->shape[dim], 
     1261                             MPI_BYTE, 
     1262                             &type1); 
     1263          MPI_Type_commit(&type1); 
     1264          size = shape[dim]; 
     1265          for (i=dim-2; i>=0; i--) { 
     1266                size *= shape[i+1]; 
     1267                MPI_Type_hvector(subcount64[i], 
     1268                                 1, 
     1269                                 size, 
     1270                                 type1, 
     1271                                 &filetype); 
     1272                MPI_Type_commit(&filetype); 
     1273 
     1274                MPI_Type_free(&type1); 
     1275                type1 = filetype; 
     1276          } 
     1277          disps[1] = substart64[dim]; 
     1278          size = 1; 
     1279          for (i=dim-1; i>=0; i--) { 
     1280            size *= shape64[i+1]; 
     1281            disps[1] += size*substart64[i]; 
     1282          } 
     1283          disps[2] = 1; 
     1284          for (i=0; i<ndims; i++) disps[2] *= shape64[i]; 
     1285 
     1286          disps[0] = 0; 
     1287          blklens[0] = blklens[1] = blklens[2] = 1; 
     1288          types[0] = MPI_LB; 
     1289          types[1] = type1; 
     1290          types[2] = MPI_UB; 
     1291 
     1292          MPI_Type_struct(3, 
     1293                    blklens, 
     1294                    disps, 
     1295                    types, 
     1296                    &filetype); 
     1297 
     1298          MPI_Type_free(&type1); 
     1299         } 
     1300 
     1301         free(shape64); 
     1302         free(subcount64); 
     1303         free(substart64); 
     1304       } 
     1305     } 
     1306  
    12071307    } 
    12081308  } 
     
    12791379  { 
    12801380    if ( (stride != NULL && stride[dim] == 0) || 
    1281         stride[dim] >= X_INT_MAX) 
     1381        stride[dim] >= X_LONG_MAX) 
    12821382    { 
    12831383      return NC_ESTRIDE; 
     
    12931393 
    12941394 if(getnotput && IS_RECVAR(varp) && 
    1295      (unsigned long)*start + (unsigned long)*count > NC_get_numrecs(ncp)) 
     1395     (uint64_t)*start + (uint64_t)*count > NC_get_numrecs(ncp)) 
    12961396      return NC_EEDGE; 
    12971397*/ 
  • trunk/CDF3/src/lib/ncx.h

    r613 r622  
    109109#define X_OFF_MAX       X_INT_MAX 
    110110 
     111#define X_INT64_T_MAX   9223372036854775808 
     112#define X_UINT64_T_MAX  18446744073709551616U 
    111113 
    112114/* Begin ncx_len */ 
  • trunk/CDF3/src/lib/var.c

    r618 r622  
    360360 * 'compile' the shape and len of a variable 
    361361 *  Formerly 
    362 ncmpii_NC_var_shape(var, dims) 
     362 *   ncmpii_NC_var_shape(var, dims) 
    363363 */ 
    364364#include <stdio.h>