X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f06041cf2c450457a0b47a49b66b19cb9133c18e..cfc676704bebcd57e5ea98bb43154245a150948f:/examples/msg/pastry/pastry.c diff --git a/examples/msg/pastry/pastry.c b/examples/msg/pastry/pastry.c index 3c33770c82..2b6efe9703 100644 --- a/examples/msg/pastry/pastry.c +++ b/examples/msg/pastry/pastry.c @@ -1,17 +1,13 @@ -/* Copyright (c) 2013-2014. The SimGrid Team. +/* Copyright (c) 2013-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include #include #include "simgrid/msg.h" -#include "xbt/log.h" -#include "xbt/asserts.h" - XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pastry, - "Messages specific for this msg example"); + XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pastry, "Messages specific for this msg example"); /*************************************** * PASTRY * @@ -40,7 +36,6 @@ static int max_simulation_time = 1000; extern long int smx_total_comms; - typedef struct s_node { int id; //128bits generated random(2^128 -1) int known_id; @@ -60,9 +55,7 @@ typedef struct s_state { int routing_table[LEVELS_COUNT][LEVEL_SIZE]; } s_state_t, *state_t; -/** - * Types of tasks exchanged between nodes. - */ +/** Types of tasks exchanged between nodes. */ typedef enum { TASK_JOIN, TASK_JOIN_REPLY, @@ -96,7 +89,6 @@ static int routing_next(node_t node, int dest); static void create(node_t node); static int join(node_t node); - /** * \brief Gets the mailbox name of a host given its chord id. * \param node_id id of a node @@ -130,7 +122,7 @@ static int shl(int a, int b) { } /* - * Get the cloest id to the dest in the node namespace_set + * Get the closest id to the dest in the node namespace_set */ static int closest_in_namespace_set(node_t node, int dest) { int best_dist; @@ -141,11 +133,11 @@ static int closest_in_namespace_set(node_t node, int dest) { int i, dist; for (i=0; inamespace_set[i]!=-1) { - dist = abs(node->namespace_set[i] - dest); - if (distnamespace_set[i]; - } + dist = abs(node->namespace_set[i] - dest); + if (distnamespace_set[i]; + } } } } @@ -226,7 +218,7 @@ static void handle_task(node_t node, msg_task_t task) { if (next!=node->id) { get_mailbox(next, mailbox); task_data->sender_id = node->id; - task_data->steps++; + task_data->steps++; task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, task_data); MSG_task_send_with_timeout(task_sent, mailbox, timeout); type = TASK_JOIN_REPLY; @@ -259,7 +251,7 @@ static void handle_task(node_t node, msg_task_t task) { // if first node touched reply, copy its neighborood set if (task_data->sender_id == node->known_id) { - node->neighborhood_set[0] = task_data->sender_id; + node->neighborhood_set[0] = task_data->sender_id; for (i=1; ineighborhood_set[i] = task_data->state->neighborhood_set[i-1]; } @@ -270,7 +262,7 @@ static void handle_task(node_t node, msg_task_t task) { for (i=min;iid, i); for (j=0; jrouting_table[i][j] = task_data->state->routing_table[i][j]; } @@ -280,15 +272,15 @@ static void handle_task(node_t node, msg_task_t task) { XBT_DEBUG("Node %i is ready!!!", node->id); while(xbt_fifo_size(node->pending_tasks)) - handle_task(node, xbt_fifo_pop(node->pending_tasks)); + handle_task(node, xbt_fifo_pop(node->pending_tasks)); - for (i=0; inamespace_set[i]; if (j!=-1) { XBT_DEBUG("Send update to %i", j); get_mailbox(j, mailbox); - - req_data = xbt_new0(s_task_data_t,1); + + req_data = xbt_new0(s_task_data_t,1); req_data->answer_id = node->id; req_data->steps = 0; req_data->type = TASK_UPDATE; @@ -320,65 +312,65 @@ static void handle_task(node_t node, msg_task_t task) { i=0; for (; inamespace_set[i]; - task_namespace_set[i] = task_data->state->namespace_set[i]; + task_namespace_set[i] = task_data->state->namespace_set[i]; } task_namespace_set[i] = task_data->state->id; for (; inamespace_set[i]; - task_namespace_set[i+1] = task_data->state->namespace_set[i]; + curr_namespace_set[i] = node->namespace_set[i]; + task_namespace_set[i+1] = task_data->state->namespace_set[i]; } // get the index of values before and after node->id in task_namespace min = -1; max = -1; for (i=0; i<=NAMESPACE_SIZE; i++) { - j = task_namespace_set[i]; + j = task_namespace_set[i]; if (iid) min = i; - if (j != -1 && max == -1 && j > node->id) max = i; + printf("%08x %08x | ", j, curr_namespace_set[i]); + if (j != -1 && j < node->id) min = i; + if (j != -1 && max == -1 && j > node->id) max = i; } printf("\n"); // add lower elements j = NAMESPACE_SIZE/2-1; for (i=NAMESPACE_SIZE/2-1; i>=0; i--) { - printf("i:%i, j:%i, min:%i, currj:%08x, taskmin:%08x\n", i, j, min, curr_namespace_set[j], task_namespace_set[min]); + printf("i:%i, j:%i, min:%i, currj:%08x, taskmin:%08x\n", i, j, min, curr_namespace_set[j], task_namespace_set[min]); if (min<0) { - node->namespace_set[i] = curr_namespace_set[j]; - j--; - } else if (curr_namespace_set[j] == task_namespace_set[min]) { - node->namespace_set[i] = curr_namespace_set[j]; - j--; min--; - } else if (curr_namespace_set[j] > task_namespace_set[min]) { + node->namespace_set[i] = curr_namespace_set[j]; + j--; + } else if (curr_namespace_set[j] == task_namespace_set[min]) { + node->namespace_set[i] = curr_namespace_set[j]; + j--; min--; + } else if (curr_namespace_set[j] > task_namespace_set[min]) { node->namespace_set[i] = curr_namespace_set[j]; - j--; - } else { + j--; + } else { node->namespace_set[i] = task_namespace_set[min]; - min--; - } + min--; + } } // add greater elements j = NAMESPACE_SIZE/2; for (i=NAMESPACE_SIZE/2; i=NAMESPACE_SIZE) { - node->namespace_set[i] = curr_namespace_set[j]; - j++; - } else if (curr_namespace_set[j] == -1) { - node->namespace_set[i] = task_namespace_set[max]; - max++; - } else if (curr_namespace_set[j] == task_namespace_set[max]) { - node->namespace_set[i] = curr_namespace_set[j]; - j++; max++; - } else if (curr_namespace_set[j] < task_namespace_set[max]) { + node->namespace_set[i] = curr_namespace_set[j]; + j++; + } else if (curr_namespace_set[j] == -1) { + node->namespace_set[i] = task_namespace_set[max]; + max++; + } else if (curr_namespace_set[j] == task_namespace_set[max]) { + node->namespace_set[i] = curr_namespace_set[j]; + j++; max++; + } else if (curr_namespace_set[j] < task_namespace_set[max]) { node->namespace_set[i] = curr_namespace_set[j]; - j++; - } else { + j++; + } else { node->namespace_set[i] = task_namespace_set[max]; - max++; - } + max++; + } } print_node_namespace_set(node); @@ -389,7 +381,7 @@ static void handle_task(node_t node, msg_task_t task) { node->routing_table[i][j] = task_data->state->routing_table[i][j]; } } - } + } } /** @@ -423,7 +415,7 @@ static int join(node_t node){ } /* - * Print the node infomations + * Print the node infomation */ static void print_node(node_t node) { printf("Node:\n"); @@ -437,7 +429,7 @@ static void print_node(node_t node) { * Print the node id */ static void print_node_id(node_t node) { - int i; + int i; printf(" id: %i '%08x' ", node->id, node->id); for (i=0;iid, i)); @@ -448,7 +440,7 @@ static void print_node_id(node_t node) { * Print the node neighborood set */ static void print_node_neighborood_set(node_t node) { - int i; + int i; printf(" neighborood:\n"); for (i=0; ineighborhood_set[i]); @@ -458,7 +450,7 @@ static void print_node_neighborood_set(node_t node) { * Print the routing table */ static void print_node_routing_table(node_t node) { - int i,j; + int i,j; printf(" routing table:\n"); for (i=0; iid = node->id; for (i=0; i 2, + "Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n" + "\tExample: %s ../msg_platform.xml pastry10.xml\n", + argv[0], argv[0]); char **options = &argv[1]; while (!strncmp(options[0], "-", 1)) { int length = strlen("-nb_bits="); if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) { - nb_bits = atoi(options[0] + length); + nb_bits = xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter: %s"); XBT_DEBUG("Set nb_bits to %d", nb_bits); } else { length = strlen("-timeout="); if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) { - timeout = atoi(options[0] + length); + timeout = xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"); XBT_DEBUG("Set timeout to %d", timeout); } else { @@ -653,9 +644,5 @@ int main(int argc, char *argv[]) XBT_CRITICAL("Messages created: %ld", smx_total_comms); XBT_INFO("Simulated time: %g", MSG_get_clock()); - if (res == MSG_OK) - return 0; - else - return 1; - + return res != MSG_OK; }