2008-01-23 12:20:34 +03:00
|
|
|
/*
|
2008-05-06 22:08:45 +04:00
|
|
|
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
|
2008-01-23 12:20:34 +03:00
|
|
|
* 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-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) 2006-2007 Cisco Systems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
|
|
|
|
/* This component will only be compiled on File, where we are
|
|
|
|
guaranteed to have <unistd.h> and friends */
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-01-26 21:54:27 +03:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2008-01-23 12:20:34 +03:00
|
|
|
#include <unistd.h>
|
2008-01-26 21:54:27 +03:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
|
|
|
#ifdef HAVE_STDLIB_H
|
2008-01-23 12:20:34 +03:00
|
|
|
#include <stdlib.h>
|
2008-01-26 21:54:27 +03:00
|
|
|
#endif /* HAVE_STDLIB_H */
|
|
|
|
#ifdef HAVE_STRING_H
|
2008-01-23 12:20:34 +03:00
|
|
|
#include <string.h>
|
2008-01-26 21:54:27 +03:00
|
|
|
#endif /* HAVE_STRING_H */
|
2008-01-23 12:20:34 +03:00
|
|
|
|
|
|
|
#include "opal/constants.h"
|
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
|
|
|
#include "opal/util/argv.h"
|
|
|
|
#include "opal/util/show_help.h"
|
|
|
|
#include "opal/mca/carto/carto.h"
|
|
|
|
#include "opal/mca/carto/base/base.h"
|
|
|
|
#include "opal/mca/carto/base/carto_base_graph.h"
|
|
|
|
#include "carto_file.h"
|
|
|
|
#include "carto_file_lex.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *carto_file_path;
|
|
|
|
|
|
|
|
static int opal_carto_file_init(void);
|
|
|
|
static int opal_carto_file_finalize(void);
|
|
|
|
static int opal_carto_file_parse(const char *cartofile);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File carto module
|
|
|
|
*/
|
2008-05-06 22:08:45 +04:00
|
|
|
static const opal_carto_base_module_1_0_0_t loc_module = {
|
2008-01-23 12:20:34 +03:00
|
|
|
opal_carto_file_init,
|
2008-05-07 23:33:49 +04:00
|
|
|
opal_carto_base_graph_get_host_graph_fn,
|
|
|
|
opal_carto_base_free_graph_fn,
|
|
|
|
opal_carto_base_get_nodes_distance_fn,
|
|
|
|
opal_carto_base_graph_spf_fn,
|
|
|
|
opal_carto_base_graph_find_node_fn,
|
2008-01-23 12:20:34 +03:00
|
|
|
opal_carto_file_finalize,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-06 22:08:45 +04:00
|
|
|
int opal_carto_file_component_query(mca_base_module_t **module, int *priority)
|
2008-01-23 12:20:34 +03:00
|
|
|
{
|
|
|
|
int param;
|
|
|
|
|
|
|
|
param = mca_base_param_find("carto", "file", "priority");
|
2008-05-06 22:08:45 +04:00
|
|
|
mca_base_param_lookup_int(param, priority);
|
2008-01-23 12:20:34 +03:00
|
|
|
|
|
|
|
param = mca_base_param_find("carto", "file", "path");
|
|
|
|
mca_base_param_lookup_string(param, &carto_file_path);
|
|
|
|
|
2008-05-06 22:08:45 +04:00
|
|
|
*module = (mca_base_module_t *)&loc_module;
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
2008-01-23 12:20:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the carto file module.
|
|
|
|
*
|
|
|
|
* @return int success or error
|
|
|
|
*/
|
|
|
|
static int opal_carto_file_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* create an empty graph */
|
2008-05-07 23:33:49 +04:00
|
|
|
if (NULL == opal_carto_base_common_host_graph) {
|
|
|
|
opal_carto_base_graph_create_fn(&opal_carto_base_common_host_graph);
|
|
|
|
}
|
2008-01-23 12:20:34 +03:00
|
|
|
if (NULL == carto_file_path) {
|
|
|
|
return OPAL_ERROR;
|
|
|
|
}
|
|
|
|
/* parse the carto file and add nodes and connections to the graph */
|
|
|
|
rc = opal_carto_file_parse(carto_file_path);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* finalize the carto file module.
|
|
|
|
*
|
|
|
|
* @return int success or error
|
|
|
|
*/
|
|
|
|
static int opal_carto_file_finalize(void)
|
|
|
|
{
|
|
|
|
/* free the host cartography graph. */
|
2008-05-07 23:33:49 +04:00
|
|
|
if (NULL != opal_carto_base_common_host_graph) {
|
|
|
|
opal_carto_base_free_graph_fn(opal_carto_base_common_host_graph);
|
|
|
|
}
|
2008-01-23 12:20:34 +03:00
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the carto file and file the host graph with nodes and
|
|
|
|
* connections.
|
|
|
|
*
|
|
|
|
* @param cartofile the path to the carto file.
|
|
|
|
*
|
|
|
|
* @return int success or error.
|
|
|
|
*/
|
|
|
|
static int opal_carto_file_parse(const char *cartofile)
|
|
|
|
{
|
|
|
|
int token;
|
|
|
|
opal_carto_base_node_t *node, *end_node;
|
|
|
|
uint32_t weight;
|
|
|
|
char *node1_name, *node2_name, *value, **argv;
|
|
|
|
int cnt, line_number = 1;
|
|
|
|
char *token_to_string[] = {
|
|
|
|
"New-line",
|
|
|
|
"File-error",
|
|
|
|
"Node deceleration",
|
|
|
|
"Connection deceleration",
|
2008-02-07 12:51:19 +03:00
|
|
|
"bi directional connection",
|
2008-01-23 12:20:34 +03:00
|
|
|
"Integer",
|
|
|
|
"Name",
|
|
|
|
"Node connection",
|
|
|
|
"Undefined"
|
2008-02-07 12:51:19 +03:00
|
|
|
"Undefined"
|
|
|
|
"Undefined"
|
2008-01-23 12:20:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* set the done flag to false. at the end of file the the lexical analyzer will set it to true */
|
|
|
|
carto_file_done = false;
|
|
|
|
carto_file_in = fopen(cartofile, "r"); /* open the carto file */
|
|
|
|
/* if the file not found, return an error */
|
|
|
|
if (NULL == carto_file_in) {
|
2008-02-07 12:02:23 +03:00
|
|
|
opal_show_help("help-opal-carto-file.txt", "file not found", true, cartofile);
|
2008-01-23 12:20:34 +03:00
|
|
|
return OPAL_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
while (!carto_file_done) {
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NEWLINE:
|
|
|
|
line_number++;
|
|
|
|
break;
|
|
|
|
case OPAL_CARTO_FILE_NODE_DECELERATION:
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NAME:
|
|
|
|
node = (opal_carto_base_node_t *)malloc(sizeof(opal_carto_base_node_t));
|
|
|
|
node->node_type = strdup(carto_file_value.sval);
|
2008-07-03 18:19:16 +04:00
|
|
|
if (0 == strcmp("socket",node->node_type)) {
|
2008-01-23 12:20:34 +03:00
|
|
|
node->is_cpu = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->is_cpu = false;
|
|
|
|
}
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NAME:
|
|
|
|
node->node_name = strdup(carto_file_value.sval);
|
2008-05-07 23:33:49 +04:00
|
|
|
opal_carto_base_graph_add_node_fn(opal_carto_base_common_host_graph, node);
|
2008-01-23 12:20:34 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(node);
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected node name",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected node type",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OPAL_CARTO_FILE_CONNECTION_DECELERATION:
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NAME:
|
|
|
|
node1_name = strdup(carto_file_value.sval);
|
|
|
|
while (OPAL_CARTO_FILE_NEWLINE != token) {
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NODE_CONNECTION:
|
|
|
|
value = carto_file_value.sval;
|
|
|
|
argv = opal_argv_split (value, ':');
|
|
|
|
cnt = opal_argv_count (argv);
|
|
|
|
if (2 == cnt) {
|
|
|
|
node2_name = strdup(argv[0]);
|
|
|
|
weight = atoi(argv[1]);
|
|
|
|
} else {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "incorrect connection", true, cartofile, line_number, value);
|
|
|
|
opal_argv_free (argv);
|
|
|
|
free(node1_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
opal_argv_free (argv);
|
|
|
|
/* find the start node of the connection */
|
2008-05-07 23:33:49 +04:00
|
|
|
node = opal_carto_base_graph_find_node_fn(opal_carto_base_common_host_graph,node1_name);
|
2008-01-23 12:20:34 +03:00
|
|
|
if (NULL == node) {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "vertex not found", true, cartofile, line_number, node1_name);
|
|
|
|
free(node1_name);
|
|
|
|
free(node2_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* find the end node of the connection */
|
2008-05-07 23:33:49 +04:00
|
|
|
end_node = opal_carto_base_graph_find_node_fn(opal_carto_base_common_host_graph,node2_name);
|
2008-01-23 12:20:34 +03:00
|
|
|
if (NULL == end_node) {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "vertex not found", true, cartofile, line_number, node2_name);
|
|
|
|
free(node1_name);
|
|
|
|
free(node2_name);
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-07 23:33:49 +04:00
|
|
|
opal_carto_base_connect_nodes_fn(opal_carto_base_common_host_graph, node, end_node, weight);
|
2008-01-23 12:20:34 +03:00
|
|
|
free(node2_name);
|
|
|
|
break;
|
|
|
|
case OPAL_CARTO_FILE_NEWLINE:
|
|
|
|
line_number++;
|
2008-02-07 12:51:19 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected Connection",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
free(node1_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(node1_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected node name",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OPAL_CARTO_FILE_BIDIRECTION_CONNECTION:
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NAME:
|
|
|
|
node1_name = strdup(carto_file_value.sval);
|
|
|
|
while (OPAL_CARTO_FILE_NEWLINE != token) {
|
|
|
|
token = carto_file_lex();
|
|
|
|
switch (token) {
|
|
|
|
case OPAL_CARTO_FILE_NODE_CONNECTION:
|
|
|
|
value = carto_file_value.sval;
|
|
|
|
argv = opal_argv_split (value, ':');
|
|
|
|
cnt = opal_argv_count (argv);
|
|
|
|
if (2 == cnt) {
|
|
|
|
node2_name = strdup(argv[0]);
|
|
|
|
weight = atoi(argv[1]);
|
|
|
|
} else {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "incorrect connection", true, cartofile, line_number, value);
|
|
|
|
opal_argv_free (argv);
|
|
|
|
free(node1_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
opal_argv_free (argv);
|
|
|
|
/* find the start node of the connection */
|
2008-05-07 23:33:49 +04:00
|
|
|
node = opal_carto_base_graph_find_node_fn(opal_carto_base_common_host_graph,node1_name);
|
2008-02-07 12:51:19 +03:00
|
|
|
if (NULL == node) {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "vertex not found", true, cartofile, line_number, node1_name);
|
|
|
|
free(node1_name);
|
|
|
|
free(node2_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* find the end node of the connection */
|
2008-05-07 23:33:49 +04:00
|
|
|
end_node = opal_carto_base_graph_find_node_fn(opal_carto_base_common_host_graph,node2_name);
|
2008-02-07 12:51:19 +03:00
|
|
|
if (NULL == end_node) {
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "vertex not found", true, cartofile, line_number, node2_name);
|
|
|
|
free(node1_name);
|
|
|
|
free(node2_name);
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-07 23:33:49 +04:00
|
|
|
opal_carto_base_connect_nodes_fn(opal_carto_base_common_host_graph, node, end_node, weight);
|
|
|
|
opal_carto_base_connect_nodes_fn(opal_carto_base_common_host_graph, end_node, node, weight);
|
2008-02-07 12:51:19 +03:00
|
|
|
free(node2_name);
|
|
|
|
break;
|
|
|
|
case OPAL_CARTO_FILE_NEWLINE:
|
|
|
|
line_number++;
|
2008-01-23 12:20:34 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected Connection",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
free(node1_name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(node1_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected node name",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
opal_show_help("help-opal-carto-file.txt", "expected deceleration",
|
|
|
|
true, cartofile, line_number, token_to_string[token]);
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
error:
|
|
|
|
fclose(carto_file_in);
|
|
|
|
return OPAL_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|