1
1

Remove all references to the orte_bitmap as well as the files.

This commit was SVN r14928.
Этот коммит содержится в:
George Bosilca 2007-06-06 20:24:07 +00:00
родитель fbb46f0ee7
Коммит 29dd535c01
4 изменённых файлов: 1 добавлений и 751 удалений

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

@ -3,7 +3,7 @@
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# Copyright (c) 2004-2007 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@ -21,12 +21,10 @@
headers += \
class/orte_proc_table.h \
class/orte_bitmap.h \
class/orte_pointer_array.h \
class/orte_value_array.h
libopen_rte_la_SOURCES += \
class/orte_proc_table.c \
class/orte_bitmap.c \
class/orte_pointer_array.c \
class/orte_value_array.c

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

@ -1,250 +0,0 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2007 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 <stdio.h>
#include "orte/orte_constants.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/class/orte_bitmap.h"
#define SIZE_OF_CHAR (sizeof(char) * 8)
#define DEFAULT_BITMAP_SIZE 64
static void orte_bitmap_construct(orte_bitmap_t *bm);
static void orte_bitmap_destruct(orte_bitmap_t *bm);
OBJ_CLASS_INSTANCE(
orte_bitmap_t,
opal_object_t,
orte_bitmap_construct,
orte_bitmap_destruct
);
static void
orte_bitmap_construct(orte_bitmap_t *bm)
{
orte_std_cntr_t size;
size = DEFAULT_BITMAP_SIZE / SIZE_OF_CHAR;
bm->array_size = size + ((size % SIZE_OF_CHAR == 0) ? 0 : 1);
bm->bitmap = (unsigned char *) malloc(bm->array_size);
bm->legal_numbits = SIZE_OF_CHAR*bm->array_size;
memset(bm->bitmap, 0, bm->array_size);
}
static void
orte_bitmap_destruct(orte_bitmap_t *bm)
{
if (NULL != bm->bitmap) {
free(bm->bitmap);
}
}
int
orte_bitmap_resize(orte_bitmap_t *bm, orte_std_cntr_t bit)
{
orte_std_cntr_t index, new_size, i;
index = bit / SIZE_OF_CHAR;
index += (bit % SIZE_OF_CHAR == 0) ? 0 : 1;
if (index >= bm->array_size) {
/* We need to allocate more space for the bitmap, since we are
out of range. We dont throw any error here, because this is
valid and we simply expand the bitmap */
new_size = (index / bm->array_size + 1 ) * bm->array_size;
/* New size is just a multiple of the original size to fit in
the index. */
bm->bitmap = (unsigned char *) realloc(bm->bitmap, new_size);
if (NULL == bm->bitmap) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
/* zero out the new elements */
for (i = bm->array_size; i < new_size; ++i) {
bm->bitmap[i] = 0;
}
/* Update the array_size */
bm->array_size = new_size;
bm->legal_numbits = new_size*SIZE_OF_CHAR;
}
return ORTE_SUCCESS;
}
int
orte_bitmap_set_bit(orte_bitmap_t *bm, orte_std_cntr_t bit)
{
orte_std_cntr_t index, offset;
int rc;
if (NULL == bm) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
/* make sure the bitmap covers the requested bit */
if (ORTE_SUCCESS != (rc = orte_bitmap_resize(bm, bit))) {
ORTE_ERROR_LOG(rc);
return rc;
}
index = bit / SIZE_OF_CHAR;
offset = bit % SIZE_OF_CHAR;
/* Now set the bit */
bm->bitmap[index] |= (1 << offset);
return ORTE_SUCCESS;
}
int
orte_bitmap_clear_bit(orte_bitmap_t *bm, orte_std_cntr_t bit)
{
orte_std_cntr_t index, offset;
int rc;
if (NULL == bm) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
/* make sure the bitmap covers the requested bit */
if (ORTE_SUCCESS != (rc = orte_bitmap_resize(bm, bit))) {
ORTE_ERROR_LOG(rc);
return rc;
}
index = bit / SIZE_OF_CHAR;
offset = bit % SIZE_OF_CHAR;
/* now clear the bit */
bm->bitmap[index] &= ~(1 << offset);
return ORTE_SUCCESS;
}
int
orte_bitmap_is_set_bit(orte_bitmap_t *bm, orte_std_cntr_t bit)
{
orte_std_cntr_t index, offset;
if ((bit > bm->legal_numbits - 1) || (NULL == bm)) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
index = bit / SIZE_OF_CHAR;
offset = bit % SIZE_OF_CHAR;
if (index >= bm->array_size) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
if (0 != (bm->bitmap[index] & (1 << offset))) {
return (int) true;
}
return (int) false;
}
int
orte_bitmap_clear_all_bits(orte_bitmap_t *bm)
{
if (NULL == bm) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
memset(bm->bitmap, 0, bm->array_size);
return ORTE_SUCCESS;
}
int
orte_bitmap_set_all_bits(orte_bitmap_t *bm)
{
orte_std_cntr_t i;
if (NULL == bm) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
for (i = 0; i < bm->array_size; ++i) {
bm->bitmap[i] = ~((char) 0);
}
return ORTE_SUCCESS;
}
int
orte_bitmap_find_and_set_first_unset_bit(orte_bitmap_t *bm, orte_std_cntr_t *position)
{
orte_std_cntr_t i = 0;
unsigned char temp;
unsigned char all_ones = 0xff;
if (NULL == bm || NULL == position) {
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
return ORTE_ERR_BAD_PARAM;
}
/* Neglect all which don't have an unset bit */
*position = 0;
while((i < bm->array_size) && (bm->bitmap[i] == all_ones)) {
++i;
}
if (i == bm->array_size) {
/* increase the bitmap size then */
*position = bm->array_size * SIZE_OF_CHAR;
return orte_bitmap_set_bit(bm, *position);
}
/* This one has an unset bit, find its bit number */
temp = bm->bitmap[i];
while (temp & 0x1) {
++(*position);
temp >>= 1;
}
/* Now set the bit number */
bm->bitmap[i] |= (bm->bitmap[i] + 1);
(*position) += i * SIZE_OF_CHAR;
return ORTE_SUCCESS;
}

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

@ -1,166 +0,0 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* 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.
* 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$
*
*/
/** @file
*
* See ompi_bitmap.h for an explanation of why there is a split
* between OMPI and ORTE for this generic class.
*
* A bitmap implementation. The bits start off with 0, so this bitmap
* has bits numbered as bit 0, bit 1, bit 2 and so on. This bitmap
* has auto-expansion capabilities, that is once the size is set
* during init, it can be automatically expanded by setting the bit
* beyond the current size. But note, this is allowed just when the
* bit is set -- so the valid functions are set_bit and
* find_and_set_bit. Other functions like clear, if passed a bit
* outside the initialized range will result in an error.
*
*/
#ifndef ORTE_BITMAP_H
#define ORTE_BITMAP_H
#include "orte_config.h"
#include "orte/orte_types.h"
#include <string.h>
#include "opal/types.h"
#include "opal/class/opal_object.h"
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
struct orte_bitmap_t {
opal_object_t super; /**< Subclass of opal_object_t */
unsigned char *bitmap; /**< The actual bitmap array of characters */
orte_std_cntr_t array_size; /**< The actual array size that maintains the bitmap */
orte_std_cntr_t legal_numbits; /**< The number of bits which are legal (the
actual bitmap may contain more bits, since
it needs to be rounded to the nearest
char */
};
typedef struct orte_bitmap_t orte_bitmap_t;
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_bitmap_t);
/**
* Sizes the bitmap to ensure it has at least the specified number of
* bits in it. If it already does, then nothing happens. However, if the
* bitmap is too small, then it is resized to accommodate the bit, with
* all bits in the new space "cleared"
*
* @param bitmap The input bitmap (IN)
* @param bit The bit that must be "covered" by the bitmap (IN)
* @return ORTE error code or success
*
*/
ORTE_DECLSPEC int orte_bitmap_resize(orte_bitmap_t *bm, orte_std_cntr_t bit);
/**
* Set a bit of the bitmap. If the bit asked for is beyond the current
* size of the bitmap, then the bitmap is extended to accomodate the
* bit
*
* @param bitmap The input bitmap (IN)
* @param bit The bit which is to be set (IN)
* @return OMPI error code or success
*
*/
ORTE_DECLSPEC int orte_bitmap_set_bit(orte_bitmap_t *bm, orte_std_cntr_t bit);
/**
* Clear/unset a bit of the bitmap. If the bit is beyond the current
* size of the bitmap, an error is returned
*
* @param bitmap The input bitmap (IN)
* @param bit The bit which is to be cleared (IN)
* @return ORTE error code if the bit is out of range, else success
*
*/
ORTE_DECLSPEC int orte_bitmap_clear_bit(orte_bitmap_t *bm, orte_std_cntr_t bit);
/**
* Find out if a bit is set in the bitmap
*
* @param bitmap The input bitmap (IN)
* @param bit The bit which is to be checked (IN)
* @return ORTE error code if the bit is out of range
* 1 if the bit is set
* 0 if the bit is not set
*
*/
ORTE_DECLSPEC int orte_bitmap_is_set_bit(orte_bitmap_t *bm, orte_std_cntr_t bit);
/**
* Find the first clear bit in the bitmap and set it
*
* @param bitmap The input bitmap (IN)
* @param position Position of the first clear bit (OUT)
* @return err ORTE_SUCCESS on success
*/
ORTE_DECLSPEC int orte_bitmap_find_and_set_first_unset_bit(orte_bitmap_t *bm,
orte_std_cntr_t *position);
/**
* Clear all bits in the bitmap
*
* @param bitmap The input bitmap (IN)
* @return ORTE error code if bm is NULL
*
*/
ORTE_DECLSPEC int orte_bitmap_clear_all_bits(orte_bitmap_t *bm);
/**
* Set all bits in the bitmap
* @param bitmap The input bitmap (IN)
* @return ORTE error code if bm is NULL
*
*/
ORTE_DECLSPEC int orte_bitmap_set_all_bits(orte_bitmap_t *bm);
/**
* Gives the current size (number of bits) in the bitmap. This is the
* legal (accessible) number of bits
*
* @param bitmap The input bitmap (IN)
* @return ORTE error code if bm is NULL
*
*/
static inline int orte_bitmap_size(orte_bitmap_t *bm)
{
return (NULL == bm) ? 0 : (int)bm->legal_numbits;
}
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
#endif

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

@ -1,332 +0,0 @@
/*
* Testcase for ORTE bitmap
*/
#include "orte_config.h"
#include "orte/orte_constants.h"
#include <stdio.h>
#include "support.h"
#include "orte/class/orte_bitmap.h"
#include "opal/runtime/opal.h"
#define STANDALONE
#define BSIZE 26
#define SIZE_OF_CHAR (sizeof(char) * 8)
#define ORTE_INVALID_BIT -1
#define ERR_CODE -2
#define PRINT_VALID_ERR \
fprintf(error_out, "================================ \n"); \
fprintf(error_out, "This is supposed to throw error \n"); \
fprintf(error_out, "================================ \n")
static void test_bitmap_set(orte_bitmap_t *bm);
static void test_bitmap_clear(orte_bitmap_t *bm);
static void test_bitmap_is_set(orte_bitmap_t *bm);
static void test_bitmap_clear_all(orte_bitmap_t *bm);
static void test_bitmap_set_all(orte_bitmap_t *bm);
static void test_bitmap_find_and_set(orte_bitmap_t *bm);
static void test_bitmap_find_size(orte_bitmap_t *bm);
static int set_bit(orte_bitmap_t *bm, int bit);
static int clear_bit(orte_bitmap_t *bm, int bit);
static int is_set_bit(orte_bitmap_t *bm, int bit);
static int clear_all(orte_bitmap_t *bm);
static int set_all(orte_bitmap_t *bm);
static int find_and_set(orte_bitmap_t *bm, int bit);
static int find_size(orte_bitmap_t *bm);
#define WANT_PRINT_BITMAP 0
#if WANT_PRINT_BITMAP
static void print_bitmap(orte_bitmap_t *bm);
#endif
static FILE *error_out=NULL;
int main(int argc, char *argv[])
{
/* Local variables */
orte_bitmap_t bm;
int err;
opal_init();
/* Perform overall test initialization */
test_init("orte_bitmap_t");
#ifdef STANDALONE
error_out = stderr;
#else
error_out = fopen( "./orte_bitmap_test_out.txt", "w" );
if( error_out == NULL ) error_out = stderr;
#endif
/* Initialize bitmap */
OBJ_CONSTRUCT(&bm, orte_bitmap_t);
PRINT_VALID_ERR;
OBJ_CONSTRUCT(&bm, orte_bitmap_t);
fprintf(error_out, "\nTesting bitmap set... \n");
test_bitmap_set(&bm);
fprintf(error_out, "\nTesting bitmap clear ... \n");
test_bitmap_clear(&bm);
fprintf(error_out, "\nTesting bitmap is_set ... \n");
test_bitmap_is_set(&bm);
fprintf(error_out, "\nTesting bitmap clear_all... \n");
test_bitmap_clear_all(&bm);
fprintf(error_out, "\nTesting bitmap set_all... \n");
test_bitmap_set_all(&bm);
fprintf(error_out, "\nTesting bitmap find_and_set... \n");
test_bitmap_find_and_set(&bm);
fprintf(error_out, "\nTesting bitmap find_size... \n");
test_bitmap_find_size(&bm);
OBJ_DESTRUCT(&bm);
fprintf(error_out, "\n~~~~~~ Testing complete ~~~~~~ \n\n");
test_finalize();
#ifndef STANDALONE
fclose(error_out);
#endif
opal_finalize();
return 0;
}
void test_bitmap_set(orte_bitmap_t *bm) {
/* start of bitmap and boundaries */
set_bit(bm, 0);
set_bit(bm, 1);
set_bit(bm, 7);
set_bit(bm, 8);
/* middle of bitmap */
set_bit(bm, 24);
/* end of bitmap initial size */
set_bit(bm, 31);
set_bit(bm, 32);
/* beyond bitmap -- this is valid */
set_bit(bm, 44);
set_bit(bm, 82);
}
void test_bitmap_clear(orte_bitmap_t *bm) {
/* Valid set bits */
clear_bit(bm, 29);
clear_bit(bm, 31);
clear_bit(bm, 33);
clear_bit(bm, 32);
clear_bit(bm, 0);
/* check auto-extend */
clear_bit(bm, 142);
clear_bit(bm, 1024);
}
void test_bitmap_is_set(orte_bitmap_t *bm)
{
int result=0;
/* First set some bits */
test_bitmap_set(bm);
is_set_bit(bm, 0);
is_set_bit(bm, 1);
is_set_bit(bm, 31);
is_set_bit(bm, 32);
PRINT_VALID_ERR;
result = is_set_bit(bm, 11122);
TEST_AND_REPORT(result,ERR_CODE,"orte_bitmap_is_set_bit");
}
void test_bitmap_find_and_set(orte_bitmap_t *bm)
{
int bsize;
int result=0;
orte_bitmap_clear_all_bits(bm);
result = find_and_set(bm, 0);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 1);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 2);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 3);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
result = orte_bitmap_set_bit(bm, 5);
result = find_and_set(bm, 4);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
result = orte_bitmap_set_bit(bm, 6);
result = orte_bitmap_set_bit(bm, 7);
/* Setting beyond a char boundary */
result = find_and_set(bm, 8);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
orte_bitmap_set_bit(bm, 9);
result = find_and_set(bm, 10);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
/* Setting beyond the current size of bitmap */
orte_bitmap_set_all_bits(bm);
bsize = bm->array_size * SIZE_OF_CHAR;
result = find_and_set(bm, bsize);
TEST_AND_REPORT(result, 0, "orte_bitmap_find_and_set_first_unset_bit");
}
void test_bitmap_clear_all(orte_bitmap_t *bm)
{
int result = clear_all(bm);
TEST_AND_REPORT(result, 0, " error in orte_bitmap_clear_all_bits");
}
void test_bitmap_set_all(orte_bitmap_t *bm)
{
int result = set_all(bm);
TEST_AND_REPORT(result, 0, " error in orte_bitmap_set_ala_bitsl");
}
void test_bitmap_find_size(orte_bitmap_t *bm)
{
int result = find_size(bm);
TEST_AND_REPORT(result, 0, " error in orte_bitmap_size");
}
int set_bit(orte_bitmap_t *bm, int bit)
{
int err = orte_bitmap_set_bit(bm, bit);
if (err != 0
|| !(bm->bitmap[bit/SIZE_OF_CHAR] & (1 << bit % SIZE_OF_CHAR))) {
fprintf(error_out, "ERROR: set_bit for bit = %d\n\n", bit);
return ERR_CODE;
}
return 0;
}
int clear_bit(orte_bitmap_t *bm, int bit)
{
int err = orte_bitmap_clear_bit(bm, bit);
if ((err != 0)
|| (bm->bitmap[bit/SIZE_OF_CHAR] & (1 << bit % SIZE_OF_CHAR))) {
fprintf(error_out, "ERROR: clear_bit for bit = %d \n\n", bit);
return ERR_CODE;
}
return 0;
}
int is_set_bit(orte_bitmap_t *bm, int bit)
{
int result = orte_bitmap_is_set_bit(bm, bit);
if (((1 == result)
&& !(bm->bitmap[bit/SIZE_OF_CHAR] & (1 << bit % SIZE_OF_CHAR)))
|| (result < 0)
|| ((0 == result)
&&(bm->bitmap[bit/SIZE_OF_CHAR] & (1 << bit % SIZE_OF_CHAR)))) {
fprintf(error_out, "ERROR: is_set_bit for bit = %d \n\n",bit);
return ERR_CODE;
}
return 0;
}
int find_and_set(orte_bitmap_t *bm, int bit)
{
int ret;
size_t pos;
/* bit here is the bit that should be found and set, in the top
level stub, this function will be called in sequence to test */
ret = orte_bitmap_find_and_set_first_unset_bit(bm, &pos);
if (ret != ORTE_SUCCESS) return ret;
if ((int)pos != bit) {
fprintf(error_out, "ERROR: find_and_set: expected to find_and_set %d\n\n",
bit);
return ERR_CODE;
}
return 0;
}
int clear_all(orte_bitmap_t *bm)
{
int i, err;
err = orte_bitmap_clear_all_bits(bm);
for (i = 0; i < (int)bm->array_size; ++i)
if (bm->bitmap[i] != 0) {
fprintf(error_out, "ERROR: clear_all for bitmap arry entry %d\n\n",
i);
return ERR_CODE;
}
return 0;
}
int set_all(orte_bitmap_t *bm)
{
int i, err;
err = orte_bitmap_set_all_bits(bm);
for (i = 0; i < (int)bm->array_size; ++i)
if (bm->bitmap[i] != 0xff) {
fprintf(error_out, "ERROR: set_all for bitmap arry entry %d\n\n", i);
return ERR_CODE;
}
return 0;
}
int find_size(orte_bitmap_t *bm)
{
if (orte_bitmap_size(bm) != (int)bm->legal_numbits) {
fprintf(error_out, "ERROR: find_size: expected %d reported %d\n\n",
(int) bm->array_size, (int) orte_bitmap_size(bm));
return ERR_CODE;
}
return 0;
}
#if WANT_PRINT_BITMAP
void print_bitmap(orte_bitmap_t *bm)
{
/* Accessing the fields within the structure, since its not an
opaque structure */
int i;
for (i = 0; i < (int)bm->array_size; ++i) {
fprintf(error_out, "---\n bitmap[%d] = %x \n---\n\n", i,
(bm->bitmap[i] & 0xff));
}
fprintf(error_out, "========================= \n");
return;
}
#endif