1
1
- remove all tabs from source code (replace with spaces)
- use size of size_t and int to determine some equivalent ORTE types
  in a header file so that it's always done consistently (at compile
  time)
- be consistent about using size_t for number of elements that are
  packed
- don't assume that size_t is uint32_t (it is uint64_t on some
  platforms)
- simplify some logic
- implement packing/unpacking for INT64 and UINT64 (so that we can do
  size_t on platforms where it's 64 bits)

This commit was SVN r5172.
Этот коммит содержится в:
Jeff Squyres 2005-04-05 02:32:36 +00:00
родитель 205ed1d9d9
Коммит 447201de15
5 изменённых файлов: 276 добавлений и 239 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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
*/

Просмотреть файл

@ -54,32 +54,26 @@ int orte_dps_pack(orte_buffer_t *buffer, void *src,
/* 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;
/* 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;
}
#if OMPI_ENABLE_DEBUG
/* debugging */
if (num_bytes+sizeof(uint32_t)+orte_dps_memory_required(NULL, 1, ORTE_DATA_TYPE) != (size_t)op_size) {
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); */
/* 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);
@ -193,9 +165,6 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
/* initialize the number of bytes */
*num_bytes = 0;
elementsize = 1024*1024*1024; /* instant memory fault on error */
/* pack the data */
switch(type) {
@ -223,7 +192,8 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
/* convert the host order to network order */
tmp_16 = htons(*s16);
memcpy (dptr, (char*) &tmp_16, elementsize);
dptr+=elementsize; s16++;
dptr+=elementsize;
s16++;
}
*num_bytes = num_vals * elementsize;
break;
@ -241,14 +211,30 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
/* convert the host order to network order */
tmp_32 = htonl(*s32);
memcpy (dptr, (char*) &tmp_32, elementsize);
dptr+=elementsize; s32++;
dptr+=elementsize;
s32++;
}
*num_bytes = num_vals * elementsize;
break;
case ORTE_INT64:
case ORTE_UINT64:
return ORTE_ERR_NOT_IMPLEMENTED;
dptr = (char *) dst;
s32 = (uint32_t *) src;
for (i=0; i<num_vals; i++) {
/* convert the host order to network order */
tmp_32 = htonl(*s32);
memcpy (dptr, (char*) &tmp_32, sizeof(uint32_t));
dptr += sizeof(uint32_t);
s32++;
/* do it twice to get 64 bits */
tmp_32 = htonl(*s32);
memcpy (dptr, (char*) &tmp_32, sizeof(uint32_t));
dptr += sizeof(uint32_t);
s32++;
}
*num_bytes = num_vals * sizeof(uint64_t);;
break;
case ORTE_FLOAT:
@ -267,7 +253,8 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
for (i=0; i<num_vals; i++) {
/* pack native bool as uint8_t */
*bool_dst = *bool_src ? (uint8_t)true : (uint8_t)false;
bool_dst++; bool_src++;
bool_dst++;
bool_src++;
}
*num_bytes = num_vals * sizeof(uint8_t);
break;
@ -280,11 +267,9 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
len = strlen(str[i]); /* exclude the null terminator */
tmp_32 = htonl(len);
memcpy (dptr, (char*) &tmp_32, elementsize); /* copy str len to buffer */
dptr+=elementsize;
memcpy(dptr, str[i], len); /* copy str to buffer */
dptr+=len;
*num_bytes += len + elementsize;
}
break;
@ -298,7 +283,8 @@ int orte_dps_pack_nobuffer(void *dst, void *src, size_t num_vals,
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++;
dptr+=elementsize;
sn++;
}
*num_bytes = num_vals * sizeof(orte_process_name_t);
break;
@ -323,9 +309,11 @@ 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;
@ -422,7 +410,6 @@ 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! */
/* pack the application index (for multiapp jobs) */

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -52,7 +52,6 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst,
orte_data_type_t stored_type;
uint32_t tmp_32;
/* check for errors */
if (buffer == NULL || dst == NULL || max_num_vals == NULL) {
return (ORTE_ERR_BAD_PARAM);
@ -76,23 +75,15 @@ int orte_dps_unpack(orte_buffer_t *buffer, void *dst,
}
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 */
@ -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) {
@ -237,14 +225,37 @@ int orte_dps_unpack_nobuffer(void *dst, void *src, size_t num_vals,
memcpy ((char*)&tmp_32, srcptr, elementsize);
/* convert the network order to host order */
*d32 = ntohl(tmp_32);
d32++; srcptr+=elementsize;
d32++;
srcptr+=elementsize;
}
*num_bytes = num_vals * elementsize;
break;
case ORTE_INT64:
case ORTE_UINT64:
return ORTE_ERR_NOT_IMPLEMENTED;
srcptr = (char *) src;
d32 = (uint32_t *) dst;
if(num_vals * sizeof(uint64_t) > *mem_left) {
num_vals = *mem_left / sizeof(uint64_t);
rc = ORTE_UNPACK_READ_PAST_END_OF_BUFFER;
}
for(i=0; i<num_vals; i++) {
memcpy ((char*)&tmp_32, srcptr, sizeof(uint32_t));
/* convert the network order to host order */
*d32 = ntohl(tmp_32);
d32++;
srcptr += sizeof(uint32_t);
/* do it twice to get 64 bits */
memcpy ((char*)&tmp_32, srcptr, sizeof(uint32_t));
/* convert the network order to host order */
*d32 = ntohl(tmp_32);
d32++;
srcptr += sizeof(uint32_t);
}
*num_bytes = num_vals * sizeof(uint64_t);
break;
case ORTE_FLOAT:
@ -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;