X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e106f396c86e8656041281680d63735549985879..8feb1c4d2fe696b8f0c723eac3d88024976f6825:/examples/msg/chord/chord.c diff --git a/examples/msg/chord/chord.c b/examples/msg/chord/chord.c index a433608577..7289d43b36 100644 --- a/examples/msg/chord/chord.c +++ b/examples/msg/chord/chord.c @@ -1,5 +1,5 @@ -/* Copyright (c) 2010. The SimGrid Team. +/* Copyright (c) 2010-2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -293,6 +293,12 @@ int node(int argc, char *argv[]) double next_check_predecessor_date = init_time + periodic_check_predecessor_delay; double next_lookup_date = init_time + periodic_lookup_delay; + #ifdef HAVE_MC + int listen = 0; + int no_op = 0; + int sub_protocol = 0; + #endif + xbt_assert(argc == 3 || argc == 5, "Wrong number of arguments for this node"); // initialize my node @@ -339,67 +345,68 @@ int node(int argc, char *argv[]) // FIXME: do not make MSG_task_irecv() calls from several functions } + //XBT_INFO("Node %d is ring member : %d", node.id, is_ring_member(known_id, node.id) != -1); + if (!MSG_comm_test(node.comm_receive)) { // no task was received: make some periodic calls - #ifdef HAVE_MC - if(MC_is_active()){ - if(MC_random()){ +#ifdef HAVE_MC + if(MC_is_active()){ + if(!MC_visited_reduction() && no_op){ + MC_cut(); + } + if(listen == 0 && (sub_protocol = MC_random(0, 4)) > 0){ + if(sub_protocol == 1) stabilize(&node); - }else if(MC_random()){ + else if(sub_protocol == 2) fix_fingers(&node); - }else if(MC_random()){ + else if(sub_protocol == 3) check_predecessor(&node); - }else if(MC_random()){ + else random_lookup(&node); - }else{ - MSG_process_sleep(5); - } + listen = 1; }else{ - if (MSG_get_clock() >= next_stabilize_date) { - stabilize(&node); - next_stabilize_date = MSG_get_clock() + periodic_stabilize_delay; - } - else if (MSG_get_clock() >= next_fix_fingers_date) { - fix_fingers(&node); - next_fix_fingers_date = MSG_get_clock() + periodic_fix_fingers_delay; - } - else if (MSG_get_clock() >= next_check_predecessor_date) { - check_predecessor(&node); - next_check_predecessor_date = MSG_get_clock() + periodic_check_predecessor_delay; - } - else if (MSG_get_clock() >= next_lookup_date) { - random_lookup(&node); - next_lookup_date = MSG_get_clock() + periodic_lookup_delay; - } - else { - // nothing to do: sleep for a while - MSG_process_sleep(5); - } + MSG_process_sleep(5); + if(!MC_visited_reduction()) + no_op = 1; } - #else + }else{ if (MSG_get_clock() >= next_stabilize_date) { stabilize(&node); next_stabilize_date = MSG_get_clock() + periodic_stabilize_delay; - } - else if (MSG_get_clock() >= next_fix_fingers_date) { + }else if (MSG_get_clock() >= next_fix_fingers_date) { fix_fingers(&node); next_fix_fingers_date = MSG_get_clock() + periodic_fix_fingers_delay; - } - else if (MSG_get_clock() >= next_check_predecessor_date) { + }else if (MSG_get_clock() >= next_check_predecessor_date) { check_predecessor(&node); next_check_predecessor_date = MSG_get_clock() + periodic_check_predecessor_delay; - } - else if (MSG_get_clock() >= next_lookup_date) { + }else if (MSG_get_clock() >= next_lookup_date) { random_lookup(&node); next_lookup_date = MSG_get_clock() + periodic_lookup_delay; - } - else { + }else { // nothing to do: sleep for a while MSG_process_sleep(5); } - #endif + } +#else + if (MSG_get_clock() >= next_stabilize_date) { + stabilize(&node); + next_stabilize_date = MSG_get_clock() + periodic_stabilize_delay; + }else if (MSG_get_clock() >= next_fix_fingers_date) { + fix_fingers(&node); + next_fix_fingers_date = MSG_get_clock() + periodic_fix_fingers_delay; + }else if (MSG_get_clock() >= next_check_predecessor_date) { + check_predecessor(&node); + next_check_predecessor_date = MSG_get_clock() + periodic_check_predecessor_delay; + }else if (MSG_get_clock() >= next_lookup_date) { + random_lookup(&node); + next_lookup_date = MSG_get_clock() + periodic_lookup_delay; + }else { + // nothing to do: sleep for a while + MSG_process_sleep(5); + } +#endif } else { // a transfer has occurred @@ -601,7 +608,12 @@ static void quit_notify(node_t node) msg_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data); XBT_DEBUG("Sending a 'PREDECESSOR_LEAVING' to my successor %d",node->fingers[0].id); - MSG_task_send_with_timeout(task_sent, node->fingers[0].mailbox, timeout); + if (MSG_task_send_with_timeout(task_sent, node->fingers[0].mailbox, timeout)== + MSG_TIMEOUT) { + XBT_DEBUG("Timeout expired when sending a 'PREDECESSOR_LEAVING' to my successor %d", + node->fingers[0].id); + task_free(task_sent); + } //send the SUCCESSOR_LEAVING to our predecessor get_mailbox(node->pred_id, mailbox); @@ -614,7 +626,12 @@ static void quit_notify(node_t node) msg_task_t task_sent_s = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data_s); XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d",node->pred_id); - MSG_task_send_with_timeout(task_sent_s, mailbox, timeout); + if (MSG_task_send_with_timeout(task_sent_s, mailbox, timeout)== + MSG_TIMEOUT) { + XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", + node->pred_id); + task_free(task_sent_s); + } } @@ -781,9 +798,9 @@ static int remote_get_predecessor(node_t node, int ask_to) msg_task_t task_received = MSG_comm_get_task(node->comm_receive); task_data_t ans_data = MSG_task_get_data(task_received); - if (MC_is_active()) { + /*if (MC_is_active()) { MC_assert(task_received == task_sent); - } + }*/ if (task_received != task_sent) { MSG_comm_destroy(node->comm_receive); @@ -987,14 +1004,19 @@ static void check_predecessor(node_t node) */ static void random_lookup(node_t node) { - //int id = 1337; // TODO pick a pseudorandom id - if(node->stream == NULL) + + int id = 1337; + find_successor(node, id); + + /*** Random lookup disabled for tesh examples ***/ + /*if(node->stream == NULL) node->stream = RngStream_CreateStream(""); int random_index = RngStream_RandInt (node->stream, 0, nb_bits - 1); int random_id = node->fingers[random_index].id; XBT_DEBUG("Making a lookup request for id %d", random_id); int res = find_successor(node, random_id); - XBT_DEBUG("The successor of node %d is %d", random_id, res); + XBT_DEBUG("The successor of node %d is %d", random_id, res);*/ + } /**