tasks that are finished and should constitute the return value of
SD_simulate.
+ XBT:
+ * Mallocators: allow value NULL for the reset function.
+ * Dicts: new function xbt_dict_new_homogeneous(void(*)(void*)) to
+ create homogeneous dictionaries, where all the elements share the
+ same free function.
+
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
SimGrid (3.6.2) stable; urgency=low
src/xbt/backtrace_windows.c
src/xbt/backtrace_dummy.c
src/xbt/setset_private.h
- src/xbt/parmap_private.h
src/xbt/mmalloc/attach.c
src/xbt/mmalloc/detach.c
src/xbt/mmalloc/keys.c
)
#### Generate the manpages
-if( NOT MANPAGE_DIR )
+if(NOT WIN32)
+if( NOT MANPAGE_DIR)
set( MANPAGE_DIR ${CMAKE_BINARY_DIR}/manpages )
endif( NOT MANPAGE_DIR)
install(FILES ${MANPAGE_DIR}/simgrid_update_xml.1
DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr/share/man/man1)
+endif(NOT WIN32)
+
# binaries
install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/smpicc
${CMAKE_BINARY_DIR}/bin/smpif2c
ADD_TEST(memcheck-tesh-simdag-parser-20 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./properties.xml --cfg=cpu/model:CpuTI --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-21 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./one_cluster_file.xml --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-22 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/is_router_test ./test_of_is_router.xml --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
+ADD_TEST(memcheck-tesh-simdag-parser-23 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test ./Two_clusters_rulebased.xml ONE_LINK --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-0 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test one_cluster_fullduplex.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-1 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test two_clusters_symmetric.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
ADD_TEST(memcheck-tesh-simdag-parser-sym-full-2 ${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms/basic_parsing_test two_hosts_one_link_symmetrical.xml FULL_LINK "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms/)
endif(HAVE_RAWCTX)
ADD_TEST(memcheck-msg-masterslave-vivaldi-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-thread-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-thread-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-thread-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
if(HAVE_RAWCTX)
ADD_TEST(memcheck-msg-masterslave-vivaldi-raw-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-raw-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-raw-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-raw-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-raw-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
endif(HAVE_RAWCTX)
if(HAVE_UCONTEXT_H)
ADD_TEST(memcheck-msg-masterslave-vivaldi-ucontext-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/vivaldi.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_vivaldi.xml --cfg=network/latency_factor:1.0 --cfg=network/bandwidth_factor:1.0 --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/)
-ADD_TEST(memcheck-msg-token-ring-ucontext-0 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
-ADD_TEST(memcheck-msg-token-ring-ucontext-1 token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-ucontext-0 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
+ADD_TEST(memcheck-msg-token-ring-ucontext-1 ${CMAKE_BINARY_DIR}/examples/msg/token_ring/token_ring ${CMAKE_HOME_DIRECTORY}/examples/msg/token_ring/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n" --cfg=contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/examples/msg/token_ring/)
endif(HAVE_UCONTEXT_H)
ADD_TEST(memcheck-msg-masterslave-multicore-thread-0 ${CMAKE_BINARY_DIR}/examples/msg/masterslave/masterslave_mailbox ${CMAKE_HOME_DIRECTORY}/examples/msg/../platforms/multicore_machine.xml ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/deployment_masterslave_mailbox_multicore.xml --cfg=cpu/model:Cas01_fullupdate --cfg=contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/examples/msg/)
xbt_peer_t h; /* iterator */
int connected = 0;
- gras_socket_t peer = NULL; /* socket to node */
+ volatile gras_socket_t peer = NULL; /* socket to node */
/* xbt_dynar for peers */
XBT_INFO("== Trying to modify a process property");
value = gras_process_property_value("new prop");
xbt_assert(!value, "Property 'new prop' exists before I add it!");
- xbt_dict_set(process_props, "new prop", xbt_strdup("new value"),
- xbt_free_f);
+ xbt_dict_set(process_props, "new prop", xbt_strdup("new value"), NULL);
/* Test if we have changed the value */
value = gras_process_property_value("new prop");
XBT_INFO
("== Set a host property that alice will try to retrieve in SG (from bob->hello)");
- xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), xbt_free_f);
+ xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), NULL);
XBT_INFO("== Dump all the properties of host1 again to check the addition");
xbt_dict_foreach(host_props, cursor, key, data)
xbt_workload_elm_t cmd;
xbt_dict_cursor_t dict_cursor;
- xbt_dict_t pals_int = xbt_dict_new();
+ xbt_dict_t pals_int = xbt_dict_new_homogeneous(NULL);
xbt_dynar_foreach(cmds, cursor, cmd) {
int *p = xbt_dict_get_or_null(pals_int, cmd->who);
if (!p) {
xbt_dict_free(&pals_int);
/* Check who came */
- xbt_dict_t pals = xbt_dict_new();
+ xbt_dict_t pals = xbt_dict_new_homogeneous(NULL);
gras_socket_t pal;
xbt_dynar_foreach(peers, cursor, peer) {
//XBT_INFO("%s is here",peer->name);
int connected = 0;
gras_cb_register("commands", worker_commands_cb);
- globals->peers = xbt_dict_new();
+ globals->peers = xbt_dict_new_homogeneous(NULL);
if (gras_if_RL())
XBT_INFO("Sensor %s starting. Connecting to master on %s",
add_executable(masterslave_console "masterslave_console.c")
add_executable(masterslave_cluster "masterslave_cluster.c")
add_executable(masterslave_kill "masterslave_kill.c")
+add_executable(masterslave_arg "masterslave_arg.c")
### Add definitions for compile
if(WIN32)
target_link_libraries(masterslave_bypass simgrid )
target_link_libraries(masterslave_console simgrid )
target_link_libraries(masterslave_kill simgrid )
+target_link_libraries(masterslave_arg simgrid )
else(WIN32)
target_link_libraries(masterslave_forwarder simgrid m )
target_link_libraries(masterslave_failure simgrid m )
target_link_libraries(masterslave_bypass simgrid m )
target_link_libraries(masterslave_console simgrid m )
target_link_libraries(masterslave_kill simgrid m )
+target_link_libraries(masterslave_arg simgrid m )
endif(WIN32)
target_link_libraries(masterslave_cluster simgrid)
\ No newline at end of file
--- /dev/null
+/* Copyright (c) 2010. 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 <stdio.h>
+#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
+#include "xbt/sysdep.h" /* calloc, printf */
+
+/* Create a log channel to have nice outputs. */
+#include "xbt/log.h"
+#include "xbt/asserts.h"
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
+ "Messages specific for this msg example");
+
+int master(int argc, char *argv[]);
+int slave(int argc, char *argv[]);
+
+#define task_comp_size 50000000
+#define task_comm_size 1000000
+
+long number_of_jobs;
+long number_of_slaves;
+
+static long my_random(long n)
+{
+ return n * (rand() / ((double)RAND_MAX + 1));
+}
+
+/** Emitter function */
+int master(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i <= number_of_jobs; i++) {
+ char mailbox[256];
+ char sprintf_buffer[256];
+ m_task_t task = NULL;
+
+ sprintf(mailbox, "slave-%ld", i % number_of_slaves);
+ sprintf(sprintf_buffer, "Task_%d", i);
+ task =
+ MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
+ NULL);
+ XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
+ number_of_jobs, mailbox);
+
+ MSG_task_send(task, mailbox);
+ }
+
+ XBT_DEBUG
+ ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ for (i = 0; i < number_of_slaves; i++) {
+ char mailbox[80];
+
+ sprintf(mailbox, "slave-%ld", i % number_of_slaves);
+ m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
+ MSG_task_send(finalize, mailbox);
+ }
+
+ XBT_DEBUG("Goodbye now!");
+ return 0;
+} /* end_of_master */
+
+/** Receiver function */
+int slave(int argc, char *argv[])
+{
+ m_task_t task = NULL;
+ _XBT_GNUC_UNUSED int res;
+
+ XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self()));
+ while (1) {
+ res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
+ xbt_assert(res == MSG_OK, "MSG_task_get failed");
+
+ XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task));
+ if (!strcmp(MSG_task_get_name(task), "finalize")) {
+ MSG_task_destroy(task);
+ break;
+ }
+ XBT_DEBUG("Processing \"%s\"", MSG_task_get_name(task));
+ MSG_task_execute(task);
+ XBT_DEBUG("\"%s\" done", MSG_task_get_name(task));
+ MSG_task_destroy(task);
+ task = NULL;
+ }
+ XBT_DEBUG("I'm done. See you!");
+ return 0;
+} /* end_of_slave */ /* end_of_test_all */
+
+/** Main function */
+int main(int argc, char *argv[])
+{
+ MSG_error_t res = MSG_OK;
+ long i;
+
+ MSG_global_init(&argc, argv);
+ if (argc < 4) {
+ printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
+ printf("example: %s msg_platform.xml 10 5\n", argv[0]);
+ exit(1);
+ }
+
+ MSG_set_channel_number(0);
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+
+ MSG_create_environment(argv[1]);
+
+ number_of_jobs = atol(argv[2]);
+ number_of_slaves = atol(argv[3]);
+ long number_max = MSG_get_host_number();
+ XBT_INFO("Got %ld slaves, %ld tasks to process, and %d hosts", number_of_slaves, number_of_jobs,MSG_get_host_number());
+
+ m_host_t *host_table = MSG_get_host_table();
+
+ MSG_process_create( "master",
+ master,
+ NULL,
+ host_table[my_random(number_max)]
+ );
+
+ for(i = 0 ; i<number_of_slaves; i++)
+ {
+ char* name_host = bprintf("slave-%ld",i);
+ MSG_process_create( name_host,
+ slave,
+ NULL,
+ host_table[my_random(number_max)]
+ );
+ free(name_host);
+ }
+ xbt_free(host_table);
+
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
+
+ MSG_clean();
+
+ if (res == MSG_OK)
+ return 0;
+ else
+ return 1;
+} /* end_of_main */
XBT_INFO(" Property: %s old value: %s", exist, value);
XBT_INFO("== Trying to modify a host property");
- xbt_dict_set(props, exist, xbt_strdup("250"), xbt_free_f);
+ xbt_dict_set(props, exist, xbt_strdup("250"), NULL);
/* Test if we have changed the value */
value = MSG_host_get_property_value(thehost, exist);
#include "msg/msg.h"
#include "surf/surf_private.h"
-extern routing_global_t global_routing;
-int totalHosts= 0;
-const m_host_t *hosts;
-
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
+int host(int argc, char *argv[]);
+unsigned int task_comp_size = 50000000;
+unsigned int task_comm_size = 1000000;
+int number_of_hosts;
XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
"Messages specific for this msg example");
-int master(int argc, char *argv[])
-{
- m_task_t task_s = NULL;
- m_task_t task_r = NULL;
- unsigned int task_comp_size = 50000000;
- unsigned int task_comm_size = 1000000;
- char mailbox[80];
- char buffer[20];
- int num = atoi(argv[1]);
-
- sprintf(mailbox, "host%d", num+1);
- if(num == totalHosts-1)
- sprintf(mailbox, "host%d", 0);
- sprintf(buffer, "Token");
-
- task_s = MSG_task_create(buffer,
- task_comp_size,
- task_comm_size,
- NULL);
- MSG_task_send(task_s,mailbox);
- XBT_INFO("Send Data to \"%s\"", mailbox);
-
- sprintf(mailbox, "host%d", num);
- MSG_task_receive(&(task_r), mailbox);
- XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r));
- return 0;
-}
-
-int slave(int argc, char *argv[])
-{
- m_task_t task_s = NULL;
- m_task_t task_r = NULL;
- unsigned int task_comp_size = 50000000;
- unsigned int task_comm_size = 1000000;
- char mailbox[80];
- char buffer[20];
- int num = atoi(argv[1]);
-
- sprintf(mailbox, "host%d", num);
- MSG_task_receive(&(task_r), mailbox);
- XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r));
- sprintf(mailbox, "host%d", num+1);
- if(num == totalHosts-1)
- sprintf(mailbox, "host%d", 0);
- sprintf(buffer, "Token");
- task_s = MSG_task_create(buffer,
- task_comp_size,
- task_comm_size,
- NULL);
- MSG_task_send(task_s, mailbox);
- XBT_INFO("Send Data to \"%s\"", mailbox);
-
- return 0;
-}
-
-static int surf_parse_bypass_application(void)
+int host(int argc, char *argv[])
{
- int i;
- static int AX_ptr;
- static int surfxml_bufferstack_size = 2048;
- static int surfxml_buffer_stack_stack_ptr = 0;
- static int surfxml_buffer_stack_stack[1024];
- /* allocating memory to the buffer, I think 2MB should be enough */
- surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
-
- totalHosts = MSG_get_host_number();
- hosts = MSG_get_host_table();
-
- /* <platform> */
- SURFXML_BUFFER_SET(platform_version, "3");
-
- SURFXML_START_TAG(platform);
-
- XBT_DEBUG("process : %s en master",MSG_host_get_name(hosts[0]));
- /* <process host="host A" function="master"> */
- SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0]));
- SURFXML_BUFFER_SET(process_function, "master");
- SURFXML_BUFFER_SET(process_start_time, "-1.0");
- SURFXML_BUFFER_SET(process_kill_time, "-1.0");
- SURFXML_START_TAG(process);
-
- /* <argument value="0"/> */
- SURFXML_BUFFER_SET(argument_value, "0");
- SURFXML_START_TAG(argument);
- SURFXML_END_TAG(argument);
- SURFXML_END_TAG(process);
-
- for(i=1;i<totalHosts;i++)
- {
- XBT_DEBUG("process : %s en slave",MSG_host_get_name(hosts[i]));
- /* <process host="host A" function="slave"> */
- SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) );
- SURFXML_BUFFER_SET(process_function, "slave");
- SURFXML_BUFFER_SET(process_start_time, "-1.0");
- SURFXML_BUFFER_SET(process_kill_time, "-1.0");
- SURFXML_START_TAG(process);
-
- /* <argument value="num"/> */
- SURFXML_BUFFER_SET(argument_value, bprintf("%d",i));
- SURFXML_START_TAG(argument);
- SURFXML_END_TAG(argument);
- SURFXML_END_TAG(process);
- }
- /* </platform> */
- SURFXML_END_TAG(platform);
-
- free(surfxml_bufferstack);
- return 0;
+ int host_number = atoi(MSG_process_get_name(MSG_process_self()));
+ char mailbox[256];
+ m_task_t task = NULL;
+ _XBT_GNUC_UNUSED int res;
+
+ if (host_number == 0){ //master send then receive
+ sprintf(mailbox, "%d", host_number+1);
+ task = MSG_task_create("Token", task_comp_size, task_comm_size, NULL);
+ XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
+ MSG_task_send(task, mailbox);
+ task = NULL;
+ res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
+ xbt_assert(res == MSG_OK, "MSG_task_get failed");
+ XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
+ MSG_task_destroy(task);
+ }
+ else{ //slave receive then send
+ res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
+ xbt_assert(res == MSG_OK, "MSG_task_get failed");
+ XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
+
+ if(host_number+1 == number_of_hosts )
+ sprintf(mailbox, "0");
+ else
+ sprintf(mailbox, "%d", host_number+1);
+ XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
+ MSG_task_send(task, mailbox);
+ }
+ return 0;
}
typedef enum {
int main(int argc, char **argv)
{
- int res;
+ int i,res;
MSG_global_init(&argc, argv);
MSG_set_channel_number(MAX_CHANNEL);
MSG_create_environment(argv[1]);
-
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- surf_parse = surf_parse_bypass_application;
- MSG_launch_application(NULL);
+ m_host_t *host_table = MSG_get_host_table();
+ number_of_hosts = MSG_get_host_number();
+ MSG_function_register("host", host);
+
+ XBT_INFO("Number of host '%d'",number_of_hosts);
+ for(i = 0 ; i<number_of_hosts; i++)
+ {
+ char* name_host = bprintf("%d",i);
+ MSG_process_create( name_host, host, NULL, host_table[i] );
+ free(name_host);
+ }
+ xbt_free(host_table);
res = MSG_main();
-
XBT_INFO("Simulation time %g", MSG_get_clock());
-
MSG_clean();
-
if (res == MSG_OK)
return 0;
else
#! ./tesh
-! output sort
-$ $SG_TEST_EXENV token_ring ${srcdir:=.}/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.
-> [ 0.066240] (1:master@bob1.hamburger.edu) Send Data to "host1"
-> [ 0.066240] (2:slave@bob3.hamburger.edu) Received "Token"
-> [ 0.242880] (2:slave@bob3.hamburger.edu) Send Data to "host2"
-> [ 0.242880] (3:slave@alice2.crepe.fr) Received "Token"
-> [ 0.309120] (3:slave@alice2.crepe.fr) Send Data to "host3"
-> [ 0.309120] (4:slave@alice3.crepe.fr) Received "Token"
-> [ 0.485760] (4:slave@alice3.crepe.fr) Send Data to "host4"
-> [ 0.485760] (5:slave@bob0.hamburger.edu) Received "Token"
-> [ 0.552000] (5:slave@bob0.hamburger.edu) Send Data to "host5"
-> [ 0.552000] (6:slave@bob2.hamburger.edu) Received "Token"
-> [ 0.618240] (6:slave@bob2.hamburger.edu) Send Data to "host6"
-> [ 0.618240] (7:slave@bob4.hamburger.edu) Received "Token"
-> [ 0.794880] (7:slave@bob4.hamburger.edu) Send Data to "host7"
-> [ 0.794880] (8:slave@alice0.crepe.fr) Received "Token"
-> [ 0.861120] (8:slave@alice0.crepe.fr) Send Data to "host8"
-> [ 0.861120] (9:slave@alice4.crepe.fr) Received "Token"
-> [ 0.927360] (10:slave@alice1.crepe.fr) Received "Token"
-> [ 0.927360] (9:slave@alice4.crepe.fr) Send Data to "host9"
+$ $SG_TEST_EXENV ${bindir:=.}/token_ring ${srcdir:=.}/two_clusters.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (0:@) Number of host '10'
+> [ 0.000000] (1:0@bob1.hamburger.edu) Host "0" send 'Token' to Host "1"
+> [ 0.066240] (2:1@bob3.hamburger.edu) Host "1" received "Token"
+> [ 0.066240] (2:1@bob3.hamburger.edu) Host "1" send 'Token' to Host "2"
+> [ 0.242880] (3:2@alice2.crepe.fr) Host "2" received "Token"
+> [ 0.242880] (3:2@alice2.crepe.fr) Host "2" send 'Token' to Host "3"
+> [ 0.309120] (4:3@alice3.crepe.fr) Host "3" received "Token"
+> [ 0.309120] (4:3@alice3.crepe.fr) Host "3" send 'Token' to Host "4"
+> [ 0.485760] (5:4@bob0.hamburger.edu) Host "4" received "Token"
+> [ 0.485760] (5:4@bob0.hamburger.edu) Host "4" send 'Token' to Host "5"
+> [ 0.552000] (6:5@bob2.hamburger.edu) Host "5" received "Token"
+> [ 0.552000] (6:5@bob2.hamburger.edu) Host "5" send 'Token' to Host "6"
+> [ 0.618240] (7:6@bob4.hamburger.edu) Host "6" received "Token"
+> [ 0.618240] (7:6@bob4.hamburger.edu) Host "6" send 'Token' to Host "7"
+> [ 0.794880] (8:7@alice0.crepe.fr) Host "7" received "Token"
+> [ 0.794880] (8:7@alice0.crepe.fr) Host "7" send 'Token' to Host "8"
+> [ 0.861120] (9:8@alice4.crepe.fr) Host "8" received "Token"
+> [ 0.861120] (9:8@alice4.crepe.fr) Host "8" send 'Token' to Host "9"
+> [ 0.927360] (10:9@alice1.crepe.fr) Host "9" received "Token"
+> [ 0.927360] (10:9@alice1.crepe.fr) Host "9" send 'Token' to Host "0"
+> [ 1.104000] (1:0@bob1.hamburger.edu) Host "0" received "Token"
> [ 1.104000] (0:@) Simulation time 1.104
-> [ 1.104000] (10:slave@alice1.crepe.fr) Send Data to "host0"
-> [ 1.104000] (1:master@bob1.hamburger.edu) Received "Token"
-! output sort
-$ $SG_TEST_EXENV token_ring ${srcdir:=.}/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
+$ $SG_TEST_EXENV ${bindir:=.}/token_ring ${srcdir:=.}/two_peers.xml --cfg=coordinates:yes "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:@) Configuration change: Set 'coordinates' to 'yes'
-> [ 0.000000] (0:@) Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.
-> [ 5.221778] (1:master@peer_100030591) Send Data to "host1"
-> [ 5.221778] (2:slave@peer_100036570) Received "Token"
-> [ 10.443556] (0:@) Simulation time 10.4436
-> [ 10.443556] (1:master@peer_100030591) Received "Token"
-> [ 10.443556] (2:slave@peer_100036570) Send Data to "host0"
\ No newline at end of file
+> [ 0.000000] (0:@) Number of host '2'
+> [ 0.000000] (1:0@peer_100030591) Host "0" send 'Token' to Host "1"
+> [ 0.110400] (2:1@peer_100036570) Host "1" received "Token"
+> [ 0.110400] (2:1@peer_100036570) Host "1" send 'Token' to Host "0"
+> [ 0.220800] (1:0@peer_100030591) Host "0" received "Token"
+> [ 0.220800] (0:@) Simulation time 0.2208
\ No newline at end of file
-/* $Id$ */
-
/* Copyright (c) 2009 The SimGrid team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
-/* $Id$ */
-
/* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+
+<platform version="3">
+<AS id="AS0" routing="Floyd">
+
+ <cluster id="my_cluster_1" prefix="c-" suffix=""
+ radical="0-1" power="1000000000" bw="125000000" lat="5E-5"
+ router_id="router1"/>
+
+ <AS id="AS1" routing="none">
+ <host id="host1" power="1000000000"/>
+ </AS>
+
+ <link id="link1" bandwidth="100000" latency="0.01"/>
+
+ <ASroute src="my_cluster_1" dst="AS1"
+ gw_src="router1"
+ gw_dst="host1">
+ <link_ctn id="link1"/>
+ </ASroute>
+
+</AS>
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+<config id="General">
+ <prop id="coordinates" value="yes"></prop>
+</config>
+
+<AS id="AS0" routing="Vivaldi">
+
+ <AS id="AS1_dc1" routing="RuleBased">
+ <!--small tier-1 datacenter, according to TIA-942 annex G tiers notation, routing : rule based, because of its regularity-->
+ <!-- 3 clusters, no zone dist area, 1 horiz dist area, no multi-homing, telecom and operation rooms omitted because not a part of the production platform -->
+ <!-- clusters -->
+ <cluster id="AS1_cb1" prefix="cb1-" suffix=".dc1.acloud.com" radical="1-40" power="5.2297E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb1" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS1_cb2" prefix="cb2-" suffix=".dc1.acloud.com" radical="1-50" power="8.8925E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb2" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS1_cb3" prefix="cb3-" suffix=".dc1.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb3" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <!-- horiz dist area switch, main dist area switch, entrance room switch, end point for ISP -->
+ <AS id="gw_AS1_dc1" routing="Floyd">
+ <!-- equipments-->
+ <router id="gw_dc1_horizdist"/>
+ <router id="gw_dc1_maindist"/>
+ <router id="gw_dc1_entranceroom"/>
+ <!-- ISP end point, entering the cloud, so it has coordinates -->
+ <router id="router_AS1_dc1" coordinates="25.5 9.4 1.4" />
+ <!-- links -->
+ <link id="dc1_horizdist_maindist" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc1_maindist_entranceroom" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc1_entranceroom_ISP" bandwidth="1.25E9" latency="1.0E-4"/>
+ <!-- links to router relationships -->
+ <route src="gw_dc1_horizdist" dst="gw_dc1_maindist"><link_ctn id="dc1_horizdist_maindist"/></route>
+ <route src="gw_dc1_maindist" dst="gw_dc1_entranceroom"><link_ctn id="dc1_maindist_entranceroom"/></route>
+ <route src="gw_dc1_entranceroom" dst="router_AS1_dc1"><link_ctn id="dc1_entranceroom_ISP"/></route>
+ </AS>
+
+ <!-- internal routes between clusters -->
+ <ASroute src="AS1_cb(.*)" dst="AS1_cb(.*)" gw_src="cb$1src-AS1_cb$1src_router.dc1.acloud.com" gw_dst="cb$1dst-AS1_cb$1dst_router.dc1.acloud.com" symmetrical="YES">
+ <link_ctn id="link_dc1_cb$1src"/>
+ <link_ctn id="link_dc1_cb$1dst"/>
+ </ASroute>
+ <!-- clusters to exit AS -->
+ <ASroute src="AS1_cb(.*)" dst="gw_AS1_(.*)" gw_src="cb$1src-AS1_cb$1src_router.dc1.acloud.com" gw_dst="gw_dc1_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc1_cb$1src"/>
+ </ASroute>
+ <ASroute dst="AS1_cb(.*)" src="gw_AS1_(.*)" gw_dst="cb$1dst-AS1_cb$1dst_router.dc1.acloud.com" gw_src="gw_dc1_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc1_cb$1dst"/>
+ </ASroute>
+ </AS>
+
+ <AS id="AS2_dc2" routing="RuleBased">
+ <!--bigger tier-1 datacenter, according to TIA-942 annex G tiers notation, routing : rule based, because of its regularity-->
+ <!-- 6 clusters, no zone dist area, 1 horiz dist area, no multi-homing, telecom and operation rooms omitted because not a part of the production platform -->
+ <!-- clusters -->
+ <cluster id="AS2_cb1" prefix="cb1-" suffix=".dc2.acloud.com" radical="1-40" power="5.2297E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb1" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS2_cb2" prefix="cb2-" suffix=".dc2.acloud.com" radical="1-50" power="8.8925E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb2" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS2_cb3" prefix="cb3-" suffix=".dc2.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb3" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS2_cb4" prefix="cb4-" suffix=".dc2.acloud.com" radical="1-40" power="5.2297E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb4" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS2_cb5" prefix="cb5-" suffix=".dc2.acloud.com" radical="1-50" power="8.8925E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb5" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS2_cb6" prefix="cb6-" suffix=".dc2.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc2_cb6" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <!-- horiz dist area switch, main dist area switch, entrance room switch, end point for ISP -->
+ <AS id="gw_AS2_dc2" routing="Floyd">
+ <!-- equipments-->
+ <router id="gw_dc2_horizdist"/>
+ <router id="gw_dc2_maindist"/>
+ <router id="gw_dc2_entranceroom"/>
+ <!-- ISP end point, entering the cloud, so it has coordinates -->
+ <router id="router_AS2_dc2" coordinates="12.8 14.4 6.4" />
+ <!-- links -->
+ <link id="dc2_horizdist_maindist" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc2_maindist_entranceroom" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc2_entranceroom_ISP" bandwidth="1.25E9" latency="1.0E-4"/>
+ <!-- links to router relationships -->
+ <route src="gw_dc2_horizdist" dst="gw_dc2_maindist"><link_ctn id="dc2_horizdist_maindist"/></route>
+ <route src="gw_dc2_maindist" dst="gw_dc2_entranceroom"><link_ctn id="dc2_maindist_entranceroom"/></route>
+ <route src="gw_dc2_entranceroom" dst="router_AS2_dc2"><link_ctn id="dc2_entranceroom_ISP"/></route>
+ </AS>
+
+ <!-- internal routes between clusters -->
+ <ASroute src="AS2_cb(.*)" dst="AS2_cb(.*)" gw_src="cb$1src-AS2_cb$1src_router.dc2.acloud.com" gw_dst="cb$1dst-AS2_cb$1dst_router.dc2.acloud.com" symmetrical="YES">
+ <link_ctn id="link_dc2_cb$1src"/>
+ <link_ctn id="link_dc2_cb$1dst"/>
+ </ASroute>
+ <!-- clusters to exit AS -->
+ <ASroute src="AS2_cb(.*)" dst="gw_AS2_(.*)" gw_src="cb$1src-AS2_cb$1src_router.dc2.acloud.com" gw_dst="gw_dc2_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc2_cb$1src"/>
+ </ASroute>
+ <ASroute dst="AS2_cb(.*)" src="gw_AS2_(.*)" gw_dst="cb$1dst-AS2_cb$1dst_router.dc2.acloud.com" gw_src="gw_dc2_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc2_cb$1dst"/>
+ </ASroute>
+ </AS>
+
+ <AS id="AS3_dc3" routing="RuleBased">
+ <!--small tier-1 datacenter, according to TIA-942 annex G tiers notation, routing : rule based, because of its regularity-->
+ <!-- 4 clusters, no zone dist area, 1 horiz dist area, no multi-homing, telecom and operation rooms omitted because not a part of the production platform -->
+ <!-- clusters -->
+ <cluster id="AS3_cb1" prefix="cb1-" suffix=".dc3.acloud.com" radical="1-40" power="5.2297E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc3_cb1" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS3_cb2" prefix="cb2-" suffix=".dc3.acloud.com" radical="1-50" power="8.8925E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc3_cb2" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS3_cb3" prefix="cb3-" suffix=".dc3.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc3_cb3" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <cluster id="AS3_cb4" prefix="cb4-" suffix=".dc3.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc3_cb4" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <!-- horiz dist area switch, main dist area switch, entrance room switch, end point for ISP -->
+ <AS id="gw_AS3_dc3" routing="Floyd">
+ <!-- equipments-->
+ <router id="gw_dc3_horizdist"/>
+ <router id="gw_dc3_maindist"/>
+ <router id="gw_dc3_entranceroom"/>
+ <!-- ISP end point, entering the cloud, so it has coordinates -->
+ <router id="router_AS3_dc3" coordinates="6.0 5.7 6.6" />
+ <!-- links -->
+ <link id="dc3_horizdist_maindist" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc3_maindist_entranceroom" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc3_entranceroom_ISP" bandwidth="1.25E9" latency="1.0E-4"/>
+ <!-- links to router relationships -->
+ <route src="gw_dc3_horizdist" dst="gw_dc3_maindist"><link_ctn id="dc3_horizdist_maindist"/></route>
+ <route src="gw_dc3_maindist" dst="gw_dc3_entranceroom"><link_ctn id="dc3_maindist_entranceroom"/></route>
+ <route src="gw_dc3_entranceroom" dst="router_AS3_dc3"><link_ctn id="dc3_entranceroom_ISP"/></route>
+ </AS>
+
+ <!-- internal routes between clusters -->
+ <ASroute src="AS3_cb(.*)" dst="AS3_cb(.*)" gw_src="cb$1src-AS3_cb$1src_router.dc3.acloud.com" gw_dst="cb$1dst-AS3_cb$1dst_router.dc3.acloud.com" symmetrical="YES">
+ <link_ctn id="link_dc3_cb$1src"/>
+ <link_ctn id="link_dc3_cb$1dst"/>
+ </ASroute>
+ <!-- clusters to exit AS -->
+ <ASroute src="AS3_cb(.*)" dst="gw_AS3_(.*)" gw_src="cb$1src-AS3_cb$1src_router.dc3.acloud.com" gw_dst="gw_dc3_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc3_cb$1src"/>
+ </ASroute>
+ <ASroute dst="AS3_cb(.*)" src="gw_AS3_(.*)" gw_dst="cb$1dst-AS3_cb$1dst_router.dc3.acloud.com" gw_src="gw_dc3_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc3_cb$1dst"/>
+ </ASroute>
+ </AS>
+
+</AS>
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+<config id="General">
+ <prop id="coordinates" value="yes"></prop>
+</config>
+
+<AS id="AS0" routing="Vivaldi">
+ <AS id="dataCenter1" routing="RuleBased">
+
+ <!-- 3 cabinets, no zone dist area, 1 horiz dist area, no multi-homing, telecom and operation rooms omitted because not a part of the production platform -->
+ <!-- cabinets -->
+ <cluster id="cabinet1" prefix="cb1-" suffix=".dc1.acloud.com" radical="1-40" power="5.2297E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb1" bandwidth="1.25E9" latency="1.0E-4"/>
+ <cluster id="cabinet2" prefix="cb2-" suffix=".dc1.acloud.com" radical="1-50" power="8.8925E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb2" bandwidth="1.25E9" latency="1.0E-4"/>
+ <cluster id="cabinet3" prefix="cb3-" suffix=".dc1.acloud.com" radical="1-30" power="13.357E9" bw="1.25E8" lat="1.0E-4" bb_bw="1.25E9" bb_lat="1.0E-4"></cluster>
+ <link id="link_dc1_cb3" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <!-- horiz dist area switch, main dist area switch, entrance room switch, end point for ISP -->
+ <AS id="gw_dataCenter1" routing="Floyd">
+ <!-- equipments-->
+ <router id="gw_dc1_horizdist"/>
+ <router id="gw_dc1_maindist"/>
+ <router id="gw_dc1_entranceroom"/>
+
+ <!-- ISP end point, entering the cloud, so it has coordinates -->
+ <router id="router_dataCenter1" coordinates="25.5 9.4 1.4" />
+
+ <!-- links -->
+ <link id="dc1_horizdist_maindist" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc1_maindist_entranceroom" bandwidth="1.25E9" latency="1.0E-4"/>
+ <link id="dc1_entranceroom_ISP" bandwidth="1.25E9" latency="1.0E-4"/>
+
+ <!-- links to router relationships -->
+ <route src="gw_dc1_horizdist" dst="gw_dc1_maindist"><link_ctn id="dc1_horizdist_maindist"/></route>
+ <route src="gw_dc1_maindist" dst="gw_dc1_entranceroom"><link_ctn id="dc1_maindist_entranceroom"/></route>
+ <route src="gw_dc1_entranceroom" dst="router_dataCenter1"><link_ctn id="dc1_entranceroom_ISP"/></route>
+ </AS>
+
+ <!-- internal routes between cabinets -->
+ <ASroute src="cabinet(.*)" dst="cabinet(.*)" gw_src="cb$1src-cabinet$1src_router.dc1.acloud.com" gw_dst="cb$1dst-cabinet$1dst_router.dc1.acloud.com" symmetrical="YES">
+ <link_ctn id="link_dc1_cb$1src"/>
+ <link_ctn id="link_dc1_cb$1dst"/>
+ </ASroute>
+ <!-- cabinets to exit AS -->
+ <ASroute src="cabinet(.*)" dst="gw_AS1_(.*)" gw_src="cb$1src-cabinet$1src_router.dc1.acloud.com" gw_dst="gw_dc1_horizdist" symmetrical="NO">
+ <link_ctn id="link_dc1_cb$1src"/>
+ </ASroute>
+ <ASroute src="gw_AS1_(.*)" dst="cabinet(.*)" gw_src="gw_dc1_horizdist" gw_dst="cb$1dst-cabinet$1dst_router.dc1.acloud.com" symmetrical="NO">
+ <link_ctn id="link_dc1_cb$1dst"/>
+ </ASroute>
+ </AS>
+
+</AS>
+</platform>
--- /dev/null
+#! /usr/bin/perl
+
+# L.Bobelin (Perl newbie) 25th of November
+#Â Quick script to generate hierarchical clusters. Usage : <the script> p s d where :
+# - p : 2^p gives the total number of hosts.
+#Â - s : cluster size
+#Â - d : degree of inner nodes.
+#
+#Â output is the standard one.
+#Â
+#
+#Each node is numbered by a DFS in the tree. Each cluster is numbered by the DFS number of the leaf it is attached to and the number of cluster for each leaf.
+# Other infos :
+# - Same bb_lat used for any routers inside (not that complicated to modify too).
+# - constants defined in the first part of the script corresponding to classic cluster parameters. links_bw and links_lat added for the inner tree links
+# - bb_lat and bb_bw used in any backbone of the tree.
+#Â - fails if you set an obviously too small total number of hosts compared to the cluster size (generates a lot of stuff for nothing actually).
+#Â
+
+use Math::BigInt;
+
+$prefix= "";
+$suffix= "";
+$bw= "125000000";
+$power= "1000000000";
+$lat= "5E-5";
+$bb_bw= "2250000000";
+$bb_lat= "5E-4";
+$links_bw= "2250000000";
+$links_lat= "5E-5";
+$id= "";
+
+$p = $ARGV[0];
+$s = $ARGV[1];
+$d = $ARGV[2];
+
+$p = Math::BigInt->new($p);
+$d = Math::BigInt->new($d);
+$s = Math::BigInt->new($s);
+
+$cabinetnodes= $d;
+$nbsons= $d;
+$radical= "1-" . $s;
+$last=$s;
+
+# Number of clusters to generate ? Update: I hate this bigInt package, the way it behaves is SO stupid
+$totalnumberofhosts = Math::BigInt->new("2");
+$totalnumberofhosts->bpow($p);
+
+$totalnumberofCluster= $totalnumberofhosts->copy();
+
+$totalnumberofCluster->bdiv($s);
+
+# checking if we have to have something non homogeneous
+if ($totalnumberofhosts->copy()->bmod($s) != 0 )
+ {
+ $totalnumberofCluster++;
+ $last= $totalnumberofhosts->copy()->bmod($s);
+ }
+
+# Calculating height
+
+$height= $totalnumberofCluster->copy();
+$height->broot($d);
+
+# Checking if an exact root exists
+if ( $height->bcmp(Math::BigInt->new("1")) != 0 && ($height->copy()->bpow($d))->bcmp($totalnumberofCluster)) {
+
+ $height++; #will have to deal with empty set of clusters.
+ }
+# debug stuff
+#print "Computed : \n";
+#print STDERR "height: " . $height . "\n";
+#print STDERR "totalnumberofhosts: " . $totalnumberofhosts . "\n";
+#print STDERR "totalnumberofcluster: " . $totalnumberofCluster . "\n";
+#print STDERR "last cluster size (if equals to cluster size, then all clusters will be homogeneous) : " . $last . "\n";
+
+#Â Counter for giving unique IDs to ASes.
+$ASnumber;
+$ASnumber = 0;
+
+#Â Printing preamble
+print "<?xml version='1.0'?>\n";
+print "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n";
+print "<platform version=\"3\">\n";
+
+
+# Initiate recursion ...
+&DF_creation(0);
+
+# Closing tag, and then back home
+print "</platform>\n";
+
+# Recursive stuff for depth first Se... Creation
+sub DF_creation {
+ my($currDepth) = @_;
+
+ #Â Curr AS creation
+ print "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
+
+ #Â Curr router AS creation stuff
+ print "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
+ print " <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
+ print "</AS>\n";
+ #Â Saving my current number to return it to my father
+ my $toReturn = $ASnumber;
+ $ASnumber++;
+ if ($currDepth<$height && $totalnumberofCluster > 0)
+ {
+ # Creating current AS inner stuff
+ # I should have a table of sons numbers.
+ my @tsons = ();
+ my $createdSons = 0;
+ for (my $i =1; $i<=$nbsons && $totalnumberofCluster > 0 ; $i++)
+ {
+ #saving this son in my tab ... recursive call to create ASes and cluster underneath
+ push(@tsons, &DF_creation($currDepth + 1));
+ $createdSons++;
+ #
+ # Creating link to this son
+ print "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
+ }
+ # curr backbone creation
+ print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
+ # Full routing AS to AS declaration
+ for (my $i =1; $i<=$createdSons ; $i++)
+ {
+ for (my $j =$i+1; $j<=$createdSons ; $j++)
+ {
+ print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
+ print " dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
+ print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
+ print " gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
+ print " symmetrical=\"YES\">\n";
+
+ print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
+ print "</ASroute>\n";
+ }
+ }
+ # Now routes to the exit AS
+ for (my $i =1; $i<=$createdSons ; $i++)
+ {
+ print "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
+ print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
+ print " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
+ print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
+ print " symmetrical=\"YES\">\n";
+ print " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print "</ASroute>\n";
+ }
+ print "</AS>\n";
+ # DO I have extra stuff to add ? I don't think so.
+ return $toReturn;
+ }
+ else { # On leaves,
+ my $lastNumberOfClusterCreated = 0;
+ #I must create clusters now
+ for(my $i = 1; $i <= $cabinetnodes && $totalnumberofCluster>0 ; $i++) {
+ $lastNumberOfClusterCreated++;
+ if ($totalnumberofCluster==1)
+ {
+ print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\"1-"
+ . $last . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
+ }
+ else
+ {
+ print "<cluster id=\"". $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-\" suffix=\"" . $suffix . "\" radical=\""
+ . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
+ }
+ $totalnumberofCluster--;
+ }
+ #Â Creating links to clusters
+ for(my $i = 1; $i <= $lastNumberOfClusterCreated ; $i++) {
+ print "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
+ }
+
+ #
+ # curr backbone creation
+ print "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
+
+ #Â I must create routes between clusters now
+ for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
+ {
+ for (my $j =$i+1; $j<=$lastNumberOfClusterCreated ; $j++)
+ {
+ print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
+ print " dst=\"" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "\"\n";
+
+ print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
+ print " gw_dst=\"" . $prefix . "c_" . $toReturn . "_" . $j . "-" . $prefix . "cl_" . $toReturn . "_" . $j . $suffix . "_router" . $suffix . "\"\n";
+ print " symmetrical=\"YES\">\n";
+
+ print " <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
+ print "</ASroute>\n";
+ }
+ }
+ # Now routes to the exit AS
+ for (my $i =1; $i<=$lastNumberOfClusterCreated ; $i++)
+ {
+ print "<ASroute src=\"" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "\"\n";
+ print " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
+ #Â SAME HERE !!
+ print " gw_src=\"" . $prefix . "c_" . $toReturn . "_" . $i . "-" . $prefix . "cl_" . $toReturn . "_" . $i . $suffix . "_router" . $suffix ."\"\n";
+ print " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
+ print " symmetrical=\"YES\">\n";
+ print " <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
+ print " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print "</ASroute>\n";
+ }
+ print "</AS>\n";
+ #Â Should be done with it...
+ return $toReturn;
+ }
+
+}
--- /dev/null
+#! /usr/bin/perl
+
+# L.Bobelin (Perl newbie) 24th of November
+#Â Quick script to generate hierarchical clusters. Usage : add the special cluster tag (description below) in your "normal" platform file. Then run the script :
+# - First arg : the input file where you midified your cluster tag
+#Â - Second one : the output file where all the stuff will be generated.
+#Â Builds a complete tree to access clusters ; each node of the tree is inclosed in an AS, where full routing applies.
+#
+# Number of cluster per leaf is given by cabinetnodes attr.
+#
+#
+# Choosed to modify a cluster tag to allow to give additional informations :
+# - nbsons : degree of inner
+# - height : tree heigth
+# - cabinetnodes : cluster per leaf
+#Â
+#Â Each node is numbered by a DFS in the tree. Each cluster is numbered by the DFS number of the leaf it is attached to and the number of cluster for each leaf.
+#Â
+#
+# Example syntax for hierarchical cluster creation :
+# <cluster id="AS_cb1" prefix="cb1-" suffix=".dc1.acloud.com" power="5.2297E9" bw="1.25E8" lat="1.0E-4 bb_bw="1.25E9" bb_lat="1.0E-4" radical="0-99" cabinetnodes="4" height="3" nbsons="2" links_lat="1.0E-4" links_bw="1.25E9"/>
+# Other infos :
+#Â - special tag has to be on one line because I don't want to bother with parsing issues
+# - Same bb_lat used for any routers inside (not that complicated to modify too)
+# - lame perl ? I'm a script kiddie in perl, it may well be my first perl stuff.
+# - Don't try to check or validate the modified file with the DTD, of course, as this is not a part of it.
+
+#Â Counter for giving unique IDs to ASes.
+$ASnumber;
+$ASnumber = 0;
+
+$infile;
+$outfile;
+
+$infile = $ARGV[0];
+$outfile = $ARGV[1];
+open IN, "$infile" || die "Cannot parse " . $infile . " ...\n";
+open OUT,">$outfile" || die "Cannot use the output file " . $outfile . " ...\n";
+my $line;
+while ($line = <IN>) {
+# looking for good lines.
+if ($line =~ / cabinetnodes=/)
+{ #Retrieving informations
+ ($line=~ /cabinetnodes=\"([^\"]*)/);
+ $cabinetnodes= $1;
+ ($line=~ /height=\"([^\"]*)/);
+ $height= $1;
+ ($line=~ /nbsons=\"([^\"]*)/);
+ $nbsons= $1;
+ ($line=~ /id=\"([^\"]*)/);
+ $id= $1;
+ ($line=~ /prefix=\"([^\"]*)/);
+ $prefix= $1;
+ ($line=~ /suffix=\"([^\"]*)/);
+ $suffix= $1;
+ ($line=~ /bw=\"([^\"]*)/);
+ $bw= $1;
+ ($line=~ /power=\"([^\"]*)/);
+ $power= $1;
+ ($line=~ /lat=\"([^\"]*)/);
+ $lat= $1;
+ ($line=~ /bb_bw=\"([^\"]*)/);
+ $bb_bw= $1;
+ ($line=~ /bb_lat=\"([^\"]*)/);
+ $bb_lat= $1;
+ ($line=~ /links_bw=\"([^\"]*)/);
+ $links_bw= $1;
+ ($line=~ /links_lat=\"([^\"]*)/);
+ $links_lat= $1;
+ ($line=~ /radical=\"([^\"]*)/);
+ $radical= $1;
+
+ print "Variables read : \n";
+ print "number of clusters in each cabinet: " . $cabinetnodes . "\n";
+ print "Tree heigth: " . $height . "\n";
+ print "Degree of each node: " . $nbsons . "\n";
+ print "General id: ". $id . "\n";
+ print "General prefix: " . $prefix . "\n";
+ print "General suffix: ". $suffix . "\n";
+ print "Bandwidth for cluster inner links: " . $bw . "\n";
+ print "Power for cluster nodes: " . $power . "\n";
+ print "Latency for clusters inner links :" . $lat . "\n";
+ print "Backbone bandwwidth (used in all backbones, including the tree ones):" . $bb_bw . "\n";
+ print "Backbone latency (used in all backbones, including the tree ones):" . $bb_lat . "\n";
+ print "Tree links bandwidth: " . $links_bw . "\n";
+ print "Tree links latency: " . $links_lat . "\n";
+ print "Radical: " . $radical . "\n";
+
+
+
+ &DF_creation(0);
+ }
+else {
+print OUT $line;
+}
+} #End while
+close IN;
+close OUT;
+print $infile . " -> " . $outfile . " ... Done.\n";
+
+# Recursive stuff for depth first Se... Creation
+sub DF_creation {
+ my($currDepth) = @_;
+
+ #Â Curr AS creation
+ print OUT "<AS id=\"". $prefix . "AS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
+
+ #Â Curr router AS creation stuff
+ print OUT "<AS id=\"". $prefix . "exitAS_" . $ASnumber . $suffix . "\" routing=\"Full\">\n";
+ print OUT " <router id=\"" . $prefix . "router_" . $ASnumber . $suffix . "\"/>\n";
+ print OUT "</AS>\n";
+ #Â Saving my current number to return it to my father
+ my $toReturn = $ASnumber;
+ $ASnumber++;
+ if ($currDepth<$height)
+ {
+ # Creating current AS inner stuff
+ # I should have a table of sons numbers.
+ my @tsons = ();
+ for (my $i =1; $i<=$nbsons ; $i++)
+ {
+ #saving this son in my tab ... recursive call to create ASes and cluster underneath
+ push(@tsons, &DF_creation($currDepth + 1));
+ #
+ # Creating link to this son
+ print OUT "<link id=\"". $prefix . $tsons[$i-1] . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
+ }
+ # curr backbone creation
+ print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
+ # Full routing AS to AS declaration
+ for (my $i =1; $i<=$nbsons ; $i++)
+ {
+ for (my $j =$i+1; $j<=$nbsons ; $j++)
+ {
+ print OUT "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
+ print OUT " dst=\"" . $prefix . "AS_" . $tsons[$j-1] . $suffix . "\"\n";
+ print OUT " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
+ print OUT " gw_dst=\"" . $prefix . "router_" . $tsons[$j-1] . $suffix . "\"\n";
+ print OUT " symmetrical=\"YES\">\n";
+
+ print OUT " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . $tsons[$j-1] . $suffix . "\"/>\n";
+ print OUT "</ASroute>\n";
+ }
+ }
+ # Now routes to the exit AS
+ for (my $i =1; $i<=$nbsons ; $i++)
+ {
+ print OUT "<ASroute src=\"" . $prefix . "AS_" . $tsons[$i-1] . $suffix . "\"\n";
+ print OUT " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
+ print OUT " gw_src=\"" . $prefix . "router_" . $tsons[$i-1] . $suffix . "\"\n";
+ print OUT " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
+ print OUT " symmetrical=\"YES\">\n";
+ print OUT " <link_ctn id=\"" . $prefix . $tsons[$i-1] . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print OUT "</ASroute>\n";
+ }
+ print OUT "</AS>\n";
+ # DO I have extra stuff to add ? I don't think so.
+ return $toReturn;
+ }
+ else { # On leaves,
+
+ #I must create clusters now
+ for(my $i = 1; $i <= $cabinetnodes; $i++) {
+ print OUT "<cluster id=\"". $prefix . "cluster_" . $toReturn . $i . $suffix . "\" prefix=\"" . $prefix . "c_" . $toReturn. $i . "-\" suffix=\"" . $suffix . "\" radical=\""
+ . $radical . "\" power=\"" . $power . "\" bw=\"" . $bw . "\" lat=\"" . $lat . "\" bb_bw=\"" . $bb_bw . "\" bb_lat=\"" . $bb_lat . "\"/>\n";
+ }
+ #Â Creating links to clusters
+ for(my $i = 1; $i <= $cabinetnodes; $i++) {
+ print OUT "<link id=\"". $prefix . $toReturn . "_" . $i . $suffix . "\" bandwidth=\"" . $links_bw . "\" latency=\"" . $links_lat . "\"/>\n";
+ }
+
+ #
+ # curr backbone creation
+ print OUT "<link id=\"". $prefix . "bb_" . $toReturn . $suffix . "\" bandwidth=\"" . $bb_bw . "\" latency=\"" . $bb_lat . "\"/>\n";
+
+ #Â I must create routes between clusters now
+ for (my $i =1; $i<=$cabinetnodes ; $i++)
+ {
+ for (my $j =$i+1; $j<=$cabinetnodes ; $j++)
+ {
+ print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
+ print OUT " dst=\"" . $prefix . "cluster_" . $toReturn . $j . $suffix . "\"\n";
+
+ print OUT " gw_src=\"" . $prefix . "c_" . $toReturn. $i . "-" . $prefix . "cluster_" . $toReturn . $i . $suffix . "_router" . $suffix ."\"\n";
+ print OUT " gw_dst=\"" . $prefix . "c_" . $toReturn. $j . "-" . $prefix . "cluster_" . $toReturn . $j . $suffix . "_router" . $suffix . "\"\n";
+ print OUT " symmetrical=\"YES\">\n";
+
+ print OUT " <link_ctn id=\"" . $prefix . $toReturn. "_" . $i . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . $toReturn . "_" . $j . $suffix . "\"/>\n";
+ print OUT "</ASroute>\n";
+ }
+ }
+ # Now routes to the exit AS
+ for (my $i =1; $i<=$cabinetnodes ; $i++)
+ {
+ print OUT "<ASroute src=\"" . $prefix . "cluster_" . $toReturn . $i . $suffix . "\"\n";
+ print OUT " dst=\"" . $prefix . "exitAS_" . $toReturn . $suffix . "\"\n";
+ #Â SAME HERE !!
+ print OUT " gw_src=\"" . $prefix . "c_" . $toReturn. $i . "-" . $prefix . "cluster_" . $toReturn . $i . $suffix . "_router" . $suffix ."\"\n";
+ print OUT " gw_dst=\"" . $prefix . "router_" . $toReturn . $suffix . "\"\n";
+ print OUT " symmetrical=\"YES\">\n";
+ print OUT " <link_ctn id=\"" . $prefix . $toReturn . "_" . $i . $suffix . "\"/>\n";
+ print OUT " <link_ctn id=\"" . $prefix . "bb_" . $toReturn . $suffix . "\"/>\n";
+ print OUT "</ASroute>\n";
+ }
+ print OUT "</AS>\n";
+ #Â Should be done with it...
+ return $toReturn;
+ }
+
+}
/* Trying to set a new property */
- xbt_dict_set(props, "NewProp", strdup("newValue"), free);
+ xbt_dict_set(props, "NewProp", strdup("newValue"), NULL);
/* Print the properties of the workstation 1 */
xbt_dict_foreach(props, cursor, key, data) {
XBT_INFO("\tProperty: %s is undefined", exist);
else {
XBT_INFO("\tProperty: %s old value: %s", exist, value);
- xbt_dict_set(props, exist, strdup("250"), free);
+ xbt_dict_set(props, exist, strdup("250"), NULL);
}
/* Test if we have changed the value */
-/* $Id$ */
-
/* simgrid_config.h - Results of the configure made visible to user code */
/* Copyright (c) 2009, 2010, 2011. Da SimGrid team. All rights reserved. */
#define MAKE_SIMGRID_VERSION(major, minor, patch) \
(100UL * (100UL * (major) + (minor)) + (patch))
-#cmakedefine SIMGRID_VERSION_MAJOR @SIMGRID_VERSION_MAJOR@
-#cmakedefine SIMGRID_VERSION_MINOR @SIMGRID_VERSION_MINOR@
-#cmakedefine SIMGRID_VERSION_PATCH @SIMGRID_VERSION_PATCH@
+#define SIMGRID_VERSION_MAJOR @SIMGRID_VERSION_MAJOR@
+#define SIMGRID_VERSION_MINOR @SIMGRID_VERSION_MINOR@
+#define SIMGRID_VERSION_PATCH @SIMGRID_VERSION_PATCH@
#define SIMGRID_VERSION MAKE_SIMGRID_VERSION(SIMGRID_VERSION_MAJOR, \
SIMGRID_VERSION_MINOR, \
typedef struct s_smx_context {
s_xbt_swag_hookup_t hookup;
xbt_main_func_t code;
- int argc;
- char **argv;
void_pfn_smxprocess_t cleanup_func;
- int iwannadie:1;
void *data; /* Here SIMIX stores the smx_process_t containing the context */
+ char **argv;
+ int argc;
+ int iwannadie:1;
} s_smx_ctx_base_t;
/* methods of this class */
*
* @{
*/
- /** @brief Configuration set are only special dynars. But don't rely on it, it may change. */
-typedef xbt_dynar_t xbt_cfg_t;
+/** @brief Configuration set's data type is opaque. */
+typedef void* xbt_cfg_t;
XBT_PUBLIC(void) xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
XBT_PUBLIC(void) xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name,
/* xbt/dict.h -- api to a generic dictionary */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
*/
/** \brief Dictionary data type (opaque structure) */
-typedef struct xbt_dict_ *xbt_dict_t;
+typedef struct s_xbt_dict *xbt_dict_t;
XBT_PUBLIC(xbt_dict_t) xbt_dict_new(void);
+XBT_PUBLIC(xbt_dict_t) xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn);
XBT_PUBLIC(void) xbt_dict_free(xbt_dict_t * dict);
XBT_PUBLIC(unsigned int) xbt_dict_size(xbt_dict_t dict);
* @{ */
/** @brief Cursor on dictionaries (opaque type) */
-typedef struct xbt_dict_cursor_ *xbt_dict_cursor_t;
+typedef struct s_xbt_dict_cursor *xbt_dict_cursor_t;
XBT_PUBLIC(xbt_dict_cursor_t) xbt_dict_cursor_new(const xbt_dict_t dict);
XBT_PUBLIC(void) xbt_dict_cursor_free(xbt_dict_cursor_t * cursor);
-/* $Id $ */
-
/* Copyright (c) 2006, 2007, 2009, 2010. The SimGrid Team.
* All rights reserved. */
-/* $Id: str.h,v 1.5 2007/05/02 10:08:55 mquinson Exp $ */
-
/* hash.h - Various hashing functions. */
/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
-/* $Id: buff.h 3483 2007-05-07 11:18:56Z mquinson $ */
-
/* strbuff -- string buffers */
/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
mod->groups = NULL;
mod->done = 0;
- mod->groups = xbt_dict_new();
+ mod->groups = xbt_dict_new_homogeneous(NULL);
/* callbacks */
gras_cb_register("amok_pm_kill", &amok_pm_cb_kill);
return -1;
}
xbt_dict_t props = MSG_host_get_properties(host);
- xbt_dict_set(props,prop_id,xbt_strdup(prop_value),free);
+ xbt_dict_set(props,prop_id,xbt_strdup(prop_value),NULL);
return 0;
}
if (xbt_dict_is_empty(machine_set)
|| xbt_dict_is_empty(process_function_set)
|| xbt_dynar_is_empty(process_list)) {
- process_function_set = xbt_dict_new();
+ process_function_set = xbt_dict_new_homogeneous(NULL);
process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
- machine_set = xbt_dict_new();
+ machine_set = xbt_dict_new_homogeneous(NULL);
}
xbt_dict_set(machine_set, process_host, NULL, NULL);
-/* $Id$ */
-
/* 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. */
res = xbt_new(s_gras_cbps_t, 1);
res->lints = xbt_dynar_new(sizeof(int), NULL);
- res->space = xbt_dict_new();
+ res->space = xbt_dict_new_homogeneous(NULL);
/* no leak, the content is freed manually on block_end */
res->frames = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
res->globals = xbt_dynar_new(sizeof(char *), NULL);
ddt = gras_datadesc_ref("xbt_peer_t", ddt);
/* Dict containing the constant value (for the parsing macro) */
- gras_dd_constants = xbt_dict_new();
+ gras_dd_constants = xbt_dict_new_homogeneous(xbt_free_f);
}
*(void **) r_ref);
if (detect_cycle)
- xbt_dict_set_ext(refs, (const char *) r_ref, r_len, ptr, xbt_free_f);
+ xbt_dict_set_ext(refs, (const char *) r_ref, r_len, ptr, NULL);
}
}
dst);
if (!state) {
state = gras_cbps_new();
- refs = xbt_dict_new();
+ refs = xbt_dict_new_homogeneous(xbt_free_f);
}
TRY {
if (!state) {
state = gras_cbps_new();
- refs = xbt_dict_new();
+ refs = xbt_dict_new_homogeneous(NULL);
}
TRY {
if (!state) {
state = gras_cbps_new();
- refs = xbt_dict_new();
+ refs = xbt_dict_new_homogeneous(xbt_free_f);
}
xbt_assert(type, "called with NULL type descriptor");
int *stored = xbt_new(int, 1);
*stored = value;
- xbt_dict_set(gras_dd_constants, name, stored, xbt_free_f);
+ xbt_dict_set(gras_dd_constants, name, stored, NULL);
}
#include "xbt/mallocator.h"
extern xbt_mallocator_t gras_msg_ctx_mallocator;
void *gras_msg_ctx_mallocator_new_f(void);
-void gras_msg_ctx_mallocator_free_f(void *dict);
+#define gras_msg_ctx_mallocator_free_f xbt_free_f
void gras_msg_ctx_mallocator_reset_f(void *dict);
return xbt_new0(s_gras_msg_cb_ctx_t, 1);
}
-void gras_msg_ctx_mallocator_free_f(void *ctx)
-{
- xbt_free(ctx);
-}
-
void gras_msg_ctx_mallocator_reset_f(void *ctx)
{
memset(ctx, 0, sizeof(s_gras_msg_cb_ctx_t));
}
if (plug)
- xbt_dict_set(_gras_trp_plugins, name, plug, gras_trp_plugin_free);
+ xbt_dict_set(_gras_trp_plugins, name, plug, NULL);
}
void gras_trp_init(void)
{
if (!_gras_trp_started) {
/* make room for all plugins */
- _gras_trp_plugins = xbt_dict_new();
+ _gras_trp_plugins = xbt_dict_new_homogeneous(gras_trp_plugin_free);
#ifdef HAVE_WINSOCK2_H
/* initialize the windows mechanism */
gras_procdata_init();
/* initialize the host & process properties */
- _host_properties = xbt_dict_new();
- _process_properties = xbt_dict_new();
+ _host_properties = xbt_dict_new_homogeneous(xbt_free_f);
+ _process_properties = xbt_dict_new_homogeneous(xbt_free_f);
env_iter = environ;
while (*env_iter) {
char *equal, *buf = xbt_strdup(*env_iter);
continue;
}
*equal = '\0';
- xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1),
- xbt_free_f);
+ xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), NULL);
free(buf);
env_iter++;
}
void gras_emul_init(void)
{
if (!benchmark_set) {
- benchmark_set = xbt_dict_new();
+ benchmark_set = xbt_dict_new_homogeneous(xbt_free_f);
timer = xbt_os_timer_new();
}
}
ir = xbt_dict_get_or_null(dict, key);
if (!ir) {
ir = xbt_new0(double, 1);
- xbt_dict_set(dict, key, ir, xbt_free_f);
+ xbt_dict_set(dict, key, ir, NULL);
}
*ir = value;
}
-/* $Id: datatypes.h 5497 2008-05-26 12:19:15Z cristianrosa $ */
-
/* Copyright (c) 2008 Martin Quinson, Cristian Rosa.
All rights reserved. */
-/* $Id: simix.h 5497 2008-05-26 12:19:15Z cristianrosa $ */
-
/* Copyright (c) 2008 Martin Quinson, Cristian Rosa.
All rights reserved. */
XBT_DEBUG ("Tracing is on");
/* other trace initialization */
- created_categories = xbt_dict_new();
+ created_categories = xbt_dict_new_homogeneous(xbt_free);
TRACE_surf_alloc();
TRACE_smpi_alloc();
return 0;
//check if category is already created
char *created = xbt_dict_get_or_null(created_categories, category);
if (created) return;
- xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
+ xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
//define final_color
char final_color[INSTR_DEFAULT_STR_SIZE];
void instr_paje_init (container_t root)
{
- allContainers = xbt_dict_new ();
- trivaNodeTypes = xbt_dict_new ();
- trivaEdgeTypes = xbt_dict_new ();
+ allContainers = xbt_dict_new_homogeneous(NULL);
+ trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free);
+ trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free);
rootContainer = root;
}
ret->name = xbt_strdup (typename);
ret->father = father;
ret->kind = kind;
- ret->children = xbt_dict_new ();
- ret->values = xbt_dict_new ();
+ ret->children = xbt_dict_new_homogeneous(NULL);
+ ret->values = xbt_dict_new_homogeneous(NULL);
ret->color = xbt_strdup (color);
char str_id[INSTR_DEFAULT_STR_SIZE];
default: xbt_die ("Congratulations, you have found a bug on newContainer function of instr_routing.c"); break;
}
}
- new->children = xbt_dict_new();
+ new->children = xbt_dict_new_homogeneous(NULL);
if (new->father){
xbt_dict_set(new->father->children, new->name, new, NULL);
new_pajeCreateContainer (new);
xbt_dict_set (allContainers, new->name, new, NULL);
//register NODE types for triva configuration
- xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), xbt_free);
+ xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), NULL);
}
return new;
}
container_t container = getContainerByName (resource);
type_t type = getVariableType (variable, NULL, container->type);
new_pajeSetVariable (now, container, type, 0);
- xbt_dict_set(platform_variables, resource, array,
- xbt_dynar_free_voidp);
+ xbt_dict_set(platform_variables, resource, array, NULL);
} else {
xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
unsigned int i;
void TRACE_surf_resource_utilization_alloc()
{
- platform_variables = xbt_dict_new();
+ platform_variables = xbt_dict_new_homogeneous(xbt_dynar_free_voidp);
}
void TRACE_surf_resource_utilization_release()
if (xbt_dict_get_or_null (filter, aux2)) return;
//ok, not found, register it
- xbt_dict_set (filter, aux1, xbt_strdup ("1"), xbt_free);
- xbt_dict_set (filter, aux2, xbt_strdup ("1"), xbt_free);
+ xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL);
+ xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL);
}
//declare type
type_t link_type = getLinkType (link_typename, father->type, src->type, dst->type);
//register EDGE types for triva configuration
- xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), xbt_free);
+ xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL);
//create the link
static long long counter = 0;
{
xbt_dynar_free(¤tContainer);
currentContainer = NULL;
- xbt_dict_t filter = xbt_dict_new ();
+ xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free);
recursiveGraphExtraction (global_routing->root, getRootContainer(), filter);
xbt_dict_free(&filter);
platform_created = 1;
xbt_graph_t instr_routing_platform_graph (void)
{
xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
- xbt_dict_t nodes = xbt_dict_new ();
- xbt_dict_t edges = xbt_dict_new ();
+ xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
+ xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
recursiveXBTGraphExtraction (ret, nodes, edges, global_routing->root, getRootContainer());
return ret;
}
xbt_dynar_t d = xbt_dict_get_or_null(keys, aux);
if (d == NULL) {
d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
- xbt_dict_set(keys, aux, d, xbt_free);
+ xbt_dict_set(keys, aux, d, NULL);
}
//generate the key
static unsigned long long counter = 0;
if (xbt_dict_get_or_null (process_category, processid))
xbt_dict_remove (process_category, processid);
if (category != NULL)
- xbt_dict_set (process_category, processid, xbt_strdup(category), xbt_free);
+ xbt_dict_set (process_category, processid, xbt_strdup(category), NULL);
}
const char *TRACE_internal_smpi_get_category (void)
void TRACE_smpi_alloc()
{
- keys = xbt_dict_new();
- process_category = xbt_dict_new();
+ keys = xbt_dict_new_homogeneous(xbt_free);
+ process_category = xbt_dict_new_homogeneous(xbt_free);
}
void TRACE_smpi_start(void)
(*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), NULL);
(*event)->characteristics_list = xbt_dynar_new(sizeof(char*), NULL);
- (*event)->info_hash = xbt_dict_new();
+ (*event)->info_hash = xbt_dict_new_homogeneous(NULL);
}
unsigned int iter;
char *host_name;
- char buf[16];
- char *buf_copy;
+ char *buf;
parent->is_lowest = 1;
xbt_dynar_free(&parent->container_children);
parent->container_children = NULL;
- parent->name2id = xbt_dict_new();
+ parent->name2id = xbt_dict_new_homogeneous(xbt_free);
parent->last_id = 0;
parent->resource_list = xbt_dynar_new(sizeof(char *), NULL);
xbt_dynar_sort (host_names, &compare_hostnames);
xbt_dynar_foreach(host_names, iter, host_name) {
- buf_copy = strdup(buf);
- sprintf(buf_copy, "%d", parent->last_id);
+ buf = bprintf("%d", parent->last_id);
(parent->last_id)++;
- xbt_dict_set(parent->name2id, host_name, buf_copy, NULL);
+ xbt_dict_set(parent->name2id, host_name, buf, NULL);
xbt_dict_set(host2_simgrid_parent_container, host_name, parent, NULL);
xbt_dynar_push(parent->resource_list, &host_name);
}
unsigned int iter;
xbt_dict_t parent2hostgroup; // group hosts by parent
- parent2hostgroup = xbt_dict_new();
+ parent2hostgroup = xbt_dict_new_homogeneous(NULL);
xbt_assert( host_names != NULL );
void jed_create_jedule(jedule_t *jedule) {
*jedule = (jedule_t)calloc(1,sizeof(s_jedule_t));
- host2_simgrid_parent_container = xbt_dict_new();
- container_name2container = xbt_dict_new();
- (*jedule)->jedule_meta_info = xbt_dict_new();
+ host2_simgrid_parent_container = xbt_dict_new_homogeneous(NULL);
+ container_name2container = xbt_dict_new_homogeneous(NULL);
+ (*jedule)->jedule_meta_info = xbt_dict_new_homogeneous(NULL);
}
void jed_free_jedule(jedule_t jedule) {
#include "xbt/dynar.h"
#include "surf/surf_private.h"
+#include "surf/surf_resource.h"
#include "surf/surf.h"
#include "instr/jedule/jedule_sd_binding.h"
-/* $Id: private.h 5497 2008-05-26 12:19:15Z cristianrosa $ */
-
/* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
All rights reserved. */
void _MSG_action_init()
{
- action_funs = xbt_dict_new();
- action_queues = xbt_dict_new();
+ action_funs = xbt_dict_new_homogeneous(NULL);
+ action_queues = xbt_dict_new_homogeneous(NULL);
MSG_function_register_default(MSG_action_runner);
}
if (path)
fclose(action_fp);
xbt_dict_free(&action_queues);
- action_queues = xbt_dict_new();
+ action_queues = xbt_dict_new_homogeneous(NULL);
return res;
}
CHECK_HOST();
#ifdef HAVE_TRACING
TRACE_msg_task_get_start();
- double start_time = MSG_get_clock();
+ volatile double start_time = MSG_get_clock();
#endif
/* Sanity check */
m_channel_t put_channel; /* used for debugging purposes */
smx_action_t waiting_action;
m_task_t waiting_task;
- int argc; /* arguments number if any */
char **argv; /* arguments table if any */
+ int argc; /* arguments number if any */
MSG_error_t last_errno; /* the last value returned by a MSG_function */
void* data; /* user data */
} s_simdata_process_t, *simdata_process_t;
SD_link_t __SD_link_create(void *surf_link, void *data);
-void __SD_link_destroy(void *link);
+#define __SD_link_destroy xbt_free_f
SD_workstation_t __SD_workstation_create(void *surf_workstation,
void *data);
dax_lineno = 1;
result = xbt_dynar_new(sizeof(SD_task_t), dax_task_free);
- files = xbt_dict_new();
- jobs = xbt_dict_new();
+ files = xbt_dict_new_homogeneous(&dax_task_free);
+ jobs = xbt_dict_new_homogeneous(NULL);
root_task = SD_task_create_comp_seq("root", NULL, 0);
/* by design the root task is always SCHEDULABLE */
__SD_task_set_state(root_task, SD_SCHEDULABLE);
file = xbt_dict_get_or_null(files, A_dax__uses_file);
if (file == NULL) {
file = SD_task_create_comm_e2e(A_dax__uses_file, NULL, size);
- xbt_dict_set(files, A_dax__uses_file, file, &dax_task_free);
+ xbt_dict_set(files, A_dax__uses_file, file, NULL);
} else {
if (SD_task_get_amount(file) != size) {
XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f",
dag_dot = agread(in_file, NIL(Agdisc_t *));
result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free);
- files = xbt_dict_new();
- jobs = xbt_dict_new();
- computers = xbt_dict_new();
+ files = xbt_dict_new_homogeneous(&dot_task_free);
+ jobs = xbt_dict_new_homogeneous(NULL);
+ computers = xbt_dict_new_homogeneous(NULL);
root_task = SD_task_create_comp_seq("root", NULL, 0);
/* by design the root task is always SCHEDULABLE */
__SD_task_set_state(root_task, SD_SCHEDULABLE);
#ifdef HAVE_TRACING
TRACE_sd_dotloader (file, agget (edge, (char*)"category"));
#endif
- xbt_dict_set(files, name, file, &dot_task_free);
+ xbt_dict_set(files, name, file, NULL);
} else {
if (SD_task_get_amount(file) != size) {
XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f",
#ifdef HAVE_TRACING
TRACE_sd_dotloader (file, agget (edge, (char*)"category"));
#endif
- xbt_dict_set(files, name, file, &dot_task_free);
+ xbt_dict_set(files, name, file, NULL);
} else {
if (SD_task_get_amount(file) != size) {
XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f",
{
return link->sharing_policy;
}
-
-
-/* Destroys a link.
- */
-void __SD_link_destroy(void *link)
-{
- /* link->surf_link is freed by surf_exit and link->data is freed by the user */
- xbt_free(link);
-}
int smx_context_stack_size = 128 * 1024;
#ifdef HAVE_THREAD_LOCAL_STORAGE
-__thread smx_context_t smx_current_context;
+static __thread smx_context_t smx_current_context_parallel;
#else
-smx_context_t smx_current_context; /* define it anyway, will be used in non-parallel mode */
static xbt_os_thread_key_t smx_current_context_key = 0;
#endif
-
+static smx_context_t smx_current_context_serial;
static int smx_parallel_contexts = 1;
static int smx_parallel_threshold = 2;
*/
XBT_INLINE smx_context_t SIMIX_context_get_current(void)
{
+ if (SIMIX_context_is_parallel()) {
#ifdef HAVE_THREAD_LOCAL_STORAGE
- return smx_current_context;
+ return smx_current_context_parallel;
#else
- return xbt_os_thread_get_specific(smx_current_context_key);
+ return xbt_os_thread_get_specific(smx_current_context_key);
#endif
+ }
+ else {
+ return smx_current_context_serial;
+ }
}
/**
*/
XBT_INLINE void SIMIX_context_set_current(smx_context_t context)
{
+ if (SIMIX_context_is_parallel()) {
#ifdef HAVE_THREAD_LOCAL_STORAGE
- smx_current_context = context;
+ smx_current_context_parallel = context;
#else
- xbt_os_thread_set_specific(smx_current_context_key, context);
+ xbt_os_thread_set_specific(smx_current_context_key, context);
#endif
+ }
+ else {
+ smx_current_context_serial = context;
+ }
}
xbt_swag_new(xbt_swag_offset(proc, destroy_hookup));
simix_global->maestro_process = NULL;
- simix_global->registered_functions = xbt_dict_new();
+ simix_global->registered_functions = xbt_dict_new_homogeneous(NULL);
simix_global->create_process_function = SIMIX_process_create;
simix_global->kill_process_function = SIMIX_process_kill;
*/
xbt_dict_t SIMIX_host_get_dict(void)
{
- xbt_dict_t host_dict = xbt_dict_new();
+ xbt_dict_t host_dict = xbt_dict_new_homogeneous(NULL);
xbt_lib_cursor_t cursor = NULL;
char *name = NULL;
void **host = NULL;
xbt_lib_foreach(host_lib, cursor, name, host){
if(host[SIMIX_HOST_LEVEL])
- xbt_dict_set(host_dict,name,host[SIMIX_HOST_LEVEL],NULL);
+ xbt_dict_set(host_dict,name,host[SIMIX_HOST_LEVEL], NULL);
}
return host_dict;
}
void SIMIX_network_init(void)
{
- rdv_points = xbt_dict_new();
+ rdv_points = xbt_dict_new_homogeneous(SIMIX_rdv_free);
}
void SIMIX_network_exit(void)
rdv->comm_fifo = xbt_fifo_new();
if (rdv->name)
- xbt_dict_set(rdv_points, rdv->name, rdv, SIMIX_rdv_free);
+ xbt_dict_set(rdv_points, rdv->name, rdv, NULL);
}
return rdv;
}
*/
void SIMIX_comm_finish(smx_action_t action)
{
- unsigned int destroy_count = 0;
+ volatile unsigned int destroy_count = 0;
smx_req_t req;
while ((req = xbt_fifo_shift(action->request_list))) {
smpi_bench_end(); /* Take time from previous MPI call into account */
if (!samples) {
- samples = xbt_dict_new();
+ samples = xbt_dict_new_homogeneous(free);
}
data = xbt_dict_get_or_null(samples, loc);
if (!data) {
data->iters = iters;
data->threshold = threshold;
data->started = 0;
- xbt_dict_set(samples, loc, data, &free);
+ xbt_dict_set(samples, loc, data, NULL);
return 0;
}
free(loc);
shared_data_t *data;
if (!allocs) {
- allocs = xbt_dict_new();
+ allocs = xbt_dict_new_homogeneous(free);
}
data = xbt_dict_get_or_null(allocs, loc);
if (!data) {
data = (shared_data_t *) xbt_malloc0(sizeof(int) + size);
data->count = 1;
- xbt_dict_set(allocs, loc, data, &free);
+ xbt_dict_set(allocs, loc, data, NULL);
} else {
data->count++;
}
int known;
if(!calls) {
- calls = xbt_dict_new();
+ calls = xbt_dict_new_homogeneous(NULL);
}
TRY {
xbt_dict_get(calls, loc); /* Succeed or throw */
void* data;
if(!calls) {
- calls = xbt_dict_new();
+ calls = xbt_dict_new_homogeneous(NULL);
}
data = xbt_dict_get(calls, loc);
free(loc);
char* loc = bprintf("%s:%s", func, input);
if(!calls) {
- calls = xbt_dict_new();
+ calls = xbt_dict_new_homogeneous(NULL);
}
xbt_dict_set(calls, loc, data, NULL);
free(loc);
comm_lookup = xbt_dynar_new(sizeof(MPI_Comm), NULL);
new_comm(MPI_COMM_WORLD);
- request_lookup = xbt_dict_new();
+ request_lookup = xbt_dict_new_homogeneous(NULL);
datatype_lookup = xbt_dynar_new(sizeof(MPI_Datatype), NULL);
new_datatype(MPI_BYTE);
s_surf_resource_t generic_resource;
double power_peak;
double power_scale;
- int core;
tmgr_trace_event_t power_event;
+ int core;
e_surf_resource_state_t state_current;
tmgr_trace_event_t state_event;
lmm_constraint_t constraint;
-/* $Id$ */
/* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
-/* $Id$ */
/* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
-/* $ID$ */
-
/* Copyright (c) 2007 Kayo Fujiwara. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
-/* $ID$ */
-
/* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
* All rights reserved. */
static void *lmm_variable_mallocator_new_f(void);
static void lmm_variable_mallocator_free_f(void *var);
-static void lmm_variable_mallocator_reset_f(void *var);
+#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)NULL)
static void lmm_update_modified_set(lmm_system_t sys,
lmm_constraint_t cnst);
static void lmm_remove_all_modified_set(lmm_system_t sys);
xbt_free(var);
}
-static void lmm_variable_mallocator_reset_f(void *var)
-{
- /* lmm_variable_new() initializes everything */
-}
-
lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
double weight,
double bound, int number_of_constraints)
double lambda;
double new_lambda;
double remaining;
- int shared;
double usage;
void *id;
int id_int;
+ int shared;
} s_lmm_constraint_t;
typedef struct lmm_variable {
if(sg_sender_gap > 0.0) {
if(!gap_lookup) {
- gap_lookup = xbt_dict_new();
+ gap_lookup = xbt_dict_new_homogeneous(NULL);
}
fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, src);
action->sender.gap = 0.0;
surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //InitializeRoutes
}
-static void free_ns3_elmts(void * elmts)
-{
-}
-
static void free_ns3_link(void * elmts)
{
ns3_link_t link = elmts;
uint32_t totalBytes,
void * action)
{
- if(!dict_socket) dict_socket = xbt_dict_new();
+ if(!dict_socket) dict_socket = xbt_dict_new_homogeneous(free);
PacketSinkHelper sink ("ns3::TcpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny(),
mysocket->action = action;
transformSocketPtr(sock);
- xbt_dict_set(dict_socket,socket_key, mysocket,free);
+ xbt_dict_set(dict_socket,socket_key, mysocket,NULL);
sock->Bind(InetSocketAddress(port_number));
XBT_DEBUG("Create flow starting to %fs + %fs = %fs",start-ns3_time(), ns3_time(), start);
static xbt_mallocator_t action_mallocator = NULL;
static int action_mallocator_allocated_size = 0;
static void* surf_action_mallocator_new_f(void);
-static void surf_action_mallocator_free_f(void* action);
+#define surf_action_mallocator_free_f xbt_free_f
static void surf_action_mallocator_reset_f(void* action);
/**
return xbt_malloc(action_mallocator_allocated_size);
}
-static void surf_action_mallocator_free_f(void* action) {
- xbt_free(action);
-}
-
static void surf_action_mallocator_reset_f(void* action) {
memset(action, 0, action_mallocator_allocated_size);
}
AS_t root;
void *loopback;
size_t size_of_link;
+ xbt_dynar_t last_route;
xbt_dynar_t(*get_onelink_routes) (void);
};
void routing_get_route_and_latency(const char *src, const char *dst,
xbt_dynar_t * route, double *latency)
{
- static xbt_dynar_t last_route = NULL;
-
- int need_cleanup = !(*route);
-
- if (need_cleanup) {
- xbt_dynar_free(&last_route);
- last_route = *route = xbt_dynar_new(global_routing->size_of_link,NULL);
+ if (!*route) {
+ xbt_dynar_reset(global_routing->last_route);
+ *route = global_routing->last_route;
}
_get_route_and_latency(src, dst, route, latency);
global_routing->get_onelink_routes = get_onelink_routes;
global_routing->loopback = loopback;
global_routing->size_of_link = size_of_links;
+ global_routing->last_route = xbt_dynar_new(global_routing->size_of_link,NULL);
/* no current routing at moment */
current_routing = NULL;
}
if (strcmp(cluster->availability_trace, "")
|| strcmp(cluster->state_trace, "")) {
- patterns = xbt_dict_new();
- xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), free);
- xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), free);
- xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), free);
+ patterns = xbt_dict_new_homogeneous(xbt_free_f);
+ xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL);
+ xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL);
+ xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL);
}
memset(&host, 0, sizeof(host));
host.id = host_id;
if (strcmp(cluster->availability_trace, "")) {
- xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free);
+ xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
host.power_trace = tmgr_trace_new(avail_file);
random->generator, random->seed, random_radical);
if (!random_value)
- random_value = xbt_dict_new();
+ random_value = xbt_dict_new_homogeneous(free);
if (!strcmp(random_radical, "")) {
res = random_generate(random);
rd_value = bprintf("%f", res);
- xbt_dict_set(random_value, random_id, rd_value, free);
+ xbt_dict_set(random_value, random_id, rd_value, NULL);
} else {
radical_elements = xbt_str_split(random_radical, ",");
xbt_dynar_foreach(radical_elements, iter, groups) {
tmpbuf =
bprintf("%s%d", random_id,
atoi(xbt_dynar_getfirst_as(radical_ends, char *)));
- xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), free);
+ xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
xbt_free(tmpbuf);
break;
i));
res = random_generate(random);
tmpbuf = bprintf("%s%d", random_id, i);
- xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), free);
+ xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL);
xbt_free(tmpbuf);
}
break;
res = random_generate(random);
rd_name = bprintf("%s_router", random_id);
rd_value = bprintf("%f", res);
- xbt_dict_set(random_value, rd_name, rd_value, free);
+ xbt_dict_set(random_value, rd_name, rd_value, NULL);
xbt_dynar_free(&radical_ends);
}
void routing_exit(void) {
if (!global_routing)
return;
+ xbt_dynar_free(&global_routing->last_route);
finalize_rec(global_routing->root);
xbt_free(global_routing);
}
void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info) {
if(!cluster_host_link)
- cluster_host_link = xbt_dict_new();
+ cluster_host_link = xbt_dict_new_homogeneous(xbt_free);
- xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
+ xbt_dict_set(cluster_host_link,host_id,info,NULL);
}
void surf_routing_cluster_add_backbone(AS_t as, void* bb) {
elm = xbt_new0(struct graph_node_map_element, 1);
elm->node = node;
xbt_dict_set_ext(as->graph_node_map, (char *) (&id), sizeof(int),
- (xbt_set_elm_t) elm, &graph_node_map_elem_free);
+ (xbt_set_elm_t) elm, NULL);
return node;
}
elm->pred_arr = pred_arr;
elm->size = size;
xbt_dict_set_ext(as->route_cache, (char *) (&src_id), sizeof(int),
- (xbt_set_elm_t) elm, &route_cache_elem_free);
+ (xbt_set_elm_t) elm, NULL);
}
if (!as->cached)
void model_dijkstra_both_end(AS_t as)
{
- as_dijkstra_t THIS = (as_dijkstra_t) as;
+ as_dijkstra_t THIS_AS = (as_dijkstra_t) as;
xbt_node_t node = NULL;
unsigned int cursor2;
xbt_dynar_t nodes = NULL;
/* Create the topology graph */
- if(!THIS->route_graph)
- THIS->route_graph = xbt_graph_new_graph(1, NULL);
- if(!THIS->graph_node_map)
- THIS->graph_node_map = xbt_dict_new();
+ if(!THIS_AS->route_graph)
+ THIS_AS->route_graph = xbt_graph_new_graph(1, NULL);
+ if(!THIS_AS->graph_node_map)
+ THIS_AS->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
- if (THIS->cached && !THIS->route_cache)
- THIS->route_cache = xbt_dict_new();
+ if (THIS_AS->cached && !THIS_AS->route_cache)
+ THIS_AS->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free);
/* Add the loopback if needed */
if (as->hierarchy == SURF_ROUTING_BASE)
- add_loopback_dijkstra(THIS);
+ add_loopback_dijkstra(THIS_AS);
/* initialize graph indexes in nodes after graph has been built */
- nodes = xbt_graph_get_nodes(THIS->route_graph);
+ nodes = xbt_graph_get_nodes(THIS_AS->route_graph);
xbt_dynar_foreach(nodes, cursor2, node) {
graph_node_data_t data = xbt_graph_node_get_data(node);
if(!as->route_graph)
as->route_graph = xbt_graph_new_graph(1, NULL);
if(!as->graph_node_map)
- as->graph_node_map = xbt_dict_new();
+ as->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
if (as->cached && !as->route_cache)
- as->route_cache = xbt_dict_new();
+ as->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free);
if( A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES
|| A_surfxml_ASroute_symmetrical == A_surfxml_ASroute_symmetrical_YES )
if (asg->hierarchy == SURF_ROUTING_RECURSIVE && !first
&& strcmp(gw_dst, prev_gw_src)) {
- xbt_dynar_t e_route_as_to_as=NULL;
+ xbt_dynar_t e_route_as_to_as;
+ e_route_as_to_as = xbt_dynar_new(global_routing->size_of_link, NULL);
routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
links = e_route_as_to_as;
int pos = 0;
*lat += surf_network_model->extension.network.get_link_latency(link);
pos++;
}
+ xbt_dynar_free(&e_route_as_to_as);
}
links = e_route->link_list;
xbt_dict_free(&as->generic_routing.bypassRoutes);
/* Delete index dict */
xbt_dict_free(&(as->generic_routing.to_index));
- /* Delete dictionary index dict, predecessor and links table */
+ /* Delete predecessor and cost table */
xbt_free(as->predecessor_table);
+ xbt_free(as->cost_table);
model_generic_finalize(rc);
}
{
if(route->dst_gateway && route->src_gateway)
{
- char *gw_src = xbt_strdup(route->src_gateway);
- char *gw_dst = xbt_strdup(route->dst_gateway);
+ char *gw_src = route->src_gateway;
+ char *gw_dst = route->dst_gateway;
route->src_gateway = gw_dst;
route->dst_gateway = gw_src;
}
generic_get_bypassroute;
new_component->finalize = model_generic_finalize;
- new_component->to_index = xbt_dict_new();
- new_component->bypassRoutes = xbt_dict_new();
+ new_component->to_index = xbt_dict_new_homogeneous(xbt_free);
+ new_component->bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route);
return new_component;
}
xbt_dict_t _to_index;
_to_index = as->to_index;
*id = xbt_dict_length(_to_index);
- xbt_dict_set(_to_index, name, id, xbt_free);
+ xbt_dict_set(_to_index, name, id, NULL);
}
void generic_parse_AS(AS_t as, const char *name)
xbt_dict_t _to_index;
_to_index = as->to_index;
*id = xbt_dict_length(_to_index);
- xbt_dict_set(_to_index, name, id, xbt_free);
+ xbt_dict_set(_to_index, name, id, NULL);
}
void generic_parse_bypassroute(AS_t rc,
xbt_dynar_free(&(e_route->link_list));
xbt_free(e_route);
- xbt_dict_set(dict_bypassRoutes, route_name, new_e_route,
- (void (*)(void *)) generic_free_route);
+ xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, NULL);
xbt_free(route_name);
}
new_component->get_bypass_route = none_get_bypass_route;
new_component->finalize = model_none_finalize;
- new_component->routing_sons = xbt_dict_new();
+ new_component->routing_sons = xbt_dict_new_homogeneous(NULL);
return new_component;
}
static void model_rulebased_parse_AS(AS_t rc, const char *name)
{
AS_rulebased_t routing = (AS_rulebased_t) rc;
- xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
- NULL);
+ xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1), NULL);
}
static void model_rulebased_parse_route(AS_t rc,
} else if (!strcmp(src, dst) && are_processing_units) {
xbt_dynar_push(route->link_list, &(global_routing->loopback));
if (lat)
- *lat += surf_network_model->extension.network.get_link_latency(link);
+ *lat += surf_network_model->extension.network.get_link_latency(global_routing->loopback);
} else {
THROWF(arg_error,0,"No route from '%s' to '%s'??",src,dst);
//xbt_dynar_reset(route->link_list);
new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route;
new_component->generic_routing.finalize = rulebased_finalize;
/* initialization of internal structures */
- new_component->dict_processing_units = xbt_dict_new();
- new_component->dict_autonomous_systems = xbt_dict_new();
+ new_component->dict_processing_units = xbt_dict_new_homogeneous(NULL);
+ new_component->dict_autonomous_systems = xbt_dict_new_homogeneous(NULL);
new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
new_component->list_ASroute =
xbt_dynar_new(sizeof(rule_route_extended_t),
memset(&host,0,sizeof(host));
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- host.properties = current_property_set = xbt_dict_new();
+ host.properties = current_property_set = xbt_dict_new_homogeneous(xbt_free_f);
host.id = A_surfxml_host_id;
host.power_peak = get_cpu_power(A_surfxml_host_power);
memset(&link,0,sizeof(link));
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- link.properties = current_property_set = xbt_dict_new();
+ link.properties = current_property_set = xbt_dict_new_homogeneous(xbt_free_f);
link.id = A_surfxml_link_id;
link.bandwidth = surf_parse_get_double(A_surfxml_link_bandwidth);
void STag_surfxml_config(void){
XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
- current_property_set = xbt_dict_new();
+ current_property_set = xbt_dict_new_homogeneous(xbt_free_f);
}
void ETag_surfxml_config(void){
void parse_properties(void)
{
if (!current_property_set)
- current_property_set = xbt_dict_new(); // Maybe, it should raise an error
+ current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
- xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), free);
+ xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), NULL);
}
case A_surfxml_trace_connect_kind_HOST_AVAIL:
xbt_dict_set(trace_connect_list_host_avail,
A_surfxml_trace_connect_trace,
- xbt_strdup(A_surfxml_trace_connect_element), free);
+ xbt_strdup(A_surfxml_trace_connect_element), NULL);
break;
case A_surfxml_trace_connect_kind_POWER:
xbt_dict_set(trace_connect_list_power, A_surfxml_trace_connect_trace,
- xbt_strdup(A_surfxml_trace_connect_element), free);
+ xbt_strdup(A_surfxml_trace_connect_element), NULL);
break;
case A_surfxml_trace_connect_kind_LINK_AVAIL:
xbt_dict_set(trace_connect_list_link_avail,
A_surfxml_trace_connect_trace,
- xbt_strdup(A_surfxml_trace_connect_element), free);
+ xbt_strdup(A_surfxml_trace_connect_element), NULL);
break;
case A_surfxml_trace_connect_kind_BANDWIDTH:
xbt_dict_set(trace_connect_list_bandwidth,
A_surfxml_trace_connect_trace,
- xbt_strdup(A_surfxml_trace_connect_element), free);
+ xbt_strdup(A_surfxml_trace_connect_element), NULL);
break;
case A_surfxml_trace_connect_kind_LATENCY:
xbt_dict_set(trace_connect_list_latency, A_surfxml_trace_connect_trace,
- xbt_strdup(A_surfxml_trace_connect_element), free);
+ xbt_strdup(A_surfxml_trace_connect_element), NULL);
break;
default:
xbt_die("Cannot connect trace %s to %s: kind of trace unknown",
if (!surfxml_bufferstack_stack)
surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
- traces_set_list = xbt_dict_new();
- trace_connect_list_host_avail = xbt_dict_new();
- trace_connect_list_power = xbt_dict_new();
- trace_connect_list_link_avail = xbt_dict_new();
- trace_connect_list_bandwidth = xbt_dict_new();
- trace_connect_list_latency = xbt_dict_new();
+ traces_set_list = xbt_dict_new_homogeneous(NULL);
+ trace_connect_list_host_avail = xbt_dict_new_homogeneous(free);
+ trace_connect_list_power = xbt_dict_new_homogeneous(free);
+ trace_connect_list_link_avail = xbt_dict_new_homogeneous(free);
+ trace_connect_list_bandwidth = xbt_dict_new_homogeneous(free);
+ trace_connect_list_latency = xbt_dict_new_homogeneous(free);
surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace);
surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace);
last_event->delta = periodicity;
if (!trace_list)
- trace_list = xbt_dict_new();
+ trace_list = xbt_dict_new_homogeneous((void (*)(void *)) tmgr_trace_free);
- xbt_dict_set(trace_list, id, (void *) trace,
- (void (*)(void *)) tmgr_trace_free);
+ xbt_dict_set(trace_list, id, (void *) trace, NULL);
xbt_dynar_free(&list);
return trace;
double power_scale;
double power_current;
tmgr_trace_event_t power_event;
- e_surf_resource_state_t state_current;
tmgr_trace_event_t state_event;
+ e_surf_resource_state_t state_current;
int id; /* cpu and network card are a single object... */
} s_cpu_L07_t, *cpu_L07_t;
double latency = 0.0;
if (ptask_parallel_task_link_set == NULL)
- ptask_parallel_task_link_set = xbt_dict_new();
+ ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL);
xbt_dict_reset(ptask_parallel_task_link_set);
link->properties);
xbt_free(link_id);
link_id = bprintf("%s_DOWN", link->id);
- ptask_link_create_resource(bprintf("%s_DOWN", link->id),
+ ptask_link_create_resource(link_id,
link->bandwidth,
link->bandwidth_trace,
link->latency,
-/* $Id: ex_interface.h 3782 2007-07-14 09:11:06Z mquinson $ */
-
/* backtrace_dummy -- stubs of this module for non-supported archs */
/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
xbt_cfg_t xbt_cfg_new(void)
{
- return (xbt_cfg_t) xbt_dict_new();
+ return (xbt_cfg_t) xbt_dict_new_homogeneous(&xbt_cfgelm_free);
}
/** \brief Copy an existing configuration set
XBT_ERROR("%d is an invalide type code", type);
}
- xbt_dict_set((xbt_dict_t) * cfg, name, res, &xbt_cfgelm_free);
+ xbt_dict_set((xbt_dict_t) * cfg, name, res, NULL);
}
/** @brief Unregister an element from a config set.
/* dict - a generic dictionary, variation over hash table */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt,
"Dictionaries provide the same functionalities than hash tables");
-/*####[ Private prototypes ]#################################################*/
-
-static xbt_mallocator_t dict_mallocator = NULL;
-static void *dict_mallocator_new_f(void);
-static void dict_mallocator_free_f(void *dict);
-static void dict_mallocator_reset_f(void *dict);
+/**
+ * \brief Constructor
+ * \return pointer to the destination
+ * \see xbt_dict_free()
+ *
+ * Creates and initialize a new dictionary with a default hashtable size.
+ * The dictionary is heterogeneous: each element can have a different free
+ * function.
+ */
+xbt_dict_t xbt_dict_new(void)
+{
+ xbt_dict_t dict = xbt_dict_new_homogeneous(NULL);
+ dict->homogeneous = 0;
-/*####[ Code ]###############################################################*/
+ return dict;
+}
/**
* \brief Constructor
+ * \param free_ctn function to call with (\a data as argument) when
+ * \a data is removed from the dictionary
* \return pointer to the destination
- * \see xbt_dict_new_ext(), xbt_dict_free()
+ * \see xbt_dict_new(), xbt_dict_free()
*
* Creates and initialize a new dictionary with a default hashtable size.
+ * The dictionary is homogeneous: each element share the same free function.
*/
-xbt_dict_t xbt_dict_new(void)
+xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn)
{
xbt_dict_t dict;
- dict = xbt_mallocator_get(dict_mallocator);
+ dict = xbt_new(s_xbt_dict_t, 1);
+ dict->free_f = free_ctn;
dict->table_size = 127;
dict->table = xbt_new0(xbt_dictelm_t, dict->table_size + 1);
dict->count = 0;
dict->fill = 0;
+ dict->homogeneous = 1;
return dict;
}
while (current != NULL) {
previous = current;
current = current->next;
- xbt_dictelm_free(previous);
+ xbt_dictelm_free(*dict, previous);
(*dict)->count--;
}
}
xbt_free(table);
- xbt_mallocator_release(dict_mallocator, *dict);
+ xbt_free(*dict);
*dict = NULL;
}
}
if (current == NULL) {
/* this key doesn't exist yet */
- current = xbt_dictelm_new(key, key_len, hash_code, data, free_ctn);
+ current = xbt_dictelm_new(dict, key, key_len, hash_code, data, free_ctn);
dict->count++;
if (previous == NULL) {
dict->table[hash_code & dict->table_size] = current;
previous->next = current;
}
} else {
-
XBT_DEBUG("Replace %.*s by %.*s under key %.*s",
key_len, (char *) current->content,
key_len, (char *) data, key_len, (char *) key);
/* there is already an element with the same key: overwrite it */
- if (current->content != NULL && current->free_f != NULL) {
- current->free_f(current->content);
- }
- current->content = data;
- current->free_f = free_ctn;
+ xbt_dictelm_set_data(dict, current, data, free_ctn);
}
}
if (!dict->table[hash_code & dict->table_size])
dict->fill--;
- xbt_dictelm_free(current);
+ xbt_dictelm_free(dict, current);
dict->count--;
}
XBT_INLINE void xbt_dicti_set(xbt_dict_t dict,
uintptr_t key, uintptr_t data)
{
-
- unsigned int hash_code =
- xbt_dict_hash_ext((void *) &key, sizeof(uintptr_t));
-
- xbt_dictelm_t current, previous = NULL;
- xbt_assert(dict);
-
- XBT_DEBUG("ADD %zu->%zu; hash = %d, size = %d, & = %d", key, data,
- hash_code, dict->table_size, hash_code & dict->table_size);
- current = dict->table[hash_code & dict->table_size];
- while (current != NULL &&
- (hash_code != current->hash_code
- || sizeof(uintptr_t) != current->key_len
- || (((uintptr_t) key) != ((uintptr_t) current->key)))) {
- previous = current;
- current = current->next;
- }
-
- if (current == NULL) {
- /* this key doesn't exist yet */
- current = xbt_dictielm_new(key, hash_code, data);
- dict->count++;
- if (previous == NULL) {
- dict->table[hash_code & dict->table_size] = current;
- dict->fill++;
- if ((dict->fill * 100) / (dict->table_size + 1) > MAX_FILL_PERCENT)
- xbt_dict_rehash(dict);
- } else {
- previous->next = current;
- }
- } else {
-
- /* there is already an element with the same key: overwrite it */
- if (current->content != NULL && current->free_f != NULL) {
- current->free_f(current->content);
- }
- current->content = (void *) data;
- current->free_f = NULL;
- }
+ xbt_dict_set_ext(dict, (void *)&key, sizeof key, (void*)data, NULL);
}
/**
*/
XBT_INLINE uintptr_t xbt_dicti_get(xbt_dict_t dict, uintptr_t key)
{
-
- unsigned int hash_code =
- xbt_dict_hash_ext(((void *) &key), sizeof(uintptr_t));
- xbt_dictelm_t current;
-
- xbt_assert(dict);
-
- current = dict->table[hash_code & dict->table_size];
- while (current != NULL &&
- (hash_code != current->hash_code
- || sizeof(uintptr_t) != current->key_len
- || (((uintptr_t) key) != ((uintptr_t) current->key)))) {
- current = current->next;
- }
-
- if (current == NULL)
- return 0;
-
- return (uintptr_t) (current->content);
+ return (uintptr_t)xbt_dict_get_or_null_ext(dict, (void *)&key, sizeof key);
}
/** Remove a uintptr_t key from the dict */
XBT_INLINE void xbt_dicti_remove(xbt_dict_t dict, uintptr_t key)
{
-
- unsigned int hash_code =
- xbt_dict_hash_ext(((void *) &key), sizeof(uintptr_t));
- xbt_dictelm_t current, previous = NULL;
-
-
- current = dict->table[hash_code & dict->table_size];
- while (current != NULL &&
- (hash_code != current->hash_code
- || sizeof(uintptr_t) != current->key_len
- || (((uintptr_t) key) != ((uintptr_t) current->key)))) {
- previous = current; /* save the previous node */
- current = current->next;
- }
-
- if (current == NULL)
- THROWF(not_found_error, 0, "key %zu not found", key);
-
- if (previous != NULL) {
- previous->next = current->next;
- } else {
- dict->table[hash_code & dict->table_size] = current->next;
- }
-
- if (!dict->table[hash_code & dict->table_size])
- dict->fill--;
-
- xbt_dictelm_free(current);
- dict->count--;
+ xbt_dict_remove_ext(dict, (void *)&key, sizeof key);
}
while (current != NULL) {
previous = current;
current = current->next;
- xbt_dictelm_free(previous);
+ xbt_dictelm_free(dict, previous);
}
dict->table[i] = NULL;
}
*/
void xbt_dict_preinit(void)
{
- if (dict_mallocator != NULL) {
+ if (dict_elm_mallocator != NULL) {
/* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */
- xbt_mallocator_free(dict_mallocator);
xbt_mallocator_free(dict_elm_mallocator);
+ xbt_mallocator_free(dict_het_elm_mallocator);
}
- dict_mallocator = xbt_mallocator_new(256,
- dict_mallocator_new_f,
- dict_mallocator_free_f,
- dict_mallocator_reset_f);
dict_elm_mallocator = xbt_mallocator_new(256,
dict_elm_mallocator_new_f,
dict_elm_mallocator_free_f,
dict_elm_mallocator_reset_f);
+ dict_het_elm_mallocator = xbt_mallocator_new(256,
+ dict_het_elm_mallocator_new_f,
+ dict_het_elm_mallocator_free_f,
+ dict_het_elm_mallocator_reset_f);
}
/**
*/
void xbt_dict_postexit(void)
{
- if (dict_mallocator != NULL) {
- xbt_mallocator_free(dict_mallocator);
- dict_mallocator = NULL;
+ if (dict_elm_mallocator != NULL) {
xbt_mallocator_free(dict_elm_mallocator);
dict_elm_mallocator = NULL;
+ xbt_mallocator_free(dict_het_elm_mallocator);
+ dict_het_elm_mallocator = NULL;
}
if (all_sizes) {
unsigned int count;
}
}
-static void *dict_mallocator_new_f(void)
-{
- return xbt_new(s_xbt_dict_t, 1);
-}
-
-static void dict_mallocator_free_f(void *dict)
-{
- xbt_free(dict);
-}
-
-static void dict_mallocator_reset_f(void *dict)
-{
- /* nothing to do because all fields are
- * initialized in xbt_dict_new
- */
-}
-
#ifdef SIMGRID_TEST
#include "xbt.h"
#include "xbt/ex.h"
}
static void debuged_add_ext(xbt_dict_t head, const char *key,
- const char *data_to_fill)
+ const char *data_to_fill, void_f_pvoid_t free_f)
{
char *data = xbt_strdup(data_to_fill);
xbt_test_log("Add %s under %s", PRINTF_STR(data_to_fill),
PRINTF_STR(key));
- xbt_dict_set(head, key, data, &free);
+ xbt_dict_set(head, key, data, free_f);
if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) {
xbt_dict_dump(head, (void (*)(void *)) &printf);
fflush(stdout);
}
}
-static void debuged_add(xbt_dict_t head, const char *key)
+static void debuged_add(xbt_dict_t head, const char *key, void_f_pvoid_t free_f)
{
- debuged_add_ext(head, key, key);
+ debuged_add_ext(head, key, key, free_f);
}
-static void fill(xbt_dict_t * head)
+static void fill(xbt_dict_t * head, int homogeneous)
{
+ void_f_pvoid_t free_f = homogeneous ? NULL : &free;
+
xbt_test_add("Fill in the dictionnary");
- *head = xbt_dict_new();
- debuged_add(*head, "12");
- debuged_add(*head, "12a");
- debuged_add(*head, "12b");
- debuged_add(*head, "123");
- debuged_add(*head, "123456");
+ *head = homogeneous ? xbt_dict_new_homogeneous(&free) : xbt_dict_new();
+ debuged_add(*head, "12", free_f);
+ debuged_add(*head, "12a", free_f);
+ debuged_add(*head, "12b", free_f);
+ debuged_add(*head, "123", free_f);
+ debuged_add(*head, "123456", free_f);
/* Child becomes child of what to add */
- debuged_add(*head, "1234");
+ debuged_add(*head, "1234", free_f);
/* Need of common ancestor */
- debuged_add(*head, "123457");
+ debuged_add(*head, "123457", free_f);
}
xbt_dict_t head = NULL;
char *data;
-
-XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse")
+static void basic_test(int homogeneous)
{
+ void_f_pvoid_t free_f;
+
xbt_test_add("Traversal the null dictionary");
traverse(head);
xbt_test_add("Traversal and search the empty dictionary");
- head = xbt_dict_new();
+ head = homogeneous ? xbt_dict_new_homogeneous(&free) : xbt_dict_new();
traverse(head);
TRY {
debuged_remove(head, "12346");
}
xbt_dict_free(&head);
+ free_f = homogeneous ? NULL : &free;
+
xbt_test_add("Traverse the full dictionary");
- fill(&head);
+ fill(&head, homogeneous);
count_check_get_key(head, 7);
- debuged_add_ext(head, "toto", "tutu");
+ debuged_add_ext(head, "toto", "tutu", free_f);
search_ext(head, "toto", "tutu");
debuged_remove(head, "toto");
xbt_dict_free(&head);
/* CHANGING */
- fill(&head);
+ fill(&head, homogeneous);
count_check_get_key(head, 7);
xbt_test_add("Change 123 to 'Changed 123'");
- xbt_dict_set(head, "123", strdup("Changed 123"), &free);
+ xbt_dict_set(head, "123", strdup("Changed 123"), free_f);
count_check_get_key(head, 7);
xbt_test_add("Change 123 back to '123'");
- xbt_dict_set(head, "123", strdup("123"), &free);
+ xbt_dict_set(head, "123", strdup("123"), free_f);
count_check_get_key(head, 7);
xbt_test_add("Change 12a to 'Dummy 12a'");
- xbt_dict_set(head, "12a", strdup("Dummy 12a"), &free);
+ xbt_dict_set(head, "12a", strdup("Dummy 12a"), free_f);
count_check_get_key(head, 7);
xbt_test_add("Change 12a to '12a'");
- xbt_dict_set(head, "12a", strdup("12a"), &free);
+ xbt_dict_set(head, "12a", strdup("12a"), free_f);
count_check_get_key(head, 7);
xbt_test_add("Traverse the resulting dictionary");
traverse(head);
}
-XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values")
+XBT_TEST_UNIT("basic (heterogeneous)", test_dict_basic_heterogeneous, "Basic usage: change, retrieve, traverse: heterogeneous dictionary")
{
- fill(&head);
+ basic_test(0);
+}
+
+XBT_TEST_UNIT("basic (homogeneous)", test_dict_basic_homogeneous, "Basic usage: change, retrieve, traverse: homogeneous dictionary")
+{
+ basic_test(1);
+}
+
+static void remove_test(int homogeneous)
+{
+ fill(&head, homogeneous);
count(head, 7);
xbt_test_add("Remove non existing data");
TRY {
xbt_test_add
("Remove each data manually (traversing the resulting dictionary each time)");
- fill(&head);
+ fill(&head, homogeneous);
debuged_remove(head, "12a");
traverse(head);
count(head, 6);
xbt_test_add
("Free dict, create new fresh one, and then reset the dict");
xbt_dict_free(&head);
- fill(&head);
+ fill(&head, homogeneous);
xbt_dict_reset(head);
count(head, 0);
traverse(head);
xbt_dict_free(&head);
}
+XBT_TEST_UNIT("remove (heterogeneous)", test_dict_remove_heterogeneous, "Removing some values: heterogeneous dictionary")
+{
+ remove_test(0);
+}
+
+XBT_TEST_UNIT("remove (homogeneous)", test_dict_remove_homogeneous, "Removing some values: homogeneous dictionary")
+{
+ remove_test(1);
+}
+
XBT_TEST_UNIT("nulldata", test_dict_nulldata, "NULL data management")
{
- fill(&head);
+ fill(&head, 1);
xbt_test_add("Store NULL under 'null'");
xbt_dict_set(head, "null", NULL, NULL);
/* dict_cursor - iterators over dictionnaries */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
/* To traverse (simple) dicts */
/* Don't add or remove entries to the dict while traversing !!! */
/*###########################################################################*/
-struct xbt_dict_cursor_ {
+struct s_xbt_dict_cursor {
xbt_dictelm_t current;
int line;
xbt_dict_t dict;
void_f_pvoid_t free_ctn)
{
__cursor_not_null(cursor);
- if (cursor->current->free_f)
- cursor->current->free_f(cursor->current->content);
-
- cursor->current->content = data;
- cursor->current->free_f = free_ctn;
- return;
+ xbt_dictelm_set_data(cursor->dict, cursor->current, data, free_ctn);
}
-/* dict - a generic dictionary, variation over the B-tree concept */
+/* dict - a generic dictionary, variation over hash table */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
"Dictionaries internals: post-removal cleanup");
xbt_mallocator_t dict_elm_mallocator = NULL;
+xbt_mallocator_t dict_het_elm_mallocator = NULL;
-xbt_dictelm_t xbt_dictelm_new(const char *key,
- int key_len,
- unsigned int hash_code,
- void *content, void_f_pvoid_t free_f)
+xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len,
+ unsigned int hash_code, void *content,
+ void_f_pvoid_t free_f)
{
- xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator);
-
- element->dictielem = 0; /* please free the key on free */
+ xbt_dictelm_t element;
+
+ if (dict->homogeneous) {
+ xbt_assert(!free_f,
+ "Cannot set an individual free function in homogeneous dicts.");
+ element = xbt_mallocator_get(dict_elm_mallocator);
+ } else {
+ xbt_het_dictelm_t het_element = xbt_mallocator_get(dict_het_elm_mallocator);
+ het_element->free_f = free_f;
+ element = &het_element->element;
+ }
element->key = xbt_new(char, key_len + 1);
- memcpy((void *) element->key, (void *) key, key_len);
+ memcpy(element->key, key, key_len);
element->key[key_len] = '\0';
element->key_len = key_len;
element->hash_code = hash_code;
element->content = content;
- element->free_f = free_f;
element->next = NULL;
return element;
}
-xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code,
- uintptr_t content)
+void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element)
{
- xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator);
-
- element->key = (void *) key;
-
- element->dictielem = 1; /* please DONT free the key on free */
- element->key_len = sizeof(uintptr_t);
- element->hash_code = hash_code;
-
- element->content = (void *) content;
- element->free_f = NULL;
- element->next = NULL;
+ if (element) {
+ char *key = element->key;
+ void *content = element->content;
+ void_f_pvoid_t free_f;
+ if (dict->homogeneous) {
+ free_f = dict->free_f;
+ xbt_mallocator_release(dict_elm_mallocator, element);
+ } else {
+ xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element;
+ free_f = het_element->free_f;
+ xbt_mallocator_release(dict_het_elm_mallocator, het_element);
+ }
- return element;
+ xbt_free(key);
+ if (free_f && content)
+ free_f(content);
+ }
}
-void xbt_dictelm_free(xbt_dictelm_t element)
+void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element,
+ void *data, void_f_pvoid_t free_ctn)
{
- if (element != NULL) {
- if (!element->dictielem)
- xbt_free(element->key);
+ void_f_pvoid_t free_f;
+ if (dict->homogeneous) {
+ free_f = dict->free_f;
+ xbt_assert(!free_ctn,
+ "Cannot set an individual free function in homogeneous dicts.");
+ } else {
+ xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element;
+ free_f = het_element->free_f;
+ het_element->free_f = free_ctn;
+ }
- if (element->free_f != NULL && element->content != NULL) {
- element->free_f(element->content);
- }
+ if (free_f && element->content)
+ free_f(element->content);
- xbt_mallocator_release(dict_elm_mallocator, element);
- }
+ element->content = data;
}
void *dict_elm_mallocator_new_f(void)
return xbt_new(s_xbt_dictelm_t, 1);
}
-void dict_elm_mallocator_free_f(void *elem)
+void *dict_het_elm_mallocator_new_f(void)
{
- xbt_free(elem);
-}
-
-void dict_elm_mallocator_reset_f(void *elem)
-{
-
+ return xbt_new(s_xbt_het_dictelm_t, 1);
}
/* dict_elm - elements of generic dictionnaries */
/* This file is not to be loaded from anywhere but dict.c */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "xbt/dict.h"
#include "xbt/mallocator.h"
-typedef struct xbt_dictelm_ *xbt_dictelm_t;
+typedef struct s_xbt_dictelm *xbt_dictelm_t;
#define MAX_FILL_PERCENT 80
-typedef struct xbt_dictelm_ {
- int dictielem:1;
+typedef struct s_xbt_dictelm {
char *key;
int key_len;
unsigned int hash_code;
void *content;
- void_f_pvoid_t free_f;
xbt_dictelm_t next;
} s_xbt_dictelm_t;
-typedef struct xbt_dict_ {
+typedef struct s_xbt_het_dictelm {
+ s_xbt_dictelm_t element;
+ void_f_pvoid_t free_f;
+} s_xbt_het_dictelm_t, *xbt_het_dictelm_t;
+
+typedef struct s_xbt_dict {
+ void_f_pvoid_t free_f;
xbt_dictelm_t *table;
int table_size;
int count;
int fill;
+ int homogeneous;
} s_xbt_dict_t;
-typedef struct xbt_dict_cursor_ s_xbt_dict_cursor_t;
+typedef struct s_xbt_dict_cursor s_xbt_dict_cursor_t;
extern xbt_mallocator_t dict_elm_mallocator;
extern void *dict_elm_mallocator_new_f(void);
-extern void dict_elm_mallocator_free_f(void *elem);
-extern void dict_elm_mallocator_reset_f(void *elem);
+#define dict_elm_mallocator_free_f xbt_free_f
+#define dict_elm_mallocator_reset_f ((void_f_pvoid_t)NULL)
+
+extern xbt_mallocator_t dict_het_elm_mallocator;
+extern void *dict_het_elm_mallocator_new_f(void);
+#define dict_het_elm_mallocator_free_f xbt_free_f
+#define dict_het_elm_mallocator_reset_f ((void_f_pvoid_t)NULL)
/*####[ Function prototypes ]################################################*/
-xbt_dictelm_t xbt_dictelm_new(const char *key, int key_len,
+xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len,
unsigned int hash_code, void *content,
void_f_pvoid_t free_f);
-xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code,
- uintptr_t content);
-void xbt_dictelm_free(xbt_dictelm_t element);
-void xbt_dict_add_element(xbt_dict_t dict, xbt_dictelm_t element);
+void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element);
+void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element,
+ void *data, void_f_pvoid_t free_ctn);
#endif /* _XBT_DICT_PRIVATE_H_ */
/* 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 "portable.h" /* SIZEOF_MAX */
#include "xbt/misc.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
static void _dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op);
static XBT_INLINE
- void _xbt_clear_mem(void *const ptr, const unsigned long length)
+void _xbt_dynar_resize(xbt_dynar_t dynar, unsigned long new_size)
{
- memset(ptr, 0, length);
+ if (new_size != dynar->size) {
+ dynar->size = new_size;
+ dynar->data = xbt_realloc(dynar->data, new_size * dynar->elmsize);
+ }
}
static XBT_INLINE
const unsigned long old_size = dynar->size;
if (nb > old_size) {
- void *const old_data = dynar->data;
- const unsigned long elmsize = dynar->elmsize;
- const unsigned long old_length = old_size * elmsize;
-
const unsigned long expand = 2 * (old_size + 1);
- const unsigned long new_size = (nb > expand ? nb : expand);
- const unsigned long new_length = new_size * elmsize;
- void *const new_data = xbt_realloc(old_data, new_length);
-
- XBT_DEBUG("expand %p from %lu to %lu elements", dynar, old_size, new_size);
-
- _xbt_clear_mem((char *)new_data + old_length, new_length - old_length);
-
- dynar->size = new_size;
- dynar->data = new_data;
+ _xbt_dynar_resize(dynar, (nb > expand ? nb : expand));
+ XBT_DEBUG("expand %p from %lu to %lu elements",
+ dynar, old_size, dynar->size);
}
}
if (object) {
_xbt_dynar_get_elm(object, dynar, idx);
} else if (dynar->free_f) {
- if (dynar->elmsize <= SIZEOF_MAX) {
- char elm[SIZEOF_MAX];
- _xbt_dynar_get_elm(elm, dynar, idx);
- dynar->free_f(elm);
- } else {
- char *elm = malloc(dynar->elmsize);
- _xbt_dynar_get_elm(elm, dynar, idx);
- dynar->free_f(elm);
- free(elm);
- }
+ dynar->free_f(_xbt_dynar_elm(dynar, idx));
}
nb_shift = dynar->used - 1 - idx;
void xbt_dynar_free_container(xbt_dynar_t * dynar)
{
if (dynar && *dynar) {
-
- if ((*dynar)->data) {
- _xbt_clear_mem((*dynar)->data, (*dynar)->size);
- free((*dynar)->data);
- }
-
- if ((*dynar)->mutex)
- xbt_mutex_destroy((*dynar)->mutex);
-
- _xbt_clear_mem(*dynar, sizeof(s_xbt_dynar_t));
-
- free(*dynar);
+ xbt_dynar_t d = *dynar;
+ free(d->data);
+ if (d->mutex)
+ xbt_mutex_destroy(d->mutex);
+ free(d);
*dynar = NULL;
}
}
if (dynar->free_f) {
_dynar_map(dynar, dynar->free_f);
}
- /*
- free(dynar->data);
-
- dynar->size = 0;
- */
dynar->used = 0;
_dynar_unlock(dynar);
-
- /* dynar->data = NULL; */
}
/**
*/
void xbt_dynar_shrink(xbt_dynar_t dynar, int empty_slots_wanted)
{
- unsigned long size_wanted;
-
_dynar_lock(dynar);
-
- size_wanted = dynar->used + empty_slots_wanted;
- if (size_wanted != dynar->size) {
- dynar->size = size_wanted;
- dynar->data = xbt_realloc(dynar->data, dynar->elmsize * dynar->size);
- }
+ _xbt_dynar_resize(dynar, dynar->used + empty_slots_wanted);
_dynar_unlock(dynar);
}
return res;
}
-XBT_INLINE void *xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
- const unsigned long idx)
+/* not synchronized */
+static XBT_INLINE void *_xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
+ const unsigned long idx)
{
-
- void *res;
- _dynar_lock(dynar);
_sanity_check_dynar(dynar);
- _xbt_dynar_expand(dynar, idx + 1);
-
if (idx >= dynar->used) {
- _xbt_clear_mem(((char * const)dynar->data) + dynar->used * dynar->elmsize,
- (idx + 1 - dynar->used)*dynar->elmsize);
+ _xbt_dynar_expand(dynar, idx + 1);
+ if (idx > dynar->used) {
+ memset(_xbt_dynar_elm(dynar, dynar->used), 0,
+ (idx - dynar->used) * dynar->elmsize);
+ }
dynar->used = idx + 1;
}
-
- _dynar_unlock(dynar);
-
- res = _xbt_dynar_elm(dynar, idx);
+ return _xbt_dynar_elm(dynar, idx);
+}
+XBT_INLINE void *xbt_dynar_set_at_ptr(const xbt_dynar_t dynar,
+ const unsigned long idx)
+{
+ void *res;
+ _dynar_lock(dynar);
+ res = _xbt_dynar_set_at_ptr(dynar, idx);
+ _dynar_unlock(dynar);
return res;
}
_xbt_dynar_set(xbt_dynar_t dynar,
const unsigned long idx, const void *const src)
{
-
- _sanity_check_dynar(dynar);
-
- _xbt_dynar_expand(dynar, idx + 1);
-
- if (idx >= dynar->used) {
- _xbt_clear_mem(((char * const)dynar->data) + dynar->used * dynar->elmsize,
- (idx + 1 - dynar->used)*dynar->elmsize);
- dynar->used = idx + 1;
- }
-
- _xbt_dynar_put_elm(dynar, idx, src);
+ memcpy(_xbt_dynar_set_at_ptr(dynar, idx), src, dynar->elmsize);
}
/** @brief Set the Nth element of a dynar (expanded if needed). Previous value at this position is NOT freed
*/
XBT_INLINE void * xbt_dynar_to_array (xbt_dynar_t dynar)
{
- void * res;
- void * last = xbt_new0(char,dynar->elmsize);
- xbt_dynar_push(dynar, last);
- free(last);
- res = dynar->data;
- free(dynar);
- return res;
+ void *res;
+ xbt_dynar_shrink(dynar, 1);
+ memset(xbt_dynar_push_ptr(dynar), 0, dynar->elmsize);
+ res = dynar->data;
+ if (dynar->mutex)
+ xbt_mutex_destroy(dynar->mutex);
+ free(dynar);
+ return res;
}
/*
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_fifo, xbt, "FIFO");
static void *fifo_item_mallocator_new_f(void);
-static void fifo_item_mallocator_free_f(void *item);
+#define fifo_item_mallocator_free_f xbt_free_f
static void fifo_item_mallocator_reset_f(void *item);
static xbt_mallocator_t item_mallocator = NULL;
return xbt_new(s_xbt_fifo_item_t, 1);
}
-static void fifo_item_mallocator_free_f(void *item)
-{
- xbt_free(item);
-}
-
static void fifo_item_mallocator_reset_f(void *item)
{
/* memset to zero like calloc */
else
parsed_graph = xbt_graph_new_graph(0, NULL);
- parsed_nodes = xbt_dict_new();
+ parsed_nodes = xbt_dict_new_homogeneous(NULL);
}
static void __parse_graph_end(void)
file = fopen (filename, "r");
xbt_assert(file, "Failed to open %s \n", filename);
- xbt_dict_t nodes_dict = xbt_dict_new ();
+ xbt_dict_t nodes_dict = xbt_dict_new_homogeneous(NULL);
xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
//read the number of nodes
{
xbt_lib_t lib;
lib = xbt_new(s_xbt_lib_t, 1);
- lib->dict = xbt_dict_new();
+ lib->dict = xbt_dict_new_homogeneous(xbt_free);
lib->levels = 0;
lib->free_f = NULL;
return lib;
void **elts = xbt_dict_get_or_null(lib->dict, key);
if (!elts) {
elts = xbt_new0(void *, lib->levels);
- xbt_dict_set(lib->dict, key, elts, xbt_free);
+ xbt_dict_set(lib->dict, key, elts, NULL);
}
if (elts[level]) {
XBT_DEBUG("Replace %p by %p element under key '%s:%d'",
typedef struct {
char *catname;
- e_xbt_log_priority_t thresh;
char *fmt;
+ e_xbt_log_priority_t thresh;
int additivity;
xbt_log_appender_t appender;
} s_xbt_log_setting_t, *xbt_log_setting_t;
* in \a xbt_mallocator_release() when the stack is full, and when
* the mallocator is freed.
* \param reset_f function to reinitialise an object of your datatype, called
- * when you extract an object from the mallocator
+ * when you extract an object from the mallocator (can be NULL)
*
* Create and initialize a new mallocator for a given datatype.
*
xbt_mallocator_t m;
xbt_assert(size > 0, "size must be positive");
- xbt_assert(new_f != NULL && free_f != NULL
- && reset_f != NULL, "invalid parameter");
+ xbt_assert(new_f != NULL && free_f != NULL, "invalid parameter");
m = xbt_new0(s_xbt_mallocator_t, 1);
XBT_VERB("Create mallocator %p", m);
* If the mallocator is empty, a new object is created,
* by calling the function new_f().
*
- * In both cases, the function reset_f() is called on the object.
+ * In both cases, the function reset_f() (if defined) is called on the object.
*
* \see xbt_mallocator_release()
*/
object = m->new_f();
}
- m->reset_f(object);
+ if (m->reset_f)
+ m->reset_f(object);
return object;
}
#define _XBT_MALLOCATOR_PRIVATE_H__
typedef struct s_xbt_mallocator {
- int current_size; /* number of objects currently stored */
void **objects; /* objects stored by the mallocator and available for the user */
+ int current_size; /* number of objects currently stored */
int max_size; /* maximum number of objects */
pvoid_f_void_t new_f; /* function to call when we are running out of objects */
void_f_pvoid_t free_f; /* function to call when we have got too many objects */
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "gras_config.h"
#include <unistd.h>
+
#ifndef _XBT_WIN32
#include <sys/syscall.h>
#endif
#ifdef HAVE_FUTEX_H
- #include <linux/futex.h>
-#else
- #include "xbt/xbt_os_thread.h"
+#include <linux/futex.h>
#endif
-#include <errno.h>
-#include "parmap_private.h"
+
+#include "xbt/parmap.h"
+#include "xbt/log.h"
+#include "xbt/function_types.h"
+#include "xbt/dynar.h"
+#include "xbt/xbt_os_thread.h"
+#include "xbt/sysdep.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_parmap, xbt, "parmap: parallel map");
XBT_LOG_NEW_SUBCATEGORY(xbt_parmap_unit, xbt_parmap, "parmap unit testing");
-static void *_xbt_parmap_worker_main(void *parmap);
+typedef enum {
+ PARMAP_WORK = 0,
+ PARMAP_DESTROY
+} e_xbt_parmap_flag_t;
+
+static void xbt_parmap_start(xbt_parmap_t parmap);
+static void xbt_parmap_signal(xbt_parmap_t parmap);
+static void xbt_parmap_wait(xbt_parmap_t parmap);
+static void xbt_parmap_end(xbt_parmap_t parmap);
+static void *xbt_parmap_worker_main(void *parmap);
+
#ifdef HAVE_FUTEX_H
- static void futex_wait(int *uaddr, int val);
- static void futex_wake(int *uaddr, int val);
+static void futex_wait(int *uaddr, int val);
+static void futex_wake(int *uaddr, int val);
#endif
+
+/**
+ * \brief Parallel map structure
+ */
+typedef struct s_xbt_parmap {
+ e_xbt_parmap_flag_t status; /* is the parmap active or being destroyed? */
+
+ int work; /* index of the current round (1 is the first) */
+ int done; /* number of rounds already done */
+ unsigned int thread_counter; /* number of threads currently working */
+ unsigned int num_workers; /* total number of worker threads */
+ unsigned int workers_max_id; /* id of the next worker thread to create */
+ void_f_pvoid_t fun; /* function to run in parallel on each element of data */
+ xbt_dynar_t data; /* parameters to pass to fun in parallel */
+ unsigned int index; /* index of the next element of data to pick */
+} s_xbt_parmap_t;
+
+/**
+ * \brief Creates a parallel map object
+ * \param num_workers number of worker threads to create
+ * \return the parmap created
+ */
xbt_parmap_t xbt_parmap_new(unsigned int num_workers)
{
unsigned int i;
/* Initialize the thread pool data structure */
xbt_parmap_t parmap = xbt_new0(s_xbt_parmap_t, 1);
-#ifdef HAVE_FUTEX_H
- parmap->sync_event = xbt_new0(s_xbt_event_t, 1);
-#endif
+
parmap->num_workers = num_workers;
parmap->status = PARMAP_WORK;
-#ifdef HAVE_FUTEX_H
- parmap->sync_event->threads_to_wait = num_workers;
-#endif
+
/* Create the pool of worker threads */
- for(i=0; i < num_workers; i++){
- worker = xbt_os_thread_create(NULL, _xbt_parmap_worker_main, parmap, NULL);
+ for (i = 0; i < num_workers; i++) {
+ worker = xbt_os_thread_create(NULL, xbt_parmap_worker_main, parmap, NULL);
xbt_os_thread_detach(worker);
}
-#ifdef HAVE_FUTEX_H
- xbt_event_init(parmap->sync_event);
-#endif
+ xbt_parmap_start(parmap);
return parmap;
}
+/**
+ * \brief Destroys a parmap
+ * \param parmap the parmap to destroy
+ */
void xbt_parmap_destroy(xbt_parmap_t parmap)
-{
+{
parmap->status = PARMAP_DESTROY;
-#ifdef HAVE_FUTEX_H
- xbt_event_signal(parmap->sync_event);
- xbt_free(parmap->sync_event);
-#endif
+ xbt_parmap_signal(parmap);
xbt_free(parmap);
}
- void xbt_parmap_apply(xbt_parmap_t parmap, void_f_pvoid_t fun, xbt_dynar_t data)
+/**
+ * \brief Applies a list of tasks in parallel.
+ * \param parmap a parallel map object
+ * \param fun the function to call in parallel
+ * \param data each element of this dynar will be passed as an argument to fun
+ */
+void xbt_parmap_apply(xbt_parmap_t parmap, void_f_pvoid_t fun, xbt_dynar_t data)
{
/* Assign resources to worker threads*/
parmap->fun = fun;
parmap->data = data;
parmap->index = 0;
-#ifdef HAVE_FUTEX_H
- xbt_event_signal(parmap->sync_event);
-#endif
+ xbt_parmap_signal(parmap);
XBT_DEBUG("Job done");
}
-void* xbt_parmap_next(xbt_parmap_t parmap) {
-
+/**
+ * \brief Returns a next task to process.
+ *
+ * Worker threads call this function to get more work.
+ *
+ * \return the next task to process, or NULL if there is no more work
+ */
+void* xbt_parmap_next(xbt_parmap_t parmap)
+{
unsigned int index = __sync_fetch_and_add(&parmap->index, 1);
if (index < xbt_dynar_length(parmap->data)) {
return xbt_dynar_get_as(parmap->data, index, void*);
return NULL;
}
-unsigned long xbt_parmap_get_worker_id(xbt_parmap_t parmap) {
+/**
+ * \brief Returns the worker id of the current thread.
+ * \param parmap a parmap
+ * \return the worker id
+ */
+unsigned long xbt_parmap_get_worker_id(xbt_parmap_t parmap)
+{
return (unsigned long) xbt_os_thread_get_extra_data();
}
-static void *_xbt_parmap_worker_main(void *arg)
+/**
+ * \brief Main function of a worker thread.
+ * \param arg the parmap
+ */
+static void *xbt_parmap_worker_main(void *arg)
{
unsigned int worker_id;
xbt_parmap_t parmap = (xbt_parmap_t) arg;
/* Worker's main loop */
while (1) {
-#ifdef HAVE_FUTEX_H
- xbt_event_wait(parmap->sync_event);
-#endif
+ xbt_parmap_wait(parmap);
if (parmap->status == PARMAP_WORK) {
XBT_DEBUG("Worker %u got a job", worker_id);
/* We are destroying the parmap */
} else {
-#ifdef HAVE_FUTEX_H
- xbt_event_end(parmap->sync_event);
-#endif
+ xbt_parmap_end(parmap);
XBT_DEBUG("Shutting down worker %u", worker_id);
return NULL;
}
XBT_VERB("Waking futex %p", uaddr);
syscall(SYS_futex, uaddr, FUTEX_WAKE_PRIVATE, val, NULL, NULL, 0);
}
+#endif
-void xbt_event_init(xbt_event_t event)
+/**
+ * \brief Starts the parmap: waits for all workers to be ready and returns.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_start(xbt_parmap_t parmap)
{
- int myflag = event->done;
- if(event->thread_counter < event->threads_to_wait)
- futex_wait(&event->done, myflag);
+#ifdef HAVE_FUTEX_H
+ int myflag = parmap->done;
+ if (parmap->thread_counter < parmap->num_workers) {
+ /* wait for all workers to be ready */
+ futex_wait(&parmap->done, myflag);
+ }
+#endif
}
-void xbt_event_signal(xbt_event_t event)
+/**
+ * \brief Wakes all workers and waits for them to finish the tasks.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_signal(xbt_parmap_t parmap)
{
- int myflag = event->done;
- event->thread_counter = 0;
- event->work++;
- futex_wake(&event->work, event->threads_to_wait);
- futex_wait(&event->done, myflag);
+#ifdef HAVE_FUTEX_H
+ int myflag = parmap->done;
+ parmap->thread_counter = 0;
+ parmap->work++;
+
+ /* wake all workers */
+ futex_wake(&parmap->work, parmap->num_workers);
+
+ /* wait for all of them to finish */
+ futex_wait(&parmap->done, myflag);
+#endif
}
-void xbt_event_wait(xbt_event_t event)
+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker when it has no more work to do.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_wait(xbt_parmap_t parmap)
{
+#ifdef HAVE_FUTEX_H
int myflag;
unsigned int mycount;
- myflag = event->work;
- mycount = __sync_add_and_fetch(&event->thread_counter, 1);
- if(mycount == event->threads_to_wait){
- event->done++;
- futex_wake(&event->done, 1);
+ myflag = parmap->work;
+ mycount = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (mycount == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ parmap->done++;
+ futex_wake(&parmap->done, 1);
}
- futex_wait(&event->work, myflag);
+ /* wait for more work */
+ futex_wait(&parmap->work, myflag);
+#endif
}
-void xbt_event_end(xbt_event_t event)
+/**
+ * \brief Ends the parmap: wakes the controller thread when all workers terminate.
+ *
+ * This function is called by all worker threads when they end.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_end(xbt_parmap_t parmap)
{
+#ifdef HAVE_FUTEX_H
unsigned int mycount;
- mycount = __sync_add_and_fetch(&event->thread_counter, 1);
- if(mycount == event->threads_to_wait){
- event->done++;
- futex_wake(&event->done, 1);
+ mycount = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (mycount == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ parmap->done++;
+ futex_wake(&parmap->done, 1);
}
-}
#endif
+}
#ifdef SIMGRID_TEST
#include "xbt.h"
XBT_TEST_SUITE("parmap", "Parallel Map");
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_parmap_unit);
-
-
xbt_parmap_t parmap;
void fun(void *arg);
{
xbt_test_add("Create the parmap");
- unsigned long i,j;
+ unsigned long i, j;
xbt_dynar_t data = xbt_dynar_new(sizeof(void *), NULL);
/* Create the parallel map */
parmap = xbt_parmap_new(10);
- for(j=0; j < 100; j++){
+ for(j = 0; j < 100; j++) {
xbt_dynar_push_as(data, void *, (void *)j);
}
- for(i=0; i < 5; i++)
+ for (i = 0; i < 5; i++) {
xbt_parmap_apply(parmap, fun, data);
+ }
/* Destroy the parmap */
xbt_parmap_destroy(parmap);
+++ /dev/null
-/* Copyright (c) 2004, 2005, 2007, 2009, 2010. 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. */
-
-#ifndef _XBT_THREADPOOL_PRIVATE_H
-#define _XBT_THREADPOOL_PRIVATE_H
-
-#include "xbt/parmap.h"
-#include "xbt/xbt_os_thread.h"
-#include "xbt/sysdep.h"
-#include "xbt/dynar.h"
-#include "xbt/log.h"
-#include "xbt/xbt_os_time.h"
-
-typedef enum{
- PARMAP_WORK = 0,
- PARMAP_DESTROY
-} e_xbt_parmap_flag_t;
-
-#ifdef HAVE_FUTEX_H
-typedef struct s_xbt_event{
- int work;
- int done;
- unsigned int thread_counter;
- unsigned int threads_to_wait;
-}s_xbt_event_t, *xbt_event_t;
-
-void xbt_event_init(xbt_event_t event);
-void xbt_event_signal(xbt_event_t event);
-void xbt_event_wait(xbt_event_t event);
-void xbt_event_end(xbt_event_t event);
-#endif
-
-typedef struct s_xbt_parmap {
- e_xbt_parmap_flag_t status;
-#ifdef HAVE_FUTEX_H
- xbt_event_t sync_event;
-#endif
- unsigned int num_workers;
- unsigned int workers_max_id;
- void_f_pvoid_t fun;
- xbt_dynar_t data;
- unsigned int index;
-} s_xbt_parmap_t;
-
-#endif
*
* \param set set to populate
* \param elm element to add.
- * \param free_func How to add the data
+ * \param free_func how to free the data
*
* elm->name must be set;
* if elm->name_len <= 0, it is recomputed. If >0, it's used as is;
-/* $Id: buff.c 3483 2007-05-07 11:18:56Z mquinson $ */
-
/* strbuff -- string buffers */
/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
char *str; /*foreach */
xbt_strbuff_t sb; /* what we test */
- p = xbt_dict_new();
+ p = xbt_dict_new_homogeneous(free);
dyn_patterns = xbt_str_split(patterns, " ");
xbt_dynar_foreach(dyn_patterns, cpt, str) {
xbt_dynar_t keyvals = xbt_str_split(str, "=");
char *key = xbt_dynar_get_as(keyvals, 0, char *);
char *val = xbt_dynar_get_as(keyvals, 1, char *);
xbt_str_subst(key, '_', ' ', 0); // to put space in names without breaking the enclosing dynar_foreach
- xbt_dict_set(p, key, xbt_strdup(val), free);
+ xbt_dict_set(p, key, xbt_strdup(val), NULL);
xbt_dynar_free(&keyvals);
}
xbt_dynar_free(&dyn_patterns);
-/* $Id: gras.c 3859 2007-07-18 12:29:51Z donassbr $ */
-
/* empty_main.c -- check what happens when the processes do nothing */
/* Thanks to Loris Marshal for reporting a problem in that case */
-/* $Id: mmrpc.c 3399 2007-04-11 19:34:43Z cherierm $ */
-
/* msg_handle - ensures the semantic of gras_msg_handle(i) for i<0,=0 or >0 */
/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
-/* $Id: gras.c 3859 2007-07-18 12:29:51Z donassbr $ */
-
/* small_sleep.c -- check what happens when the processes do sleeps very shortly*/
/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
-/* $Id$ */
-
/* gras_stub_generator - creates the main() to use a GRAS program */
/* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
static void parse_process_init(void)
{
- xbt_dict_set(process_function_set, A_surfxml_process_function, NULL,
- NULL);
+ xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
process.argc = 1;
process.argv = xbt_new(char *, 1);
int i;
surf_init(&argc, argv);
- process_function_set = xbt_dict_new();
+ process_function_set = xbt_dict_new_homogeneous(NULL);
process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
- machine_set = xbt_dict_new();
+ machine_set = xbt_dict_new_homogeneous(NULL);
for (i = 1; i < argc; i++) {
int need_removal = 0;
-/* $Id$ */
-
/* gras_stub_generator - creates the main() to use a GRAS program */
/* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
-/* $Id$ */
-
/* gras_stub_generator - creates the main() to use a GRAS program */
/* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
rctx->cmd = xbt_strdup(line);
rctx->filepos = xbt_strdup(filepos);
- if(option){
- rctx->cmd = bprintf("%s %s",rctx->cmd,option);
+ if (option){
+ char *newcmd = bprintf("%s %s", rctx->cmd, option);
+ free(rctx->cmd);
+ rctx->cmd = newcmd;
}
XBT_INFO("[%s] %s%s", filepos, rctx->cmd,
((rctx->is_background) ? " (background command)" : ""));
int len = strlen("setenv ");
char *eq = strchr(line + len, '=');
char *key = bprintf("%.*s", (int) (eq - line - len), line + len);
- xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
+ xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL);
free(key);
rctx->env = realloc(rctx->env, ++(rctx->env_size) * sizeof(char *));
int child_out[2];
XBT_DEBUG("Cmd before rewriting %s", rctx->cmd);
- rctx->cmd = xbt_str_varsubst(rctx->cmd, env);
+ char *newcmd = xbt_str_varsubst(rctx->cmd, env);
+ free(rctx->cmd);
+ rctx->cmd = newcmd;
XBT_VERB("Start %s %s", rctx->cmd,
(rctx->is_background ? "(background job)" : ""));
xbt_os_mutex_acquire(armageddon_mutex);
/* Helper function to sort the output */
static int cmpstringp(const void *p1, const void *p2) {
- /* Sort only using the 19 first chars (date+pid)
- * If the dates are the same, then, sort using pointer address (be stable wrt output of each process)
+ /* Sort only using the sort_len first chars
+ * If they are the same, then, sort using pointer address
+ * (be stable wrt output of each process)
*/
- const char *s1 = *((const char**) p1);
- const char *s2 = *((const char**) p2);
+ const char **s1 = *(const char***)p1;
+ const char **s2 = *(const char***)p2;
- XBT_DEBUG("Compare strings '%s' and '%s'", s1, s2);
+ XBT_DEBUG("Compare strings '%s' and '%s'", *s1, *s2);
- int res = strncmp(s1, s2, sort_len);
+ int res = strncmp(*s1, *s2, sort_len);
if (res == 0)
- return p1>p2;
+ res = s1 > s2 ? 1 : (s1 < s2 ? -1 : 0);
return res;
}
+static void stable_sort(xbt_dynar_t a)
+{
+ unsigned long len = xbt_dynar_length(a);
+ void **b = xbt_new(void*, len);
+ unsigned long i;
+ for (i = 0 ; i < len ; i++) /* fill the array b with pointers to strings */
+ b[i] = xbt_dynar_get_ptr(a, i);
+ qsort(b, len, sizeof *b, cmpstringp); /* sort it */
+ for (i = 0 ; i < len ; i++) /* dereference the pointers to get the strings */
+ b[i] = *(char**)b[i];
+ for (i = 0 ; i < len ; i++) /* put everything in place */
+ xbt_dynar_set_as(a, i, char*, b[i]);
+ xbt_free(b);
+}
/* Waits for the child to end (or to timeout), and check its
ending conditions. This is launched from rctx_start but either in main
}
if (rctx->output_sort) {
- xbt_dynar_sort(b, cmpstringp);
+ stable_sort(b);
/* If empty lines moved in first position, remove them */
while (!xbt_dynar_is_empty(b) && *xbt_dynar_getfirst_as(b, char*) == '\0')
xbt_dynar_shift(b, NULL);
int i;
char *eq = NULL;
char *key = NULL;
- env = xbt_dict_new();
+ env = xbt_dict_new_homogeneous(xbt_free_f);
for (i = 0; environ[i]; i++) {
p = environ[i];
eq = strchr(p, '=');
key = bprintf("%.*s", (int) (eq - p), p);
- xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
+ xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL);
free(key);
}
}
char *eq = strchr(argv[i+1], '=');
xbt_assert(eq,"The argument of --setenv must contain a '=' (got %s instead)",argv[i+1]);
char *key = bprintf("%.*s", (int) (eq - argv[i+1]), argv[i+1]);
- xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
+ xbt_dict_set(env, key, xbt_strdup(eq + 1), NULL);
XBT_INFO("setting environment variable '%s' to '%s'", key, eq+1);
free(key);
memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
XBT_ERROR("--cfg argument requires an argument");
exit(1);
}
- if(!option){ //if option is NULL
+ if (!option){ //if option is NULL
option = bprintf("--cfg=%s",argv[i+1]);
- }else{
- option = bprintf("%s --cfg=%s",option,argv[i+1]);
+ } else {
+ char *newoption = bprintf("%s --cfg=%s", option, argv[i+1]);
+ free(option);
+ option = newoption;
}
XBT_INFO("Add option \'--cfg=%s\' to command line",argv[i+1]);
memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
rctx_exit();
xbt_dict_free(&env);
- xbt_free_f(option);
+ free(option);
return 0;
}