diff --git a/configure.ac b/configure.ac index 867a35d982..51a8c53990 100644 --- a/configure.ac +++ b/configure.ac @@ -184,6 +184,7 @@ fi AC_CHECK_SIZEOF(float) AC_CHECK_SIZEOF(double) AC_CHECK_SIZEOF(void *) +AC_CHECK_SIZEOF(size_t) # # Check for type alignments diff --git a/src/dps/dps_internal.h b/src/dps/dps_internal.h index 923746b226..bb25430cfb 100644 --- a/src/dps/dps_internal.h +++ b/src/dps/dps_internal.h @@ -33,6 +33,40 @@ extern "C" { */ #define ORTE_DPS_DEFAULT_PAGE_SIZE 1 +/* + * ORTE type corresponding to size_t + */ +#if SIZEOF_SIZE_T == 1 +#define DPS_TYPE_SIZE_T ORTE_UINT8 +#elif SIZEOF_SIZE_T == 2 +#define DPS_TYPE_SIZE_T ORTE_UINT16 +#elif SIZEOF_SIZE_T == 4 +#define DPS_TYPE_SIZE_T ORTE_UINT32 +#elif SIZEOF_SIZE_T == 8 +#define DPS_TYPE_SIZE_T ORTE_UINT64 +#else +#error Unsupported size_t size! +#endif + +/* + * ORTE type corresponding to int and unsigned int + */ +#if SIZEOF_INT == 1 +#define DPS_TYPE_INT ORTE_INT8 +#define DPS_TYPE_UINT ORTE_UINT8 +#elif SIZEOF_INT == 2 +#define DPS_TYPE_INT ORTE_INT16 +#define DPS_TYPE_UINT ORTE_UINT16 +#elif SIZEOF_INT == 4 +#define DPS_TYPE_INT ORTE_INT32 +#define DPS_TYPE_UINT ORTE_UINT32 +#elif SIZEOF_INT == 8 +#define DPS_TYPE_INT ORTE_INT64 +#define DPS_TYPE_UINT ORTE_UINT64 +#else +#error Unsupported int size! +#endif + /* * globals needed within dps */ diff --git a/src/dps/dps_pack.c b/src/dps/dps_pack.c index 8df8da27bc..f47dc069f2 100644 --- a/src/dps/dps_pack.c +++ b/src/dps/dps_pack.c @@ -49,37 +49,31 @@ int orte_dps_pack(orte_buffer_t *buffer, void *src, int32_t op_size=0; size_t num_bytes, hdr_bytes; - /* hdr_bytes = header for each packed type. */ - /* num_bytes = packed size of data type. */ - /* op_size = total size = (num_bytes+hdr_bytes) */ + /* hdr_bytes = header for each packed type. */ + /* num_bytes = packed size of data type. */ + /* op_size = total size = (num_bytes+hdr_bytes) */ /* check for error */ - if (!buffer || !src || 0 >= num_vals) { return (ORTE_ERROR); } + if (!buffer || !src || 0 >= num_vals) { + return (ORTE_ERROR); + } dst = buffer->data_ptr; /* get location in buffer */ - /* change into to fixed size type for local size */ - if (ORTE_INT == type || ORTE_UINT == type) { - switch(sizeof(int)) { - case 1: - type = (type == ORTE_INT) ? ORTE_INT8 : ORTE_UINT8; - break; - case 2: - type = (type == ORTE_INT) ? ORTE_INT16 : ORTE_UINT16; - break; - case 4: - type = (type == ORTE_INT) ? ORTE_INT32 : ORTE_UINT32; - break; - case 8: - type = (type == ORTE_INT) ? ORTE_INT64 : ORTE_UINT64; - break; - default: - return ORTE_ERR_NOT_IMPLEMENTED; - } + /* check for size of generic data types so they can be properly + packed NOTE we convert the generic data type flag to a hard + type for storage to handle heterogeneity */ + if (ORTE_INT == type) { + type = DPS_TYPE_INT; + } else if (ORTE_UINT == type) { + type = DPS_TYPE_UINT; + } else if (ORTE_SIZE == type) { + type = DPS_TYPE_SIZE_T; } /* calculate the required memory size for this operation */ - if (0 == (op_size = orte_dps_memory_required(src, num_vals, type))) { /* got error */ + if (0 == (op_size = orte_dps_memory_required(src, num_vals, type))) { + /* got error */ return ORTE_ERROR; } @@ -87,42 +81,19 @@ int orte_dps_pack(orte_buffer_t *buffer, void *src, hdr_bytes = orte_dps_memory_required(NULL, 1, ORTE_DATA_TYPE); /* add in the space to store the number of values */ - hdr_bytes += sizeof(uint32_t); + hdr_bytes += sizeof(size_t); - /* total space needed */ - op_size += hdr_bytes; + /* total space needed */ + op_size += hdr_bytes; /* check to see if current buffer has enough room */ if (op_size > buffer->space) { /* need to extend the buffer */ - if (ORTE_SUCCESS != (rc = orte_dps_buffer_extend(buffer, op_size))) { /* got an error */ + if (ORTE_SUCCESS != (rc = orte_dps_buffer_extend(buffer, op_size))) { + /* got an error */ return rc; } - dst = buffer->data_ptr; /* need to reset the dst since it could have moved */ - } - - /* check for size of generic data types so they can be properly packed - * NOTE we convert the generic data type flag to a hard type for storage - * to handle heterogeneity - */ - - - if (ORTE_SIZE == type) { - switch(sizeof(size_t)) { - case 1: - type = (type == ORTE_SIZE) ? ORTE_INT8 : ORTE_UINT8; - break; - case 2: - type = (type == ORTE_SIZE) ? ORTE_INT16 : ORTE_UINT16; - break; - case 4: - type = (type == ORTE_SIZE) ? ORTE_INT32 : ORTE_UINT32; - break; - case 8: - type = (type == ORTE_SIZE) ? ORTE_INT64 : ORTE_UINT64; - break; - default: - return ORTE_ERR_NOT_IMPLEMENTED; - } + /* need to reset the dst since it could have moved */ + dst = buffer->data_ptr; } /* store the data type */ @@ -135,7 +106,7 @@ int orte_dps_pack(orte_buffer_t *buffer, void *src, /* store the number of values as uint32_t */ if (ORTE_SUCCESS != (rc = orte_dps_pack_nobuffer(dst, &num_vals, 1, - ORTE_UINT32, &num_bytes))) { + DPS_TYPE_SIZE_T, &num_bytes))) { return rc; } dst = (void *)((char*)dst + num_bytes); @@ -146,15 +117,16 @@ int orte_dps_pack(orte_buffer_t *buffer, void *src, return rc; } - /* debugging */ - if (num_bytes+sizeof(uint32_t)+orte_dps_memory_required(NULL, 1, ORTE_DATA_TYPE) != (size_t)op_size) { - fprintf(stderr,"orte_dps_pack: Ops, num_bytes %d + headers %d = %d, but op_size was %d?!\n", - (int)num_bytes, (int)hdr_bytes, (int)(num_bytes+hdr_bytes), (int)op_size); - } -/* fflush(stdout); fflush(stderr); */ -/* fprintf(stderr,"packed total of %d bytes. Hdr %d datatype %d\n", op_size, hdr_bytes, num_bytes); */ -/* fflush(stdout); fflush(stderr); */ - +#if OMPI_ENABLE_DEBUG + /* debugging */ + if (num_bytes+sizeof(size_t)+orte_dps_memory_required(NULL, 1, ORTE_DATA_TYPE) != (size_t)op_size) { + fprintf(stderr,"orte_dps_pack: Ops, num_bytes %d + headers %d = %d, but op_size was %d?!\n", + (int)num_bytes, (int)hdr_bytes, (int)(num_bytes+hdr_bytes), (int)op_size); + } + /* fflush(stdout); fflush(stderr); */ + /* fprintf(stderr,"packed total of %d bytes. Hdr %d datatype %d\n", op_size, hdr_bytes, num_bytes); */ + /* fflush(stdout); fflush(stderr); */ +#endif /* ok, we managed to pack some more stuff, so update all ptrs/cnts */ buffer->data_ptr = (void*)((char*)dst + num_bytes); @@ -170,10 +142,10 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, orte_data_type_t type, size_t *num_bytes) { size_t i, len, n, elementsize; - char *dptr; /* my moving destination pointer */ - uint16_t tmp_16; /* temp location of converted data */ - uint32_t tmp_32; /* temp location of converted data */ - orte_process_name_t tmp_procname; /* temp location of converted data */ + char *dptr; /* my moving destination pointer */ + uint16_t tmp_16; /* temp location of converted data */ + uint32_t tmp_32; /* temp location of converted data */ + orte_process_name_t tmp_procname; /* temp location of converted data */ uint16_t * s16; uint32_t * s32; @@ -185,17 +157,14 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, orte_byte_object_t *sbyteptr; orte_gpr_keyval_t **keyval; orte_gpr_value_t **values; - orte_app_context_t **app_context; - orte_app_context_map_t **app_context_map; + orte_app_context_t **app_context; + orte_app_context_map_t **app_context_map; orte_gpr_subscription_t **subs; orte_gpr_notify_data_t **data; /* initialize the number of bytes */ *num_bytes = 0; - elementsize = 1024*1024*1024; /* instant memory fault on error */ - - /* pack the data */ switch(type) { @@ -216,14 +185,15 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, case ORTE_GPR_CMD: case ORTE_INT16: case ORTE_UINT16: - dptr = (char *) dst; - s16 = (uint16_t *) src; - elementsize = sizeof (uint16_t); + dptr = (char *) dst; + s16 = (uint16_t *) src; + elementsize = sizeof (uint16_t); for (i=0; icellid); tmp_procname.jobid = htonl(sn->jobid); tmp_procname.vpid = htonl(sn->vpid); - memcpy (dptr, (char*) &tmp_procname, elementsize); /* copy converted proc name to buffer */ - dptr+=elementsize; sn++; + memcpy (dptr, (char*) &tmp_procname, elementsize); /* copy converted proc name to buffer */ + dptr+=elementsize; + sn++; } *num_bytes = num_vals * sizeof(orte_process_name_t); break; @@ -306,12 +292,12 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, case ORTE_BYTE_OBJECT: sbyteptr = (orte_byte_object_t *) src; dbyte = (uint8_t *) dst; - elementsize = sizeof (uint32_t); + elementsize = sizeof (uint32_t); for (i=0; isize); - memcpy (dbyte, (char*) &tmp_32, elementsize); /* copy byte count to buffer */ - dbyte += elementsize; + memcpy (dbyte, (char*) &tmp_32, elementsize); /* copy byte count to buffer */ + dbyte += elementsize; *num_bytes += elementsize; /* pack actual bytes */ @@ -323,36 +309,38 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, break; case ORTE_KEYVAL: - /* array of pointers to keyval objects - need to pack the objects */ + /* array of pointers to keyval objects - need to pack the + objects */ keyval = (orte_gpr_keyval_t**) src; - /* use temp count of bytes packed 'n'. Must add these to num_bytes at each stage */ + /* use temp count of bytes packed 'n'. Must add these to + num_bytes at each stage */ for (i=0; i < num_vals; i++) { /* pack the key */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(keyval[i]->key)), 1, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the data type so we can read it for unpacking */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, &(keyval[i]->type), 1, ORTE_DATA_TYPE, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the value */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, &(keyval[i]->value), 1, keyval[i]->type, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; } break; @@ -370,51 +358,51 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, *num_bytes+=n; /* pack the segment name */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(values[i]->segment)), 1, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the number of tokens so we can read it for unpacking */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(values[i]->num_tokens)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* if there are tokens, pack them */ if (0 < values[i]->num_tokens) { - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)((values[i]->tokens)), values[i]->num_tokens, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; } /* pack the number of keyval pairs so we can read it for unpacking */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(values[i]->cnt)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the keyval pairs */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)((values[i]->keyvals)), values[i]->cnt, ORTE_KEYVAL, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; } break; @@ -422,8 +410,7 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, /* array of pointers to orte_app_context objects - need to pack the objects a set of fields at a time */ app_context = (orte_app_context_t**) src; for (i=0; i < num_vals; i++) { - - n = 0; /* must always start count at zero! */ + n = 0; /* must always start count at zero! */ /* pack the application index (for multiapp jobs) */ if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, @@ -431,68 +418,68 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the application name */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->app)), 1, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the number of processes */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->num_procs)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* pack the number of entries in the argv array */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->argc)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* if there are entries, pack the argv entries */ if (0 < app_context[i]->argc) { - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(app_context[i]->argv), app_context[i]->argc, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; } /* pack the number of entries in the enviro array */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->num_env)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; /* if there are entries, pack the enviro entries */ if (0 < app_context[i]->num_env) { - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(app_context[i]->env), app_context[i]->num_env, ORTE_STRING, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); - *num_bytes+=n; + *num_bytes+=n; } /* pack the cwd */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->cwd)), 1, ORTE_STRING, &n)) { return ORTE_ERROR; @@ -502,7 +489,7 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, /* Pack the map data */ - n = 0; + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(&(app_context[i]->num_map)), 1, ORTE_INT32, &n)) { return ORTE_ERROR; @@ -511,37 +498,37 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals, *num_bytes += n; if (app_context[i]->num_map > 0) { - n = 0; - if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, + n = 0; + if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, (void*)(app_context[i]->map_data), app_context[i]->num_map, ORTE_APP_CONTEXT_MAP, &n)) { - return ORTE_ERROR; - } - dst = (void*)((char*)dst + n); - *num_bytes += n; + return ORTE_ERROR; + } + dst = (void*)((char*)dst + n); + *num_bytes += n; } } break; - case ORTE_APP_CONTEXT_MAP: + case ORTE_APP_CONTEXT_MAP: app_context_map = (orte_app_context_map_t**) src; for (i=0; i < num_vals; i++) { n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, - (void*)(&(app_context_map[i]->map_type)), 1, ORTE_UINT8, &n)) { + (void*)(&(app_context_map[i]->map_type)), 1, ORTE_UINT8, &n)) { return ORTE_ERROR; } dst = (void*)((char*)dst + n); *num_bytes += n; - + n = 0; if (ORTE_SUCCESS != orte_dps_pack_nobuffer(dst, - (void*)(&(app_context_map[i]->map_data)), 1, ORTE_STRING, &n)) { - return ORTE_ERROR; + (void*)(&(app_context_map[i]->map_data)), 1, ORTE_STRING, &n)) { + return ORTE_ERROR; } dst = (void*)((char*)dst + n); *num_bytes += n; } - break; + break; case ORTE_GPR_SUBSCRIPTION: /* array of pointers to subscription objects - need to pack the objects */ diff --git a/src/dps/dps_peek.c b/src/dps/dps_peek.c index b92033322a..f576a07184 100644 --- a/src/dps/dps_peek.c +++ b/src/dps/dps_peek.c @@ -39,7 +39,6 @@ int orte_dps_peek(orte_buffer_t *buffer, size_t mem_left; size_t num_bytes, hdr_bytes; void *src; - uint32_t * s32; orte_data_type_t stored_type; /* check for errors */ @@ -66,17 +65,21 @@ int orte_dps_peek(orte_buffer_t *buffer, src = (void*)((char*)src + hdr_bytes); /* got enough left for num_vals? */ - if (sizeof(uint32_t) > mem_left) { /* not enough memory */ + if (sizeof(size_t) > mem_left) { /* not enough memory */ return ORTE_ERR_UNPACK_FAILURE; } /* unpack the number of values */ - s32 = (uint32_t *) src; - num_vals = (size_t)ntohl(*s32); + if (ORTE_SUCCESS != (rc =orte_dps_unpack_nobuffer(&num_vals, src, 1, + DPS_TYPE_SIZE_T, &mem_left, &num_bytes))) { + return rc; + } - if (type != NULL) + if (type != NULL) { *type = stored_type; - if (number != NULL) + } + if (number != NULL) { *number = num_vals; + } return ORTE_SUCCESS; } diff --git a/src/dps/dps_unpack.c b/src/dps/dps_unpack.c index ef3ddc64da..12a3b5e4ec 100644 --- a/src/dps/dps_unpack.c +++ b/src/dps/dps_unpack.c @@ -50,16 +50,15 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst, void *src; char *srcptr; orte_data_type_t stored_type; - uint32_t tmp_32; - + uint32_t tmp_32; /* check for errors */ if (buffer == NULL || dst == NULL || max_num_vals == NULL) { return (ORTE_ERR_BAD_PARAM); } - num_bytes = 0; /* have not unpacked any yet */ - hdr_bytes = 0; + num_bytes = 0; /* have not unpacked any yet */ + hdr_bytes = 0; src = buffer->from_ptr; /* get location in buffer */ mem_left = buffer->toend; /* how much data is left in buffer */ @@ -75,24 +74,16 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst, return rc; } src = (void*)((char*)src + hdr_bytes); - - if(type == ORTE_INT || type == ORTE_UINT) { - switch(sizeof(int)) { - case 1: - type = (type == ORTE_INT) ? ORTE_INT8 : ORTE_UINT8; - break; - case 2: - type = (type == ORTE_INT) ? ORTE_INT16 : ORTE_UINT16; - break; - case 4: - type = (type == ORTE_INT) ? ORTE_INT32 : ORTE_UINT32; - break; - case 8: - type = (type == ORTE_INT) ? ORTE_INT64 : ORTE_UINT64; - break; - default: - return ORTE_ERR_NOT_IMPLEMENTED; - } + + /* check for size of generic data types so they can be properly + packed NOTE we convert the generic data type flag to a hard + type for storage to handle heterogeneity */ + if (ORTE_INT == type) { + type = DPS_TYPE_INT; + } else if (ORTE_UINT == type) { + type = DPS_TYPE_UINT; + } else if (ORTE_SIZE == type) { + type = DPS_TYPE_SIZE_T; } /* check for type match - for now we require this to be an exact match - @@ -104,21 +95,17 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst, } /* got enough left for num_vals? */ - if (sizeof(uint32_t) > mem_left) { /* not enough memory */ + if (mem_left < sizeof(size_t)) { /* not enough memory */ return ORTE_ERR_UNPACK_FAILURE; } /* unpack the number of values */ - srcptr = (char*) src; - memcpy ((char*)&tmp_32, srcptr, sizeof(uint32_t)); - num_vals = (size_t)ntohl(tmp_32); - if (num_vals > *max_num_vals) { /* not enough space provided */ - return ORTE_UNPACK_INADEQUATE_SPACE; + if (ORTE_SUCCESS != (rc =orte_dps_unpack_nobuffer(&num_vals, src, 1, + DPS_TYPE_SIZE_T, &mem_left, &num_bytes))) { + return rc; } - srcptr+=sizeof(uint32_t); - src = (void *)srcptr; - mem_left -= sizeof(uint32_t); /* we do this here but this is normally a function of unpack_nobuffer */ - hdr_bytes += sizeof(uint32_t); + src = (void*)((char*)src + num_bytes); + hdr_bytes += num_bytes; /* will check to see if adequate storage in buffer prior * to unpacking the item @@ -127,9 +114,11 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst, stored_type, &mem_left, &num_bytes))) { return rc; } +#if OMPI_ENABLE_DEBUG /* fflush(stdout); fflush(stderr); */ /* fprintf(stderr,"unpacked total bytes %d, (hdr %d datatype %d)\n", num_bytes+hdr_bytes, hdr_bytes, num_bytes); */ /* fflush(stdout); fflush(stderr); */ +#endif /* ok, we managed to unpack some stuff, so update all ptrs/cnts */ buffer->from_ptr = (void*)((char*)src + num_bytes); /* move by data type size only as src is after the header */ @@ -149,8 +138,8 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, int rc; size_t i; size_t n; - size_t elementsize; /* size in bytes of an unpacked element */ - char* srcptr; /* temp moving source pointer */ + size_t elementsize; /* size in bytes of an unpacked element */ + char* srcptr; /* temp moving source pointer */ uint16_t * d16; uint32_t * d32; uint16_t tmp_16; @@ -163,8 +152,8 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, orte_byte_object_t* dbyteptr; orte_gpr_keyval_t **keyval; orte_gpr_value_t **values; - orte_app_context_t **app_context; - orte_app_context_map_t **app_context_map; + orte_app_context_t **app_context; + orte_app_context_map_t **app_context_map; uint32_t len; char *str; orte_gpr_subscription_t **subs; @@ -173,7 +162,6 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, /* defaults */ rc = ORTE_SUCCESS; *num_bytes = 0; - elementsize = 1024*1024*1024; /* instant memory fault on error */ switch(type) { @@ -201,7 +189,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, srcptr = (char *) src; d16 = (uint16_t *) dst; - elementsize = sizeof (uint16_t); + elementsize = sizeof (uint16_t); if(num_vals * elementsize > *mem_left) { num_vals = *mem_left / elementsize; @@ -209,10 +197,10 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } for(i=0; i *mem_left) { num_vals = *mem_left / elementsize; @@ -234,19 +222,42 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } for(i=0; i *mem_left) { + num_vals = *mem_left / sizeof(uint64_t); + rc = ORTE_UNPACK_READ_PAST_END_OF_BUFFER; + } + + for(i=0; icellid = ntohl(tmp_procname.cellid); dn->jobid = ntohl(tmp_procname.jobid); dn->vpid = ntohl(tmp_procname.vpid); @@ -325,13 +336,13 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, dbyteptr = (orte_byte_object_t*)dst; srcptr = (char*) src; /* iterate from start of buffer */ - elementsize = sizeof (uint32_t); + elementsize = sizeof (uint32_t); for(i=0; isize = ntohl(tmp_32); srcptr += elementsize; *num_bytes += elementsize; @@ -356,35 +367,35 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, /* unpack into an array of keyval objects */ keyval = (orte_gpr_keyval_t**) dst; - /* use temp count of unpacked 'n' which we sum to produce correct value later */ + /* use temp count of unpacked 'n' which we sum to produce correct value later */ for (i=0; i < num_vals; i++) { keyval[i] = OBJ_NEW(orte_gpr_keyval_t); if (NULL == keyval[i]) { return ORTE_ERR_OUT_OF_RESOURCE; } - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(keyval[i]->key), src, 1, ORTE_STRING, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(keyval[i]->type), src, 1, ORTE_DATA_TYPE, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(keyval[i]->value), src, 1, keyval[i]->type, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; } /* must return here for composite unpacks that change mem_left directly */ @@ -412,22 +423,22 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, *num_bytes+=n; /* unpack the segment name */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(values[i]->segment), src, 1, ORTE_STRING, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* get the number of tokens */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(values[i]->num_tokens), src, 1, ORTE_INT32, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* if there are tokens, allocate the required space for the char * pointers */ if (0 < values[i]->num_tokens) { @@ -437,7 +448,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* and unpack them */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(values[i]->tokens, src, values[i]->num_tokens, ORTE_STRING, mem_left, &n))) { return rc; @@ -447,13 +458,13 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* get the number of keyval pairs */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(values[i]->cnt), src, 1, ORTE_INT32, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* allocate the required space for the keyval object pointers */ if(values[i]->cnt) { @@ -463,7 +474,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* unpack the keyval pairs */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(values[i]->keyvals, src, values[i]->cnt, ORTE_KEYVAL, mem_left, &n))) { return rc; @@ -489,34 +500,34 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* get the app index number */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->idx), src, 1, ORTE_INT32, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* unpack the application name */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->app), src, 1, ORTE_STRING, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* get the number of processes */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->num_procs), src, 1, ORTE_INT32, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* get the number of argv strings */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->argc), src, 1, ORTE_INT32, mem_left, &n))) { return rc; @@ -533,7 +544,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, app_context[i]->argv[app_context[i]->argc] = NULL; /* and unpack them */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(app_context[i]->argv, src, app_context[i]->argc, ORTE_STRING, mem_left, &n))) { return rc; @@ -543,13 +554,13 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* get the number of env strings */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->num_env), src, 1, ORTE_INT32, mem_left, &n))) { return rc; } src = (void*)((char*)src + n); - *num_bytes+=n; + *num_bytes+=n; /* if there are env strings, allocate the required space for the char * pointers */ if (0 < app_context[i]->num_env) { @@ -560,7 +571,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, app_context[i]->env[app_context[i]->num_env] = NULL; /* and unpack them */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(app_context[i]->env, src, app_context[i]->num_env, ORTE_STRING, mem_left, &n))) { return rc; @@ -570,7 +581,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } /* unpack the cwd */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&app_context[i]->cwd, src, 1, ORTE_STRING, mem_left, &n))) { return rc; @@ -580,7 +591,7 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, /* unpack the map data */ - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context[i]->num_map), src, 1, ORTE_INT32, mem_left, &n))) { return rc; @@ -593,10 +604,10 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, if (NULL == app_context[i]->map_data) { return ORTE_ERR_OUT_OF_RESOURCE; } - n = 0; + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(app_context[i]->map_data, src, app_context[i]->num_map, ORTE_APP_CONTEXT_MAP, mem_left, &n))) { - return rc; + return rc; } src = (void*)((char*)src + n); *num_bytes += n; @@ -604,7 +615,8 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, } } - /* must return here for composite unpacks that change mem_left directly */ + /* must return here for composite unpacks that change + mem_left directly */ return ORTE_SUCCESS; break; @@ -620,8 +632,8 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, return ORTE_ERR_OUT_OF_RESOURCE; } - /* map type */ - n = 0; + /* map type */ + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context_map[i]->map_type), src, 1, ORTE_UINT8, mem_left, &n))) { return rc; @@ -629,8 +641,8 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals, src = (void*)((char*)src + n); *num_bytes+=n; - /* map data */ - n = 0; + /* map data */ + n = 0; if (ORTE_SUCCESS != (rc = orte_dps_unpack_nobuffer(&(app_context_map[i]->map_data), src, 1, ORTE_STRING, mem_left, &n))) { return rc;