Wraped the carto API in carto_base_wrapers.c
This commit was SVN r17380.
Этот коммит содержится в:
родитель
9ef46de2f5
Коммит
98e8de264d
@ -58,6 +58,7 @@ static const opal_carto_base_module_1_0_0_t module = {
|
||||
opal_carto_base_free_graph,
|
||||
opal_carto_base_get_nodes_distance,
|
||||
opal_carto_base_graph_spf,
|
||||
opal_carto_base_graph_find_node,
|
||||
opal_carto_auto_detect_finalize,
|
||||
};
|
||||
|
||||
|
@ -25,4 +25,5 @@ libmca_carto_la_SOURCES += \
|
||||
base/carto_base_close.c \
|
||||
base/carto_base_select.c \
|
||||
base/carto_base_graph.c \
|
||||
base/carto_base_wrapers.c \
|
||||
base/carto_base_open.c
|
||||
|
@ -129,6 +129,64 @@ OPAL_DECLSPEC extern bool opal_carto_base_components_opened_valid;
|
||||
*/
|
||||
OPAL_DECLSPEC extern opal_list_t opal_carto_base_components_opened;
|
||||
|
||||
|
||||
/**
|
||||
* Get the local host graph. you can reduce the graph for only
|
||||
* the nodes that interst you using the node type.
|
||||
*
|
||||
* @param graph
|
||||
* @param graph_type
|
||||
*
|
||||
* @return OPAL_DECLSPEC int
|
||||
*/
|
||||
OPAL_DECLSPEC int carto_base_get_host_graph(opal_carto_graph_t **graph, const char *graph_type);
|
||||
|
||||
|
||||
/**
|
||||
* Frre a graph
|
||||
*
|
||||
* @param graph
|
||||
*
|
||||
* @return OPAL_DECLSPEC void
|
||||
*/
|
||||
OPAL_DECLSPEC void carto_base_free_graph(opal_carto_graph_t *graph);
|
||||
|
||||
/**
|
||||
* Get the distance (weight) from a start node to all other
|
||||
* nodes. you can reduce the list to the list to the node types
|
||||
* that intersts you.
|
||||
*
|
||||
* @param graph
|
||||
* @param start
|
||||
* @param node_type
|
||||
* @param distance_
|
||||
*
|
||||
* @return OPAL_DECLSPEC int
|
||||
*/
|
||||
OPAL_DECLSPEC int carto_base_get_nodes_distance(opal_carto_graph_t *graph, opal_carto_base_node_t *start, const char *node_type, opal_value_array_t *distance_);
|
||||
|
||||
/**
|
||||
* find the distance between two nodes.
|
||||
*
|
||||
* @param graph
|
||||
* @param start
|
||||
* @param end
|
||||
*
|
||||
* @return OPAL_DECLSPEC uint32_t
|
||||
*/
|
||||
OPAL_DECLSPEC uint32_t carto_base_spf(opal_carto_graph_t *graph,opal_carto_base_node_t *start, opal_carto_base_node_t *end);
|
||||
|
||||
/**
|
||||
* Find a node in the graph
|
||||
*
|
||||
* @param graph
|
||||
* @param node_name
|
||||
*
|
||||
* @return OPAL_DECLSPEC opal_carto_base_node_t
|
||||
*/
|
||||
OPAL_DECLSPEC opal_carto_base_node_t *carto_base_find_node(opal_carto_graph_t *graph, const char *node_name);
|
||||
|
||||
|
||||
/**
|
||||
* Debugging output stream
|
||||
*/
|
||||
|
@ -248,7 +248,7 @@ int opal_carto_base_connect_nodes(opal_carto_graph_t *graph, opal_carto_base_nod
|
||||
* @param node_type the node type(s) that the new graph will
|
||||
* include.
|
||||
*/
|
||||
void opal_carto_base_duplicate_graph(opal_carto_graph_t **destination, const opal_carto_graph_t *source, char *node_type)
|
||||
void opal_carto_base_duplicate_graph(opal_carto_graph_t **destination, const opal_carto_graph_t *source, const char *node_type)
|
||||
{
|
||||
opal_pointer_array_t *vertices;
|
||||
int i, graph_order;
|
||||
@ -289,7 +289,7 @@ void opal_carto_base_duplicate_graph(opal_carto_graph_t **destination, const opa
|
||||
* @return int number of nodes in the returned array.
|
||||
*/
|
||||
int opal_carto_base_get_nodes_distance(opal_carto_graph_t *graph, opal_carto_base_node_t *reference_node,
|
||||
char *node_type, opal_value_array_t *dist_array)
|
||||
const char *node_type, opal_value_array_t *dist_array)
|
||||
{
|
||||
opal_value_array_t *distance_array;
|
||||
vertex_distance_from_t *vertex_distance;
|
||||
@ -343,13 +343,13 @@ uint32_t opal_carto_base_graph_spf(opal_carto_graph_t *graph, opal_carto_base_no
|
||||
* @return opal_carto_base_node_t* the node with the name -if
|
||||
* found or NULL.
|
||||
*/
|
||||
opal_carto_base_node_t *opal_carto_base_graph_find_node(opal_carto_graph_t *graph, char *node_name)
|
||||
opal_carto_base_node_t *opal_carto_base_graph_find_node(opal_carto_graph_t *graph, const char *node_name)
|
||||
{
|
||||
opal_carto_base_node_t node;
|
||||
opal_graph_vertex_t *vertex;
|
||||
|
||||
/* build a temporary node */
|
||||
node.node_name = node_name;
|
||||
node.node_name = strdup(node_name);
|
||||
/**
|
||||
* find a vertex in the graph. the find_vertex uses the
|
||||
* compare_vertex_data method. in our case, compare_vertex_data
|
||||
@ -357,6 +357,7 @@ opal_carto_base_node_t *opal_carto_base_graph_find_node(opal_carto_graph_t *grap
|
||||
* nodes names.
|
||||
*/
|
||||
vertex = opal_graph_find_vertex((opal_graph_t *)graph, (void *)&node);
|
||||
free(node.node_name);
|
||||
if (NULL != vertex) {
|
||||
/* return the fund vertex data (node) */
|
||||
return vertex->vertex_data;
|
||||
@ -384,7 +385,7 @@ void opal_carto_print_graph(opal_carto_graph_t *graph)
|
||||
*
|
||||
* @return int success or error
|
||||
*/
|
||||
int opal_carto_base_graph_get_host_graph(opal_carto_graph_t **graph, char *graph_type)
|
||||
int opal_carto_base_graph_get_host_graph(opal_carto_graph_t **graph, const char *graph_type)
|
||||
{
|
||||
/* duplicate the host graph and delete all the relevant nodes */
|
||||
opal_carto_base_duplicate_graph(graph, carto_base_common_host_graph, graph_type);
|
||||
|
@ -75,7 +75,7 @@ opal_carto_base_connect_nodes(opal_carto_graph_t *graph, opal_carto_base_node_t
|
||||
*/
|
||||
OPAL_DECLSPEC void
|
||||
opal_carto_base_duplicate_graph(opal_carto_graph_t **destination, const opal_carto_graph_t *source,
|
||||
char *node_type);
|
||||
const char *node_type);
|
||||
|
||||
|
||||
/**
|
||||
@ -91,7 +91,7 @@ opal_carto_base_duplicate_graph(opal_carto_graph_t **destination, const opal_car
|
||||
*/
|
||||
OPAL_DECLSPEC int
|
||||
opal_carto_base_get_nodes_distance(opal_carto_graph_t *graph, opal_carto_base_node_t *reference_node,
|
||||
char *node_type, opal_value_array_t *dist_array);
|
||||
const char *node_type, opal_value_array_t *dist_array);
|
||||
|
||||
/**
|
||||
* Find the shortest path between two nodes in the graph
|
||||
@ -116,7 +116,7 @@ opal_carto_base_graph_spf(opal_carto_graph_t *graph, opal_carto_base_node_t *nod
|
||||
* found or NULL.
|
||||
*/
|
||||
OPAL_DECLSPEC opal_carto_base_node_t
|
||||
*opal_carto_base_graph_find_node(opal_carto_graph_t *graph, char *node_name);
|
||||
*opal_carto_base_graph_find_node(opal_carto_graph_t *graph, const char *node_name);
|
||||
|
||||
/**
|
||||
* Print a carto graph (for debug uses)
|
||||
@ -134,6 +134,6 @@ OPAL_DECLSPEC void opal_carto_print_graph(opal_carto_graph_t *graph);
|
||||
*
|
||||
* @return int success or error
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_carto_base_graph_get_host_graph(opal_carto_graph_t **graph, char * graph_type);
|
||||
OPAL_DECLSPEC int opal_carto_base_graph_get_host_graph(opal_carto_graph_t **graph, const char * graph_type);
|
||||
|
||||
#endif
|
||||
|
73
opal/mca/carto/base/carto_base_wrapers.c
Обычный файл
73
opal/mca/carto/base/carto_base_wrapers.c
Обычный файл
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 (c) 2007 Cisco Systems, Inc. All rights reserved.
|
||||
*
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
|
||||
#include "opal_config.h"
|
||||
|
||||
#include "opal/constants.h"
|
||||
#include "opal/mca/carto/carto.h"
|
||||
#include "opal/mca/carto/base/base.h"
|
||||
|
||||
|
||||
int carto_base_get_host_graph(opal_carto_graph_t **graph, const char *graph_type)
|
||||
{
|
||||
if (!opal_carto_base_selected) {
|
||||
return OPAL_ERR_NOT_FOUND;
|
||||
}
|
||||
return opal_carto_base_module->get_host_graph(graph, graph_type);
|
||||
}
|
||||
|
||||
void carto_base_free_graph(opal_carto_graph_t *graph)
|
||||
{
|
||||
if (!opal_carto_base_selected) {
|
||||
return ;
|
||||
}
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
}
|
||||
|
||||
|
||||
int carto_base_get_nodes_distance(opal_carto_graph_t *graph, opal_carto_base_node_t *start, const char *node_type, opal_value_array_t *distance_)
|
||||
{
|
||||
if (!opal_carto_base_selected) {
|
||||
return OPAL_ERR_NOT_FOUND;
|
||||
}
|
||||
return opal_carto_base_module->get_nodes_distance(graph, start, node_type, distance_);
|
||||
}
|
||||
|
||||
uint32_t carto_base_spf(opal_carto_graph_t *graph,opal_carto_base_node_t *start, opal_carto_base_node_t *end)
|
||||
{
|
||||
if (!opal_carto_base_selected) {
|
||||
return OPAL_ERR_NOT_FOUND;
|
||||
}
|
||||
return opal_carto_base_module->spf(graph, start, end);
|
||||
}
|
||||
|
||||
opal_carto_base_node_t *carto_base_find_node(opal_carto_graph_t *graph, const char *node_name)
|
||||
{
|
||||
if (!opal_carto_base_selected) {
|
||||
return NULL;
|
||||
}
|
||||
return opal_carto_base_module->find_node(graph, node_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ typedef int (*opal_carto_base_module_init_1_0_0_fn_t)(void);
|
||||
* the nodes that interst you using the node type.
|
||||
*/
|
||||
typedef int (*opal_carto_base_get_host_graph_fn_t)
|
||||
(opal_carto_graph_t **graph, char *graph_type);
|
||||
(opal_carto_graph_t **graph, const char *graph_type);
|
||||
|
||||
/**
|
||||
* Frre a graph
|
||||
@ -101,7 +101,7 @@ typedef void (*opal_carto_base_free_graph_fn_t)
|
||||
* that intersts you.
|
||||
*/
|
||||
typedef int (*opal_carto_base_get_nodes_distance_fn_t)
|
||||
(opal_carto_graph_t *graph, opal_carto_base_node_t *start, char *node_type, opal_value_array_t *distance_);
|
||||
(opal_carto_graph_t *graph, opal_carto_base_node_t *start, const char *node_type, opal_value_array_t *distance_);
|
||||
|
||||
/**
|
||||
* find the distance between two nodes.
|
||||
@ -109,6 +109,12 @@ typedef int (*opal_carto_base_get_nodes_distance_fn_t)
|
||||
typedef uint32_t (*opal_carto_base_spf_fn_t)
|
||||
(opal_carto_graph_t *graph,opal_carto_base_node_t *start, opal_carto_base_node_t *end);
|
||||
|
||||
/**
|
||||
* Find a node in the graph
|
||||
*/
|
||||
typedef opal_carto_base_node_t *(*opal_carto_base_find_node)
|
||||
(opal_carto_graph_t *graph, const char *node_name);
|
||||
|
||||
|
||||
/**
|
||||
* Module finalize function. Invoked by the base on the selected
|
||||
@ -151,6 +157,8 @@ struct opal_carto_base_module_1_0_0_t {
|
||||
opal_carto_base_get_nodes_distance_fn_t get_nodes_distance;
|
||||
/** Find the distance between two nodes */
|
||||
opal_carto_base_spf_fn_t spf;
|
||||
/** Find a node in the graph */
|
||||
opal_carto_base_find_node find_node;
|
||||
/** Shut down this module */
|
||||
opal_carto_base_module_finalize_fn_t carto_module_finalize;
|
||||
};
|
||||
|
@ -65,6 +65,7 @@ static const opal_carto_base_module_1_0_0_t module = {
|
||||
opal_carto_base_free_graph,
|
||||
opal_carto_base_get_nodes_distance,
|
||||
opal_carto_base_graph_spf,
|
||||
opal_carto_base_graph_find_node,
|
||||
opal_carto_file_finalize,
|
||||
};
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <stdio.h>
|
||||
#include "../../opal/mca/carto/carto.h"
|
||||
#include "../../opal/mca/carto/base/base.h"
|
||||
#include "../../opal/mca/carto/base/carto_base_graph.h"
|
||||
#include "../../opal/util/output.h"
|
||||
|
||||
int
|
||||
@ -52,125 +51,125 @@ main(int argc, char* argv[])
|
||||
*/
|
||||
|
||||
opal_output(0," \n\nget_host_graph Full\n");
|
||||
opal_carto_base_module->get_host_graph(&graph,NULL);
|
||||
carto_base_get_host_graph(&graph,NULL);
|
||||
opal_graph_print(graph);
|
||||
slot0 = opal_carto_base_graph_find_node(graph, "slot0");
|
||||
slot0 = carto_base_find_node(graph, "slot0");
|
||||
if (NULL == slot0) {
|
||||
opal_output(0,"couldnt find slot0 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
end_node = opal_carto_base_graph_find_node(graph, "slot3");
|
||||
end_node = carto_base_find_node(graph, "slot3");
|
||||
if (NULL == end_node) {
|
||||
opal_output(0,"couldnt find mthca1 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
distance = opal_carto_base_module->spf(graph, slot0, end_node);
|
||||
distance = carto_base_spf(graph, slot0, end_node);
|
||||
opal_output(0,"\nThe distance between slot0 and slot3 is %d\n",distance);
|
||||
distance_array = OBJ_NEW(opal_value_array_t);
|
||||
opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t));
|
||||
opal_value_array_reserve(distance_array, 50);
|
||||
distance_array_size = opal_carto_base_module->get_nodes_distance(graph, slot0, NULL, distance_array);
|
||||
distance_array_size = carto_base_get_nodes_distance(graph, slot0, NULL, distance_array);
|
||||
for (i=0; i < distance_array_size; i++) {
|
||||
node_distance = opal_value_array_get_item(distance_array, i);
|
||||
opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance);
|
||||
}
|
||||
OBJ_RELEASE(distance_array);
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
opal_output(0," \n\nget_host_graph Infiniband\n");
|
||||
opal_carto_base_module->get_host_graph(&graph,"Infiniband");
|
||||
carto_base_get_host_graph(&graph,"Infiniband");
|
||||
opal_graph_print(graph);
|
||||
slot0 = opal_carto_base_graph_find_node(graph, "slot0");
|
||||
slot0 = carto_base_find_node(graph, "slot0");
|
||||
if (NULL == slot0) {
|
||||
opal_output(0,"couldnt find slot0 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
end_node = opal_carto_base_graph_find_node(graph, "mthca1");
|
||||
end_node = carto_base_find_node(graph, "mthca1");
|
||||
if (NULL == end_node) {
|
||||
opal_output(0,"couldnt find mthca1 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
distance = opal_carto_base_module->spf(graph, slot0, end_node);
|
||||
distance = carto_base_spf(graph, slot0, end_node);
|
||||
opal_output(0,"\nThe distance between slot0 and mthca1 is %d\n",distance);
|
||||
distance_array = OBJ_NEW(opal_value_array_t);
|
||||
opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t));
|
||||
opal_value_array_reserve(distance_array, 50);
|
||||
distance_array_size = opal_carto_base_module->get_nodes_distance(graph, slot0, "Infiniband", distance_array);
|
||||
distance_array_size = carto_base_get_nodes_distance(graph, slot0, "Infiniband", distance_array);
|
||||
for (i=0; i < distance_array_size; i++) {
|
||||
node_distance = opal_value_array_get_item(distance_array, i);
|
||||
opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance);
|
||||
}
|
||||
OBJ_RELEASE(distance_array);
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
opal_output(0," \n\nget_host_graph Ethernet\n");
|
||||
opal_carto_base_module->get_host_graph(&graph,"Ethernet");
|
||||
carto_base_get_host_graph(&graph,"Ethernet");
|
||||
opal_graph_print(graph);
|
||||
slot0 = opal_carto_base_graph_find_node(graph, "slot0");
|
||||
slot0 = carto_base_find_node(graph, "slot0");
|
||||
if (NULL == slot0) {
|
||||
opal_output(0,"couldnt find slot0 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
end_node = opal_carto_base_graph_find_node(graph, "eth1");
|
||||
end_node = carto_base_find_node(graph, "eth1");
|
||||
if (NULL == end_node) {
|
||||
opal_output(0,"couldnt find mthca1 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
distance = opal_carto_base_module->spf(graph, slot0, end_node);
|
||||
distance = carto_base_spf(graph, slot0, end_node);
|
||||
opal_output(0,"\nThe distance between slot0 and eth1 is %d\n",distance);
|
||||
distance_array = OBJ_NEW(opal_value_array_t);
|
||||
opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t));
|
||||
opal_value_array_reserve(distance_array, 50);
|
||||
distance_array_size = opal_carto_base_module->get_nodes_distance(graph, slot0, "Ethernet", distance_array);
|
||||
distance_array_size = carto_base_get_nodes_distance(graph, slot0, "Ethernet", distance_array);
|
||||
for (i=0; i < distance_array_size; i++) {
|
||||
node_distance = opal_value_array_get_item(distance_array, i);
|
||||
opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance);
|
||||
}
|
||||
OBJ_RELEASE(distance_array);
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
opal_output(0," \n\nget_host_graph Memory\n");
|
||||
opal_carto_base_module->get_host_graph(&graph,"Memory");
|
||||
carto_base_get_host_graph(&graph,"Memory");
|
||||
opal_graph_print(graph);
|
||||
slot0 = opal_carto_base_graph_find_node(graph, "slot0");
|
||||
slot0 = carto_base_find_node(graph, "slot0");
|
||||
if (NULL == slot0) {
|
||||
opal_output(0,"couldnt find slot0 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
end_node = opal_carto_base_graph_find_node(graph, "mem3");
|
||||
end_node = carto_base_find_node(graph, "mem3");
|
||||
if (NULL == end_node) {
|
||||
opal_output(0,"couldnt find mthca1 in the graph exiting\n");
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
return -1;
|
||||
}
|
||||
distance = opal_carto_base_module->spf(graph, slot0, end_node);
|
||||
distance = carto_base_spf(graph, slot0, end_node);
|
||||
opal_output(0,"\nThe distance between slot0 and mem3 is %d\n",distance);
|
||||
distance_array = OBJ_NEW(opal_value_array_t);
|
||||
opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t));
|
||||
opal_value_array_reserve(distance_array, 50);
|
||||
distance_array_size = opal_carto_base_module->get_nodes_distance(graph, slot0, "Memory", distance_array);
|
||||
distance_array_size = carto_base_get_nodes_distance(graph, slot0, "Memory", distance_array);
|
||||
for (i=0; i < distance_array_size; i++) {
|
||||
node_distance = opal_value_array_get_item(distance_array, i);
|
||||
opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance);
|
||||
}
|
||||
OBJ_RELEASE(distance_array);
|
||||
opal_carto_base_module->free_graph(graph);
|
||||
carto_base_free_graph(graph);
|
||||
|
||||
}
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
@ -179,3 +178,4 @@ main(int argc, char* argv[])
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user