2006-02-07 06:32:36 +03:00
|
|
|
/*
|
2007-03-17 02:11:45 +03:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2006-08-23 07:32:36 +04:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2006-02-07 06:32:36 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "orte_config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#if HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
|
|
|
|
#include "orte/dss/dss_internal.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
|
|
|
|
int orte_dss_compare(void *value1, void *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
orte_dss_type_info_t *info;
|
|
|
|
|
|
|
|
/* check for error */
|
|
|
|
if (NULL == value1 || NULL == value2) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup the compare function for this type and call it */
|
|
|
|
|
|
|
|
if (!(type < orte_dss_types->size) ||
|
2006-08-23 07:32:36 +04:00
|
|
|
(NULL == (info = (orte_dss_type_info_t*)orte_pointer_array_get_item(orte_dss_types, type)))) {
|
2006-02-07 06:32:36 +03:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_UNKNOWN_DATA_TYPE);
|
|
|
|
return ORTE_ERR_UNKNOWN_DATA_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info->odti_compare_fn(value1, value2, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NUMERIC COMPARE FUNCTIONS
|
|
|
|
*/
|
|
|
|
int orte_dss_compare_int(int *value1, int *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_uint(uint *value1, uint *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_size(size_t *value1, size_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_pid(pid_t *value1, pid_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_byte(char *value1, char *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_char(char *value1, char *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_int8(int8_t *value1, int8_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_uint8(uint8_t *value1, uint8_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_int16(int16_t *value1, int16_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_uint16(uint16_t *value1, uint16_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_int32(int32_t *value1, int32_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_uint32(uint32_t *value1, uint32_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_int64(int64_t *value1, int64_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_dss_compare_uint64(uint64_t *value1, uint64_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NON-NUMERIC SYSTEM TYPES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* NULL */
|
|
|
|
int orte_dss_compare_null(char *value1, char *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BOOL */
|
|
|
|
int orte_dss_compare_bool(bool *value1, bool *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 && !(*value2)) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 && !(*value1)) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STRING */
|
|
|
|
int orte_dss_compare_string(char *value1, char *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (0 < strcmp(value1, value2)) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
if (0 > strcmp(value1, value2)) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* COMPARE FUNCTIONS FOR GENERIC ORTE TYPES */
|
|
|
|
|
Bring over the ORTE 2.0 DSS. This introduces a few changes, almost all of which are transparent to the user:
1. Introduces a flag for the type of buffer that now allows a user to either have a fully described or a completely non-described buffer. In the latter case, no data type descriptions are included in the buffer. This obviously limits what we can do for debugging purposes, but the intent here was to provide an optimized communications capability for those wanting it.
Note that individual buffers can be designated for either type using the orte_dss.set_buffer_type command. In other words, the buffer type can be set dynamically - it isn't a configuration setting at all. The type will default to fully described. A buffer MUST be empty to set its type - this is checked by the set_buffer_type command, and you will receive an error if you violate that rule.
IMPORTANT NOTE: ORTE 1.x actually will NOT work with non-described buffers. This capability should therefore NOT be used until we tell you it is okay. For now, it is here simply so we can begin bringing over parts of ORTE 2.0. The problem is that ORTE 1.x depends upon the transmission of non-hard-cast data types such as size_t. These "soft" types currently utilize a "peek" function to see their actual type in the buffer - obviously, without description, the system has no idea how to unpack these "soft" types. We will deal with this later - for now, please don't use the non-described buffer option.
2. Introduces the orte_std_cntr_t type. This will become the replacement for the size_t's used throughout ORTE 1.x. At the moment, it is actually typedef'd to size_t for backward compatibility.
3. Introduces the orte_dss.arith API that supports arbitrary arithmetic functions on numeric data types. Calling the function with any other data type will generate an error.
This commit was SVN r11075.
2006-08-01 22:42:25 +04:00
|
|
|
/* ORTE_STD_CNTR */
|
|
|
|
int orte_dss_compare_std_cntr(orte_std_cntr_t *value1, orte_std_cntr_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/* ORTE_DATA_TYPE */
|
|
|
|
int orte_dss_compare_dt(orte_data_type_t *value1, orte_data_type_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
|
2007-03-17 02:11:45 +03:00
|
|
|
#if OPAL_ENABLE_FT == 1
|
|
|
|
/* ORTE_CKPT_CMD */
|
|
|
|
int orte_dss_compare_ckpt_cmd(size_t *value1, size_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
if (*value1 > *value2) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (*value2 > *value1) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
return ORTE_EQUAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/* ORTE_DATA_VALUE */
|
|
|
|
int orte_dss_compare_data_value(orte_data_value_t *value1, orte_data_value_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
/* can't compare if the two types don't match */
|
|
|
|
if (value1->type != value2->type) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_TYPE_MISMATCH);
|
|
|
|
return ORTE_ERR_TYPE_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* okay, go ahead and compare the values themselves */
|
|
|
|
return orte_dss.compare(value1->data, value2->data, value1->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ORTE_BYTE_OBJECT */
|
|
|
|
int orte_dss_compare_byte_object(orte_byte_object_t *value1, orte_byte_object_t *value2, orte_data_type_t type)
|
|
|
|
{
|
|
|
|
int checksum, diff;
|
Bring over the ORTE 2.0 DSS. This introduces a few changes, almost all of which are transparent to the user:
1. Introduces a flag for the type of buffer that now allows a user to either have a fully described or a completely non-described buffer. In the latter case, no data type descriptions are included in the buffer. This obviously limits what we can do for debugging purposes, but the intent here was to provide an optimized communications capability for those wanting it.
Note that individual buffers can be designated for either type using the orte_dss.set_buffer_type command. In other words, the buffer type can be set dynamically - it isn't a configuration setting at all. The type will default to fully described. A buffer MUST be empty to set its type - this is checked by the set_buffer_type command, and you will receive an error if you violate that rule.
IMPORTANT NOTE: ORTE 1.x actually will NOT work with non-described buffers. This capability should therefore NOT be used until we tell you it is okay. For now, it is here simply so we can begin bringing over parts of ORTE 2.0. The problem is that ORTE 1.x depends upon the transmission of non-hard-cast data types such as size_t. These "soft" types currently utilize a "peek" function to see their actual type in the buffer - obviously, without description, the system has no idea how to unpack these "soft" types. We will deal with this later - for now, please don't use the non-described buffer option.
2. Introduces the orte_std_cntr_t type. This will become the replacement for the size_t's used throughout ORTE 1.x. At the moment, it is actually typedef'd to size_t for backward compatibility.
3. Introduces the orte_dss.arith API that supports arbitrary arithmetic functions on numeric data types. Calling the function with any other data type will generate an error.
This commit was SVN r11075.
2006-08-01 22:42:25 +04:00
|
|
|
orte_std_cntr_t i;
|
2006-02-07 06:32:36 +03:00
|
|
|
|
|
|
|
/* compare the sizes first - bigger size object is "greater than" */
|
|
|
|
if (value1->size > value2->size) return ORTE_VALUE1_GREATER;
|
|
|
|
|
|
|
|
if (value2->size > value1->size) return ORTE_VALUE2_GREATER;
|
|
|
|
|
|
|
|
/* get here if the two sizes are identical - now do a simple checksum-style
|
|
|
|
* calculation to determine "biggest"
|
|
|
|
*/
|
|
|
|
checksum = 0;
|
|
|
|
|
|
|
|
for (i=0; i < value1->size; i++) {
|
|
|
|
/* protect against overflows */
|
|
|
|
diff = value1->bytes[i] - value2->bytes[i];
|
|
|
|
if (INT_MAX-abs(checksum)-abs(diff) < 0) { /* got an overflow condition */
|
|
|
|
checksum = 0;
|
|
|
|
}
|
|
|
|
checksum += diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 > checksum) return ORTE_VALUE2_GREATER; /* sum of value2 bytes was greater */
|
|
|
|
|
|
|
|
if (0 < checksum) return ORTE_VALUE1_GREATER; /* of value1 bytes was greater */
|
|
|
|
|
|
|
|
return ORTE_EQUAL; /* sum of both value's bytes was identical */
|
|
|
|
}
|