OpenMPI  0.1.1
opal_pointer_array.h File Reference

See opal_bitmap.h for an explanation of why there is a split between OPAL and ORTE for this generic class. More...

#include "opal_config.h"
#include "opal/threads/mutex.h"
#include "opal/class/opal_object.h"

Go to the source code of this file.

Data Structures

struct  opal_pointer_array_t
 dynamic pointer array More...
 

Typedefs

typedef struct opal_pointer_array_t opal_pointer_array_t
 Convenience typedef.
 

Functions

OPAL_DECLSPEC OBJ_CLASS_DECLARATION (opal_pointer_array_t)
 Class declaration.
 
OPAL_DECLSPEC int opal_pointer_array_init (opal_pointer_array_t *array, int initial_allocation, int max_size, int block_size)
 Initialize the pointer array with an initial size of initial_allocation. More...
 
OPAL_DECLSPEC int opal_pointer_array_add (opal_pointer_array_t *array, void *ptr)
 Add a pointer to the array (Grow the array, if need be) More...
 
OPAL_DECLSPEC int opal_pointer_array_set_item (opal_pointer_array_t *array, int index, void *value)
 Set the value of an element in array. More...
 
static void * opal_pointer_array_get_item (opal_pointer_array_t *table, int element_index)
 Get the value of an element in array. More...
 
static int opal_pointer_array_get_size (opal_pointer_array_t *array)
 Get the size of the pointer array. More...
 
OPAL_DECLSPEC int opal_pointer_array_set_size (opal_pointer_array_t *array, int size)
 Set the size of the pointer array. More...
 
OPAL_DECLSPEC bool opal_pointer_array_test_and_set_item (opal_pointer_array_t *table, int index, void *value)
 Test whether a certain element is already in use. More...
 
static void opal_pointer_array_remove_all (opal_pointer_array_t *array)
 Empty the array. More...
 

Detailed Description

See opal_bitmap.h for an explanation of why there is a split between OPAL and ORTE for this generic class.

Utility functions to manage fortran <-> c opaque object translation. Note that since MPI defines fortran handles as [signed] int's, we use int everywhere in here where you would normally expect size_t. There's some code that makes sure indices don't go above FORTRAN_HANDLE_MAX (which is min(INT_MAX, fortran INTEGER max)), just to be sure.

Function Documentation

OPAL_DECLSPEC int opal_pointer_array_add ( opal_pointer_array_t table,
void *  ptr 
)

Add a pointer to the array (Grow the array, if need be)

Parameters
arrayPointer to array (IN)
ptrPointer value (IN)
Returns
Index of inserted array element. Return value of (-1) indicates an error.

Add a pointer to the array (Grow the array, if need be)

Parameters
tablePointer to opal_pointer_array_t object (IN)
ptrPointer to be added to table (IN)
Returns
Array index where ptr is inserted or OPAL_ERROR if it fails

References opal_pointer_array_t::addr, opal_pointer_array_t::lock, opal_pointer_array_t::lowest_free, opal_pointer_array_t::number_free, OPAL_THREAD_LOCK, OPAL_THREAD_UNLOCK, and opal_pointer_array_t::size.

Referenced by ompi_request_init(), opal_graph_get_graph_vertices(), orte_ras_base_node_insert(), and orte_sensor_base_select().

static int opal_pointer_array_get_size ( opal_pointer_array_t array)
inlinestatic

Get the size of the pointer array.

Parameters
arrayPointer to array (IN)
Returns
size Size of the array

Simple inline function to return the size of the array in order to hide the member field from external users.

References opal_pointer_array_t::size.

Referenced by btl_openib_handle_failover_control_messages(), mca_btl_openib_dump_all_internal_queues(), mca_btl_openib_endpoint_notify(), mca_btl_openib_handle_btl_error(), and opal_dss_close().

OPAL_DECLSPEC int opal_pointer_array_init ( opal_pointer_array_t array,
int  initial_allocation,
int  max_size,
int  block_size 
)

Initialize the pointer array with an initial size of initial_allocation.

Set the maximum size of the array, as well as the size of the allocation block for all subsequent growing operations. Remarque: The pointer array has to be created bfore calling this function.

Parameters
arrayPointer to pointer of an array (IN/OUT)
initial_allocationThe number of elements in the initial array (IN)
max_sizeThe maximum size of the array (IN)
block_sizeThe size for all subsequent grows of the array (IN).
Returns
OPAL_SUCCESS if all initializations were succesfull. Otherwise, the error indicate what went wrong in the function.

Initialize the pointer array with an initial size of initial_allocation.

References opal_pointer_array_t::addr, opal_pointer_array_t::block_size, opal_pointer_array_t::max_size, opal_pointer_array_t::number_free, and opal_pointer_array_t::size.

Referenced by mca_btl_udapl_init(), ompi_errcode_intern_init(), ompi_errhandler_init(), ompi_group_init(), ompi_mpi_errcode_init(), ompi_request_init(), opal_carto_base_duplicate_graph_fn(), opal_carto_base_free_graph_fn(), opal_dss_open(), and orte_sensor_base_open().

static void opal_pointer_array_remove_all ( opal_pointer_array_t array)
inlinestatic
OPAL_DECLSPEC int opal_pointer_array_set_item ( opal_pointer_array_t table,
int  index,
void *  value 
)

Set the value of an element in array.

Parameters
arrayPointer to array (IN)
indexIndex of element to be reset (IN)
valueNew value to be set at element index (IN)
Returns
Error code. (-1) indicates an error.

Set the value of an element in array.

Parameters
tablePointer to opal_pointer_array_t object (IN)
ptrPointer to be added to table (IN)
Returns
Error code

Assumption: NULL element is free element.

References opal_pointer_array_t::addr, opal_pointer_array_t::lock, opal_pointer_array_t::lowest_free, opal_pointer_array_t::number_free, opal_output(), OPAL_THREAD_LOCK, OPAL_THREAD_UNLOCK, and opal_pointer_array_t::size.

Referenced by ompi_errcode_intern_init(), ompi_mpi_errclass_add(), ompi_mpi_errcode_add(), opal_dss_close(), and orte_sensor_base_select().

OPAL_DECLSPEC int opal_pointer_array_set_size ( opal_pointer_array_t array,
int  size 
)

Set the size of the pointer array.

Parameters
arrayPointer to array (IN)
sizeDesired size of the array

Simple function to set the size of the array in order to hide the member field from external users.

References opal_pointer_array_t::lock, OPAL_THREAD_LOCK, OPAL_THREAD_UNLOCK, and opal_pointer_array_t::size.

Referenced by orte_ras_base_node_insert().

OPAL_DECLSPEC bool opal_pointer_array_test_and_set_item ( opal_pointer_array_t table,
int  index,
void *  value 
)

Test whether a certain element is already in use.

If not yet in use, reserve it.

Parameters
arrayPointer to array (IN)
indexIndex of element to be tested (IN)
valueNew value to be set at element index (IN)
Returns
true/false True if element could be reserved False if element could not be reserved (e.g., in use).

In contrary to array_set, this function does not allow to overwrite a value, unless the previous value is NULL ( equiv. to free ).

If not yet in use, reserve it.

Parameters
arrayPointer to array (IN)
indexIndex of element to be tested (IN)
valueNew value to be set at element index (IN)
Returns
true/false True if element could be reserved False if element could not be reserved (e.g.in use).

In contrary to array_set, this function does not allow to overwrite a value, unless the previous value is NULL ( equiv. to free ).

References opal_pointer_array_t::addr, opal_pointer_array_t::lock, opal_pointer_array_t::lowest_free, opal_pointer_array_t::number_free, opal_output(), OPAL_THREAD_LOCK, OPAL_THREAD_UNLOCK, and opal_pointer_array_t::size.