1
1

Handle the alignement problems. The same error as in the email from Ferris McCormick showed up

on all 64 bits architectures. The problem was the for unpack the source pointer was cast to a
specific type (uint32_t for 32 bits data) and then hton* was applied. The result was ... unexpected.

This patch always memcpy the data in a temporary variable with the correct size before calling
ntoh* functions, so we can insure that the data is always correctly aligned.

Moreover I add a debuging layer. OMPI_OUTPUT is used to print out the data being packed and
unpacked. It generate a lot of output but hopefully allow us to spot few bugs. This layer is not
completed the output stream descriptor is set to -1 (no output).

This commit was SVN r5617.
Этот коммит содержится в:
George Bosilca 2005-05-05 23:59:59 +00:00
родитель 4c04dde93d
Коммит d60565e043
4 изменённых файлов: 27 добавлений и 15 удалений

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

@ -113,6 +113,7 @@ typedef struct orte_dps_type_info_t orte_dps_type_info_t;
*/
extern bool orte_dps_initialized;
extern bool orte_dps_debug;
extern int orte_dps_verbose;
extern int orte_dps_page_size;
extern orte_pointer_array_t *orte_dps_types;

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

@ -24,6 +24,7 @@
#include "mca/errmgr/errmgr.h"
#include "dps/dps_internal.h"
#include "util/output.h"
int orte_dps_pack(orte_buffer_t *buffer, void *src, size_t num_vals,
orte_data_type_t type)
@ -60,6 +61,7 @@ int orte_dps_pack_buffer(orte_buffer_t *buffer, void *src, size_t num_vals,
int rc;
orte_dps_type_info_t *info;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_pack_buffer( %p, %p, %lu, %d )\n", buffer, src, num_vals, (int)type ) );
/* Pack the declared data type */
if (ORTE_SUCCESS != (rc = orte_dps_pack_data_type(buffer, &type, 1, type))) {
ORTE_ERROR_LOG(rc);
@ -161,6 +163,7 @@ int orte_dps_pack_byte(orte_buffer_t *buffer, void *src,
{
char *dst;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_pack_byte * %d\n", num_vals ) );
/* check to see if buffer needs extending */
if (NULL == (dst = orte_dps_buffer_extend(buffer, num_vals))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
@ -188,6 +191,7 @@ int orte_dps_pack_int16(orte_buffer_t *buffer, void *src,
uint16_t tmp, *srctmp = (uint16_t*) src;
char *dst;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_pack_int16 * %d\n", num_vals ) );
/* check to see if buffer needs extending */
if (NULL == (dst = orte_dps_buffer_extend(buffer, num_vals*sizeof(tmp)))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
@ -216,6 +220,7 @@ int orte_dps_pack_int32(orte_buffer_t *buffer, void *src,
uint32_t tmp, *srctmp = (uint32_t*) src;
char *dst;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_pack_int32 * %d\n", num_vals ) );
/* check to see if buffer needs extending */
if (NULL == (dst = orte_dps_buffer_extend(buffer, num_vals*sizeof(tmp)))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
@ -245,6 +250,7 @@ int orte_dps_pack_int64(orte_buffer_t *buffer, void *src,
char *dst;
size_t bytes_packed = num_vals * sizeof(tmp) * 2;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_pack_int64 * %d\n", num_vals ) );
/* check to see if buffer needs extending */
if (NULL == (dst = orte_dps_buffer_extend(buffer, bytes_packed))) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);

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

@ -25,6 +25,7 @@
#include "mca/errmgr/errmgr.h"
#include "dps/dps_internal.h"
#include "util/output.h"
int orte_dps_unpack(orte_buffer_t *buffer, void *dst, size_t *num_vals,
orte_data_type_t type)
@ -107,6 +108,7 @@ int orte_dps_unpack_buffer(orte_buffer_t *buffer, void *dst, size_t *num_vals,
orte_data_type_t local_type;
orte_dps_type_info_t *info;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_unpack_buffer( %p, %p, %lu, %d )\n", buffer, dst, *num_vals, (int)type ) );
/* Unpack the declared data type */
if (ORTE_SUCCESS != (rc = orte_dps_get_data_type(buffer, &local_type))) {
ORTE_ERROR_LOG(rc);
@ -211,6 +213,7 @@ int orte_dps_unpack_sizet(orte_buffer_t *buffer, void *dest,
int orte_dps_unpack_byte(orte_buffer_t *buffer, void *dest,
size_t *num_vals, orte_data_type_t type)
{
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_unpack_byte * %d\n", (int)*num_vals ) );
/* check to see if there's enough data in buffer */
if (orte_dps_too_small(buffer, *num_vals)) {
ORTE_ERROR_LOG(ORTE_UNPACK_READ_PAST_END_OF_BUFFER);
@ -231,8 +234,8 @@ int orte_dps_unpack_int16(orte_buffer_t *buffer, void *dest,
{
size_t i;
uint16_t tmp, *desttmp = (uint16_t*) dest;
uint16_t *srctmp = (uint16_t*) buffer->unpack_ptr;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_unpack_int16 * %d\n", (int)*num_vals ) );
/* check to see if there's enough data in buffer */
if (orte_dps_too_small(buffer, (*num_vals)*sizeof(tmp))) {
ORTE_ERROR_LOG(ORTE_UNPACK_READ_PAST_END_OF_BUFFER);
@ -241,10 +244,10 @@ int orte_dps_unpack_int16(orte_buffer_t *buffer, void *dest,
/* unpack the data */
for (i = 0; i < (*num_vals); ++i) {
tmp = ntohs(srctmp[i]);
memcpy(&desttmp[i], &tmp, sizeof(tmp));
memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
desttmp[i] = ntohs(tmp);
buffer->unpack_ptr += sizeof(tmp);
}
buffer->unpack_ptr += (*num_vals) * sizeof(tmp);
return ORTE_SUCCESS;
}
@ -254,8 +257,8 @@ int orte_dps_unpack_int32(orte_buffer_t *buffer, void *dest,
{
size_t i;
uint32_t tmp, *desttmp = (uint32_t*) dest;
uint32_t *srctmp = (uint32_t*) buffer->unpack_ptr;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_unpack_int32 * %d\n", (int)*num_vals ) );
/* check to see if there's enough data in buffer */
if (orte_dps_too_small(buffer, (*num_vals)*sizeof(tmp))) {
ORTE_ERROR_LOG(ORTE_UNPACK_READ_PAST_END_OF_BUFFER);
@ -264,10 +267,10 @@ int orte_dps_unpack_int32(orte_buffer_t *buffer, void *dest,
/* unpack the data */
for (i = 0; i < (*num_vals); ++i) {
tmp = ntohl(srctmp[i]);
memcpy(&desttmp[i], &tmp, sizeof(tmp));
memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
desttmp[i] = ntohl(tmp);
buffer->unpack_ptr += sizeof(tmp);
}
buffer->unpack_ptr += (*num_vals) * sizeof(tmp);
return ORTE_SUCCESS;
}
@ -277,8 +280,8 @@ int orte_dps_unpack_int64(orte_buffer_t *buffer, void *dest,
{
size_t i;
uint32_t tmp, *desttmp = (uint32_t*) dest;
uint32_t *srctmp = (uint32_t*) buffer->unpack_ptr;
OMPI_OUTPUT( ( orte_dps_verbose, "orte_dps_unpack_int64 * %d\n", (int)*num_vals ) );
/* check to see if there's enough data in buffer */
if (orte_dps_too_small(buffer, 2*(*num_vals)*sizeof(tmp))) {
ORTE_ERROR_LOG(ORTE_UNPACK_READ_PAST_END_OF_BUFFER);
@ -286,13 +289,14 @@ int orte_dps_unpack_int64(orte_buffer_t *buffer, void *dest,
}
/* unpack the data */
for (i = 0; i < 2*(*num_vals); i += 2) {
tmp = ntohl(srctmp[i]);
memcpy(&desttmp[i], &tmp, sizeof(tmp));
tmp = ntohl(srctmp[i+1]);
memcpy(&desttmp[i+1], &tmp, sizeof(tmp));
for (i = 0; i < (2 * (*num_vals)); i += 2) {
memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
desttmp[i] = ntohl(tmp);
buffer->unpack_ptr += sizeof(tmp);
memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
desttmp[i+1] = ntohl(tmp);
buffer->unpack_ptr += sizeof(tmp);
}
buffer->unpack_ptr += 2*(*num_vals) * sizeof(tmp);
return ORTE_SUCCESS;
}

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

@ -34,6 +34,7 @@
*/
bool orte_dps_initialized = false;
bool orte_dps_debug = false;
int orte_dps_verbose = -1; /* by default disabled */
int orte_dps_page_size;
orte_pointer_array_t *orte_dps_types;