From 0f5e8daaa6e9f74521068aa75837200bcd182ea6 Mon Sep 17 00:00:00 2001 From: alegrand Date: Mon, 11 Oct 2010 09:48:30 +0000 Subject: [PATCH] Indent include and src using this command: indent -kr -br -brs -ce -bbo --dont-break-procedure-type --no-tabs --cuddle-do-while --cuddle-else --indent-level2 --leave-preprocessor-space --no-space-after-function-call-names I also had to play with fromdos and to check that sg_unit_extractor.pl did not get fooled by XBT_TEST_UNIT lines splitted in half by indent. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8394 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/amok/bandwidth.h | 12 +- include/amok/base.h | 2 +- include/amok/peermanagement.h | 2 +- include/gras.h | 2 +- include/gras/datadesc.h | 119 +- include/gras/emul.h | 2 +- include/gras/messages.h | 68 +- include/gras/module.h | 5 +- include/gras/process.h | 6 +- include/gras/timer.h | 2 +- include/gras/transport.h | 4 +- include/gras/virtu.h | 18 +- include/instr/instr.h | 45 +- include/mc/modelchecker.h | 2 +- include/msg/datatypes.h | 78 +- include/msg/msg.h | 84 +- include/simdag/datatypes.h | 6 +- include/simdag/simdag.h | 43 +- include/smpi/smpi.h | 255 +- include/surf/simgrid_dtd.h | 2 +- include/surf/surfxml_parse.h | 26 +- include/xbt.h | 2 +- include/xbt/asserts.h | 4 +- include/xbt/config.h | 47 +- include/xbt/cunit.h | 18 +- include/xbt/dict.h | 27 +- include/xbt/dynar.h | 55 +- include/xbt/ex.h | 63 +- include/xbt/fifo.h | 12 +- include/xbt/function_types.h | 18 +- include/xbt/graph.h | 41 +- include/xbt/graphxml.h | 2 +- include/xbt/graphxml_parse.h | 2 +- include/xbt/hash.h | 2 +- include/xbt/heap.h | 12 +- include/xbt/log.h | 102 +- include/xbt/mallocator.h | 4 +- include/xbt/matrix.h | 17 +- include/xbt/misc.h | 8 +- include/xbt/mmalloc.h | 36 +- include/xbt/module.h | 2 +- include/xbt/peer.h | 10 +- include/xbt/queue.h | 11 +- include/xbt/set.h | 19 +- include/xbt/setset.h | 13 +- include/xbt/str.h | 8 +- include/xbt/strbuff.h | 3 +- include/xbt/swag.h | 32 +- include/xbt/synchro.h | 6 +- include/xbt/synchro_core.h | 10 +- include/xbt/sysdep.h | 18 +- include/xbt/virtu.h | 6 +- include/xbt/win32_ucontext.h | 51 +- src/amok/Bandwidth/bandwidth.c | 64 +- src/amok/Bandwidth/bandwidth_private.h | 2 +- src/amok/Bandwidth/saturate.c | 14 +- src/amok/PeerManagement/peermanagement.c | 21 +- src/amok/amok_modinter.h | 2 +- src/bindings/lua/lua_stub_generator.c | 46 +- src/bindings/lua/simgrid_lua.c | 1662 ++++----- src/bindings/ruby/rb_application_handler.c | 131 +- src/bindings/ruby/rb_msg_host.c | 79 +- src/bindings/ruby/rb_msg_process.c | 142 +- src/bindings/ruby/rb_msg_task.c | 164 +- src/bindings/ruby/simgrid_ruby.c | 213 +- src/bindings/rubyDag/rb_SD_task.c | 161 +- src/bindings/rubyDag/rb_SD_task.h | 32 +- src/bindings/rubyDag/rb_SD_workstation.c | 30 +- src/bindings/rubyDag/rb_SD_workstation.h | 4 +- src/bindings/rubyDag/rb_simdag.c | 139 +- src/bindings/ruby_bindings.h | 95 +- src/config_unit.c | 17 +- src/cunit_unit.c | 2 +- src/dict_unit.c | 62 +- src/dynar_unit.c | 119 +- src/ex_unit.c | 2 +- src/gras/DataDesc/cbps.c | 6 +- src/gras/DataDesc/datadesc.c | 22 +- src/gras/DataDesc/datadesc_interface.h | 16 +- src/gras/DataDesc/datadesc_private.h | 2 +- src/gras/DataDesc/ddt_convert.c | 25 +- src/gras/DataDesc/ddt_create.c | 107 +- src/gras/DataDesc/ddt_exchange.c | 126 +- src/gras/DataDesc/ddt_parse.c | 113 +- src/gras/Msg/gras_msg_exchange.c | 53 +- src/gras/Msg/gras_msg_listener.c | 33 +- src/gras/Msg/gras_msg_mod.c | 12 +- src/gras/Msg/gras_msg_types.c | 26 +- src/gras/Msg/msg_interface.h | 2 +- src/gras/Msg/msg_private.h | 4 +- src/gras/Msg/rl_msg.c | 20 +- src/gras/Msg/rpc.c | 32 +- src/gras/Msg/sg_msg.c | 74 +- src/gras/Msg/timer.c | 19 +- src/gras/Transport/rl_transport.c | 15 +- src/gras/Transport/sg_transport.c | 6 +- src/gras/Transport/transport.c | 53 +- src/gras/Transport/transport_interface.h | 93 +- src/gras/Transport/transport_plugin_file.c | 10 +- src/gras/Transport/transport_plugin_sg.c | 63 +- src/gras/Transport/transport_plugin_tcp.c | 50 +- src/gras/Transport/transport_private.h | 2 +- src/gras/Virtu/gras_module.c | 7 +- src/gras/Virtu/process.c | 19 +- src/gras/Virtu/rl_emul.c | 7 +- src/gras/Virtu/rl_process.c | 31 +- src/gras/Virtu/sg_dns.c | 20 +- src/gras/Virtu/sg_emul.c | 19 +- src/gras/Virtu/sg_process.c | 89 +- src/gras/Virtu/virtu_interface.h | 14 +- src/gras/Virtu/virtu_private.h | 2 +- src/gras/Virtu/virtu_rl.h | 2 +- src/gras/Virtu/virtu_sg.h | 10 +- src/gras_modinter.h | 2 +- src/include/mc/datatypes.h | 3 +- src/include/mc/mc.h | 7 +- src/include/simix/context.h | 31 +- src/include/simix/datatypes.h | 56 +- src/include/simix/simix.h | 105 +- src/include/surf/datatypes.h | 2 +- src/include/surf/maxmin.h | 70 +- src/include/surf/random_mgr.h | 16 +- src/include/surf/surf.h | 463 +-- src/include/surf/surf_resource.h | 21 +- src/include/surf/surf_resource_lmm.h | 38 +- src/include/surf/trace_mgr.h | 13 +- src/include/xbt/wine_dbghelp.h | 117 +- src/include/xbt/xbt_os_thread.h | 16 +- src/include/xbt/xbt_os_time.h | 2 +- src/instr/categories.c | 32 +- src/instr/general.c | 90 +- src/instr/instr_config.c | 32 +- src/instr/interface.c | 222 +- src/instr/msg_process_instr.c | 161 +- src/instr/msg_task_instr.c | 189 +- src/instr/msg_volume.c | 68 +- src/instr/paje.c | 173 +- src/instr/private.h | 247 +- src/instr/resource_utilization.c | 482 +-- src/instr/sd_instr.c | 20 +- src/instr/smpi_instr.c | 125 +- src/instr/smx_instr.c | 45 +- src/instr/surf_instr.c | 232 +- src/instr/variables_instr.c | 56 +- src/java/jmsg.c | 218 +- src/java/jmsg.h | 82 +- src/java/jmsg_application_handler.c | 66 +- src/java/jmsg_application_handler.h | 6 +- src/java/jmsg_host.h | 2 +- src/java/jmsg_process.c | 24 +- src/java/jmsg_process.h | 2 +- src/java/jmsg_task.h | 2 +- src/java/jxbt_utilities.c | 86 +- src/java/jxbt_utilities.h | 10 +- src/mc/mc_checkpoint.c | 10 +- src/mc/mc_dfs.c | 99 +- src/mc/mc_dpor.c | 153 +- src/mc/mc_global.c | 149 +- src/mc/mc_memory.c | 83 +- src/mc/mc_transition.c | 164 +- src/mc/memory_map.c | 118 +- src/mc/private.h | 52 +- src/msg/deployment.c | 5 +- src/msg/environment.c | 24 +- src/msg/global.c | 6 +- src/msg/gos.c | 951 ++--- src/msg/m_process.c | 25 +- src/msg/mailbox.h | 23 +- src/msg/msg_actions.c | 84 +- src/msg/msg_mailbox.c | 118 +- src/msg/private.h | 142 +- src/msg/task.c | 38 +- src/portable.h | 28 +- src/set_unit.c | 12 +- src/simdag/dax_dtd.c | 4 +- src/simdag/dax_dtd.h | 2 +- src/simdag/dax_dtd.l | 4 +- src/simdag/private.h | 13 +- src/simdag/sd_daxloader.c | 231 +- src/simdag/sd_dotloader.c | 386 ++- src/simdag/sd_global.c | 125 +- src/simdag/sd_link.c | 4 +- src/simdag/sd_task.c | 390 ++- src/simdag/sd_workstation.c | 74 +- src/simgrid_units_main.c | 10 +- src/simix/private.h | 104 +- src/simix/smx_action.c | 93 +- src/simix/smx_context.c | 87 +- src/simix/smx_context_base.c | 24 +- src/simix/smx_context_java.c | 23 +- src/simix/smx_context_java.h | 8 +- src/simix/smx_context_lua.c | 55 +- src/simix/smx_context_private.h | 11 +- src/simix/smx_context_ruby.c | 64 +- src/simix/smx_context_sysv.c | 106 +- src/simix/smx_context_sysv_private.h | 19 +- src/simix/smx_context_thread.c | 53 +- src/simix/smx_deployment.c | 45 +- src/simix/smx_environment.c | 2 +- src/simix/smx_global.c | 83 +- src/simix/smx_host.c | 17 +- src/simix/smx_network.c | 295 +- src/simix/smx_process.c | 35 +- src/simix/smx_synchro.c | 106 +- src/smpi/private.h | 141 +- src/smpi/sample/reduce.c | 13 +- src/smpi/smpi_base.c | 381 +- src/smpi/smpi_bench.c | 290 +- src/smpi/smpi_coll.c | 219 +- src/smpi/smpi_comm.c | 15 +- src/smpi/smpi_global.c | 89 +- src/smpi/smpi_group.c | 60 +- src/smpi/smpi_mpi.c | 850 +++-- src/smpi/smpi_mpi_dt.c | 436 ++- src/surf/cpu.c | 93 +- src/surf/cpu_im.c | 151 +- src/surf/cpu_ti.c | 293 +- src/surf/cpu_ti_private.h | 2 +- src/surf/fair_bottleneck.c | 16 +- src/surf/gtnets/gtnets_interface.h | 2 +- src/surf/gtnets/gtnets_simulator.h | 19 +- src/surf/gtnets/gtnets_topology.h | 16 +- src/surf/lagrange.c | 58 +- src/surf/maxmin.c | 80 +- src/surf/maxmin_private.h | 5 +- src/surf/network.c | 338 +- src/surf/network_constant.c | 33 +- src/surf/network_gtnets.c | 111 +- src/surf/network_gtnets_private.h | 4 +- src/surf/network_private.h | 10 +- src/surf/network_vivaldi.c | 89 +- src/surf/random_mgr.c | 26 +- src/surf/simgrid_dtd.c | 2 +- src/surf/simgrid_dtd.l | 349 +- src/surf/surf.c | 101 +- src/surf/surf_action.c | 3 +- src/surf/surf_config.c | 207 +- src/surf/surf_model.c | 11 +- src/surf/surf_model_timer.c | 13 +- src/surf/surf_private.h | 110 +- src/surf/surf_routing.c | 3088 ++++++++++------- src/surf/surfxml_parse.c | 268 +- src/surf/trace_mgr.c | 10 +- src/surf/trace_mgr_private.h | 2 +- src/surf/workstation.c | 73 +- src/surf/workstation_ptask_L07.c | 264 +- src/swag_unit.c | 2 +- src/win32/compiler/borland.h | 132 +- src/win32/compiler/select_compiler_features.h | 14 +- src/win32/compiler/visualc.h | 222 +- src/win32/config.h | 48 +- src/win32/platform/select_platform_features.h | 64 +- src/xbt/backtrace_linux.c | 28 +- src/xbt/backtrace_windows.c | 57 +- src/xbt/config.c | 129 +- src/xbt/cunit.c | 58 +- src/xbt/dict.c | 149 +- src/xbt/dict_cursor.c | 15 +- src/xbt/dict_elm.c | 14 +- src/xbt/dict_multi.c | 15 +- src/xbt/dict_private.h | 5 +- src/xbt/dynar.c | 181 +- src/xbt/error.c | 36 +- src/xbt/ex.c | 8 +- src/xbt/ex_interface.h | 2 +- src/xbt/fifo.c | 6 +- src/xbt/fifo_private.h | 2 +- src/xbt/graph.c | 21 +- src/xbt/graph_private.h | 6 +- src/xbt/graphxml.c | 2 +- src/xbt/graphxml.l | 2 +- src/xbt/graphxml_parse.c | 6 +- src/xbt/heap.c | 29 +- src/xbt/heap_private.h | 2 +- src/xbt/log.c | 47 +- src/xbt/log_private.h | 2 +- src/xbt/mallocator.c | 15 +- src/xbt/mallocator_private.h | 2 +- src/xbt/mmalloc/attach.c | 85 +- src/xbt/mmalloc/detach.c | 48 +- src/xbt/mmalloc/keys.c | 24 +- src/xbt/mmalloc/mcalloc.c | 16 +- src/xbt/mmalloc/mfree.c | 232 +- src/xbt/mmalloc/mm.c | 2 +- src/xbt/mmalloc/mm_legacy.c | 62 +- src/xbt/mmalloc/mmalloc.c | 312 +- src/xbt/mmalloc/mmap-sup.c | 199 +- src/xbt/mmalloc/mmcheck.c | 148 +- src/xbt/mmalloc/mmemalign.c | 39 +- src/xbt/mmalloc/mmprivate.h | 132 +- src/xbt/mmalloc/mmstats.c | 16 +- src/xbt/mmalloc/mmtrace.c | 133 +- src/xbt/mmalloc/mrealloc.c | 101 +- src/xbt/mmalloc/mvalloc.c | 21 +- src/xbt/mmalloc/sbrk-sup.c | 35 +- src/xbt/mmalloc/test/mmalloc_test.c | 41 +- src/xbt/set.c | 31 +- src/xbt/setset.c | 158 +- src/xbt/setset_private.h | 21 +- src/xbt/snprintf.c | 22 +- src/xbt/swag.c | 17 +- src/xbt/win32_ucontext.c | 147 +- src/xbt/xbt_log_layout_format.c | 193 +- src/xbt/xbt_log_layout_simple.c | 31 +- src/xbt/xbt_main.c | 31 +- src/xbt/xbt_matrix.c | 20 +- src/xbt/xbt_os_thread.c | 56 +- src/xbt/xbt_os_time.c | 28 +- src/xbt/xbt_queue.c | 31 +- src/xbt/xbt_rl_synchro.c | 6 +- src/xbt/xbt_sg_stubs.c | 60 +- src/xbt/xbt_sg_synchro.c | 18 +- src/xbt/xbt_sha.c | 6 +- src/xbt/xbt_str.c | 51 +- src/xbt/xbt_strbuff.c | 20 +- src/xbt/xbt_synchro.c | 58 +- src/xbt_modinter.h | 2 +- src/xbt_str_unit.c | 7 +- src/xbt_strbuff_unit.c | 7 +- src/xbt_synchro_unit.c | 13 +- 320 files changed, 14640 insertions(+), 11944 deletions(-) diff --git a/include/amok/bandwidth.h b/include/amok/bandwidth.h index cafc960b46..787a6c0406 100644 --- a/include/amok/bandwidth.h +++ b/include/amok/bandwidth.h @@ -99,8 +99,8 @@ XBT_PUBLIC(void) amok_bw_test(gras_socket_t peer, /*OUT*/ double *sec, double *bw); XBT_PUBLIC(void) amok_bw_request(const char *from_name, - unsigned int from_port, const char *to_name, - unsigned int to_port, + unsigned int from_port, + const char *to_name, unsigned int to_port, unsigned long int buf_size, unsigned long int msg_size, unsigned long int msg_amount, @@ -109,7 +109,8 @@ XBT_PUBLIC(void) amok_bw_request(const char *from_name, XBT_PUBLIC(double *) amok_bw_matrix(xbt_dynar_t hosts, /* dynar of xbt_host_t */ int buf_size_bw, int msg_size_bw, - int msg_amount_bw, double min_duration); + int msg_amount_bw, + double min_duration); /* *************************************************************************** * Link saturation @@ -127,7 +128,8 @@ XBT_PUBLIC(void) amok_bw_saturate_begin(const char *to_name, unsigned int to_port, unsigned int msg_size, double duration, - /*out */ double *elapsed, double *bw); + /*out */ double *elapsed, + double *bw); XBT_PUBLIC(void) amok_bw_saturate_stop(const char *from_name, unsigned int from_port, @@ -135,4 +137,4 @@ XBT_PUBLIC(void) amok_bw_saturate_stop(const char *from_name, /** @} */ -#endif /* AMOK_BANDWIDTH_H */ +#endif /* AMOK_BANDWIDTH_H */ diff --git a/include/amok/base.h b/include/amok/base.h index 601e00dfe7..8d115ac3eb 100644 --- a/include/amok/base.h +++ b/include/amok/base.h @@ -30,4 +30,4 @@ XBT_PUBLIC(void) amok_base_init(void); XBT_PUBLIC(void) amok_base_exit(void); -#endif /* AMOK_BASE_H */ +#endif /* AMOK_BASE_H */ diff --git a/include/amok/peermanagement.h b/include/amok/peermanagement.h index 41144874b1..0b3e8c63bc 100644 --- a/include/amok/peermanagement.h +++ b/include/amok/peermanagement.h @@ -80,4 +80,4 @@ XBT_PUBLIC(void) amok_pm_group_shutdown_remote(gras_socket_t master, /** @} */ -#endif /* AMOK_peer_MANAGEMENT_H */ +#endif /* AMOK_peer_MANAGEMENT_H */ diff --git a/include/gras.h b/include/gras.h index ce22412ab3..5e1f08369a 100644 --- a/include/gras.h +++ b/include/gras.h @@ -25,4 +25,4 @@ XBT_PUBLIC(void) gras_init(int *argc, char **argv); XBT_PUBLIC(void) gras_exit(void); -#endif /* GRAS_H */ +#endif /* GRAS_H */ diff --git a/include/gras/datadesc.h b/include/gras/datadesc.h index e8ed2bf31e..8523c197f5 100644 --- a/include/gras/datadesc.h +++ b/include/gras/datadesc.h @@ -53,7 +53,7 @@ SG_BEGIN_DECL() */ /* @{ */ /** @brief Opaque type describing a type description. */ - typedef struct s_gras_datadesc_type *gras_datadesc_type_t; +typedef struct s_gras_datadesc_type *gras_datadesc_type_t; /** \brief Search a type description from its name */ XBT_PUBLIC(gras_datadesc_type_t) gras_datadesc_by_name(const char *name); @@ -272,7 +272,7 @@ XBT_PUBLIC(void) gras_datadesc_set_const(const char *name, int value); /* @} */ XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_parse(const char *name, const char *C_statement); + gras_datadesc_parse(const char *name, const char *C_statement); /** @defgroup GRAS_dd_manual Simple manual data description * @ingroup GRAS_dd @@ -313,28 +313,28 @@ XBT_PUBLIC(gras_datadesc_type_t) /** \brief Opaque type describing a type description callback persistant state. */ - typedef struct s_gras_cbps *gras_cbps_t; +typedef struct s_gras_cbps *gras_cbps_t; /* callbacks prototypes */ /** \brief Prototype of type callbacks returning nothing. */ - typedef void (*gras_datadesc_type_cb_void_t) (gras_datadesc_type_t - typedesc, gras_cbps_t vars, - void *data); +typedef void (*gras_datadesc_type_cb_void_t) (gras_datadesc_type_t + typedesc, gras_cbps_t vars, + void *data); /** \brief Prototype of type callbacks returning an int. */ - typedef int (*gras_datadesc_type_cb_int_t) (gras_datadesc_type_t - typedesc, gras_cbps_t vars, - void *data); +typedef int (*gras_datadesc_type_cb_int_t) (gras_datadesc_type_t + typedesc, gras_cbps_t vars, + void *data); /** \brief Prototype of type callbacks selecting a type. */ - typedef +typedef + - - gras_datadesc_type_t(*gras_datadesc_selector_t) (gras_datadesc_type_t - typedesc, - gras_cbps_t vars, - void *data); +gras_datadesc_type_t(*gras_datadesc_selector_t) (gras_datadesc_type_t + typedesc, + gras_cbps_t vars, + void *data); /****************************************** @@ -342,44 +342,49 @@ XBT_PUBLIC(gras_datadesc_type_t) ******************************************/ XBT_PUBLIC(gras_datadesc_type_t) gras_datadesc_struct(const char *name); -XBT_PUBLIC(void) gras_datadesc_struct_append(gras_datadesc_type_t struct_type, - const char *name, - gras_datadesc_type_t field_type); -XBT_PUBLIC(void) gras_datadesc_struct_close(gras_datadesc_type_t struct_type); +XBT_PUBLIC(void) gras_datadesc_struct_append(gras_datadesc_type_t + struct_type, const char *name, + gras_datadesc_type_t + field_type); +XBT_PUBLIC(void) gras_datadesc_struct_close(gras_datadesc_type_t + struct_type); XBT_PUBLIC(gras_datadesc_type_t) gras_datadesc_union(const char *name, gras_datadesc_type_cb_int_t selector); -XBT_PUBLIC(void) gras_datadesc_union_append(gras_datadesc_type_t union_type, - const char *name, - gras_datadesc_type_t field_type); -XBT_PUBLIC(void) gras_datadesc_union_close(gras_datadesc_type_t union_type); +XBT_PUBLIC(void) gras_datadesc_union_append(gras_datadesc_type_t + union_type, const char *name, + gras_datadesc_type_t + field_type); +XBT_PUBLIC(void) gras_datadesc_union_close(gras_datadesc_type_t + union_type); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type); + gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_copy(const char *name, gras_datadesc_type_t copied_type); + gras_datadesc_copy(const char *name, gras_datadesc_type_t copied_type); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_ref_generic(const char *name, + gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_array_fixed(const char *name, + gras_datadesc_array_fixed(const char *name, gras_datadesc_type_t element_type, long int fixed_size); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_array_dyn(const char *name, + gras_datadesc_array_dyn(const char *name, gras_datadesc_type_t element_type, gras_datadesc_type_cb_int_t dynamic_size); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type); + gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func); + gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func); XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f); + gras_datadesc_matrix(gras_datadesc_type_t elm_t, + void_f_pvoid_t const free_f); /********************************* * Change stuff within datadescs * @@ -409,9 +414,10 @@ XBT_PUBLIC(void) gras_datadesc_cb_field_recv(gras_datadesc_type_t type, XBT_PUBLIC(void) gras_datadesc_cb_field_push(gras_datadesc_type_t type, const char *field_name); /** \brief Add a pre-send callback to the given field resulting in its value multiplied to any previously pushed value and then pushed back */ -XBT_PUBLIC(void) gras_datadesc_cb_field_push_multiplier(gras_datadesc_type_t - type, const char - *field_name); +XBT_PUBLIC(void) +gras_datadesc_cb_field_push_multiplier(gras_datadesc_type_t type, + const char + *field_name); /****************************** * Get stuff within datadescs * @@ -485,16 +491,20 @@ XBT_PUBLIC(void) gras_datadesc_cb_push_lint(gras_datadesc_type_t typedesc, XBT_PUBLIC(void) gras_datadesc_cb_push_ulint(gras_datadesc_type_t typedesc, gras_cbps_t vars, void *data); -XBT_PUBLIC(void) gras_datadesc_cb_push_int_mult(gras_datadesc_type_t typedesc, - gras_cbps_t vars, void *data); +XBT_PUBLIC(void) gras_datadesc_cb_push_int_mult(gras_datadesc_type_t + typedesc, gras_cbps_t vars, + void *data); XBT_PUBLIC(void) gras_datadesc_cb_push_uint_mult(gras_datadesc_type_t - typedesc, gras_cbps_t vars, + typedesc, + gras_cbps_t vars, void *data); XBT_PUBLIC(void) gras_datadesc_cb_push_lint_mult(gras_datadesc_type_t - typedesc, gras_cbps_t vars, + typedesc, + gras_cbps_t vars, void *data); XBT_PUBLIC(void) gras_datadesc_cb_push_ulint_mult(gras_datadesc_type_t - typedesc, gras_cbps_t vars, + typedesc, + gras_cbps_t vars, void *data); @@ -547,10 +557,10 @@ XBT_PUBLIC(int) gras_arch_selfid(void); /* ID of this arch */ /** * Basic types we can embeed in DataDescriptors. */ - typedef enum - { CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE, - UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE - } DataTypes; +typedef enum + { CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE, + UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE +} DataTypes; #define SIMPLE_TYPE_COUNT 9 /** \brief Describe a collection of data. @@ -565,14 +575,14 @@ XBT_PUBLIC(int) gras_arch_selfid(void); /* ID of this arch */ ** padding bytes the compiler adds to the end of the structure. */ - typedef struct DataDescriptorStruct { - DataTypes type; - size_t repetitions; - size_t offset; - /*@null@ */ struct DataDescriptorStruct *members; - size_t length; - size_t tailPadding; - } DataDescriptor; +typedef struct DataDescriptorStruct { + DataTypes type; + size_t repetitions; + size_t offset; + /*@null@ */ struct DataDescriptorStruct *members; + size_t length; + size_t tailPadding; +} DataDescriptor; /** DataDescriptor for an array */ #define SIMPLE_DATA(type,repetitions) \ {type, repetitions, 0, NULL, 0, 0} @@ -585,9 +595,10 @@ XBT_PUBLIC(int) gras_arch_selfid(void); /* ID of this arch */ sizeof(memberType) * repetitions XBT_PUBLIC(gras_datadesc_type_t) - gras_datadesc_import_nws(const char *name, - const DataDescriptor * desc, unsigned long howmany); + gras_datadesc_import_nws(const char *name, + const DataDescriptor * desc, + unsigned long howmany); SG_END_DECL() -#endif /* GRAS_DATADESC_H */ +#endif /* GRAS_DATADESC_H */ diff --git a/include/gras/emul.h b/include/gras/emul.h index 8d96a8683b..789b622ce6 100644 --- a/include/gras/emul.h +++ b/include/gras/emul.h @@ -167,4 +167,4 @@ XBT_PUBLIC(void) gras_cpu_burn(double flops); /** @} */ SG_END_DECL() -#endif /* GRAS_COND_H */ +#endif /* GRAS_COND_H */ diff --git a/include/gras/messages.h b/include/gras/messages.h index dd49e2c847..5bf5fae803 100644 --- a/include/gras/messages.h +++ b/include/gras/messages.h @@ -57,7 +57,7 @@ SG_BEGIN_DECL() */ /** @{ */ /** \brief Opaque type */ - typedef struct s_gras_msgtype *gras_msgtype_t; +typedef struct s_gras_msgtype *gras_msgtype_t; XBT_PUBLIC(void) gras_msgtype_declare(const char *name, gras_datadesc_type_t payload); @@ -70,7 +70,7 @@ XBT_PUBLIC(gras_msgtype_t) gras_msgtype_by_name_or_null(const char *name); XBT_PUBLIC(gras_msgtype_t) gras_msgtype_by_namev(const char *name, short int version); XBT_PUBLIC(gras_msgtype_t) gras_msgtype_by_id(int id); -XBT_PUBLIC(const char*) gras_msgtype_get_name(gras_msgtype_t type); +XBT_PUBLIC(const char *) gras_msgtype_get_name(gras_msgtype_t type); XBT_PUBLIC(void) gras_msgtype_dumpall(void); @@ -93,7 +93,7 @@ XBT_PUBLIC(void) gras_msgtype_dumpall(void); */ /** \brief Context of callbacks (opaque structure, created by the middleware only, never by user) */ - typedef struct s_gras_msg_cb_ctx *gras_msg_cb_ctx_t; +typedef struct s_gras_msg_cb_ctx *gras_msg_cb_ctx_t; XBT_PUBLIC(void) gras_msg_cb_ctx_free(gras_msg_cb_ctx_t ctx); XBT_PUBLIC(gras_socket_t) gras_msg_cb_ctx_from(gras_msg_cb_ctx_t ctx); @@ -113,7 +113,7 @@ XBT_PUBLIC(gras_socket_t) gras_msg_cb_ctx_from(gras_msg_cb_ctx_t ctx); * * If the callback accepts the message, it should free it after use. */ - typedef int (*gras_msg_cb_t) (gras_msg_cb_ctx_t ctx, void *payload); +typedef int (*gras_msg_cb_t) (gras_msg_cb_ctx_t ctx, void *payload); /** * @brief Bind the given callback to the given message type (described by its name) @@ -137,7 +137,8 @@ XBT_PUBLIC(gras_socket_t) gras_msg_cb_ctx_from(gras_msg_cb_ctx_t ctx); */ #define gras_cb_unregister(msgtype_name, cb) gras_cb_unregister_(gras_msgtype_by_name(msgtype_name),cb) -XBT_PUBLIC(void) gras_cb_register_(gras_msgtype_t msgtype, gras_msg_cb_t cb); +XBT_PUBLIC(void) gras_cb_register_(gras_msgtype_t msgtype, + gras_msg_cb_t cb); XBT_PUBLIC(void) gras_cb_unregister_(gras_msgtype_t msgtype, gras_msg_cb_t cb); @@ -229,10 +230,11 @@ XBT_PUBLIC(gras_msg_cb_ctx_t) * @hideinitializer */ #define gras_msg_rpc_async_call(server,timeout,msg,req) gras_msg_rpc_async_call_(server,timeout,gras_msgtype_by_name(msg),req) - gras_msg_rpc_async_call_(gras_socket_t server, + gras_msg_rpc_async_call_(gras_socket_t server, double timeOut, gras_msgtype_t msgtype, void *request); -XBT_PUBLIC(void) gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, void *answer); +XBT_PUBLIC(void) gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, + void *answer); /* server side */ XBT_PUBLIC(void) gras_msg_rpcreturn(double timeOut, gras_msg_cb_ctx_t ctx, @@ -248,43 +250,43 @@ XBT_PUBLIC(void) gras_msg_rpcreturn(double timeOut, gras_msg_cb_ctx_t ctx, /** @{ */ /** @brief Message kind (internal enum) */ - typedef enum { - e_gras_msg_kind_unknown = 0, +typedef enum { + e_gras_msg_kind_unknown = 0, - e_gras_msg_kind_oneway = 1, + e_gras_msg_kind_oneway = 1, /**< good old regular messages */ - e_gras_msg_kind_rpccall = 2, + e_gras_msg_kind_rpccall = 2, /**< RPC request */ - /* HACK: e_gras_msg_kind_rpccall also designate RPC message *type* in - msgtype_t, not only in msg_t */ - e_gras_msg_kind_rpcanswer = 3, + /* HACK: e_gras_msg_kind_rpccall also designate RPC message *type* in + msgtype_t, not only in msg_t */ + e_gras_msg_kind_rpcanswer = 3, /**< RPC successful answer */ - e_gras_msg_kind_rpcerror = 4, + e_gras_msg_kind_rpcerror = 4, /**< RPC failure on server (payload=exception); should not leak to user-space */ - /* future: - call cancel, and others - even after: - forwarding request and other application level routing stuff - group communication - */ + /* future: + call cancel, and others + even after: + forwarding request and other application level routing stuff + group communication + */ - e_gras_msg_kind_count = 5 /* sentinel, dont mess with */ - } e_gras_msg_kind_t; + e_gras_msg_kind_count = 5 /* sentinel, dont mess with */ +} e_gras_msg_kind_t; /** @brief Message instance (internal struct) */ - typedef struct { - gras_socket_t expe; - e_gras_msg_kind_t kind; - gras_msgtype_t type; - unsigned long int ID; - void *payl; - int payl_size; - } s_gras_msg_t, *gras_msg_t; +typedef struct { + gras_socket_t expe; + e_gras_msg_kind_t kind; + gras_msgtype_t type; + unsigned long int ID; + void *payl; + int payl_size; +} s_gras_msg_t, *gras_msg_t; - typedef int (*gras_msg_filter_t) (gras_msg_t msg, void *ctx); +typedef int (*gras_msg_filter_t) (gras_msg_t msg, void *ctx); #define gras_msg_wait_ext(timeout, msg, expe, filter, fctx,got) gras_msg_wait_ext_(timeout, gras_msgtype_by_name(msg), expe, filter, fctx,got) XBT_PUBLIC(void) gras_msg_wait_ext_(double timeout, @@ -302,4 +304,4 @@ XBT_PUBLIC(void) gras_msg_wait_or(double timeout, /* @} */ SG_END_DECL() -#endif /* GRAS_MSG_H */ +#endif /* GRAS_MSG_H */ diff --git a/include/gras/module.h b/include/gras/module.h index 300a054fa8..d318e49b9a 100644 --- a/include/gras/module.h +++ b/include/gras/module.h @@ -18,11 +18,12 @@ XBT_PUBLIC(void) gras_module_leave(const char *name); /* Functions module implementor should use */ XBT_PUBLIC(void) gras_module_add(const char *name, unsigned int data_size, int *ID, void_f_void_t init_f, - void_f_void_t exit_f, void_f_pvoid_t join_f, + void_f_void_t exit_f, + void_f_pvoid_t join_f, void_f_pvoid_t leave_f); XBT_PUBLIC(void *) gras_moddata_by_id(unsigned int ID); -#endif /* GRAS_MODULE_H */ +#endif /* GRAS_MODULE_H */ diff --git a/include/gras/process.h b/include/gras/process.h index 0449193c5a..a91114a097 100644 --- a/include/gras/process.h +++ b/include/gras/process.h @@ -14,8 +14,8 @@ SG_BEGIN_DECL() - void gras_agent_spawn(const char *name, void *data, xbt_main_func_t code, - int argc, char *argv[], xbt_dict_t properties); +void gras_agent_spawn(const char *name, void *data, xbt_main_func_t code, + int argc, char *argv[], xbt_dict_t properties); /****************************************************************************/ @@ -65,4 +65,4 @@ XBT_PUBLIC(void *) gras_userdata_set(void *ud); /* @} */ SG_END_DECL() -#endif /* GRAS_PROCESS_H */ +#endif /* GRAS_PROCESS_H */ diff --git a/include/gras/timer.h b/include/gras/timer.h index bb266bda0a..fa6e7c0012 100644 --- a/include/gras/timer.h +++ b/include/gras/timer.h @@ -51,4 +51,4 @@ XBT_PUBLIC(void) gras_timer_cancel_all(void); /** @} */ SG_END_DECL() -#endif /* GRAS_TIMER_H */ +#endif /* GRAS_TIMER_H */ diff --git a/include/gras/transport.h b/include/gras/transport.h index 8ad34fda3b..8479a8ba9e 100644 --- a/include/gras/transport.h +++ b/include/gras/transport.h @@ -53,7 +53,7 @@ XBT_PUBLIC(gras_socket_t) gras_socket_server_ext(unsigned short port, unsigned long int bufSize, int measurement); XBT_PUBLIC(gras_socket_t) - gras_socket_server_range(unsigned short minport, unsigned short maxport, + gras_socket_server_range(unsigned short minport, unsigned short maxport, unsigned long int buf_size, int measurement); /* @}*/ @@ -130,4 +130,4 @@ XBT_PUBLIC(gras_socket_t) gras_socket_server_from_file(const char *path); /* @} */ -#endif /* GRAS_TRANSPORT_H */ +#endif /* GRAS_TRANSPORT_H */ diff --git a/include/gras/virtu.h b/include/gras/virtu.h index 43bc908f4a..d4b80ca809 100644 --- a/include/gras/virtu.h +++ b/include/gras/virtu.h @@ -17,14 +17,14 @@ SG_BEGIN_DECL() /* Initialization of the simulation world. Do not call them in RL. Indeed, do not call them at all. Let gras_stub_generator do it for you. */ - void gras_global_init(int *argc, char **argv); - void gras_create_environment(const char *file); - void gras_function_register(const char *name, xbt_main_func_t code); - void gras_function_register_default(xbt_main_func_t code); - void gras_launch_application(const char *file); - void gras_load_environment_script(const char *file); - void gras_clean(void); - void gras_main(void); +void gras_global_init(int *argc, char **argv); +void gras_create_environment(const char *file); +void gras_function_register(const char *name, xbt_main_func_t code); +void gras_function_register_default(xbt_main_func_t code); +void gras_launch_application(const char *file); +void gras_load_environment_script(const char *file); +void gras_clean(void); +void gras_main(void); /** @addtogroup GRAS_virtu @@ -77,4 +77,4 @@ XBT_PUBLIC(const char *) gras_os_host_property_value(const char *name); /** @} */ SG_END_DECL() -#endif /* GRAS_VIRTU_H */ +#endif /* GRAS_VIRTU_H */ diff --git a/include/instr/instr.h b/include/instr/instr.h index 0e587b521c..5475cb6cda 100644 --- a/include/instr/instr.h +++ b/include/instr/instr.h @@ -25,20 +25,31 @@ #define TRACE_ERROR_FILE_OPEN 401 #define TRACE_ERROR_START 500 -XBT_PUBLIC(int) TRACE_start (void); -XBT_PUBLIC(int) TRACE_end (void); -XBT_PUBLIC(int) TRACE_category (const char *category); -XBT_PUBLIC(void) TRACE_define_type (const char *type, const char *parent_type, int final); -XBT_PUBLIC(int) TRACE_create_category (const char *category, const char *type, const char *parent_category); -XBT_PUBLIC(void) TRACE_msg_set_task_category (m_task_t task, const char *category); -XBT_PUBLIC(void) TRACE_msg_set_process_category (m_process_t process, const char *category); -XBT_PUBLIC(void) TRACE_set_mask (int mask); -XBT_PUBLIC(void) TRACE_user_host_variable (double time, const char *variable, double value, const char *what); -XBT_PUBLIC(void) TRACE_user_link_variable (double time, const char *src, const char *dst, const char *variable, double value, const char *what); -XBT_PUBLIC(void) TRACE_declare_mark (const char *mark_type); -XBT_PUBLIC(void) TRACE_mark (const char *mark_type, const char *mark_value); -XBT_PUBLIC(int) TRACE_smpi_set_category (const char *category); -XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, const char *category); +XBT_PUBLIC(int) TRACE_start(void); +XBT_PUBLIC(int) TRACE_end(void); +XBT_PUBLIC(int) TRACE_category(const char *category); +XBT_PUBLIC(void) TRACE_define_type(const char *type, + const char *parent_type, int final); +XBT_PUBLIC(int) TRACE_create_category(const char *category, + const char *type, + const char *parent_category); +XBT_PUBLIC(void) TRACE_msg_set_task_category(m_task_t task, + const char *category); +XBT_PUBLIC(void) TRACE_msg_set_process_category(m_process_t process, + const char *category); +XBT_PUBLIC(void) TRACE_set_mask(int mask); +XBT_PUBLIC(void) TRACE_user_host_variable(double time, + const char *variable, + double value, const char *what); +XBT_PUBLIC(void) TRACE_user_link_variable(double time, const char *src, + const char *dst, + const char *variable, + double value, const char *what); +XBT_PUBLIC(void) TRACE_declare_mark(const char *mark_type); +XBT_PUBLIC(void) TRACE_mark(const char *mark_type, const char *mark_value); +XBT_PUBLIC(int) TRACE_smpi_set_category(const char *category); +XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, + const char *category); #define TRACE_host_variable_declare(var) \ TRACE_user_host_variable(0,var,0,"declare"); @@ -82,7 +93,7 @@ XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, const char *category #define TRACE_link_variable_sub(src,dst,var,value) \ TRACE_user_link_variable(MSG_get_clock(),src,dst,var,value,"sub"); -#else /* HAVE_TRACING */ +#else /* HAVE_TRACING */ #define TRACE_start() #define TRACE_end() @@ -112,6 +123,6 @@ XBT_PUBLIC(void) TRACE_sd_set_task_category(SD_task_t task, const char *category #define TRACE_smpi_set_category(cat) #define TRACE_sd_set_task_category(task,cat) -#endif /* HAVE_TRACING */ +#endif /* HAVE_TRACING */ -#endif /* INSTR_H_ */ +#endif /* INSTR_H_ */ diff --git a/include/mc/modelchecker.h b/include/mc/modelchecker.h index 9bc3a80f04..2ca38fa4f8 100644 --- a/include/mc/modelchecker.h +++ b/include/mc/modelchecker.h @@ -1,4 +1,4 @@ #include "xbt.h" XBT_PUBLIC(void) MC_assert(int); -XBT_PUBLIC(int) MC_random(int min, int max); \ No newline at end of file +XBT_PUBLIC(int) MC_random(int min, int max); diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index e3069262f2..494661e31d 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -7,21 +7,21 @@ #ifndef MSG_DATATYPE_H #define MSG_DATATYPE_H #include "xbt/misc.h" -#include "simgrid_config.h" // for HAVE_TRACING +#include "simgrid_config.h" // for HAVE_TRACING SG_BEGIN_DECL() /* ******************************** Host ************************************ */ /** @defgroup m_datatypes_management_details Details on MSG datatypes @ingroup m_datatypes_management*/ - typedef struct simdata_host *simdata_host_t; +typedef struct simdata_host *simdata_host_t; /** @brief Host datatype @ingroup m_datatypes_management_details */ - typedef struct m_host { - char *name; /**< @brief host name if any */ - simdata_host_t simdata; /**< @brief simulator data */ - void *data; /**< @brief user data */ - } s_m_host_t; +typedef struct m_host { + char *name; /**< @brief host name if any */ + simdata_host_t simdata; /**< @brief simulator data */ + void *data; /**< @brief user data */ +} s_m_host_t; /** @brief Host datatype @ingroup m_datatypes_management @@ -34,22 +34,22 @@ SG_BEGIN_DECL() \see m_host_management @{ */ - typedef struct m_host *m_host_t; +typedef struct m_host *m_host_t; /** @} */ /* ******************************** Task ************************************ */ - typedef struct simdata_task *simdata_task_t; +typedef struct simdata_task *simdata_task_t; /** @brief Task datatype @ingroup m_datatypes_management_details */ - typedef struct m_task { - char *name; /**< @brief task name if any */ - simdata_task_t simdata; /**< @brief simulator data */ - void *data; /**< @brief user data */ +typedef struct m_task { + char *name; /**< @brief task name if any */ + simdata_task_t simdata; /**< @brief simulator data */ + void *data; /**< @brief user data */ #ifdef HAVE_TRACING - long long int counter; /* task unique identifier for instrumentation */ - char *category; /* task category for instrumentation */ + long long int counter; /* task unique identifier for instrumentation */ + char *category; /* task category for instrumentation */ #endif - } s_m_task_t; +} s_m_task_t; /** @brief Task datatype @ingroup m_datatypes_management @@ -58,29 +58,29 @@ SG_BEGIN_DECL() data. \see m_task_management @{ */ - typedef struct m_task *m_task_t; +typedef struct m_task *m_task_t; /** \brief Default value for an uninitialized #m_task_t. \ingroup m_datatypes_management */ #define MSG_TASK_UNINITIALIZED NULL - typedef struct s_smx_comm *msg_comm_t; +typedef struct s_smx_comm *msg_comm_t; /** @} */ /* ****************************** Process *********************************** */ - typedef struct simdata_process *simdata_process_t; +typedef struct simdata_process *simdata_process_t; /** @brief Process datatype @ingroup m_datatypes_management_details @{ */ - typedef struct m_process { - char *name; /**< @brief process name if any */ - simdata_process_t simdata; +typedef struct m_process { + char *name; /**< @brief process name if any */ + simdata_process_t simdata; /**< @brief simulator data */ - void *data; /**< @brief user data */ - char *category; /* process category for instrumentation */ - } s_m_process_t; + void *data; /**< @brief user data */ + char *category; /* process category for instrumentation */ +} s_m_process_t; /** @} */ /** @brief Agent datatype @ingroup m_datatypes_management @@ -89,7 +89,7 @@ SG_BEGIN_DECL() data, executing in a location. \see m_process_management @{ */ - typedef struct m_process *m_process_t; +typedef struct m_process *m_process_t; /** @} */ /* ********************************* Channel ******************************** */ @@ -100,17 +100,17 @@ SG_BEGIN_DECL() port number does). \see m_channel_management @{ */ - typedef int m_channel_t; +typedef int m_channel_t; /** @} */ /* ******************************** Mailbox ************************************ */ - typedef struct s_msg_mailbox *msg_mailbox_t; +typedef struct s_msg_mailbox *msg_mailbox_t; /** @brief Mailbox datatype @ingroup m_datatypes_management_details @{ */ - msg_mailbox_t MSG_mailbox_create(const char *alias); - void MSG_mailbox_free(void *mailbox); +msg_mailbox_t MSG_mailbox_create(const char *alias); +void MSG_mailbox_free(void *mailbox); /** @} */ @@ -119,19 +119,19 @@ SG_BEGIN_DECL() /* ***************************** Error handling ***************************** */ /** @brief Error handling @ingroup m_datatypes_management - @{ -*/ /* Keep these code as binary values: java bindings manipulate | of these values */ - typedef enum { - MSG_OK = 0, /**< @brief Everything is right. Keep on going this way ! */ - MSG_TIMEOUT=1, /**< @brief nothing good happened before the timer you provided elapsed */ - MSG_TRANSFER_FAILURE=2,/**< @brief There has been a problem during you task + @{ +*//* Keep these code as binary values: java bindings manipulate | of these values */ +typedef enum { + MSG_OK = 0, /**< @brief Everything is right. Keep on going this way ! */ + MSG_TIMEOUT = 1, /**< @brief nothing good happened before the timer you provided elapsed */ + MSG_TRANSFER_FAILURE = 2, /**< @brief There has been a problem during you task transfer. Either the network is down or the remote host has been shutdown. */ - MSG_HOST_FAILURE=4, /**< @brief System shutdown. The host on which you are + MSG_HOST_FAILURE = 4, /**< @brief System shutdown. The host on which you are running has just been rebooted. Free your datastructures and return now !*/ - MSG_TASK_CANCELLED=8, /**< @brief Canceled task. This task has been canceled by somebody!*/ - } MSG_error_t; + MSG_TASK_CANCELLED = 8, /**< @brief Canceled task. This task has been canceled by somebody!*/ +} MSG_error_t; /** @} */ SG_END_DECL() diff --git a/include/msg/msg.h b/include/msg/msg.h index 9251b2231d..1d0784106b 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -27,7 +27,9 @@ XBT_PUBLIC(void) MSG_function_register_default(xbt_main_func_t code); XBT_PUBLIC(xbt_main_func_t) MSG_get_registered_function(const char *name); XBT_PUBLIC(void) MSG_launch_application(const char *file); /*Bypass the parser */ -XBT_PUBLIC(void) MSG_set_function(const char* host_id,const char *function_name,xbt_dynar_t arguments); +XBT_PUBLIC(void) MSG_set_function(const char *host_id, + const char *function_name, + xbt_dynar_t arguments); XBT_PUBLIC(double) MSG_get_clock(void); XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(void); @@ -57,17 +59,19 @@ XBT_PUBLIC(m_host_t *) MSG_get_host_table(void); /************************** Process handling *********************************/ XBT_PUBLIC(m_process_t) MSG_process_create(const char *name, - xbt_main_func_t code, void *data, - m_host_t host); + xbt_main_func_t code, + void *data, m_host_t host); XBT_PUBLIC(m_process_t) MSG_process_create_with_arguments(const char *name, xbt_main_func_t code, void *data, m_host_t host, int argc, char **argv); -XBT_PUBLIC(m_process_t) MSG_process_create_with_environment(const char *name, +XBT_PUBLIC(m_process_t) MSG_process_create_with_environment(const char + *name, xbt_main_func_t - code, void *data, + code, + void *data, m_host_t host, int argc, char **argv, @@ -79,7 +83,8 @@ XBT_PUBLIC(int) MSG_process_killall(int reset_PIDs); XBT_PUBLIC(MSG_error_t) MSG_process_change_host(m_host_t host); XBT_PUBLIC(void *) MSG_process_get_data(m_process_t process); -XBT_PUBLIC(MSG_error_t) MSG_process_set_data(m_process_t process, void *data); +XBT_PUBLIC(MSG_error_t) MSG_process_set_data(m_process_t process, + void *data); XBT_PUBLIC(m_host_t) MSG_process_get_host(m_process_t process); XBT_PUBLIC(m_process_t) MSG_process_from_PID(int PID); XBT_PUBLIC(int) MSG_process_get_PID(m_process_t process); @@ -91,7 +96,8 @@ XBT_PUBLIC(m_process_t) MSG_process_self(void); /*property handlers*/ XBT_PUBLIC(xbt_dict_t) MSG_process_get_properties(m_process_t process); -XBT_PUBLIC(const char *) MSG_process_get_property_value(m_process_t process, +XBT_PUBLIC(const char *) MSG_process_get_property_value(m_process_t + process, const char *name); XBT_PUBLIC(MSG_error_t) MSG_process_suspend(m_process_t process); @@ -103,17 +109,18 @@ XBT_PUBLIC(int) MSG_process_is_suspended(m_process_t process); XBT_PUBLIC(m_task_t) MSG_task_create(const char *name, double compute_duration, double message_size, void *data); -XBT_PUBLIC(m_task_t) MSG_parallel_task_create(const char *name, int host_nb, +XBT_PUBLIC(m_task_t) MSG_parallel_task_create(const char *name, + int host_nb, const m_host_t * host_list, double *computation_amount, double *communication_amount, void *data); XBT_PUBLIC(void *) MSG_task_get_data(m_task_t task); -XBT_PUBLIC(void) MSG_task_set_data(m_task_t task,void*data); +XBT_PUBLIC(void) MSG_task_set_data(m_task_t task, void *data); XBT_PUBLIC(m_process_t) MSG_task_get_sender(m_task_t task); XBT_PUBLIC(m_host_t) MSG_task_get_source(m_task_t task); XBT_PUBLIC(const char *) MSG_task_get_name(m_task_t task); -XBT_PUBLIC(void) MSG_task_set_name(m_task_t task,const char*name); +XBT_PUBLIC(void) MSG_task_set_name(m_task_t task, const char *name); XBT_PUBLIC(MSG_error_t) MSG_task_cancel(m_task_t task); XBT_PUBLIC(MSG_error_t) MSG_task_destroy(m_task_t task); XBT_PUBLIC(void) MSG_task_refcount_dec(m_task_t task); @@ -122,12 +129,13 @@ XBT_PUBLIC(MSG_error_t) MSG_task_get(m_task_t * task, m_channel_t channel); XBT_PUBLIC(MSG_error_t) MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, double max_duration); -XBT_PUBLIC(MSG_error_t) MSG_task_get_from_host(m_task_t * task, int channel, - m_host_t host); - MSG_error_t MSG_task_receive_from_host(m_task_t * task, - const char *alias, m_host_t host); +XBT_PUBLIC(MSG_error_t) MSG_task_get_from_host(m_task_t * task, + int channel, m_host_t host); +MSG_error_t MSG_task_receive_from_host(m_task_t * task, const char *alias, + m_host_t host); XBT_PUBLIC(MSG_error_t) MSG_task_get_ext(m_task_t * task, int channel, - double max_duration, m_host_t host); + double max_duration, + m_host_t host); XBT_PUBLIC(MSG_error_t) MSG_task_put(m_task_t task, m_host_t dest, @@ -154,66 +162,70 @@ XBT_PUBLIC(MSG_error_t) MSG_process_sleep(double nb_sec); XBT_PUBLIC(MSG_error_t) MSG_get_errno(void); XBT_PUBLIC(double) MSG_task_get_compute_duration(m_task_t task); -XBT_PUBLIC(void) MSG_task_set_compute_duration(m_task_t task,double compute_duration); +XBT_PUBLIC(void) MSG_task_set_compute_duration(m_task_t task, + double compute_duration); XBT_PUBLIC(double) MSG_task_get_remaining_computation(m_task_t task); XBT_PUBLIC(double) MSG_task_get_remaining_communication(m_task_t task); -XBT_PUBLIC(int) MSG_task_is_latency_bounded(m_task_t task); +XBT_PUBLIC(int) MSG_task_is_latency_bounded(m_task_t task); XBT_PUBLIC(double) MSG_task_get_data_size(m_task_t task); XBT_PUBLIC(MSG_error_t) - MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout, + MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout, m_host_t host); XBT_PUBLIC(MSG_error_t) - MSG_task_receive_with_timeout(m_task_t * task, const char *alias, + MSG_task_receive_with_timeout(m_task_t * task, const char *alias, double timeout); XBT_PUBLIC(MSG_error_t) - MSG_task_receive(m_task_t * task, const char *alias); - -XBT_PUBLIC(msg_comm_t) MSG_task_isend(m_task_t task, const char *alias); -XBT_PUBLIC(msg_comm_t) MSG_task_irecv(m_task_t * task, const char *alias); -XBT_PUBLIC(int) MSG_comm_test(msg_comm_t comm); -XBT_PUBLIC(void) MSG_comm_destroy(msg_comm_t comm); -XBT_PUBLIC(MSG_error_t) MSG_comm_wait(msg_comm_t comm,double timeout); -XBT_PUBLIC(void) MSG_comm_waitall(msg_comm_t *comm,int nb_elem, double timeout); + MSG_task_receive(m_task_t * task, const char *alias); + +XBT_PUBLIC(msg_comm_t) MSG_task_isend(m_task_t task, const char *alias); +XBT_PUBLIC(msg_comm_t) MSG_task_irecv(m_task_t * task, const char *alias); +XBT_PUBLIC(int) MSG_comm_test(msg_comm_t comm); +XBT_PUBLIC(void) MSG_comm_destroy(msg_comm_t comm); +XBT_PUBLIC(MSG_error_t) MSG_comm_wait(msg_comm_t comm, double timeout); +XBT_PUBLIC(void) MSG_comm_waitall(msg_comm_t * comm, int nb_elem, + double timeout); XBT_PUBLIC(int) MSG_comm_waitany(xbt_dynar_t comms); XBT_PUBLIC(m_task_t) MSG_comm_get_task(msg_comm_t comm); XBT_PUBLIC(int) MSG_task_listen(const char *alias); -XBT_PUBLIC(int) MSG_task_listen_from_host(const char *alias, m_host_t host); +XBT_PUBLIC(int) MSG_task_listen_from_host(const char *alias, + m_host_t host); XBT_PUBLIC(MSG_error_t) - MSG_alias_select_from(const char *alias, double timeout, int *PID); + MSG_alias_select_from(const char *alias, double timeout, int *PID); XBT_PUBLIC(MSG_error_t) - MSG_task_send_with_timeout(m_task_t task, const char *alias, double timeout); + MSG_task_send_with_timeout(m_task_t task, const char *alias, + double timeout); XBT_PUBLIC(MSG_error_t) - MSG_task_send(m_task_t task, const char *alias); + MSG_task_send(m_task_t task, const char *alias); XBT_PUBLIC(MSG_error_t) - MSG_task_send_bounded(m_task_t task, const char *alias, double rate); + MSG_task_send_bounded(m_task_t task, const char *alias, double rate); XBT_PUBLIC(int) MSG_task_listen_from(const char *alias); /************************** Task handling ************************************/ XBT_PUBLIC(MSG_error_t) - MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task, + MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task, m_host_t host, double timeout); XBT_PUBLIC(MSG_error_t) - MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, + MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, double timeout); /************************** Action handling **********************************/ - typedef void (*msg_action_fun) (xbt_dynar_t args); +typedef void (*msg_action_fun) (xbt_dynar_t args); XBT_PUBLIC(void) MSG_action_register(const char *action_name, msg_action_fun function); XBT_PUBLIC(void) MSG_action_unregister(const char *action_name); - MSG_error_t MSG_action_trace_run(char *path); +MSG_error_t MSG_action_trace_run(char *path); #ifdef MSG_USE_DEPRECATED diff --git a/include/simdag/datatypes.h b/include/simdag/datatypes.h index 9a3f827598..c2ecb0fdb1 100644 --- a/include/simdag/datatypes.h +++ b/include/simdag/datatypes.h @@ -65,7 +65,7 @@ typedef struct SD_task *SD_task_t; @see SD_task_management */ typedef enum { SD_NOT_SCHEDULED = 0, /**< @brief Initial state (not valid for SD_watch and SD_unwatch). */ - SD_SCHEDULABLE = 0x0001, /**< @brief A task becomes SD_READY as soon as its dependencies are satisfied */ + SD_SCHEDULABLE = 0x0001, /**< @brief A task becomes SD_READY as soon as its dependencies are satisfied */ SD_SCHEDULED = 0x0002, /**< @brief A task becomes SD_SCHEDULED when you call function SD_task_schedule. SD_simulate will execute it when it becomes SD_RUNNABLE. */ SD_RUNNABLE = 0x0004, /**< @brief A scheduled task becomes runnable is SD_simulate as soon as its dependencies are satisfied. */ @@ -81,8 +81,8 @@ typedef enum { @see SD_task_management */ typedef enum { SD_TASK_NOT_TYPED = 0, /**< @no specified type */ - SD_TASK_COMM_E2E = 1, /**< @brief end to end communication */ - SD_TASK_COMP_SEQ = 2, /**< @brief sequential computation */ + SD_TASK_COMM_E2E = 1, /**< @brief end to end communication */ + SD_TASK_COMP_SEQ = 2, /**< @brief sequential computation */ } e_SD_task_kind_t; diff --git a/include/simdag/simdag.h b/include/simdag/simdag.h index 23fb9693d9..ec39a0276e 100644 --- a/include/simdag/simdag.h +++ b/include/simdag/simdag.h @@ -68,17 +68,20 @@ XBT_PUBLIC(xbt_dict_t) SD_workstation_get_properties(SD_workstation_t workstation); XBT_PUBLIC(const char *) SD_workstation_get_property_value(SD_workstation_t workstation, - const char *name); + const char + *name); XBT_PUBLIC(const SD_link_t *) SD_route_get_list(SD_workstation_t src, SD_workstation_t dst); -XBT_PUBLIC(int) SD_route_get_size(SD_workstation_t src, SD_workstation_t dst); +XBT_PUBLIC(int) SD_route_get_size(SD_workstation_t src, + SD_workstation_t dst); XBT_PUBLIC(double) SD_workstation_get_power(SD_workstation_t workstation); XBT_PUBLIC(double) SD_workstation_get_available_power(SD_workstation_t workstation); XBT_PUBLIC(e_SD_workstation_access_mode_t) - SD_workstation_get_access_mode(SD_workstation_t workstation); -XBT_PUBLIC(void) SD_workstation_set_access_mode(SD_workstation_t workstation, + SD_workstation_get_access_mode(SD_workstation_t workstation); +XBT_PUBLIC(void) SD_workstation_set_access_mode(SD_workstation_t + workstation, e_SD_workstation_access_mode_t access_mode); @@ -95,7 +98,8 @@ XBT_PUBLIC(double) SD_route_get_communication_time(SD_workstation_t src, double communication_amount); -XBT_PUBLIC(SD_task_t) SD_workstation_get_current_task (SD_workstation_t workstation); +XBT_PUBLIC(SD_task_t) SD_workstation_get_current_task(SD_workstation_t + workstation); /** @} */ /************************** Task handling ************************************/ @@ -128,12 +132,14 @@ XBT_PUBLIC(double) SD_task_get_remaining_amount(SD_task_t task); XBT_PUBLIC(double) SD_task_get_execution_time(SD_task_t task, int workstation_nb, const SD_workstation_t * - workstation_list, const double + workstation_list, + const double *computation_amount, const double *communication_amount); XBT_PUBLIC(int) SD_task_get_kind(SD_task_t task); XBT_PUBLIC(void) SD_task_schedule(SD_task_t task, int workstation_nb, - const SD_workstation_t * workstation_list, + const SD_workstation_t * + workstation_list, const double *computation_amount, const double *communication_amount, double rate); @@ -143,14 +149,18 @@ XBT_PUBLIC(double) SD_task_get_finish_time(SD_task_t task); XBT_PUBLIC(xbt_dynar_t) SD_task_get_parents(SD_task_t task); XBT_PUBLIC(xbt_dynar_t) SD_task_get_children(SD_task_t task); XBT_PUBLIC(int) SD_task_get_workstation_count(SD_task_t task); -XBT_PUBLIC(SD_workstation_t*) SD_task_get_workstation_list(SD_task_t task); +XBT_PUBLIC(SD_workstation_t *) SD_task_get_workstation_list(SD_task_t + task); XBT_PUBLIC(void) SD_task_destroy(SD_task_t task); XBT_PUBLIC(void) SD_task_dump(SD_task_t task); -XBT_PUBLIC(void) SD_task_dotty(SD_task_t task,void* out_FILE); - -XBT_PUBLIC(SD_task_t) SD_task_create_comp_seq(const char*name,void *data,double amount); -XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char*name,void *data,double amount); -XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list); +XBT_PUBLIC(void) SD_task_dotty(SD_task_t task, void *out_FILE); + +XBT_PUBLIC(SD_task_t) SD_task_create_comp_seq(const char *name, void *data, + double amount); +XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char *name, void *data, + double amount); +XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, + const SD_workstation_t * list); XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...); /** @brief A constant to use in SD_task_schedule to mean that there is no cost. @@ -179,7 +189,8 @@ XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...); XBT_PUBLIC(void) SD_task_dependency_add(const char *name, void *data, SD_task_t src, SD_task_t dst); XBT_PUBLIC(void) SD_task_dependency_remove(SD_task_t src, SD_task_t dst); -XBT_PUBLIC(void *) SD_task_dependency_get_data(SD_task_t src, SD_task_t dst); +XBT_PUBLIC(void *) SD_task_dependency_get_data(SD_task_t src, + SD_task_t dst); XBT_PUBLIC(int) SD_task_dependency_exists(SD_task_t src, SD_task_t dst); /** @} */ @@ -200,8 +211,8 @@ XBT_PUBLIC(void) SD_load_environment_script(const char *script_file); XBT_PUBLIC(xbt_dynar_t) SD_simulate(double how_long); XBT_PUBLIC(double) SD_get_clock(void); XBT_PUBLIC(void) SD_exit(void); -XBT_PUBLIC(xbt_dynar_t) SD_daxload(const char*filename); -XBT_PUBLIC(xbt_dynar_t) SD_dotload(const char*filename); +XBT_PUBLIC(xbt_dynar_t) SD_daxload(const char *filename); +XBT_PUBLIC(xbt_dynar_t) SD_dotload(const char *filename); XBT_PUBLIC(void) uniq_transfer_task_name(SD_task_t task); /** @} */ diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 9842282c7b..65fcb2fab5 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -17,7 +17,6 @@ SG_BEGIN_DECL() #define MPI_THREAD_FUNNELED 1 #define MPI_THREAD_SERIALIZED 2 #define MPI_THREAD_MULTIPLE 3 - //FIXME: check values #define MPI_MAX_PROCESSOR_NAME 100 #define MPI_MAX_ERROR_STRING 100 @@ -26,13 +25,11 @@ SG_BEGIN_DECL() #define MPI_MAX_INFO_VAL 100 #define MPI_MAX_OBJECT_NAME 100 #define MPI_MAX_PORT_NAME 100 - #define SMPI_RAND_SEED 5 #define MPI_ANY_SOURCE -1 #define MPI_PROC_NULL -2 #define MPI_ANY_TAG -1 #define MPI_UNDEFINED -1 - // errorcodes #define MPI_SUCCESS 0 #define MPI_ERR_COMM 1 @@ -46,19 +43,16 @@ SG_BEGIN_DECL() #define MPI_ERR_TRUNCATE 9 #define MPI_ERR_GROUP 10 #define MPI_ERR_OP 11 - #define MPI_IDENT 0 #define MPI_SIMILAR 1 #define MPI_UNEQUAL 2 #define MPI_CONGRUENT 3 - #define MPI_WTIME_IS_GLOBAL 1 - typedef ptrdiff_t MPI_Aint; typedef long long MPI_Offset; struct s_smpi_mpi_datatype; -typedef struct s_smpi_mpi_datatype* MPI_Datatype; +typedef struct s_smpi_mpi_datatype *MPI_Datatype; typedef struct { int MPI_SOURCE; @@ -112,9 +106,10 @@ extern MPI_Datatype MPI_2INT; extern MPI_Datatype MPI_LONG_DOUBLE_INT; -typedef void MPI_User_function(void* invec, void* inoutvec, int* len, MPI_Datatype* datatype); +typedef void MPI_User_function(void *invec, void *inoutvec, int *len, + MPI_Datatype * datatype); struct s_smpi_mpi_op; -typedef struct s_smpi_mpi_op* MPI_Op; +typedef struct s_smpi_mpi_op *MPI_Op; #define MPI_OP_NULL NULL extern MPI_Op MPI_MAX; @@ -131,102 +126,178 @@ extern MPI_Op MPI_BOR; extern MPI_Op MPI_BXOR; struct s_smpi_mpi_group; -typedef struct s_smpi_mpi_group* MPI_Group; +typedef struct s_smpi_mpi_group *MPI_Group; #define MPI_GROUP_NULL NULL extern MPI_Group MPI_GROUP_EMPTY; struct s_smpi_mpi_communicator; -typedef struct s_smpi_mpi_communicator* MPI_Comm; +typedef struct s_smpi_mpi_communicator *MPI_Comm; #define MPI_COMM_NULL NULL extern MPI_Comm MPI_COMM_WORLD; #define MPI_COMM_SELF smpi_process_comm_self() struct s_smpi_mpi_request; -typedef struct s_smpi_mpi_request* MPI_Request; +typedef struct s_smpi_mpi_request *MPI_Request; #define MPI_REQUEST_NULL NULL -XBT_PUBLIC(int) MPI_Init(int* argc, char*** argv); +XBT_PUBLIC(int) MPI_Init(int *argc, char ***argv); XBT_PUBLIC(int) MPI_Finalize(void); -XBT_PUBLIC(int) MPI_Init_thread(int* argc, char*** argv, int required, int* provided); -XBT_PUBLIC(int) MPI_Query_thread(int* provided); -XBT_PUBLIC(int) MPI_Is_thread_main(int* flag); +XBT_PUBLIC(int) MPI_Init_thread(int *argc, char ***argv, int required, + int *provided); +XBT_PUBLIC(int) MPI_Query_thread(int *provided); +XBT_PUBLIC(int) MPI_Is_thread_main(int *flag); XBT_PUBLIC(int) MPI_Abort(MPI_Comm comm, int errorcode); XBT_PUBLIC(double) MPI_Wtime(void); -XBT_PUBLIC(int) MPI_Address(void *location, MPI_Aint *address); - -XBT_PUBLIC(int) MPI_Type_free(MPI_Datatype* datatype); -XBT_PUBLIC(int) MPI_Type_size(MPI_Datatype datatype, int* size); -XBT_PUBLIC(int) MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent); -XBT_PUBLIC(int) MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent); -XBT_PUBLIC(int) MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp); -XBT_PUBLIC(int) MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp); - -XBT_PUBLIC(int) MPI_Op_create(MPI_User_function* function, int commute, MPI_Op* op); -XBT_PUBLIC(int) MPI_Op_free(MPI_Op* op); - -XBT_PUBLIC(int) MPI_Group_free(MPI_Group *group); -XBT_PUBLIC(int) MPI_Group_size(MPI_Group group, int* size); -XBT_PUBLIC(int) MPI_Group_rank(MPI_Group group, int* rank); -XBT_PUBLIC(int) MPI_Group_translate_ranks (MPI_Group group1, int n, int* ranks1, MPI_Group group2, int* ranks2); -XBT_PUBLIC(int) MPI_Group_compare(MPI_Group group1, MPI_Group group2, int* result); -XBT_PUBLIC(int) MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_excl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup); -XBT_PUBLIC(int) MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup); - -XBT_PUBLIC(int) MPI_Comm_rank(MPI_Comm comm, int* rank); -XBT_PUBLIC(int) MPI_Comm_size(MPI_Comm comm, int* size); +XBT_PUBLIC(int) MPI_Address(void *location, MPI_Aint * address); + +XBT_PUBLIC(int) MPI_Type_free(MPI_Datatype * datatype); +XBT_PUBLIC(int) MPI_Type_size(MPI_Datatype datatype, int *size); +XBT_PUBLIC(int) MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, + MPI_Aint * extent); +XBT_PUBLIC(int) MPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent); +XBT_PUBLIC(int) MPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp); +XBT_PUBLIC(int) MPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp); + +XBT_PUBLIC(int) MPI_Op_create(MPI_User_function * function, int commute, + MPI_Op * op); +XBT_PUBLIC(int) MPI_Op_free(MPI_Op * op); + +XBT_PUBLIC(int) MPI_Group_free(MPI_Group * group); +XBT_PUBLIC(int) MPI_Group_size(MPI_Group group, int *size); +XBT_PUBLIC(int) MPI_Group_rank(MPI_Group group, int *rank); +XBT_PUBLIC(int) MPI_Group_translate_ranks(MPI_Group group1, int n, + int *ranks1, MPI_Group group2, + int *ranks2); +XBT_PUBLIC(int) MPI_Group_compare(MPI_Group group1, MPI_Group group2, + int *result); +XBT_PUBLIC(int) MPI_Group_union(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_intersection(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_difference(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_incl(MPI_Group group, int n, int *ranks, + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_excl(MPI_Group group, int n, int *ranks, + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_range_incl(MPI_Group group, int n, + int ranges[][3], + MPI_Group * newgroup); +XBT_PUBLIC(int) MPI_Group_range_excl(MPI_Group group, int n, + int ranges[][3], + MPI_Group * newgroup); + +XBT_PUBLIC(int) MPI_Comm_rank(MPI_Comm comm, int *rank); +XBT_PUBLIC(int) MPI_Comm_size(MPI_Comm comm, int *size); XBT_PUBLIC(int) MPI_Get_processor_name(char *name, int *resultlen); -XBT_PUBLIC(int) MPI_Get_count(MPI_Status* status, MPI_Datatype datatype, int* count); - -XBT_PUBLIC(int) MPI_Comm_group(MPI_Comm comm, MPI_Group* group); -XBT_PUBLIC(int) MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int* result); -XBT_PUBLIC(int) MPI_Comm_dup(MPI_Comm comm, MPI_Comm* newcomm); -XBT_PUBLIC(int) MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm* newcomm); -XBT_PUBLIC(int) MPI_Comm_free(MPI_Comm* comm); - -XBT_PUBLIC(int) MPI_Send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request); -XBT_PUBLIC(int) MPI_Recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request); -XBT_PUBLIC(int) MPI_Start(MPI_Request* request); -XBT_PUBLIC(int) MPI_Startall(int count, MPI_Request* requests); -XBT_PUBLIC(int) MPI_Request_free(MPI_Request* request); -XBT_PUBLIC(int) MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request); -XBT_PUBLIC(int) MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request); -XBT_PUBLIC(int) MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status); -XBT_PUBLIC(int) MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status); -XBT_PUBLIC(int) MPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag, MPI_Comm comm, MPI_Status* status); - - -XBT_PUBLIC(int) MPI_Test(MPI_Request* request, int* flag, MPI_Status* status); -XBT_PUBLIC(int) MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status); -XBT_PUBLIC(int) MPI_Wait(MPI_Request* request, MPI_Status* status); -XBT_PUBLIC(int) MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* status); -XBT_PUBLIC(int) MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]); -XBT_PUBLIC(int) MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[]); - -XBT_PUBLIC(int) MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Get_count(MPI_Status * status, MPI_Datatype datatype, + int *count); + +XBT_PUBLIC(int) MPI_Comm_group(MPI_Comm comm, MPI_Group * group); +XBT_PUBLIC(int) MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, + int *result); +XBT_PUBLIC(int) MPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm); +XBT_PUBLIC(int) MPI_Comm_create(MPI_Comm comm, MPI_Group group, + MPI_Comm * newcomm); +XBT_PUBLIC(int) MPI_Comm_free(MPI_Comm * comm); + +XBT_PUBLIC(int) MPI_Send_init(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm, + MPI_Request * request); +XBT_PUBLIC(int) MPI_Recv_init(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm, + MPI_Request * request); +XBT_PUBLIC(int) MPI_Start(MPI_Request * request); +XBT_PUBLIC(int) MPI_Startall(int count, MPI_Request * requests); +XBT_PUBLIC(int) MPI_Request_free(MPI_Request * request); +XBT_PUBLIC(int) MPI_Irecv(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm, + MPI_Request * request); +XBT_PUBLIC(int) MPI_Isend(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm, + MPI_Request * request); +XBT_PUBLIC(int) MPI_Recv(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm, + MPI_Status * status); +XBT_PUBLIC(int) MPI_Send(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Sendrecv(void *sendbuf, int sendcount, + MPI_Datatype sendtype, int dst, int sendtag, + void *recvbuf, int recvcount, + MPI_Datatype recvtype, int src, int recvtag, + MPI_Comm comm, MPI_Status * status); +XBT_PUBLIC(int) MPI_Sendrecv_replace(void *buf, int count, + MPI_Datatype datatype, int dst, + int sendtag, int src, int recvtag, + MPI_Comm comm, MPI_Status * status); + + +XBT_PUBLIC(int) MPI_Test(MPI_Request * request, int *flag, + MPI_Status * status); +XBT_PUBLIC(int) MPI_Testany(int count, MPI_Request requests[], int *index, + int *flag, MPI_Status * status); +XBT_PUBLIC(int) MPI_Wait(MPI_Request * request, MPI_Status * status); +XBT_PUBLIC(int) MPI_Waitany(int count, MPI_Request requests[], int *index, + MPI_Status * status); +XBT_PUBLIC(int) MPI_Waitall(int count, MPI_Request requests[], + MPI_Status status[]); +XBT_PUBLIC(int) MPI_Waitsome(int incount, MPI_Request requests[], + int *outcount, int *indices, + MPI_Status status[]); + +XBT_PUBLIC(int) MPI_Bcast(void *buf, int count, MPI_Datatype datatype, + int root, MPI_Comm comm); XBT_PUBLIC(int) MPI_Barrier(MPI_Comm comm); -XBT_PUBLIC(int) MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -XBT_PUBLIC(int) MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Gather(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, int root, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Gatherv(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int *recvcounts, int *displs, + MPI_Datatype recvtype, int root, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Allgather(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Allgatherv(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int *recvcounts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Scatter(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, int root, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Reduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Allreduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Scan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Reduce_scatter(void *sendbuf, void *recvbuf, + int *recvcounts, MPI_Datatype datatype, + MPI_Op op, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Alltoall(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm); +XBT_PUBLIC(int) MPI_Alltoallv(void *sendbuf, int *sendcounts, + int *senddisps, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, + int *recvdisps, MPI_Datatype recvtype, + MPI_Comm comm); /* TODO @@ -234,17 +305,18 @@ XBT_PUBLIC(int) MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out); */ // smpi functions -XBT_IMPORT_NO_EXPORT(int) smpi_simulated_main(int argc, char** argv); +XBT_IMPORT_NO_EXPORT(int) smpi_simulated_main(int argc, char **argv); XBT_PUBLIC(MPI_Comm) smpi_process_comm_self(void); /* XBT_PUBLIC(void) smpi_exit(int); */ XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int secs); -XBT_PUBLIC(int) smpi_gettimeofday(struct timeval* tv, struct timezone* tz); -XBT_PUBLIC(void) smpi_sample_1(int global, const char* file, int line, int max); -XBT_PUBLIC(int) smpi_sample_2(int global, const char* file, int line); -XBT_PUBLIC(void) smpi_sample_3(int global, const char* file, int line); +XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, struct timezone *tz); +XBT_PUBLIC(void) smpi_sample_1(int global, const char *file, int line, + int max); +XBT_PUBLIC(int) smpi_sample_2(int global, const char *file, int line); +XBT_PUBLIC(void) smpi_sample_3(int global, const char *file, int line); XBT_PUBLIC(void) smpi_sample_flops(double flops); #define SMPI_SAMPLE_LOCAL(num) for(smpi_sample_1(0, __FILE__, __LINE__, num); \ @@ -257,10 +329,11 @@ XBT_PUBLIC(void) smpi_sample_flops(double flops); #define SMPI_SAMPLE_DELAY(flops) for(smpi_sample_flops(flops); 0; ) -XBT_PUBLIC(void*) smpi_shared_malloc(size_t size, const char* file, int line); +XBT_PUBLIC(void *) smpi_shared_malloc(size_t size, const char *file, + int line); #define SMPI_SHARED_MALLOC(size) smpi_shared_malloc(size, __FILE__, __LINE__) -XBT_PUBLIC(void) smpi_shared_free(void* data); +XBT_PUBLIC(void) smpi_shared_free(void *data); #define SMPI_SHARED_FREE(data) smpi_shared_free(data) SG_END_DECL() diff --git a/include/surf/simgrid_dtd.h b/include/surf/simgrid_dtd.h index 66bcfcbbda..433358e0b3 100644 --- a/include/surf/simgrid_dtd.h +++ b/include/surf/simgrid_dtd.h @@ -1,5 +1,5 @@ /* XML processor/application API for src/surf/simgrid.dtd. - * Generated 2010/10/06 15:20:08. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/include/surf/surfxml_parse.h b/include/surf/surfxml_parse.h index 3d48dca056..24d4b91a08 100644 --- a/include/surf/surfxml_parse.h +++ b/include/surf/surfxml_parse.h @@ -15,7 +15,7 @@ SG_BEGIN_DECL() /* Hook for the different tags. All the functions which pointer to are push into here are run when the tag is encountered */ -XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_platform_cb_list; + XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_platform_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_platform_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_host_cb_list; XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_host_cb_list; @@ -58,18 +58,18 @@ XBT_PUBLIC(void) surf_parse_get_double(double *value, const char *string); XBT_PUBLIC(void) surf_parse_get_int(int *value, const char *string); /* Prototypes of the functions offered by flex */ -XBT_PUBLIC(int) surf_parse_lex(void); -XBT_PUBLIC(int) surf_parse_get_lineno(void); +XBT_PUBLIC(int) surf_parse_lex(void); +XBT_PUBLIC(int) surf_parse_get_lineno(void); XBT_PUBLIC(FILE *) surf_parse_get_in(void); XBT_PUBLIC(FILE *) surf_parse_get_out(void); -XBT_PUBLIC(int) surf_parse_get_leng(void); +XBT_PUBLIC(int) surf_parse_get_leng(void); XBT_PUBLIC(char *) surf_parse_get_text(void); -XBT_PUBLIC(void) surf_parse_set_lineno(int line_number); -XBT_PUBLIC(void) surf_parse_set_in(FILE * in_str); -XBT_PUBLIC(void) surf_parse_set_out(FILE * out_str); -XBT_PUBLIC(int) surf_parse_get_debug(void); -XBT_PUBLIC(void) surf_parse_set_debug(int bdebug); -XBT_PUBLIC(int) surf_parse_lex_destroy(void); +XBT_PUBLIC(void) surf_parse_set_lineno(int line_number); +XBT_PUBLIC(void) surf_parse_set_in(FILE * in_str); +XBT_PUBLIC(void) surf_parse_set_out(FILE * out_str); +XBT_PUBLIC(int) surf_parse_get_debug(void); +XBT_PUBLIC(void) surf_parse_set_debug(int bdebug); +XBT_PUBLIC(int) surf_parse_lex_destroy(void); /* What is needed to bypass the parser. */ @@ -102,8 +102,10 @@ extern unsigned int surfxml_buffer_stack_stack[1024]; ETag_surfxml_##tag();\ } while(0) -XBT_PUBLIC(void) surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function); -XBT_PUBLIC(void) surfxml_del_callback(xbt_dynar_t* cb_list, void_f_void_t function); +XBT_PUBLIC(void) surfxml_add_callback(xbt_dynar_t cb_list, + void_f_void_t function); +XBT_PUBLIC(void) surfxml_del_callback(xbt_dynar_t * cb_list, + void_f_void_t function); SG_END_DECL() #endif diff --git a/include/xbt.h b/include/xbt.h index 798b1365a8..7b53927901 100644 --- a/include/xbt.h +++ b/include/xbt.h @@ -33,4 +33,4 @@ /* pimple to display the message sizes */ XBT_PUBLIC(void) SIMIX_message_sizes_output(const char *filename); -#endif /* xbt_H */ +#endif /* xbt_H */ diff --git a/include/xbt/asserts.h b/include/xbt/asserts.h index 7173df7ab8..fa1af88227 100644 --- a/include/xbt/asserts.h +++ b/include/xbt/asserts.h @@ -53,5 +53,5 @@ SG_BEGIN_DECL() #define xbt_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) THROW6(0,0,msg,a,b,c,d,e,f) #endif /** @} */ - SG_END_DECL() -#endif /* _XBT_ASSERTS_H */ + SG_END_DECL() +#endif /* _XBT_ASSERTS_H */ diff --git a/include/xbt/config.h b/include/xbt/config.h index 74378940a1..6000dbb659 100644 --- a/include/xbt/config.h +++ b/include/xbt/config.h @@ -89,7 +89,7 @@ SG_BEGIN_DECL() * @{ */ /** @brief Configuration set are only special dynars. But don't rely on it, it may change. */ - typedef xbt_dynar_t xbt_cfg_t; +typedef xbt_dynar_t 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, @@ -112,10 +112,14 @@ XBT_PUBLIC(void) xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, Set the default value of the cell \a name in \a cfg with the provided value. If it was already set to something (possibly from the command line), do nothing. */ -XBT_PUBLIC(void) xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, int val); -XBT_PUBLIC(void) xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, double val); -XBT_PUBLIC(void) xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name, const char* val); -XBT_PUBLIC(void) xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name, const char* host, int port); +XBT_PUBLIC(void) xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, + int val); +XBT_PUBLIC(void) xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, + double val); +XBT_PUBLIC(void) xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name, + const char *val); +XBT_PUBLIC(void) xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name, + const char *host, int port); /* @@ -146,24 +150,25 @@ XBT_PUBLIC(void) xbt_cfg_empty(xbt_cfg_t cfg, const char *name); */ /** @brief possible content of each configuration cell */ - typedef enum { - xbt_cfgelm_int = 0, +typedef enum { + xbt_cfgelm_int = 0, /**< int */ - xbt_cfgelm_double, + xbt_cfgelm_double, /**< double */ - xbt_cfgelm_string, + xbt_cfgelm_string, /**< char* */ - xbt_cfgelm_peer,/**< both a char* (representing the peername) and an integer (representing the port) */ + xbt_cfgelm_peer, /**< both a char* (representing the peername) and an integer (representing the port) */ - xbt_cfgelm_any, /* not shown to users to prevent errors */ - xbt_cfgelm_type_count - } e_xbt_cfgelm_type_t; + xbt_cfgelm_any, /* not shown to users to prevent errors */ + xbt_cfgelm_type_count +} e_xbt_cfgelm_type_t; /** \brief Callback types. They get the name of the modified entry, and the position of the changed value */ - typedef void (*xbt_cfg_cb_t) (const char *, int); +typedef void (*xbt_cfg_cb_t) (const char *, int); XBT_PUBLIC(xbt_cfg_t) xbt_cfg_new(void); -XBT_PUBLIC(void) xbt_cfg_cpy(xbt_cfg_t tocopy, /* OUT */ xbt_cfg_t * whereto); +XBT_PUBLIC(void) xbt_cfg_cpy(xbt_cfg_t tocopy, /* OUT */ + xbt_cfg_t * whereto); XBT_PUBLIC(void) xbt_cfg_free(xbt_cfg_t * cfg); XBT_PUBLIC(void) xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg); @@ -179,7 +184,8 @@ XBT_PUBLIC(void) xbt_cfg_dump(const char *name, const char *indent, * @{ */ XBT_PUBLIC(void) xbt_cfg_register(xbt_cfg_t * cfg, - const char *name, const char *description, + const char *name, + const char *description, e_xbt_cfgelm_type_t type, void *default_value, int min, int max, xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm); @@ -211,15 +217,16 @@ XBT_PUBLIC(void) xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name, char **peer, int *port); XBT_PUBLIC(xbt_dynar_t) xbt_cfg_get_dynar(xbt_cfg_t cfg, const char *name); -XBT_PUBLIC(int) xbt_cfg_get_int_at(xbt_cfg_t cfg, const char *name, int pos); +XBT_PUBLIC(int) xbt_cfg_get_int_at(xbt_cfg_t cfg, const char *name, + int pos); XBT_PUBLIC(double) xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos); XBT_PUBLIC(char *) xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos); -XBT_PUBLIC(void) xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name, int pos, - char **peer, int *port); +XBT_PUBLIC(void) xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name, + int pos, char **peer, int *port); /** @} */ SG_END_DECL() -#endif /* _XBT_CONFIG_H_ */ +#endif /* _XBT_CONFIG_H_ */ diff --git a/include/xbt/cunit.h b/include/xbt/cunit.h index ba306a7d00..97106f238d 100644 --- a/include/xbt/cunit.h +++ b/include/xbt/cunit.h @@ -17,13 +17,13 @@ SG_BEGIN_DECL() /* test suite object type */ - typedef struct s_xbt_test_suite *xbt_test_suite_t; +typedef struct s_xbt_test_suite *xbt_test_suite_t; /* test object type */ - typedef struct s_xbt_test_unit *xbt_test_unit_t; +typedef struct s_xbt_test_unit *xbt_test_unit_t; /* test callback function type */ - typedef void (*ts_test_cb_t) (void); +typedef void (*ts_test_cb_t) (void); /* test suite operations */ XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_new(const char *name, @@ -31,8 +31,9 @@ XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_new(const char *name, XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_by_name(const char *name, const char *fmt, ...); XBT_PUBLIC(void) xbt_test_suite_dump(xbt_test_suite_t suite); -XBT_PUBLIC(void) xbt_test_suite_push(xbt_test_suite_t suite, const char *name, - ts_test_cb_t func, const char *fmt, ...); +XBT_PUBLIC(void) xbt_test_suite_push(xbt_test_suite_t suite, + const char *name, ts_test_cb_t func, + const char *fmt, ...); /* Run all the specified tests. what_to_do allows to disable some tests. * It is a coma (,) separated list of directives. They are applied from left to right. @@ -66,8 +67,9 @@ XBT_PUBLIC(void) _xbt_test_add(const char *file, int line, const char *fmt, #define xbt_test_add4(fmt,a,b,c,d) _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d) #define xbt_test_add5(fmt,a,b,c,d,e) _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d,e) -XBT_PUBLIC(void) _xbt_test_fail(const char *file, int line, const char *fmt, - ...) _XBT_GNUC_PRINTF(3, 4); +XBT_PUBLIC(void) _xbt_test_fail(const char *file, int line, + const char *fmt, ...) _XBT_GNUC_PRINTF(3, + 4); #define xbt_test_fail0(fmt) _xbt_test_fail(__FILE__, __LINE__, fmt) #define xbt_test_fail1(fmt,a) _xbt_test_fail(__FILE__, __LINE__, fmt,a) #define xbt_test_fail2(fmt,a,b) _xbt_test_fail(__FILE__, __LINE__, fmt,a,b) @@ -103,4 +105,4 @@ XBT_PUBLIC(void) xbt_test_skip(void); void func(void) SG_END_DECL() -#endif /* _TS_H_ */ +#endif /* _TS_H_ */ diff --git a/include/xbt/dict.h b/include/xbt/dict.h index 0463bb58e3..e8ea361617 100644 --- a/include/xbt/dict.h +++ b/include/xbt/dict.h @@ -12,7 +12,7 @@ #include "xbt/misc.h" /* SG_BEGIN_DECL */ #include "xbt/dynar.h" /* void_f_pvoid_t */ -#include /* uintptr_t */ +#include /* uintptr_t */ SG_BEGIN_DECL(); @@ -61,7 +61,7 @@ XBT_PUBLIC(void) xbt_dict_set(xbt_dict_t dict, const char *key, void *data, void_f_pvoid_t free_ctn); XBT_PUBLIC(void *) xbt_dict_get(xbt_dict_t dict, const char *key); XBT_PUBLIC(void *) xbt_dict_get_or_null(xbt_dict_t dict, const char *key); -XBT_PUBLIC(char *) xbt_dict_get_key(xbt_dict_t dict, const void*data); +XBT_PUBLIC(char *) xbt_dict_get_key(xbt_dict_t dict, const void *data); XBT_PUBLIC(void) xbt_dict_remove(xbt_dict_t dict, const char *key); XBT_PUBLIC(void) xbt_dict_reset(xbt_dict_t dict); @@ -85,13 +85,14 @@ XBT_PUBLIC(void) xbt_dict_set_ext(xbt_dict_t dict, void *data, void_f_pvoid_t free_ctn); XBT_PUBLIC(void *) xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len); -XBT_PUBLIC(void *) xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, - int key_len); +XBT_PUBLIC(void *) xbt_dict_get_or_null_ext(xbt_dict_t dict, + const char *key, int key_len); XBT_PUBLIC(void) xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len); -XBT_PUBLIC(void) xbt_dicti_set(xbt_dict_t dict, uintptr_t key, uintptr_t data); +XBT_PUBLIC(void) xbt_dicti_set(xbt_dict_t dict, uintptr_t key, + uintptr_t data); XBT_PUBLIC(uintptr_t) xbt_dicti_get(xbt_dict_t dict, uintptr_t key); XBT_PUBLIC(void) xbt_dicti_remove(xbt_dict_t dict, uintptr_t key); @@ -119,17 +120,19 @@ XBT_PUBLIC(void) xbt_dicti_remove(xbt_dict_t dict, uintptr_t key); * @{ */ /** @brief Cursor on dictionaries (opaque type) */ - typedef struct xbt_dict_cursor_ *xbt_dict_cursor_t; +typedef struct 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); -XBT_INLINE XBT_PUBLIC(void) xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor); +XBT_INLINE XBT_PUBLIC(void) xbt_dict_cursor_rewind(xbt_dict_cursor_t + cursor); XBT_PUBLIC(char *) xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor); XBT_PUBLIC(void *) xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor); XBT_PUBLIC(void) xbt_dict_cursor_set_data(xbt_dict_cursor_t cursor, - void *data, void_f_pvoid_t free_ctn); + void *data, + void_f_pvoid_t free_ctn); XBT_PUBLIC(void) xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t * cursor); @@ -174,16 +177,18 @@ xbt_multidict_set_ext(xbt_dict_t mdict, /*----[ xbt_multidict_get ]--------------------------------------------------*/ XBT_PUBLIC(void *) xbt_multidict_get(xbt_dict_t mdict, xbt_dynar_t keys); -XBT_PUBLIC(void *) xbt_multidict_get_ext(xbt_dict_t mdict, xbt_dynar_t keys, +XBT_PUBLIC(void *) xbt_multidict_get_ext(xbt_dict_t mdict, + xbt_dynar_t keys, xbt_dynar_t lens); /*----[ xbt_multidict_remove ]-----------------------------------------------*/ /*---------------------------------------------------------------------------*/ XBT_PUBLIC(void) xbt_multidict_remove(xbt_dict_t mdict, xbt_dynar_t keys); -XBT_PUBLIC(void) xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, +XBT_PUBLIC(void) xbt_multidict_remove_ext(xbt_dict_t mdict, + xbt_dynar_t keys, xbt_dynar_t lens); /** @} */ SG_END_DECL() -#endif /* _XBT_DICT_H */ +#endif /* _XBT_DICT_H */ diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index b8ae658b86..49d2334617 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -9,7 +9,7 @@ #ifndef _XBT_DYNAR_H #define _XBT_DYNAR_H -#include /* memcpy */ +#include /* memcpy */ #include "xbt/misc.h" /* SG_BEGIN_DECL */ #include "xbt/function_types.h" @@ -59,7 +59,7 @@ SG_BEGIN_DECL() * @{ */ /** \brief Dynar data type (opaque type) */ - typedef struct xbt_dynar_s *xbt_dynar_t; +typedef struct xbt_dynar_s *xbt_dynar_t; XBT_PUBLIC(xbt_dynar_t) xbt_dynar_new(const unsigned long elm_size, @@ -70,8 +70,9 @@ XBT_INLINE XBT_PUBLIC(void) xbt_dynar_free(xbt_dynar_t * dynar); XBT_PUBLIC(void) xbt_dynar_free_voidp(void *dynar); XBT_PUBLIC(void) xbt_dynar_free_container(xbt_dynar_t * dynar); -XBT_INLINE XBT_PUBLIC(unsigned long) xbt_dynar_length(const xbt_dynar_t dynar); -XBT_INLINE XBT_PUBLIC (int) xbt_dynar_is_empty(const xbt_dynar_t dynar); +XBT_INLINE XBT_PUBLIC(unsigned long) xbt_dynar_length(const xbt_dynar_t + dynar); +XBT_INLINE XBT_PUBLIC(int) xbt_dynar_is_empty(const xbt_dynar_t dynar); XBT_PUBLIC(void) xbt_dynar_reset(xbt_dynar_t const dynar); XBT_PUBLIC(void) xbt_dynar_shrink(xbt_dynar_t dynar, int empty_slots); @@ -85,21 +86,25 @@ XBT_PUBLIC(void) xbt_dynar_dump(xbt_dynar_t dynar); */ XBT_PUBLIC(void) xbt_dynar_get_cpy(const xbt_dynar_t dynar, - const unsigned long idx, void *const dst); + const unsigned long idx, + void *const dst); XBT_PUBLIC(void) xbt_dynar_set(xbt_dynar_t dynar, const int idx, const void *src); -XBT_PUBLIC(void) xbt_dynar_replace(xbt_dynar_t dynar, const unsigned long idx, +XBT_PUBLIC(void) xbt_dynar_replace(xbt_dynar_t dynar, + const unsigned long idx, const void *object); -XBT_PUBLIC(void) xbt_dynar_insert_at(xbt_dynar_t const dynar, const int idx, - const void *src); -XBT_PUBLIC(void) xbt_dynar_remove_at(xbt_dynar_t const dynar, const int idx, - void *const dst); +XBT_PUBLIC(void) xbt_dynar_insert_at(xbt_dynar_t const dynar, + const int idx, const void *src); +XBT_PUBLIC(void) xbt_dynar_remove_at(xbt_dynar_t const dynar, + const int idx, void *const dst); -XBT_PUBLIC(unsigned int) xbt_dynar_search(xbt_dynar_t const dynar, void *elem); +XBT_PUBLIC(unsigned int) xbt_dynar_search(xbt_dynar_t const dynar, + void *elem); XBT_PUBLIC(int) xbt_dynar_member(xbt_dynar_t const dynar, void *elem); -XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar, int_f_cpvoid_cpvoid_t compar_fn); +XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar, + int_f_cpvoid_cpvoid_t compar_fn); /** @} */ /** @defgroup XBT_dynar_perl Perl-like use of dynars @@ -108,9 +113,12 @@ XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar, int_f_cpvoid_cpvoid_t c * @{ */ -XBT_INLINE XBT_PUBLIC(void) xbt_dynar_push(xbt_dynar_t const dynar, const void *src); -XBT_INLINE XBT_PUBLIC(void) xbt_dynar_pop(xbt_dynar_t const dynar, void *const dst); -XBT_PUBLIC(void) xbt_dynar_unshift(xbt_dynar_t const dynar, const void *src); +XBT_INLINE XBT_PUBLIC(void) xbt_dynar_push(xbt_dynar_t const dynar, + const void *src); +XBT_INLINE XBT_PUBLIC(void) xbt_dynar_pop(xbt_dynar_t const dynar, + void *const dst); +XBT_PUBLIC(void) xbt_dynar_unshift(xbt_dynar_t const dynar, + const void *src); XBT_PUBLIC(void) xbt_dynar_shift(xbt_dynar_t const dynar, void *const dst); XBT_PUBLIC(void) xbt_dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op); @@ -125,7 +133,7 @@ XBT_PUBLIC(void) xbt_dynar_map(const xbt_dynar_t dynar, */ XBT_INLINE XBT_PUBLIC(void *) xbt_dynar_get_ptr(const xbt_dynar_t dynar, - const unsigned long idx); + const unsigned long idx); XBT_PUBLIC(void *) xbt_dynar_insert_at_ptr(xbt_dynar_t const dynar, const int idx); XBT_PUBLIC(void *) xbt_dynar_push_ptr(xbt_dynar_t const dynar); @@ -186,7 +194,8 @@ XBT_PUBLIC(void *) xbt_dynar_pop_ptr(xbt_dynar_t const dynar); */ XBT_INLINE XBT_PUBLIC(void) xbt_dynar_cursor_rm(xbt_dynar_t dynar, - unsigned int *const cursor); + unsigned int *const + cursor); XBT_PUBLIC(void) xbt_dynar_cursor_unlock(xbt_dynar_t dynar); /* do not use this structure internals directly, but use the public interface @@ -206,10 +215,11 @@ typedef struct xbt_dynar_s { } s_xbt_dynar_t; static XBT_INLINE void -_xbt_dynar_cursor_first(const xbt_dynar_t dynar, unsigned int *const cursor) +_xbt_dynar_cursor_first(const xbt_dynar_t dynar, + unsigned int *const cursor) { /* don't test for dynar!=NULL. The segfault would tell us */ - if (dynar->mutex) /* ie _dynar_lock(dynar) but not public */ + if (dynar->mutex) /* ie _dynar_lock(dynar) but not public */ xbt_mutex_acquire(dynar->mutex); //DEBUG1("Set cursor on %p to the first position", (void *) dynar); @@ -223,13 +233,14 @@ _xbt_dynar_cursor_get(const xbt_dynar_t dynar, if (idx >= dynar->used) { //DEBUG1("Cursor on %p already on last elem", (void *) dynar); - if (dynar->mutex) /* unlock */ + if (dynar->mutex) /* unlock */ xbt_mutex_release(dynar->mutex); return FALSE; } // DEBUG2("Cash out cursor on %p at %u", (void *) dynar, *idx); - memcpy(dst, ((char*)dynar->data) + idx * dynar->elmsize, dynar->elmsize); + memcpy(dst, ((char *) dynar->data) + idx * dynar->elmsize, + dynar->elmsize); return TRUE; } @@ -261,4 +272,4 @@ xbt_dynar_foreach (dyn,cpt,str) { /** @} */ SG_END_DECL() -#endif /* _XBT_DYNAR_H */ +#endif /* _XBT_DYNAR_H */ diff --git a/include/xbt/ex.h b/include/xbt/ex.h index 76673411e0..26d2033c8b 100644 --- a/include/xbt/ex.h +++ b/include/xbt/ex.h @@ -51,11 +51,9 @@ SG_BEGIN_DECL() /*-*-* Emergency debuging: define this when the exceptions get crazy *-*-*/ #undef __EX_MAYDAY - #ifdef __EX_MAYDAY # include #include - # define MAYDAY_SAVE(m) printf("%d %s:%d save %p\n", \ (*xbt_getpid)(),__FILE__,__LINE__, \ (m)->jb \ @@ -73,23 +71,19 @@ SG_BEGIN_DECL() # define MAYDAY_RESTORE(m) # define MAYDAY_CATCH(e) #endif - /*-*-* end of debugging stuff *-*-*/ - #if defined(__EX_MCTX_MCSC__) #include /* POSIX.1 ucontext(3) */ #define __ex_mctx_struct ucontext_t uc; #define __ex_mctx_save(mctx) (getcontext(&(mctx)->uc) == 0) #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) (void)setcontext(&(mctx)->uc) - #elif defined(__EX_MCTX_SSJLJ__) #include /* POSIX.1 sigjmp_buf(3) */ #define __ex_mctx_struct sigjmp_buf jb; #define __ex_mctx_save(mctx) (sigsetjmp((mctx)->jb, 1) == 0) #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) (void)siglongjmp((mctx)->jb, 1) - #elif defined(__EX_MCTX_SJLJ__) || !defined(__EX_MCTX_CUSTOM__) || defined(__EX_MAYDAY) #include /* ISO-C jmp_buf(3) */ #define __ex_mctx_struct jmp_buf jb; @@ -97,7 +91,6 @@ SG_BEGIN_DECL() #define __ex_mctx_restored(mctx) /* noop */ #define __ex_mctx_restore(mctx) ( MAYDAY_RESTORE(mctx) (void)longjmp((mctx)->jb, 1)) #endif - /* declare the machine context type */ typedef struct { __ex_mctx_struct} __ex_mctx_t; @@ -274,34 +267,34 @@ typedef enum { XBT_PUBLIC(const char *) xbt_ex_catname(xbt_errcat_t cat); /** @brief Structure describing an exception */ - typedef struct { - char *msg; /**< human readable message */ - xbt_errcat_t category; +typedef struct { + char *msg; /**< human readable message */ + xbt_errcat_t category; /**< category like HTTP (what went wrong) */ - int value; /**< like errno (why did it went wrong) */ - /* throw point */ - short int remote; + int value; /**< like errno (why did it went wrong) */ + /* throw point */ + short int remote; /**< whether it was raised remotely */ - char *host;/**< NULL locally thrown exceptions; full hostname if remote ones */ - /* FIXME: host should be hostname:port[#thread] */ - char *procname; + char *host; /**< NULL locally thrown exceptions; full hostname if remote ones */ + /* FIXME: host should be hostname:port[#thread] */ + char *procname; /**< Name of the process who thrown this */ - int pid; /**< PID of the process who thrown this */ - char *file;/**< Thrown point */ - int line; /**< Thrown point */ - char *func;/**< Thrown point */ - /* Backtrace */ - int used; - char **bt_strings; /* only filed on display (or before the network propagation) */ - void *bt[XBT_BACKTRACE_SIZE]; - } xbt_ex_t; + int pid; /**< PID of the process who thrown this */ + char *file; /**< Thrown point */ + int line; /**< Thrown point */ + char *func; /**< Thrown point */ + /* Backtrace */ + int used; + char **bt_strings; /* only filed on display (or before the network propagation) */ + void *bt[XBT_BACKTRACE_SIZE]; +} xbt_ex_t; /* declare the context type (private) */ - typedef struct { - __ex_mctx_t *ctx_mctx; /* permanent machine context of enclosing try/catch */ - volatile int ctx_caught; /* temporary flag whether exception was caught */ - volatile xbt_ex_t ctx_ex; /* temporary exception storage */ - } ex_ctx_t; +typedef struct { + __ex_mctx_t *ctx_mctx; /* permanent machine context of enclosing try/catch */ + volatile int ctx_caught; /* temporary flag whether exception was caught */ + volatile xbt_ex_t ctx_ex; /* temporary exception storage */ +} ex_ctx_t; /* the static and dynamic initializers for a context structure */ #define XBT_CTX_INITIALIZER \ @@ -337,14 +330,14 @@ XBT_PUBLIC(const char *) xbt_ex_catname(xbt_errcat_t cat); } while (0) /* the exception context */ - typedef ex_ctx_t *(*ex_ctx_cb_t) (void); +typedef ex_ctx_t *(*ex_ctx_cb_t) (void); XBT_PUBLIC_DATA(ex_ctx_cb_t) __xbt_ex_ctx; - extern ex_ctx_t *__xbt_ex_ctx_default(void); +extern ex_ctx_t *__xbt_ex_ctx_default(void); /* the termination handler */ - typedef void (*ex_term_cb_t) (xbt_ex_t *); +typedef void (*ex_term_cb_t) (xbt_ex_t *); XBT_PUBLIC_DATA(ex_term_cb_t) __xbt_ex_terminate; - extern void __xbt_ex_terminate_default(xbt_ex_t * e); +extern void __xbt_ex_terminate_default(xbt_ex_t * e); /** @brief Introduce a block where exception may be dealed with * @hideinitializer @@ -548,4 +541,4 @@ XBT_PUBLIC(void) xbt_backtrace_display(xbt_ex_t * e); SG_END_DECL() /** @} */ -#endif /* __XBT_EX_H__ */ +#endif /* __XBT_EX_H__ */ diff --git a/include/xbt/fifo.h b/include/xbt/fifo.h index 6d27abbad9..81762b5a5a 100644 --- a/include/xbt/fifo.h +++ b/include/xbt/fifo.h @@ -23,11 +23,11 @@ SG_BEGIN_DECL() */ /** \brief Bucket structure */ - typedef struct xbt_fifo_item *xbt_fifo_item_t; +typedef struct xbt_fifo_item *xbt_fifo_item_t; /** \brief FIFO structure */ - typedef struct xbt_fifo *xbt_fifo_t; +typedef struct xbt_fifo *xbt_fifo_t; XBT_PUBLIC(xbt_fifo_t) xbt_fifo_new(void); XBT_PUBLIC(void) xbt_fifo_free(xbt_fifo_t); @@ -66,8 +66,10 @@ XBT_PUBLIC(int) xbt_fifo_remove(xbt_fifo_t, void *); XBT_PUBLIC(int) xbt_fifo_remove_all(xbt_fifo_t, void *); XBT_PUBLIC(void) xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t); -XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_first_item(xbt_fifo_t l); -XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_last_item(xbt_fifo_t l); +XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_first_item(xbt_fifo_t + l); +XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_last_item(xbt_fifo_t + l); XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_next_item(xbt_fifo_item_t i); XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_prev_item(xbt_fifo_item_t i); @@ -108,4 +110,4 @@ XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_getPrevItem(xbt_fifo_item_t i); SG_END_DECL() -#endif /* _XBT_FIFO_H */ +#endif /* _XBT_FIFO_H */ diff --git a/include/xbt/function_types.h b/include/xbt/function_types.h index 201bdb7751..c8b0f0fb6d 100644 --- a/include/xbt/function_types.h +++ b/include/xbt/function_types.h @@ -15,17 +15,17 @@ SG_BEGIN_DECL() typedef void (*void_f_ppvoid_t) (void **); typedef void (*void_f_pvoid_t) (void *); -typedef void (*void_f_int_pvoid_t) (int,void *); - typedef void *(*pvoid_f_void_t) (void); - typedef void *(*pvoid_f_pvoid_t) (void *); - typedef void (*void_f_void_t) (void); +typedef void (*void_f_int_pvoid_t) (int, void *); +typedef void *(*pvoid_f_void_t) (void); +typedef void *(*pvoid_f_pvoid_t) (void *); +typedef void (*void_f_void_t) (void); - typedef int (*int_f_void_t) (void); +typedef int (*int_f_void_t) (void); - typedef int (*int_f_pvoid_pvoid_t) (void *, void *); - typedef int (*int_f_cpvoid_cpvoid_t) (const void *, const void *); +typedef int (*int_f_pvoid_pvoid_t) (void *, void *); +typedef int (*int_f_cpvoid_cpvoid_t) (const void *, const void *); - typedef int (*xbt_main_func_t) (int argc, char *argv[]); +typedef int (*xbt_main_func_t) (int argc, char *argv[]); SG_END_DECL() -#endif /* XBT_FUNCTION_TYPE_H */ +#endif /* XBT_FUNCTION_TYPE_H */ diff --git a/include/xbt/graph.h b/include/xbt/graph.h index e37223251d..a35336e3d8 100644 --- a/include/xbt/graph.h +++ b/include/xbt/graph.h @@ -15,9 +15,9 @@ SG_BEGIN_DECL() * * @{ */ - typedef struct xbt_node *xbt_node_t; - typedef struct xbt_edge *xbt_edge_t; - typedef struct xbt_graph *xbt_graph_t; +typedef struct xbt_node *xbt_node_t; +typedef struct xbt_edge *xbt_edge_t; +typedef struct xbt_graph *xbt_graph_t; /* API */ XBT_PUBLIC(xbt_graph_t) xbt_graph_new_graph(unsigned short int directed, @@ -55,27 +55,28 @@ XBT_PUBLIC(xbt_dynar_t) xbt_graph_node_get_outedges(xbt_node_t n); XBT_PUBLIC(xbt_node_t) xbt_graph_edge_get_source(xbt_edge_t e); XBT_PUBLIC(xbt_node_t) xbt_graph_edge_get_target(xbt_edge_t e); XBT_PUBLIC(xbt_graph_t) xbt_graph_read(const char *filename, void - * (node_label_and_data) (xbt_node_t, - const char *, - const char *), - void - * (edge_label_and_data) (xbt_edge_t, - const char *, - const char *) - ); + *(node_label_and_data) (xbt_node_t, + const char + *, + const char + *), void + *(edge_label_and_data) (xbt_edge_t, + const char + *, + const char + *) + ); XBT_PUBLIC(void) xbt_graph_export_graphviz(xbt_graph_t g, const char *filename, const char - * (node_name) (xbt_node_t), const char - * (edge_name) (xbt_edge_t)); + *(node_name) (xbt_node_t), const char + *(edge_name) (xbt_edge_t)); XBT_PUBLIC(void) xbt_graph_export_graphxml(xbt_graph_t g, const char *filename, const char - * (node_name) (xbt_node_t), const char - * (edge_name) (xbt_edge_t), - const char *(node_data_print) (void - *), - const char *(edge_data_print) (void - *)); + *(node_name) (xbt_node_t), const char + *(edge_name) (xbt_edge_t), const char + *(node_data_print) (void *), const char + *(edge_data_print) (void *)); /* Not implemented yet ! */ /* void *xbt_graph_to_array(xbt_graph_t g); */ @@ -110,5 +111,5 @@ XBT_PUBLIC(xbt_edge_t *) xbt_graph_spanning_tree_prim(xbt_graph_t g); SG_END_DECL() -#endif /* _XBT_GRAPH_H */ +#endif /* _XBT_GRAPH_H */ /** @} */ diff --git a/include/xbt/graphxml.h b/include/xbt/graphxml.h index c06d64cc32..67473ceac8 100644 --- a/include/xbt/graphxml.h +++ b/include/xbt/graphxml.h @@ -1,5 +1,5 @@ /* XML processor/application API for src/xbt/graphxml.dtd. - * Generated 2010/10/01 22:34:15. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/include/xbt/graphxml_parse.h b/include/xbt/graphxml_parse.h index 84d3df835c..9e3ff4fefa 100644 --- a/include/xbt/graphxml_parse.h +++ b/include/xbt/graphxml_parse.h @@ -9,7 +9,7 @@ #ifndef _XBT_GRAPHXML_PARSE_H #define _XBT_GRAPHXML_PARSE_H -#include /* to have FILE */ +#include /* to have FILE */ #include "xbt/misc.h" #include "xbt/graphxml.h" #include "simgrid_config.h" diff --git a/include/xbt/hash.h b/include/xbt/hash.h index a238d98a4c..b4bd66dccd 100644 --- a/include/xbt/hash.h +++ b/include/xbt/hash.h @@ -28,4 +28,4 @@ XBT_PUBLIC(char *) xbt_sha_read(xbt_sha_t sha); XBT_PUBLIC(void) xbt_sha(const char *data, char *hash); -#endif /* XBT_HASH_H */ +#endif /* XBT_HASH_H */ diff --git a/include/xbt/heap.h b/include/xbt/heap.h index 4b5e707030..ab20dfea89 100644 --- a/include/xbt/heap.h +++ b/include/xbt/heap.h @@ -18,7 +18,8 @@ /* @brief heap datatype */ typedef struct xbt_heap *xbt_heap_t; -XBT_PUBLIC(xbt_heap_t) xbt_heap_new(int num, void_f_pvoid_t const free_func); +XBT_PUBLIC(xbt_heap_t) xbt_heap_new(int num, + void_f_pvoid_t const free_func); XBT_PUBLIC(void) xbt_heap_free(xbt_heap_t H); XBT_PUBLIC(int) xbt_heap_size(xbt_heap_t H); @@ -27,8 +28,11 @@ XBT_PUBLIC(void *) xbt_heap_pop(xbt_heap_t H); XBT_PUBLIC(double) xbt_heap_maxkey(xbt_heap_t H); XBT_PUBLIC(void *) xbt_heap_maxcontent(xbt_heap_t H); -XBT_PUBLIC(void) xbt_heap_set_update_callback(xbt_heap_t H, void (*update_callback)(void*, int)); -XBT_PUBLIC(void*) xbt_heap_remove(xbt_heap_t H, int i); +XBT_PUBLIC(void) xbt_heap_set_update_callback(xbt_heap_t H, + void (*update_callback) (void + *, + int)); +XBT_PUBLIC(void *) xbt_heap_remove(xbt_heap_t H, int i); /* @} */ -#endif /* _XBT_HEAP_H */ +#endif /* _XBT_HEAP_H */ diff --git a/include/xbt/log.h b/include/xbt/log.h index e51c491c12..a964acdc04 100644 --- a/include/xbt/log.h +++ b/include/xbt/log.h @@ -42,20 +42,20 @@ SG_BEGIN_DECL() * * The different existing priorities. */ - typedef enum { - xbt_log_priority_none = 0, /* used internally (don't poke with) */ - xbt_log_priority_trace = 1, /**< enter and return of some functions */ - xbt_log_priority_debug = 2, /**< crufty output */ - xbt_log_priority_verbose = 3, /**< verbose output for the user wanting more */ - xbt_log_priority_info = 4, /**< output about the regular functionning */ - xbt_log_priority_warning = 5, /**< minor issue encountered */ - xbt_log_priority_error = 6, /**< issue encountered */ - xbt_log_priority_critical = 7, /**< major issue encountered */ +typedef enum { + xbt_log_priority_none = 0, /* used internally (don't poke with) */ + xbt_log_priority_trace = 1, /**< enter and return of some functions */ + xbt_log_priority_debug = 2, /**< crufty output */ + xbt_log_priority_verbose = 3, /**< verbose output for the user wanting more */ + xbt_log_priority_info = 4, /**< output about the regular functionning */ + xbt_log_priority_warning = 5, /**< minor issue encountered */ + xbt_log_priority_error = 6, /**< issue encountered */ + xbt_log_priority_critical = 7, /**< major issue encountered */ - xbt_log_priority_infinite = 8, /**< value for XBT_LOG_STATIC_THRESHOLD to not log */ + xbt_log_priority_infinite = 8, /**< value for XBT_LOG_STATIC_THRESHOLD to not log */ - xbt_log_priority_uninitialized = -1 /* used internally (don't poke with) */ - } e_xbt_log_priority_t; + xbt_log_priority_uninitialized = -1 /* used internally (don't poke with) */ +} e_xbt_log_priority_t; /* @@ -77,13 +77,13 @@ SG_BEGIN_DECL() # ifdef NDEBUG # define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_verbose -# else /* !NLOG && !NDEBUG */ +# else /* !NLOG && !NDEBUG */ # ifndef XBT_LOG_STATIC_THRESHOLD # define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_none -# endif /* !XBT_LOG_STATIC_THRESHOLD */ -# endif /* NDEBUG */ -#endif /* !defined(NLOG) */ +# endif /* !XBT_LOG_STATIC_THRESHOLD */ +# endif /* NDEBUG */ +#endif /* !defined(NLOG) */ /* Transforms a category name to a global variable name. */ #define _XBT_LOGV(cat) _XBT_LOG_CONCAT(_simgrid_log_category__, cat) @@ -169,7 +169,7 @@ SG_BEGIN_DECL() * Indicates which category is the default one. */ -#if defined(XBT_LOG_MAYDAY) || defined(SUPERNOVAE_MODE) /*|| defined (NLOG) * turning logging off */ +#if defined(XBT_LOG_MAYDAY) || defined(SUPERNOVAE_MODE) /*|| defined (NLOG) * turning logging off */ # define XBT_LOG_DEFAULT_CATEGORY(cname) #else # define XBT_LOG_DEFAULT_CATEGORY(cname) \ @@ -232,12 +232,12 @@ SG_BEGIN_DECL() XBT_PUBLIC(void) xbt_log_control_set(const char *cs); /* Forward declarations */ - typedef struct xbt_log_appender_s s_xbt_log_appender_t, - *xbt_log_appender_t; - typedef struct xbt_log_layout_s s_xbt_log_layout_t, *xbt_log_layout_t; - typedef struct xbt_log_event_s s_xbt_log_event_t, *xbt_log_event_t; - typedef struct xbt_log_category_s s_xbt_log_category_t, - *xbt_log_category_t; +typedef struct xbt_log_appender_s s_xbt_log_appender_t, + *xbt_log_appender_t; +typedef struct xbt_log_layout_s s_xbt_log_layout_t, *xbt_log_layout_t; +typedef struct xbt_log_event_s s_xbt_log_event_t, *xbt_log_event_t; +typedef struct xbt_log_category_s s_xbt_log_category_t, + *xbt_log_category_t; /* * Do NOT access any members of this structure directly. FIXME: move to private? @@ -247,32 +247,32 @@ XBT_PUBLIC(void) xbt_log_control_set(const char *cs); #else #define XBT_LOG_BUFF_SIZE 2048 /* Size of the static string in which we build the log string */ #endif - struct xbt_log_category_s { - xbt_log_category_t parent; - xbt_log_category_t firstChild; - xbt_log_category_t nextSibling; - const char *name; - int threshold; - int isThreshInherited; - xbt_log_appender_t appender; - xbt_log_layout_t layout; - int additivity; - }; - - struct xbt_log_event_s { - xbt_log_category_t cat; - e_xbt_log_priority_t priority; - const char *fileName; - const char *functionName; - int lineNum; - va_list ap; - va_list ap_copy; /* need a copy to launch dynamic layouts when the static ones overflowed */ +struct xbt_log_category_s { + xbt_log_category_t parent; + xbt_log_category_t firstChild; + xbt_log_category_t nextSibling; + const char *name; + int threshold; + int isThreshInherited; + xbt_log_appender_t appender; + xbt_log_layout_t layout; + int additivity; +}; + +struct xbt_log_event_s { + xbt_log_category_t cat; + e_xbt_log_priority_t priority; + const char *fileName; + const char *functionName; + int lineNum; + va_list ap; + va_list ap_copy; /* need a copy to launch dynamic layouts when the static ones overflowed */ #ifdef _XBT_WIN32 - char *buffer; + char *buffer; #else - char buffer[XBT_LOG_BUFF_SIZE]; + char buffer[XBT_LOG_BUFF_SIZE]; #endif - }; +}; /** * \ingroup XBT_log_implem @@ -344,8 +344,8 @@ XBT_PUBLIC(int) _xbt_log_cat_init(xbt_log_category_t category, XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); - extern xbt_log_appender_t xbt_log_default_appender; - extern xbt_log_layout_t xbt_log_default_layout; +extern xbt_log_appender_t xbt_log_default_appender; +extern xbt_log_layout_t xbt_log_default_layout; /* ********************** */ /* Public functions again */ @@ -391,7 +391,7 @@ XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); * Setting the LogEvent's valist member is done inside _log_logEvent. */ #ifdef _XBT_WIN32 -#include /* calloc */ +#include /* calloc */ #define _XBT_LOG_PRE(catv, prio) do { \ if (_XBT_LOG_ISENABLEDV(catv, prio)) { \ s_xbt_log_event_t _log_ev; \ @@ -403,7 +403,7 @@ XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); _log_ev.buffer = (char*) calloc(XBT_LOG_BUFF_SIZE + 1, sizeof(char)); \ _xbt_log_event_log(&_log_ev #else -#include /* memset */ +#include /* memset */ #define _XBT_LOG_PRE(catv, prio) do { \ if (_XBT_LOG_ISENABLEDV(catv, prio)) { \ s_xbt_log_event_t _log_ev; \ @@ -718,4 +718,4 @@ XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); SG_END_DECL() -#endif /* ! _XBT_LOG_H_ */ +#endif /* ! _XBT_LOG_H_ */ diff --git a/include/xbt/mallocator.h b/include/xbt/mallocator.h index 7049ac9fe1..e65d0e2db9 100644 --- a/include/xbt/mallocator.h +++ b/include/xbt/mallocator.h @@ -35,7 +35,7 @@ SG_BEGIN_DECL() * @{ */ /** \brief Mallocator data type (opaque structure) */ - typedef struct s_xbt_mallocator *xbt_mallocator_t; +typedef struct s_xbt_mallocator *xbt_mallocator_t; XBT_PUBLIC(xbt_mallocator_t) xbt_mallocator_new(int size, pvoid_f_void_t new_f, void_f_pvoid_t free_f, @@ -55,4 +55,4 @@ XBT_PUBLIC(void) xbt_mallocator_release(xbt_mallocator_t mallocator, /** @} */ SG_END_DECL() -#endif /* _XBT_MALLOCATOR_H */ +#endif /* _XBT_MALLOCATOR_H */ diff --git a/include/xbt/matrix.h b/include/xbt/matrix.h index 976e7d08d0..53d5062a6a 100644 --- a/include/xbt/matrix.h +++ b/include/xbt/matrix.h @@ -14,13 +14,13 @@ SG_BEGIN_DECL() - typedef struct { - unsigned int lines, rows; - unsigned long elmsize; +typedef struct { + unsigned int lines, rows; + unsigned long elmsize; - char *data; - void_f_pvoid_t free_f; - } s_xbt_matrix_t, *xbt_matrix_t; + char *data; + void_f_pvoid_t free_f; +} s_xbt_matrix_t, *xbt_matrix_t; /** @brief Retrieve the address of a cell (not its content) @@ -43,7 +43,8 @@ XBT_PUBLIC(xbt_matrix_t) xbt_matrix_new_sub(xbt_matrix_t from, XBT_PUBLIC(void) xbt_matrix_free(xbt_matrix_t matrix); XBT_PUBLIC(void) xbt_matrix_free_voidp(void *d); -XBT_PUBLIC(void) xbt_matrix_copy_values(xbt_matrix_t dest, xbt_matrix_t src, +XBT_PUBLIC(void) xbt_matrix_copy_values(xbt_matrix_t dest, + xbt_matrix_t src, unsigned int lsize, unsigned int rsize, unsigned int lpos_dst, @@ -67,4 +68,4 @@ XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_mult(xbt_matrix_t A, XBT_PUBLIC(void) xbt_matrix_double_addmult(xbt_matrix_t A, xbt_matrix_t B, /*OUT*/ xbt_matrix_t C); SG_END_DECL() -#endif /* XBT_MATRIX_H */ +#endif /* XBT_MATRIX_H */ diff --git a/include/xbt/misc.h b/include/xbt/misc.h index 36bc11c53f..212ba11e6a 100644 --- a/include/xbt/misc.h +++ b/include/xbt/misc.h @@ -23,7 +23,7 @@ # define _XBT_GNUC_DESTRUCTOR __attribute__((__destructor__)) # undef _XBT_NEED_INIT_PRAGMA -#else /* !__GNUC__ */ +#else /* !__GNUC__ */ # define _XBT_GNUC_PRINTF( format_idx, arg_idx ) # define _XBT_GNUC_SCANF( format_idx, arg_idx ) # define _XBT_GNUC_FORMAT( arg_idx ) @@ -33,14 +33,14 @@ # define _XBT_GNUC_DESTRUCTOR # define _XBT_NEED_INIT_PRAGMA 1 -#endif /* !__GNUC__ */ +#endif /* !__GNUC__ */ /* inline and __FUNCTION__ are only in GCC when -ansi is off */ #if defined(__GNUC__) && ! defined(__STRICT_ANSI__) # define _XBT_FUNCTION __FUNCTION__ #elif (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) -# define _XBT_FUNCTION __func__ /* ISO-C99 compliant */ +# define _XBT_FUNCTION __func__ /* ISO-C99 compliant */ #else # define _XBT_FUNCTION "function" #endif @@ -194,4 +194,4 @@ XBT_PUBLIC(const char *) xbt_procname(void); #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */ SG_END_DECL() -#endif /* XBT_MISC_H */ +#endif /* XBT_MISC_H */ diff --git a/include/xbt/mmalloc.h b/include/xbt/mmalloc.h index f813b78016..d3b2aa7b6a 100644 --- a/include/xbt/mmalloc.h +++ b/include/xbt/mmalloc.h @@ -4,53 +4,53 @@ #ifdef HAVE_STDDEF_H # include #else -# include /* for size_t */ -# include /* for NULL */ +# include /* for size_t */ +# include /* for NULL */ #endif //#include "./include/ansidecl.h" /* Allocate SIZE bytes of memory. */ -extern void* mmalloc(void* md, size_t size); +extern void *mmalloc(void *md, size_t size); /* Re-allocate the previously allocated block in void*, making the new block SIZE bytes long. */ -extern void* mrealloc(void* md, void* ptr, size_t size); +extern void *mrealloc(void *md, void *ptr, size_t size); /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ -extern void* mcalloc (void* md, size_t nmemb, size_t size); +extern void *mcalloc(void *md, size_t nmemb, size_t size); /* Free a block allocated by `mmalloc', `mrealloc' or `mcalloc'. */ -extern void mfree (void* md, void* ptr); +extern void mfree(void *md, void *ptr); /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ -extern void* mmemalign (void* md, size_t alignment, size_t size); +extern void *mmemalign(void *md, size_t alignment, size_t size); /* Allocate SIZE bytes on a page boundary. */ -extern void* mvalloc (void* md, size_t size); +extern void *mvalloc(void *md, size_t size); /* Activate a standard collection of debugging hooks. */ -extern int mmcheck (void* md, void (*func) (void)); +extern int mmcheck(void *md, void (*func) (void)); -extern int mmcheckf (void* md, void (*func) (void), int force); +extern int mmcheckf(void *md, void (*func) (void), int force); /* Pick up the current statistics. (see FIXME elsewhere) */ -extern struct mstats mmstats (void* md); +extern struct mstats mmstats(void *md); -extern void* mmalloc_attach (int fd, void* baseaddr); +extern void *mmalloc_attach(int fd, void *baseaddr); -extern void* mmalloc_detach (void* md); +extern void *mmalloc_detach(void *md); -extern int mmalloc_setkey (void* md, int keynum, void* key); +extern int mmalloc_setkey(void *md, int keynum, void *key); -extern void* mmalloc_getkey (void* md, int keynum); +extern void *mmalloc_getkey(void *md, int keynum); // FIXME: this function is not implemented anymore? //extern int mmalloc_errno (void* md); @@ -60,12 +60,12 @@ extern void *mmalloc_get_default_md(void); extern int mmtrace(void); -extern void* mmalloc_findbase(int size); +extern void *mmalloc_findbase(int size); /* To change the heap used when using the legacy version malloc/free/realloc and such */ void mmalloc_set_current_heap(void *new_heap); -void* mmalloc_get_current_heap(void); +void *mmalloc_get_current_heap(void); -#endif /* MMALLOC_H */ +#endif /* MMALLOC_H */ diff --git a/include/xbt/module.h b/include/xbt/module.h index 4dba2b808a..af669467bf 100644 --- a/include/xbt/module.h +++ b/include/xbt/module.h @@ -15,4 +15,4 @@ extern char *xbt_binary_name; XBT_PUBLIC(void) xbt_init(int *argc, char **argv); XBT_PUBLIC(void) xbt_exit(void); -#endif /* _XBT_MODULE_H */ +#endif /* _XBT_MODULE_H */ diff --git a/include/xbt/peer.h b/include/xbt/peer.h index 7c5b03d3f8..a04d9c0b64 100644 --- a/include/xbt/peer.h +++ b/include/xbt/peer.h @@ -13,10 +13,10 @@ SG_BEGIN_DECL() - typedef struct { - char *name; - int port; - } s_xbt_peer_t, *xbt_peer_t; +typedef struct { + char *name; + int port; +} s_xbt_peer_t, *xbt_peer_t; XBT_PUBLIC(xbt_peer_t) xbt_peer_new(const char *name, int port); XBT_PUBLIC(xbt_peer_t) xbt_peer_from_string(const char *peerport); @@ -25,4 +25,4 @@ XBT_PUBLIC(void) xbt_peer_free(xbt_peer_t peer); XBT_PUBLIC(void) xbt_peer_free_voidp(void *d); SG_END_DECL() -#endif /* XBT_PEER_H */ +#endif /* XBT_PEER_H */ diff --git a/include/xbt/queue.h b/include/xbt/queue.h index a3b846a65d..9084a5c4de 100644 --- a/include/xbt/queue.h +++ b/include/xbt/queue.h @@ -27,10 +27,11 @@ SG_BEGIN_DECL() * @{ */ /** \brief Queue data type (opaque type) */ - typedef struct s_xbt_queue_ *xbt_queue_t; +typedef struct s_xbt_queue_ *xbt_queue_t; -XBT_PUBLIC(xbt_queue_t) xbt_queue_new(int capacity, unsigned long elm_size); +XBT_PUBLIC(xbt_queue_t) xbt_queue_new(int capacity, + unsigned long elm_size); XBT_PUBLIC(void) xbt_queue_free(xbt_queue_t * queue); XBT_PUBLIC(unsigned long) xbt_queue_length(const xbt_queue_t queue); @@ -42,8 +43,8 @@ XBT_PUBLIC(void) xbt_queue_shift(xbt_queue_t queue, void *const dst); XBT_PUBLIC(void) xbt_queue_push_timed(xbt_queue_t queue, const void *src, double delay); -XBT_PUBLIC(void) xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, - double delay); +XBT_PUBLIC(void) xbt_queue_unshift_timed(xbt_queue_t queue, + const void *src, double delay); XBT_PUBLIC(void) xbt_queue_shift_timed(xbt_queue_t queue, void *const dst, double delay); XBT_PUBLIC(void) xbt_queue_pop_timed(xbt_queue_t queue, void *const dst, @@ -52,4 +53,4 @@ XBT_PUBLIC(void) xbt_queue_pop_timed(xbt_queue_t queue, void *const dst, /** @} */ SG_END_DECL() -#endif /* _XBT_QUEUE_H */ +#endif /* _XBT_QUEUE_H */ diff --git a/include/xbt/set.h b/include/xbt/set.h index a463a09ea7..0df9ff167f 100644 --- a/include/xbt/set.h +++ b/include/xbt/set.h @@ -49,7 +49,7 @@ SG_BEGIN_DECL() * @{ */ /** \brief Opaque type representing a set */ - typedef struct xbt_set_ *xbt_set_t; +typedef struct xbt_set_ *xbt_set_t; #define XBT_SET_HEADERS \ unsigned int ID; \ @@ -57,12 +57,12 @@ SG_BEGIN_DECL() unsigned int name_len /** \brief It must be possible to cast set elements to this type */ - typedef struct xbt_set_elm_ { - unsigned int ID; /**< Identificator (system assigned) */ - char *name; /**< Name (user assigned) */ - unsigned int name_len; +typedef struct xbt_set_elm_ { + unsigned int ID; /**< Identificator (system assigned) */ + char *name; /**< Name (user assigned) */ + unsigned int name_len; /**< Length of the name */ - } s_xbt_set_elm_t, *xbt_set_elm_t; +} s_xbt_set_elm_t, *xbt_set_elm_t; /*####[ Functions ]##########################################################*/ XBT_PUBLIC(xbt_set_t) xbt_set_new(void); @@ -85,7 +85,8 @@ XBT_PUBLIC(void) xbt_set_remove_by_name_ext(xbt_set_t set, const char *key, int key_len); XBT_PUBLIC(void) xbt_set_remove_by_id(xbt_set_t set, int id); -XBT_PUBLIC(xbt_set_elm_t) xbt_set_get_by_name(xbt_set_t set, const char *key); +XBT_PUBLIC(xbt_set_elm_t) xbt_set_get_by_name(xbt_set_t set, + const char *key); XBT_PUBLIC(xbt_set_elm_t) xbt_set_get_by_name_ext(xbt_set_t set, const char *key, int key_len); @@ -104,7 +105,7 @@ XBT_PUBLIC(unsigned long) xbt_set_length(const xbt_set_t set); */ /** @brief Cursor type */ - typedef struct xbt_set_cursor_ *xbt_set_cursor_t; +typedef struct xbt_set_cursor_ *xbt_set_cursor_t; XBT_PUBLIC(void) xbt_set_cursor_first(xbt_set_t set, xbt_set_cursor_t * cursor); @@ -122,4 +123,4 @@ XBT_PUBLIC(int) xbt_set_cursor_get_or_free(xbt_set_cursor_t * cursor, /* @} */ SG_END_DECL() -#endif /* _XBT_SET_H */ +#endif /* _XBT_SET_H */ diff --git a/include/xbt/setset.h b/include/xbt/setset.h index 140c016cf1..2c11a20323 100644 --- a/include/xbt/setset.h +++ b/include/xbt/setset.h @@ -21,7 +21,7 @@ void xbt_setset_destroy(xbt_setset_t setset); void xbt_setset_elm_add(xbt_setset_t setset, void *obj); /* Remove an object from the setset */ -void xbt_setset_elm_remove(xbt_setset_t setset, void * obj); +void xbt_setset_elm_remove(xbt_setset_t setset, void *obj); /* Create a new set in the setset */ xbt_setset_set_t xbt_setset_new_set(xbt_setset_t setset); @@ -30,10 +30,10 @@ xbt_setset_set_t xbt_setset_new_set(xbt_setset_t setset); void xbt_setset_destroy_set(xbt_setset_set_t); /* Insert an element into a set */ -void xbt_setset_set_insert(xbt_setset_set_t set, void* obj); +void xbt_setset_set_insert(xbt_setset_set_t set, void *obj); /* Remove an element from a set */ -void xbt_setset_set_remove(xbt_setset_set_t set, void* obj); +void xbt_setset_set_remove(xbt_setset_set_t set, void *obj); /* Remove all the elements of a set */ void xbt_setset_set_reset(xbt_setset_set_t set); @@ -45,7 +45,7 @@ void *xbt_setset_set_choose(xbt_setset_set_t set); void *xbt_setset_set_extract(xbt_setset_set_t set); /* Test if an element belongs to a set */ -int xbt_setset_set_belongs(xbt_setset_set_t set, void* obj); +int xbt_setset_set_belongs(xbt_setset_set_t set, void *obj); /* Get the number of elements in a set */ int xbt_setset_set_size(xbt_setset_set_t set); @@ -60,7 +60,8 @@ void xbt_setset_substract(xbt_setset_set_t set1, xbt_setset_set_t set2); void xbt_setset_intersect(xbt_setset_set_t set1, xbt_setset_set_t set2); /* Get the cursor to point to the first element of a set */ -void xbt_setset_cursor_first(xbt_setset_set_t set, xbt_setset_cursor_t *cursor); +void xbt_setset_cursor_first(xbt_setset_set_t set, + xbt_setset_cursor_t * cursor); /* Get the data pointed by a cursor */ int xbt_setset_cursor_get_data(xbt_setset_cursor_t cursor, void **data); @@ -72,6 +73,6 @@ void xbt_setset_cursor_next(xbt_setset_cursor_t cursor); #define xbt_setset_foreach(set, cursor, data) \ for(xbt_setset_cursor_first(set, &cursor); \ xbt_setset_cursor_get_data(cursor, (void **)&data); \ - xbt_setset_cursor_next(cursor)) + xbt_setset_cursor_next(cursor)) #endif diff --git a/include/xbt/str.h b/include/xbt/str.h index ebe4c01d5a..b08a4dae6c 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -25,8 +25,6 @@ SG_BEGIN_DECL() * asprintf()), while some other are a bit more exotic. * @{ */ - - /* Trim related functions */ XBT_PUBLIC(void) xbt_str_rtrim(char *s, const char *char_list); XBT_PUBLIC(void) xbt_str_ltrim(char *s, const char *char_list); @@ -46,15 +44,15 @@ XBT_PUBLIC(char *) xbt_str_varsubst(char *str, xbt_dict_t patterns); XBT_PUBLIC(void) xbt_str_strip_spaces(char *); XBT_PUBLIC(char *) xbt_str_diff(char *a, char *b); -XBT_PUBLIC(char*)xbt_str_from_file(FILE *file); +XBT_PUBLIC(char *) xbt_str_from_file(FILE * file); /** @brief Classical alias to (char*) * * This of almost no use, beside cosmetics and the GRAS parsing macro (see \ref GRAS_dd_auto). */ - typedef char *xbt_string_t; +typedef char *xbt_string_t; /**@}*/ SG_END_DECL() -#endif /* XBT_STR_H */ +#endif /* XBT_STR_H */ diff --git a/include/xbt/strbuff.h b/include/xbt/strbuff.h index 8c63cd8a5e..021de28377 100644 --- a/include/xbt/strbuff.h +++ b/include/xbt/strbuff.h @@ -34,6 +34,7 @@ XBT_INLINE XBT_PUBLIC(void) xbt_strbuff_free_container(xbt_strbuff_t b); XBT_PUBLIC(void) xbt_strbuff_append(xbt_strbuff_t b, const char *toadd); XBT_PUBLIC(void) xbt_strbuff_chomp(xbt_strbuff_t b); XBT_PUBLIC(void) xbt_strbuff_trim(xbt_strbuff_t b); -XBT_PUBLIC(void) xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns); +XBT_PUBLIC(void) xbt_strbuff_varsubst(xbt_strbuff_t b, + xbt_dict_t patterns); #endif diff --git a/include/xbt/swag.h b/include/xbt/swag.h index 8a14e7e510..a16c2544f7 100644 --- a/include/xbt/swag.h +++ b/include/xbt/swag.h @@ -38,10 +38,10 @@ SG_BEGIN_DECL() those structs directly. Use them as an abstract datatype. */ /* @{ */ - typedef struct xbt_swag_hookup { - void *next; - void *prev; - } s_xbt_swag_hookup_t; +typedef struct xbt_swag_hookup { + void *next; + void *prev; +} s_xbt_swag_hookup_t; /**< This type should be added to a type that is to be used in a swag. * * Whenever a new object with this struct is created, all fields have @@ -68,15 +68,15 @@ typedef struct foo { } \endcode */ - typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t; +typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t; - typedef struct xbt_swag { - void *head; - void *tail; - size_t offset; - int count; - } s_xbt_swag_t, *xbt_swag_t; +typedef struct xbt_swag { + void *head; + void *tail; + size_t offset; + int count; +} s_xbt_swag_t, *xbt_swag_t; /**< A typical swag */ /* @} */ @@ -99,9 +99,11 @@ XBT_PUBLIC(int) xbt_swag_size(xbt_swag_t swag); #define xbt_swag_getNext(obj,offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->prev) #define xbt_swag_getPrev(obj,offset) (((xbt_swag_hookup_t)(((char *) (obj)) + (offset)))->next) -static XBT_INLINE int xbt_swag_belongs(void *obj, xbt_swag_t swag) { - return ((xbt_swag_getNext(obj, swag->offset)) || (xbt_swag_getPrev(obj, swag->offset)) - || (swag->head == obj)); +static XBT_INLINE int xbt_swag_belongs(void *obj, xbt_swag_t swag) +{ + return ((xbt_swag_getNext(obj, swag->offset)) + || (xbt_swag_getPrev(obj, swag->offset)) + || (swag->head == obj)); } static XBT_INLINE void *xbt_swag_getFirst(xbt_swag_t swag) @@ -164,4 +166,4 @@ static XBT_INLINE void *xbt_swag_getFirst(xbt_swag_t swag) /* @} */ SG_END_DECL() -#endif /* _XBT_SWAG_H */ +#endif /* _XBT_SWAG_H */ diff --git a/include/xbt/synchro.h b/include/xbt/synchro.h index cb7abd099d..e735325a1d 100644 --- a/include/xbt/synchro.h +++ b/include/xbt/synchro.h @@ -15,8 +15,8 @@ #include "xbt/dynar.h" SG_BEGIN_DECL() -XBT_PUBLIC(void) xbt_dynar_dopar(xbt_dynar_t datas, void_f_int_pvoid_t function); +XBT_PUBLIC(void) xbt_dynar_dopar(xbt_dynar_t datas, + void_f_int_pvoid_t function); SG_END_DECL() - -#endif /* SYNCHRO_H_ */ +#endif /* SYNCHRO_H_ */ diff --git a/include/xbt/synchro_core.h b/include/xbt/synchro_core.h index fadf8c532e..5a270d3f71 100644 --- a/include/xbt/synchro_core.h +++ b/include/xbt/synchro_core.h @@ -30,11 +30,11 @@ SG_BEGIN_DECL() * @{ */ /** \brief Thread data type (opaque structure) */ - typedef struct s_xbt_thread_ *xbt_thread_t; +typedef struct s_xbt_thread_ *xbt_thread_t; XBT_PUBLIC(xbt_thread_t) xbt_thread_create(const char *name, void_f_pvoid_t start_routine, - void *param,int joinable); + void *param, int joinable); XBT_PUBLIC(xbt_thread_t) xbt_thread_self(void); XBT_PUBLIC(const char *) xbt_thread_name(xbt_thread_t t); XBT_PUBLIC(const char *) xbt_thread_self_name(void); @@ -49,7 +49,7 @@ XBT_PUBLIC(void) xbt_thread_yield(void); /** \brief Thread mutex data type (opaque structure) */ - typedef struct s_xbt_mutex_ *xbt_mutex_t; +typedef struct s_xbt_mutex_ *xbt_mutex_t; XBT_PUBLIC(xbt_mutex_t) xbt_mutex_init(void); XBT_PUBLIC(void) xbt_mutex_acquire(xbt_mutex_t mutex); @@ -59,7 +59,7 @@ XBT_PUBLIC(void) xbt_mutex_destroy(xbt_mutex_t mutex); /** \brief Thread condition data type (opaque structure) */ - typedef struct s_xbt_cond_ *xbt_cond_t; +typedef struct s_xbt_cond_ *xbt_cond_t; XBT_PUBLIC(xbt_cond_t) xbt_cond_init(void); XBT_PUBLIC(void) xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex); @@ -72,4 +72,4 @@ XBT_PUBLIC(void) xbt_cond_destroy(xbt_cond_t cond); /** @} */ SG_END_DECL() -#endif /* _XBT_THREAD_H */ +#endif /* _XBT_THREAD_H */ diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 1592e9e905..1e8f1cdb1c 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -50,7 +50,8 @@ XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2); #if defined(__GNUC__) || defined(DOXYGEN) /** @brief Like strdup, but xbt_die() on error */ -static inline __attribute__((always_inline)) char *xbt_strdup(const char *s) +static inline __attribute__ ((always_inline)) +char *xbt_strdup(const char *s) { char *res = NULL; if (s) { @@ -65,7 +66,8 @@ XBT_PUBLIC(void) xbt_backtrace_display_current(void); /** @brief Like malloc, but xbt_die() on error @hideinitializer */ -static inline __attribute__((always_inline)) void *xbt_malloc(unsigned int n) +static inline __attribute__ ((always_inline)) +void *xbt_malloc(unsigned int n) { void *res; /* if (n==0) { @@ -81,7 +83,8 @@ static inline __attribute__((always_inline)) void *xbt_malloc(unsigned int n) /** @brief like malloc, but xbt_die() on error and memset data to 0 @hideinitializer */ -static inline __attribute__((always_inline)) void *xbt_malloc0(unsigned int n) +static inline __attribute__ ((always_inline)) +void *xbt_malloc0(unsigned int n) { void *res; //if (n==0) xbt_die("calloc(0) is not portable"); @@ -93,7 +96,8 @@ static inline __attribute__((always_inline)) void *xbt_malloc0(unsigned int n) /** @brief like realloc, but xbt_die() on error @hideinitializer */ -static inline __attribute__((always_inline)) void *xbt_realloc(void *p, unsigned int s) +static inline __attribute__ ((always_inline)) +void *xbt_realloc(void *p, unsigned int s) { void *res = res; //if (s==0) xbt_die("realloc(0) is not portable"); @@ -112,12 +116,12 @@ static inline __attribute__((always_inline)) void *xbt_realloc(void *p, unsigned } return res; } -#else /* non __GNUC__ */ +#else /* non __GNUC__ */ # define xbt_strdup(s) strdup(s) # define xbt_malloc(n) malloc(n) # define xbt_malloc0(n) calloc(n,1) # define xbt_realloc(p,s) realloc(p,s) -#endif /* __GNUC__ ? */ +#endif /* __GNUC__ ? */ /** @brief like free @hideinitializer */ @@ -140,4 +144,4 @@ XBT_PUBLIC(void) xbt_free_ref(void *d); SG_END_DECL() -#endif /* _XBT_SYSDEP_H */ +#endif /* _XBT_SYSDEP_H */ diff --git a/include/xbt/virtu.h b/include/xbt/virtu.h index de872c77e1..e960c4a4a4 100644 --- a/include/xbt/virtu.h +++ b/include/xbt/virtu.h @@ -15,8 +15,8 @@ SG_BEGIN_DECL() - /* Get the PID of the current process */ - XBT_PUBLIC_DATA(int_f_void_t) xbt_getpid; + /* Get the PID of the current process */ + XBT_PUBLIC_DATA(int_f_void_t) xbt_getpid; SG_END_DECL() -#endif /* __XBT_VIRTU_H__ */ +#endif /* __XBT_VIRTU_H__ */ diff --git a/include/xbt/win32_ucontext.h b/include/xbt/win32_ucontext.h index af3c78c775..4b85617841 100644 --- a/include/xbt/win32_ucontext.h +++ b/include/xbt/win32_ucontext.h @@ -18,34 +18,29 @@ * License along with QueueUserAPCEx in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - + */ + #ifndef UCONTEXT_H #define UCONTEXT_H - + #include - -typedef struct __stack { - void *ss_sp; - size_t ss_size; - int ss_flags; -} stack_t; - -typedef CONTEXT mcontext_t; -typedef unsigned long __sigset_t; - -typedef struct __ucontext { - unsigned long int uc_flags; - struct __ucontext *uc_link; - stack_t uc_stack; - mcontext_t uc_mcontext; - __sigset_t uc_sigmask; -} ucontext_t; - - -int getcontext(ucontext_t *ucp); -int setcontext(const ucontext_t *ucp); -int makecontext(ucontext_t *, void (*)(), int, ...); -int swapcontext(ucontext_t *, const ucontext_t *); - -#endif /* UCONTEXT_H */ + typedef struct __stack { + void *ss_sp; + size_t ss_size; + int ss_flags; + } stack_t; + typedef CONTEXT mcontext_t; + typedef unsigned long __sigset_t; + typedef struct __ucontext { + unsigned long int uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + __sigset_t uc_sigmask; + } ucontext_t; + int getcontext(ucontext_t * ucp); + int setcontext(const ucontext_t * ucp); + int makecontext(ucontext_t *, void (*)(), int, ...); + int swapcontext(ucontext_t *, const ucontext_t *); + +#endif /* UCONTEXT_H */ diff --git a/src/amok/Bandwidth/bandwidth.c b/src/amok/Bandwidth/bandwidth.c index 32e9890ec0..af79f6061e 100644 --- a/src/amok/Bandwidth/bandwidth.c +++ b/src/amok/Bandwidth/bandwidth.c @@ -81,7 +81,8 @@ void amok_bw_bw_init() gras_datadesc_struct_close(bw_res_desc); bw_res_desc = gras_datadesc_ref("bw_res_t", bw_res_desc); - gras_msgtype_declare_rpc("BW handshake", bw_request_desc, bw_request_desc); + gras_msgtype_declare_rpc("BW handshake", bw_request_desc, + bw_request_desc); gras_msgtype_declare_rpc("BW reask", bw_request_desc, NULL); gras_msgtype_declare("BW stop", NULL); @@ -167,10 +168,10 @@ void amok_bw_test(gras_socket_t peer, request->peer.name = NULL; request->peer.port = gras_socket_my_port(measMasterIn); DEBUG6 - ("Handshaking with %s:%d to connect it back on my %d (bufsize=%ld, msg_size=%ld, msg_amount=%ld)", - gras_socket_peer_name(peer), gras_socket_peer_port(peer), - request->peer.port, request->buf_size, request->msg_size, - request->msg_amount); + ("Handshaking with %s:%d to connect it back on my %d (bufsize=%ld, msg_size=%ld, msg_amount=%ld)", + gras_socket_peer_name(peer), gras_socket_peer_port(peer), + request->peer.port, request->buf_size, request->msg_size, + request->msg_amount); TRY { gras_msg_rpccall(peer, 15, "BW handshake", &request, &request_ack); @@ -187,11 +188,12 @@ void amok_bw_test(gras_socket_t peer, } CATCH(e) { RETHROW2 - ("Error encountered while opening the measurement socket to %s:%d for BW test: %s", - gras_socket_peer_name(peer), request_ack->peer.port); + ("Error encountered while opening the measurement socket to %s:%d for BW test: %s", + gras_socket_peer_name(peer), request_ack->peer.port); } - DEBUG2("Got ACK; conduct the experiment (msg_size = %ld, msg_amount=%ld)", - request->msg_size, request->msg_amount); + DEBUG2 + ("Got ACK; conduct the experiment (msg_size = %ld, msg_amount=%ld)", + request->msg_size, request->msg_amount); *sec = 0; first_pass = 1; @@ -215,8 +217,8 @@ void amok_bw_test(gras_socket_t peer, And then increase the number of messages to compensate (check for overflow there, too) */ if (request->msg_size > 64 * 1024 * 1024) { unsigned long int new_amount = - ((request->msg_size / ((double) 64 * 1024 * 1024)) - * request->msg_amount) + 1; + ((request->msg_size / ((double) 64 * 1024 * 1024)) + * request->msg_amount) + 1; xbt_assert0(new_amount > request->msg_amount, "Overflow on the number of messages! You must have a *really* fat pipe. Please fix your platform"); @@ -226,10 +228,11 @@ void amok_bw_test(gras_socket_t peer, } VERB5 - ("The experiment was too short (%f sec<%f sec). Redo it with msg_size=%lu (nb_messages=%lu) (got %fMb/s)", - meas_duration, min_duration, request->msg_size, request->msg_amount, - ((double) request->msg_size) * ((double) request->msg_amount / - (*sec) / 1024.0 / 1024.0)); + ("The experiment was too short (%f sec<%f sec). Redo it with msg_size=%lu (nb_messages=%lu) (got %fMb/s)", + meas_duration, min_duration, request->msg_size, + request->msg_amount, + ((double) request->msg_size) * ((double) request->msg_amount / + (*sec) / 1024.0 / 1024.0)); gras_msg_rpccall(peer, 60, "BW reask", &request, NULL); } @@ -250,8 +253,8 @@ void amok_bw_test(gras_socket_t peer, *sec = gras_os_time() - *sec; if (*sec != 0.0) { *bw = - ((double) request->msg_size) * ((double) request->msg_amount) / - (*sec); + ((double) request->msg_size) * ((double) request->msg_amount) / + (*sec); } DEBUG1("Experiment done ; it took %f sec", *sec); if (*sec <= 0) { @@ -260,8 +263,9 @@ void amok_bw_test(gras_socket_t peer, } while (*sec < min_duration); - DEBUG2("This measurement was long enough (%f sec; found %f b/s). Stop peer", - *sec, *bw); + DEBUG2 + ("This measurement was long enough (%f sec; found %f b/s). Stop peer", + *sec, *bw); gras_msg_send(peer, "BW stop", NULL); free(request_ack); @@ -294,9 +298,9 @@ int amok_bw_cb_bw_handshake(gras_msg_cb_ctx_t ctx, void *payload) static xbt_dynar_t msgtwaited = NULL; DEBUG5 - ("Handshaked to connect to %s:%d (sizes: buf=%lu msg=%lu msg_amount=%lu)", - gras_socket_peer_name(expeditor), request->peer.port, request->buf_size, - request->msg_size, request->msg_amount); + ("Handshaked to connect to %s:%d (sizes: buf=%lu msg=%lu msg_amount=%lu)", + gras_socket_peer_name(expeditor), request->peer.port, + request->buf_size, request->msg_size, request->msg_amount); /* Build our answer */ answer = xbt_new0(s_bw_request_t, 1); @@ -312,7 +316,7 @@ int amok_bw_cb_bw_handshake(gras_msg_cb_ctx_t ctx, void *payload) else /* FIXME: tell error to remote */ RETHROW0 - ("Error encountered while opening a measurement server socket: %s"); + ("Error encountered while opening a measurement server socket: %s"); } } @@ -339,17 +343,17 @@ int amok_bw_cb_bw_handshake(gras_msg_cb_ctx_t ctx, void *payload) } CATCH(e) { RETHROW2 - ("Error encountered while opening a measurement socket back to %s:%d : %s", - gras_socket_peer_name(expeditor), request->peer.port); + ("Error encountered while opening a measurement socket back to %s:%d : %s", + gras_socket_peer_name(expeditor), request->peer.port); /* FIXME: tell error to remote */ } TRY { measIn = gras_socket_meas_accept(measMasterIn); DEBUG4 - ("BW handshake answered. buf_size=%lu msg_size=%lu msg_amount=%lu port=%d", - answer->buf_size, answer->msg_size, answer->msg_amount, - answer->peer.port); + ("BW handshake answered. buf_size=%lu msg_size=%lu msg_amount=%lu port=%d", + answer->buf_size, answer->msg_size, answer->msg_amount, + answer->peer.port); } CATCH(e) { gras_socket_close(measMasterIn); @@ -529,8 +533,8 @@ double *amok_bw_matrix(xbt_dynar_t peers, if (i != j) { /* Mesurements of Bandwidth */ amok_bw_request(p1->name, p1->port, p2->name, p2->port, - buf_size_bw, msg_size_bw, msg_amount_bw, min_duration, - &sec, &matrix_res[i * len + j]); + buf_size_bw, msg_size_bw, msg_amount_bw, + min_duration, &sec, &matrix_res[i * len + j]); } } } diff --git a/src/amok/Bandwidth/bandwidth_private.h b/src/amok/Bandwidth/bandwidth_private.h index bd449f0d3d..aa3097a704 100644 --- a/src/amok/Bandwidth/bandwidth_private.h +++ b/src/amok/Bandwidth/bandwidth_private.h @@ -63,4 +63,4 @@ void amok_bw_sat_start(const char *from_name, unsigned int from_port, const char *to_name, unsigned int to_port, unsigned int msg_size, unsigned int duration); -#endif /* AMOK_BANDWIDTH_PRIVATE_H */ +#endif /* AMOK_BANDWIDTH_PRIVATE_H */ diff --git a/src/amok/Bandwidth/saturate.c b/src/amok/Bandwidth/saturate.c index 21ec6fd4f9..c2b74ecdb1 100644 --- a/src/amok/Bandwidth/saturate.c +++ b/src/amok/Bandwidth/saturate.c @@ -175,7 +175,8 @@ void amok_bw_saturate_begin(const char *to_name, unsigned int to_port, /* Launch the saturation */ - ctx = gras_msg_rpc_async_call(peer_cmd, 60, "amok_bw_sat begin", &request); + ctx = + gras_msg_rpc_async_call(peer_cmd, 60, "amok_bw_sat begin", &request); free(request); gras_msg_rpc_async_wait(ctx, &request); meas = gras_socket_client_ext(to_name, request->peer.port, @@ -247,9 +248,9 @@ void amok_bw_saturate_begin(const char *to_name, unsigned int to_port, free(answer); } else { INFO6 - ("Saturation from %s:%d to %s:%d elapsed after %f sec (achieving %f kb/s)", - gras_os_myname(), gras_os_myport(), to_name, to_port, elapsed, - bw / 1024.0); + ("Saturation from %s:%d to %s:%d elapsed after %f sec (achieving %f kb/s)", + gras_os_myname(), gras_os_myport(), to_name, to_port, elapsed, + bw / 1024.0); } gras_socket_close(meas); @@ -277,7 +278,7 @@ static int amok_bw_cb_sat_begin(gras_msg_cb_ctx_t ctx, void *payload) xbt_ex_free(e); else RETHROW0 - ("Error encountered while opening a measurement server socket: %s"); + ("Error encountered while opening a measurement server socket: %s"); } if (measMaster == NULL) port++; /* prepare for a new loop */ @@ -337,7 +338,8 @@ void amok_bw_saturate_stop(const char *from_name, unsigned int from_port, TRY { gras_msg_rpccall(sock, 60, "amok_bw_sat stop", NULL, &answer); } CATCH(e) { - RETHROW2("Cannot ask %s:%d to stop saturation: %s", from_name, from_port); + RETHROW2("Cannot ask %s:%d to stop saturation: %s", from_name, + from_port); } gras_socket_close(sock); if (time) diff --git a/src/amok/PeerManagement/peermanagement.c b/src/amok/PeerManagement/peermanagement.c index dc8219de8a..3cff2c316a 100644 --- a/src/amok/PeerManagement/peermanagement.c +++ b/src/amok/PeerManagement/peermanagement.c @@ -54,7 +54,7 @@ static int amok_pm_cb_get(gras_msg_cb_ctx_t ctx, void *payload) static int amok_pm_cb_join(gras_msg_cb_ctx_t ctx, void *payload) { amok_pm_moddata_t g = gras_moddata_by_id(amok_pm_moddata_id); - char* group_name = *(char* *) payload; + char *group_name = *(char **) payload; xbt_dynar_t group = xbt_dict_get(g->groups, group_name); int rank; @@ -64,7 +64,8 @@ static int amok_pm_cb_join(gras_msg_cb_ctx_t ctx, void *payload) rank = xbt_dynar_length(group); xbt_dynar_push(group, &dude); - VERB3("Contacted by %s:%d. Give it rank #%d", dude->name, dude->port,rank); + VERB3("Contacted by %s:%d. Give it rank #%d", dude->name, dude->port, + rank); gras_msg_rpcreturn(10, ctx, &rank); free(group_name); @@ -181,8 +182,7 @@ int amok_pm_group_join(gras_socket_t master, const char *group_name) gras_msg_rpccall(master, 30, "amok_pm_join", &group_name, &rank); VERB4("Joined group '%s' on %s:%d. Got rank %d", group_name, gras_socket_peer_name(master), - gras_socket_peer_port(master), - rank); + gras_socket_peer_port(master), rank); return rank; } @@ -236,15 +236,16 @@ static void _amok_pm_init(void) /* no world-wide globals */ /* Datatype and message declarations */ gras_datadesc_type_t pm_group_type = - gras_datadesc_dynar(gras_datadesc_by_name("xbt_peer_t"), - xbt_peer_free_voidp); + gras_datadesc_dynar(gras_datadesc_by_name("xbt_peer_t"), + xbt_peer_free_voidp); gras_msgtype_declare("amok_pm_kill", NULL); gras_msgtype_declare_rpc("amok_pm_killrpc", NULL, NULL); gras_msgtype_declare_rpc("amok_pm_get", gras_datadesc_by_name("string"), pm_group_type); - gras_msgtype_declare_rpc("amok_pm_join", gras_datadesc_by_name("string"), gras_datadesc_by_name("int")); + gras_msgtype_declare_rpc("amok_pm_join", gras_datadesc_by_name("string"), + gras_datadesc_by_name("int")); gras_msgtype_declare_rpc("amok_pm_leave", gras_datadesc_by_name("string"), NULL); @@ -297,9 +298,9 @@ static void _amok_pm_leave(void *p) void amok_pm_modulecreate() { - gras_module_add("amok_pm", sizeof(s_amok_pm_moddata_t), &amok_pm_moddata_id, - _amok_pm_init, _amok_pm_exit, _amok_pm_join, - _amok_pm_leave); + gras_module_add("amok_pm", sizeof(s_amok_pm_moddata_t), + &amok_pm_moddata_id, _amok_pm_init, _amok_pm_exit, + _amok_pm_join, _amok_pm_leave); } diff --git a/src/amok/amok_modinter.h b/src/amok/amok_modinter.h index da66e51755..96c837482c 100644 --- a/src/amok/amok_modinter.h +++ b/src/amok/amok_modinter.h @@ -15,4 +15,4 @@ void amok_exit(void); /* module creation functions */ void amok_pm_modulecreate(void); -#endif /* AMOK_BASE_H */ +#endif /* AMOK_BASE_H */ diff --git a/src/bindings/lua/lua_stub_generator.c b/src/bindings/lua/lua_stub_generator.c index 2508247078..585576790e 100644 --- a/src/bindings/lua/lua_stub_generator.c +++ b/src/bindings/lua/lua_stub_generator.c @@ -45,14 +45,14 @@ char *warning = NULL; /**********************************************/ const char *SIM_PREEMBULE = - "/* specific to Borland Compiler */\n" - "#ifdef __BORLANDC__\n" - "#pragma hdrstop\n" - "#endif\n\n" - "#include \n" - "#include \n" - "#include \"msg/msg.h\"\n" - "#include \n" "\n" "char *gras_log=NULL;\n"; + "/* specific to Borland Compiler */\n" + "#ifdef __BORLANDC__\n" + "#pragma hdrstop\n" + "#endif\n\n" + "#include \n" + "#include \n" + "#include \"msg/msg.h\"\n" + "#include \n" "\n" "char *gras_log=NULL;\n"; #define SIM_LAUNCH_FUNC \ @@ -75,15 +75,15 @@ const char *SIM_PREEMBULE = "}\n" const char *SIM_MAIN_POSTEMBULE = "\n" - "\n" - " gras_load_environment_script(argv[1]);\n" - "\n" - " /* Run the simulation */\n" - " gras_main();\n" - "\n" - " /* cleanup the place */\n" - " gras_clean();\n" - " if (gras_log)\n" " free(gras_log);\n" " return 0;\n" "}\n"; + "\n" + " gras_load_environment_script(argv[1]);\n" + "\n" + " /* Run the simulation */\n" + " gras_main();\n" + "\n" + " /* cleanup the place */\n" + " gras_clean();\n" + " if (gras_log)\n" " free(gras_log);\n" " return 0;\n" "}\n"; /*************************************** @@ -133,10 +133,10 @@ void generate_sim(const char *project) " if (argc != 2) {\n" " fprintf(stderr, \"Usage: lua platform_script.lua [--log=...]\\n\");\n" " exit(1);\n" " }\n" "\n"); - fprintf(OUT, - "\n" " /* Application deployment */\n"); + fprintf(OUT, "\n" " /* Application deployment */\n"); xbt_dict_foreach(process_function_set, cursor, key, data) { - fprintf(OUT, " gras_function_register(\"%s\", launch_%s);\n", key, key); + fprintf(OUT, " gras_function_register(\"%s\", launch_%s);\n", key, + key); } fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE); fclose(OUT); @@ -157,7 +157,8 @@ void generate_rl(const char *project) xbt_dict_foreach(process_function_set, cursor, key, data) { filename = - xbt_new(char, strlen(project) + strlen(RL_SOURCENAME) + strlen(key)); + xbt_new(char, + strlen(project) + strlen(RL_SOURCENAME) + strlen(key)); sprintf(filename, RL_SOURCENAME, project, key); @@ -264,7 +265,8 @@ void generate_makefile_local(const char *project) char *filename = NULL; FILE *OUT = NULL; - filename = xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL)); + filename = + xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL)); sprintf(filename, MAKEFILE_FILENAME_LOCAL, project); OUT = fopen(filename, "w"); diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index de08abce87..105ac869a6 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -15,7 +15,7 @@ #include "xbt.h" #include "lua_stub_generator.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua,bindings,"Lua Bindings"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings"); #define TASK_MODULE_NAME "simgrid.Task" #define HOST_MODULE_NAME "simgrid.Host" @@ -27,37 +27,38 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua,bindings,"Lua Bindings"); /* ********************************************************************************* */ /* helper functions */ /* ********************************************************************************* */ -static void stackDump (const char *msg, lua_State *L) { +static void stackDump(const char *msg, lua_State * L) +{ char buff[2048]; - char *p=buff; + char *p = buff; int i; int top = lua_gettop(L); fflush(stdout); - p+=sprintf(p,"STACK(top=%d): ",top); + p += sprintf(p, "STACK(top=%d): ", top); for (i = 1; i <= top; i++) { /* repeat for each level */ int t = lua_type(L, i); switch (t) { - case LUA_TSTRING: /* strings */ - p+=sprintf(p,"`%s'", lua_tostring(L, i)); + case LUA_TSTRING: /* strings */ + p += sprintf(p, "`%s'", lua_tostring(L, i)); break; - case LUA_TBOOLEAN: /* booleans */ - p+=sprintf(p,lua_toboolean(L, i) ? "true" : "false"); + case LUA_TBOOLEAN: /* booleans */ + p += sprintf(p, lua_toboolean(L, i) ? "true" : "false"); break; - case LUA_TNUMBER: /* numbers */ - p+=sprintf(p,"%g", lua_tonumber(L, i)); + case LUA_TNUMBER: /* numbers */ + p += sprintf(p, "%g", lua_tonumber(L, i)); break; case LUA_TTABLE: - p+=sprintf(p, "Table"); + p += sprintf(p, "Table"); break; - default: /* other values */ - p+=sprintf(p, "???"); + default: /* other values */ + p += sprintf(p, "???"); /* if ((ptr = luaL_checkudata(L,i,TASK_MODULE_NAME))) { p+=sprintf(p,"task"); } else { @@ -66,25 +67,27 @@ static void stackDump (const char *msg, lua_State *L) { break; } - p+=sprintf(p," "); /* put a separator */ + p += sprintf(p, " "); /* put a separator */ } - INFO2("%s%s",msg,buff); + INFO2("%s%s", msg, buff); } /** @brief ensures that a userdata on the stack is a task and returns the pointer inside the userdata */ -static m_task_t checkTask (lua_State *L,int index) { - m_task_t *pi,tk; - luaL_checktype(L,index,LUA_TTABLE); - lua_getfield(L,index,"__simgrid_task"); - pi = (m_task_t*)luaL_checkudata(L,-1,TASK_MODULE_NAME); - if(pi == NULL) - luaL_typerror(L,index,TASK_MODULE_NAME); +static m_task_t checkTask(lua_State * L, int index) +{ + m_task_t *pi, tk; + luaL_checktype(L, index, LUA_TTABLE); + lua_getfield(L, index, "__simgrid_task"); + pi = (m_task_t *) luaL_checkudata(L, -1, TASK_MODULE_NAME); + if (pi == NULL) + luaL_typerror(L, index, TASK_MODULE_NAME); tk = *pi; - if(!tk) - luaL_error(L,"null Task"); - lua_pop(L,1); - return tk; + if (!tk) + luaL_error(L, "null Task"); + lua_pop(L, 1); + return tk; } + /* ********************************************************************************* */ /* wrapper functions */ /* ********************************************************************************* */ @@ -112,191 +115,208 @@ static m_task_t checkTask (lua_State *L,int index) { * If 0, then it cannot be transfered with the get() and put() methods. * This value has to be >= 0. */ -static int Task_new(lua_State* L) { - const char *name=luaL_checkstring(L,1); - int comp_size = luaL_checkint(L,2); - int msg_size = luaL_checkint(L,3); - m_task_t msg_task = MSG_task_create(name,comp_size,msg_size,NULL); - lua_newtable (L); /* create a table, put the userdata on top of it */ - m_task_t *lua_task = (m_task_t*)lua_newuserdata(L,sizeof(m_task_t)); - *lua_task = msg_task; - luaL_getmetatable(L,TASK_MODULE_NAME); - lua_setmetatable(L,-2); - lua_setfield (L, -2, "__simgrid_task"); /* put the userdata as field of the table */ - /* remove the args from the stack */ - lua_remove(L,1); - lua_remove(L,1); - lua_remove(L,1); - return 1; +static int Task_new(lua_State * L) +{ + const char *name = luaL_checkstring(L, 1); + int comp_size = luaL_checkint(L, 2); + int msg_size = luaL_checkint(L, 3); + m_task_t msg_task = MSG_task_create(name, comp_size, msg_size, NULL); + lua_newtable(L); /* create a table, put the userdata on top of it */ + m_task_t *lua_task = (m_task_t *) lua_newuserdata(L, sizeof(m_task_t)); + *lua_task = msg_task; + luaL_getmetatable(L, TASK_MODULE_NAME); + lua_setmetatable(L, -2); + lua_setfield(L, -2, "__simgrid_task"); /* put the userdata as field of the table */ + /* remove the args from the stack */ + lua_remove(L, 1); + lua_remove(L, 1); + lua_remove(L, 1); + return 1; } -static int Task_get_name(lua_State *L) { - m_task_t tk = checkTask(L,-1); - lua_pushstring(L,MSG_task_get_name(tk)); +static int Task_get_name(lua_State * L) +{ + m_task_t tk = checkTask(L, -1); + lua_pushstring(L, MSG_task_get_name(tk)); return 1; } -static int Task_computation_duration(lua_State *L){ - m_task_t tk = checkTask(L,-1); - lua_pushnumber(L,MSG_task_get_compute_duration (tk)); +static int Task_computation_duration(lua_State * L) +{ + m_task_t tk = checkTask(L, -1); + lua_pushnumber(L, MSG_task_get_compute_duration(tk)); return 1; } -static int Task_execute(lua_State *L){ - m_task_t tk = checkTask(L,-1); +static int Task_execute(lua_State * L) +{ + m_task_t tk = checkTask(L, -1); int res = MSG_task_execute(tk); - lua_pushnumber(L,res); + lua_pushnumber(L, res); return 1; } -static int Task_destroy(lua_State *L) { - m_task_t tk = checkTask(L,-1); +static int Task_destroy(lua_State * L) +{ + m_task_t tk = checkTask(L, -1); int res = MSG_task_destroy(tk); - lua_pushnumber(L,res); + lua_pushnumber(L, res); return 1; } -static int Task_send(lua_State *L) { +static int Task_send(lua_State * L) +{ //stackDump("send ",L); - m_task_t tk = checkTask(L,-2); - const char *mailbox = luaL_checkstring(L,-1); - lua_pop(L,1); // remove the string so that the task is on top of it - MSG_task_set_data(tk,L); // Copy my stack into the task, so that the receiver can copy the lua task directly - MSG_error_t res = MSG_task_send(tk,mailbox); - while (MSG_task_get_data(tk)!=NULL) // Don't mess up with my stack: the receiver didn't copy the data yet - MSG_process_sleep(0); // yield - - if (res != MSG_OK) switch(res) { - case MSG_TIMEOUT : + m_task_t tk = checkTask(L, -2); + const char *mailbox = luaL_checkstring(L, -1); + lua_pop(L, 1); // remove the string so that the task is on top of it + MSG_task_set_data(tk, L); // Copy my stack into the task, so that the receiver can copy the lua task directly + MSG_error_t res = MSG_task_send(tk, mailbox); + while (MSG_task_get_data(tk) != NULL) // Don't mess up with my stack: the receiver didn't copy the data yet + MSG_process_sleep(0); // yield + + if (res != MSG_OK) + switch (res) { + case MSG_TIMEOUT: ERROR0("MSG_task_send failed : Timeout"); break; - case MSG_TRANSFER_FAILURE : + case MSG_TRANSFER_FAILURE: ERROR0("MSG_task_send failed : Transfer Failure"); break; - case MSG_HOST_FAILURE : + case MSG_HOST_FAILURE: ERROR0("MSG_task_send failed : Host Failure "); break; - default : - ERROR0("MSG_task_send failed : Unexpected error , please report this bug"); + default: + ERROR0 + ("MSG_task_send failed : Unexpected error , please report this bug"); break; } return 0; } -static int Task_recv(lua_State *L) { +static int Task_recv(lua_State * L) +{ m_task_t tk = NULL; - const char *mailbox = luaL_checkstring(L,-1); - MSG_error_t res = MSG_task_receive(&tk,mailbox); + const char *mailbox = luaL_checkstring(L, -1); + MSG_error_t res = MSG_task_receive(&tk, mailbox); lua_State *sender_stack = MSG_task_get_data(tk); - lua_xmove(sender_stack,L,1); // copy the data directly from sender's stack - MSG_task_set_data(tk,NULL); - - if(res != MSG_OK) switch(res){ - case MSG_TIMEOUT : - ERROR0("MSG_task_receive failed : Timeout"); - break; - case MSG_TRANSFER_FAILURE : - ERROR0("MSG_task_receive failed : Transfer Failure"); - break; - case MSG_HOST_FAILURE : - ERROR0("MSG_task_receive failed : Host Failure "); - break; - default : - ERROR0("MSG_task_receive failed : Unexpected error , please report this bug"); - break; - } + lua_xmove(sender_stack, L, 1); // copy the data directly from sender's stack + MSG_task_set_data(tk, NULL); + + if (res != MSG_OK) + switch (res) { + case MSG_TIMEOUT: + ERROR0("MSG_task_receive failed : Timeout"); + break; + case MSG_TRANSFER_FAILURE: + ERROR0("MSG_task_receive failed : Transfer Failure"); + break; + case MSG_HOST_FAILURE: + ERROR0("MSG_task_receive failed : Host Failure "); + break; + default: + ERROR0 + ("MSG_task_receive failed : Unexpected error , please report this bug"); + break; + } return 1; } static const luaL_reg Task_methods[] = { - {"new", Task_new}, - {"name", Task_get_name}, - {"computation_duration", Task_computation_duration}, - {"execute", Task_execute}, - {"destroy", Task_destroy}, - {"send", Task_send}, - {"recv", Task_recv}, - {0,0} + {"new", Task_new}, + {"name", Task_get_name}, + {"computation_duration", Task_computation_duration}, + {"execute", Task_execute}, + {"destroy", Task_destroy}, + {"send", Task_send}, + {"recv", Task_recv}, + {0, 0} }; -static int Task_gc(lua_State *L) { - m_task_t tk=checkTask(L,-1); - if (tk) MSG_task_destroy(tk); + +static int Task_gc(lua_State * L) +{ + m_task_t tk = checkTask(L, -1); + if (tk) + MSG_task_destroy(tk); return 0; } -static int Task_tostring(lua_State *L) { - lua_pushfstring(L, "Task :%p",lua_touserdata(L,1)); +static int Task_tostring(lua_State * L) +{ + lua_pushfstring(L, "Task :%p", lua_touserdata(L, 1)); return 1; } static const luaL_reg Task_meta[] = { - {"__gc", Task_gc}, - {"__tostring", Task_tostring}, - {0,0} + {"__gc", Task_gc}, + {"__tostring", Task_tostring}, + {0, 0} }; /** * Host */ -static m_host_t checkHost (lua_State *L,int index) { - m_host_t *pi,ht; - luaL_checktype(L,index,LUA_TTABLE); - lua_getfield(L,index,"__simgrid_host"); - pi = (m_host_t*)luaL_checkudata(L,-1,HOST_MODULE_NAME); - if(pi == NULL) - luaL_typerror(L,index,HOST_MODULE_NAME); +static m_host_t checkHost(lua_State * L, int index) +{ + m_host_t *pi, ht; + luaL_checktype(L, index, LUA_TTABLE); + lua_getfield(L, index, "__simgrid_host"); + pi = (m_host_t *) luaL_checkudata(L, -1, HOST_MODULE_NAME); + if (pi == NULL) + luaL_typerror(L, index, HOST_MODULE_NAME); ht = *pi; - if(!ht) - luaL_error(L,"null Host"); - lua_pop(L,1); - return ht; + if (!ht) + luaL_error(L, "null Host"); + lua_pop(L, 1); + return ht; } -static int Host_get_by_name(lua_State *L) +static int Host_get_by_name(lua_State * L) { - const char *name=luaL_checkstring(L,1); - DEBUG0("Getting Host from name..."); - m_host_t msg_host = MSG_get_host_by_name(name); - if (!msg_host) - { - luaL_error(L,"null Host : MSG_get_host_by_name failled"); - } - lua_newtable (L); /* create a table, put the userdata on top of it */ - m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t)); - *lua_host = msg_host; - luaL_getmetatable(L,HOST_MODULE_NAME); - lua_setmetatable(L,-2); - lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */ - /* remove the args from the stack */ - lua_remove(L,1); - return 1; + const char *name = luaL_checkstring(L, 1); + DEBUG0("Getting Host from name..."); + m_host_t msg_host = MSG_get_host_by_name(name); + if (!msg_host) { + luaL_error(L, "null Host : MSG_get_host_by_name failled"); + } + lua_newtable(L); /* create a table, put the userdata on top of it */ + m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t)); + *lua_host = msg_host; + luaL_getmetatable(L, HOST_MODULE_NAME); + lua_setmetatable(L, -2); + lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */ + /* remove the args from the stack */ + lua_remove(L, 1); + return 1; } -static int Host_get_name(lua_State *L) { - m_host_t ht = checkHost(L,-1); - lua_pushstring(L,MSG_host_get_name(ht)); +static int Host_get_name(lua_State * L) +{ + m_host_t ht = checkHost(L, -1); + lua_pushstring(L, MSG_host_get_name(ht)); return 1; } -static int Host_number(lua_State *L) { - lua_pushnumber(L,MSG_get_host_number()); +static int Host_number(lua_State * L) +{ + lua_pushnumber(L, MSG_get_host_number()); return 1; } -static int Host_at(lua_State *L) +static int Host_at(lua_State * L) { - int index = luaL_checkinteger(L,1); - m_host_t host = MSG_get_host_table()[index-1]; // lua indexing start by 1 (lua[1] <=> C[0]) - lua_newtable (L); /* create a table, put the userdata on top of it */ - m_host_t *lua_host = (m_host_t*)lua_newuserdata(L,sizeof(m_host_t)); - *lua_host = host; - luaL_getmetatable(L,HOST_MODULE_NAME); - lua_setmetatable(L,-2); - lua_setfield (L, -2, "__simgrid_host"); /* put the userdata as field of the table */ - return 1; + int index = luaL_checkinteger(L, 1); + m_host_t host = MSG_get_host_table()[index - 1]; // lua indexing start by 1 (lua[1] <=> C[0]) + lua_newtable(L); /* create a table, put the userdata on top of it */ + m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t)); + *lua_host = host; + luaL_getmetatable(L, HOST_MODULE_NAME); + lua_setmetatable(L, -2); + lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */ + return 1; } @@ -308,97 +328,94 @@ static int Host_at(lua_State *L) #include "surf/surfxml_parse.h" /* to override surf_parse and bypass the parser */ #include "surf/surf_private.h" -typedef struct t_AS_attr -{ - const char* id; - const char *mode; -}AS_attr,*p_AS_attr; - -typedef struct t_host_attr -{ - //platform attribute - // Mandatory attributes - const char* id; - double power_peak; - // Optional attributes - double power_scale; - const char *power_trace; - int state_initial; - const char *state_trace; - //deployment attribute - const char* function; - xbt_dynar_t args_list; -}host_attr,*p_host_attr; - -typedef struct t_link_attr -{ - //mandatory attributes - const char* id; - double bandwidth; - double latency; - // Optional attributes - const char* bandwidth_trace; - const char* latency_trace; - const char* state_trace; - int state_initial; - int policy; -}link_attr,*p_link_attr; - -typedef struct t_route_attr -{ - const char *src_id; - const char *dest_id; - xbt_dynar_t links_id; - -}route_attr,*p_route_attr; +typedef struct t_AS_attr { + const char *id; + const char *mode; +} AS_attr, *p_AS_attr; + +typedef struct t_host_attr { + //platform attribute + // Mandatory attributes + const char *id; + double power_peak; + // Optional attributes + double power_scale; + const char *power_trace; + int state_initial; + const char *state_trace; + //deployment attribute + const char *function; + xbt_dynar_t args_list; +} host_attr, *p_host_attr; + +typedef struct t_link_attr { + //mandatory attributes + const char *id; + double bandwidth; + double latency; + // Optional attributes + const char *bandwidth_trace; + const char *latency_trace; + const char *state_trace; + int state_initial; + int policy; +} link_attr, *p_link_attr; + +typedef struct t_route_attr { + const char *src_id; + const char *dest_id; + xbt_dynar_t links_id; + +} route_attr, *p_route_attr; //AS : One struct needed static p_AS_attr AS; //using xbt_dynar_t : -static xbt_dynar_t host_list_d ; -static xbt_dynar_t link_list_d ; -static xbt_dynar_t route_list_d ; +static xbt_dynar_t host_list_d; +static xbt_dynar_t link_list_d; +static xbt_dynar_t route_list_d; /* * Initialize platform model routing */ -static void create_AS(const char* id,const char * mode) +static void create_AS(const char *id, const char *mode) { - surf_AS_new(id,mode); + surf_AS_new(id, mode); } /** * create host resource via CPU model [for MSG] */ -static void create_host(const char* id,double power_peak,double power_sc, - const char* power_tr,int state_init, - const char* state_tr) +static void create_host(const char *id, double power_peak, double power_sc, + const char *power_tr, int state_init, + const char *state_tr) { - double power_scale = 1.0; - tmgr_trace_t power_trace = NULL; - e_surf_resource_state_t state_initial; - tmgr_trace_t state_trace; - if(power_sc) // !=0 - power_scale = power_sc; - if (state_init == -1) - state_initial = SURF_RESOURCE_OFF; - else - state_initial = SURF_RESOURCE_ON; - if(power_tr) - power_trace = tmgr_trace_new(power_tr); - else - power_trace = tmgr_trace_new(""); - if(state_tr) - state_trace = tmgr_trace_new(state_tr); - else - state_trace = tmgr_trace_new(""); - current_property_set = xbt_dict_new(); - surf_host_create_resource(xbt_strdup(id), power_peak, power_scale, - power_trace, state_initial, state_trace, current_property_set); + double power_scale = 1.0; + tmgr_trace_t power_trace = NULL; + e_surf_resource_state_t state_initial; + tmgr_trace_t state_trace; + if (power_sc) // !=0 + power_scale = power_sc; + if (state_init == -1) + state_initial = SURF_RESOURCE_OFF; + else + state_initial = SURF_RESOURCE_ON; + if (power_tr) + power_trace = tmgr_trace_new(power_tr); + else + power_trace = tmgr_trace_new(""); + if (state_tr) + state_trace = tmgr_trace_new(state_tr); + else + state_trace = tmgr_trace_new(""); + current_property_set = xbt_dict_new(); + surf_host_create_resource(xbt_strdup(id), power_peak, power_scale, + power_trace, state_initial, state_trace, + current_property_set); } @@ -406,68 +423,71 @@ static void create_host(const char* id,double power_peak,double power_sc, * create link resource via network model */ static void create_link(const char *name, - double bw_initial,const char *trace,double lat_initial, - const char* latency_trace,int state_init, const char* state_trace,int policy) + double bw_initial, const char *trace, + double lat_initial, const char *latency_trace, + int state_init, const char *state_trace, + int policy) { - tmgr_trace_t bw_trace; - tmgr_trace_t lat_trace; - e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; - e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; - tmgr_trace_t st_trace; - if(trace) - bw_trace = tmgr_trace_new(trace); - else - bw_trace = tmgr_trace_new(""); - - if(latency_trace) - lat_trace = tmgr_trace_new(latency_trace); - else - lat_trace = tmgr_trace_new(""); - - if(state_trace) - st_trace = tmgr_trace_new(state_trace); - else - st_trace = tmgr_trace_new(""); - - if(state_init == -1) - state_initial_link = SURF_RESOURCE_OFF; - if(policy == -1) - policy_initial_link = SURF_LINK_FATPIPE; - - surf_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, st_trace, - policy_initial_link, xbt_dict_new()); + tmgr_trace_t bw_trace; + tmgr_trace_t lat_trace; + e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; + e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; + tmgr_trace_t st_trace; + if (trace) + bw_trace = tmgr_trace_new(trace); + else + bw_trace = tmgr_trace_new(""); + + if (latency_trace) + lat_trace = tmgr_trace_new(latency_trace); + else + lat_trace = tmgr_trace_new(""); + + if (state_trace) + st_trace = tmgr_trace_new(state_trace); + else + st_trace = tmgr_trace_new(""); + + if (state_init == -1) + state_initial_link = SURF_RESOURCE_OFF; + if (policy == -1) + policy_initial_link = SURF_LINK_FATPIPE; + + surf_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, + lat_initial, lat_trace, state_initial_link, + st_trace, policy_initial_link, xbt_dict_new()); } /* *create host resource via workstation_ptask_L07 model [for SimDag] */ -static void create_host_wsL07(const char* id,double power_peak,double power_sc, - const char* power_tr,int state_init, - const char* state_tr) +static void create_host_wsL07(const char *id, double power_peak, + double power_sc, const char *power_tr, + int state_init, const char *state_tr) { - double power_scale = 1.0; - tmgr_trace_t power_trace = NULL; - e_surf_resource_state_t state_initial; - tmgr_trace_t state_trace; - if(power_sc) // !=0 - power_scale = power_sc; - if (state_init == -1) - state_initial = SURF_RESOURCE_OFF; - else - state_initial = SURF_RESOURCE_ON; - if(power_tr) - power_trace = tmgr_trace_new(power_tr); - else - power_trace = tmgr_trace_new(""); - if(state_tr) - state_trace = tmgr_trace_new(state_tr); - else - state_trace = tmgr_trace_new(""); - current_property_set = xbt_dict_new(); - surf_wsL07_host_create_resource(xbt_strdup(id), power_peak, power_scale, - power_trace, state_initial, state_trace, current_property_set); + double power_scale = 1.0; + tmgr_trace_t power_trace = NULL; + e_surf_resource_state_t state_initial; + tmgr_trace_t state_trace; + if (power_sc) // !=0 + power_scale = power_sc; + if (state_init == -1) + state_initial = SURF_RESOURCE_OFF; + else + state_initial = SURF_RESOURCE_ON; + if (power_tr) + power_trace = tmgr_trace_new(power_tr); + else + power_trace = tmgr_trace_new(""); + if (state_tr) + state_trace = tmgr_trace_new(state_tr); + else + state_trace = tmgr_trace_new(""); + current_property_set = xbt_dict_new(); + surf_wsL07_host_create_resource(xbt_strdup(id), power_peak, power_scale, + power_trace, state_initial, state_trace, + current_property_set); } @@ -476,37 +496,40 @@ static void create_host_wsL07(const char* id,double power_peak,double power_sc, */ static void create_link_wsL07(const char *name, - double bw_initial,const char *trace,double lat_initial, - const char* latency_trace,int state_init, const char* state_trace,int policy) + double bw_initial, const char *trace, + double lat_initial, + const char *latency_trace, int state_init, + const char *state_trace, int policy) { - tmgr_trace_t bw_trace; - tmgr_trace_t lat_trace; - e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; - e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; - tmgr_trace_t st_trace; - if(trace) - bw_trace = tmgr_trace_new(trace); - else - bw_trace = tmgr_trace_new(""); - - if(latency_trace) - lat_trace = tmgr_trace_new(latency_trace); - else - lat_trace = tmgr_trace_new(""); - - if(state_trace) - st_trace = tmgr_trace_new(state_trace); - else - st_trace = tmgr_trace_new(""); - - if(state_init == -1) - state_initial_link = SURF_RESOURCE_OFF; - if(policy == -1) - policy_initial_link = SURF_LINK_FATPIPE; - - surf_wsL07_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, st_trace, - policy_initial_link, xbt_dict_new()); + tmgr_trace_t bw_trace; + tmgr_trace_t lat_trace; + e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; + e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; + tmgr_trace_t st_trace; + if (trace) + bw_trace = tmgr_trace_new(trace); + else + bw_trace = tmgr_trace_new(""); + + if (latency_trace) + lat_trace = tmgr_trace_new(latency_trace); + else + lat_trace = tmgr_trace_new(""); + + if (state_trace) + st_trace = tmgr_trace_new(state_trace); + else + st_trace = tmgr_trace_new(""); + + if (state_init == -1) + state_initial_link = SURF_RESOURCE_OFF; + if (policy == -1) + policy_initial_link = SURF_LINK_FATPIPE; + + surf_wsL07_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, + lat_initial, lat_trace, + state_initial_link, st_trace, + policy_initial_link, xbt_dict_new()); } @@ -514,253 +537,253 @@ static void create_link_wsL07(const char *name, * init AS */ -static int AS_new(lua_State *L) +static int AS_new(lua_State * L) { - const char *id; - const char *mode; - if(lua_istable(L,1)) - { - lua_pushstring(L,"id"); - lua_gettable(L,-2); - id = lua_tostring(L,-1); - lua_pop(L,1); - - lua_pushstring(L,"mode"); - lua_gettable(L,-2); - mode = lua_tostring(L,-1); - lua_pop(L,1); - } - else { - ERROR0("Bad Arguments to AS.new, Should be a table with named arguments"); - return -1; - } - AS = malloc(sizeof(AS_attr)); - AS->id = id; - AS->mode = mode; - - return 0; + const char *id; + const char *mode; + if (lua_istable(L, 1)) { + lua_pushstring(L, "id"); + lua_gettable(L, -2); + id = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "mode"); + lua_gettable(L, -2); + mode = lua_tostring(L, -1); + lua_pop(L, 1); + } else { + ERROR0 + ("Bad Arguments to AS.new, Should be a table with named arguments"); + return -1; + } + AS = malloc(sizeof(AS_attr)); + AS->id = id; + AS->mode = mode; + + return 0; } /* * add new host to platform hosts list */ -static int Host_new(lua_State *L) +static int Host_new(lua_State * L) { - if(xbt_dynar_is_empty(host_list_d)) - host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref); - - p_host_attr host; - const char * id; - const char *power_trace; - const char *state_trace; - double power,power_scale; - int state_initial; - //get values from the table passed as argument - if (lua_istable(L,-1)) { - - // get Id Value - lua_pushstring(L,"id"); - lua_gettable(L, -2 ); - id = lua_tostring(L,-1); - lua_pop(L,1); - - // get power value - lua_pushstring(L,"power"); - lua_gettable(L, -2 ); - power = lua_tonumber(L,-1); - lua_pop(L,1); - - //get power_scale - lua_pushstring(L,"power_scale"); - lua_gettable(L, -2 ); - power_scale = lua_tonumber(L,-1); - lua_pop(L,1); - - //get power_trace - lua_pushstring(L,"power_trace"); - lua_gettable(L, -2 ); - power_trace = lua_tostring(L,-1); - lua_pop(L,1); - - //get state initial - lua_pushstring(L,"state_initial"); - lua_gettable(L, -2 ); - state_initial = lua_tonumber(L,-1); - lua_pop(L,1); - - //get trace state - lua_pushstring(L,"state_trace"); - lua_gettable(L, -2 ); - state_trace = lua_tostring(L,-1); - lua_pop(L,1); - - } else { - ERROR0("Bad Arguments to create host, Should be a table with named arguments"); - return -1; - } + if (xbt_dynar_is_empty(host_list_d)) + host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref); + + p_host_attr host; + const char *id; + const char *power_trace; + const char *state_trace; + double power, power_scale; + int state_initial; + //get values from the table passed as argument + if (lua_istable(L, -1)) { + + // get Id Value + lua_pushstring(L, "id"); + lua_gettable(L, -2); + id = lua_tostring(L, -1); + lua_pop(L, 1); + + // get power value + lua_pushstring(L, "power"); + lua_gettable(L, -2); + power = lua_tonumber(L, -1); + lua_pop(L, 1); + + //get power_scale + lua_pushstring(L, "power_scale"); + lua_gettable(L, -2); + power_scale = lua_tonumber(L, -1); + lua_pop(L, 1); + + //get power_trace + lua_pushstring(L, "power_trace"); + lua_gettable(L, -2); + power_trace = lua_tostring(L, -1); + lua_pop(L, 1); + + //get state initial + lua_pushstring(L, "state_initial"); + lua_gettable(L, -2); + state_initial = lua_tonumber(L, -1); + lua_pop(L, 1); + + //get trace state + lua_pushstring(L, "state_trace"); + lua_gettable(L, -2); + state_trace = lua_tostring(L, -1); + lua_pop(L, 1); + + } else { + ERROR0 + ("Bad Arguments to create host, Should be a table with named arguments"); + return -1; + } + + host = malloc(sizeof(host_attr)); + host->id = id; + host->power_peak = power; + host->power_scale = power_scale; + host->power_trace = power_trace; + host->state_initial = state_initial; + host->state_trace = state_trace; + host->function = NULL; + xbt_dynar_push(host_list_d, &host); - host = malloc(sizeof(host_attr)); - host->id = id; - host->power_peak = power; - host->power_scale = power_scale; - host->power_trace = power_trace; - host->state_initial = state_initial; - host->state_trace = state_trace; - host->function = NULL; - xbt_dynar_push(host_list_d, &host); - - return 0; + return 0; } /** * add link to platform links list */ -static int Link_new(lua_State *L) // (id,bandwidth,latency) +static int Link_new(lua_State * L) // (id,bandwidth,latency) { - if(xbt_dynar_is_empty(link_list_d)) - link_list_d = xbt_dynar_new(sizeof(p_link_attr), &xbt_free_ref); - - const char* id; - double bandwidth,latency; - const char* bandwidth_trace; - const char* latency_trace; - const char* state_trace; - int state_initial,policy; - - //get values from the table passed as argument - if (lua_istable(L,-1)) { - // get Id Value - lua_pushstring(L,"id"); - lua_gettable(L, -2 ); - id = lua_tostring(L,-1); - lua_pop(L,1); - - // get bandwidth value - lua_pushstring(L,"bandwidth"); - lua_gettable(L, -2 ); - bandwidth = lua_tonumber(L,-1); - lua_pop(L,1); - - //get latency value - lua_pushstring(L,"latency"); - lua_gettable(L, -2 ); - latency = lua_tonumber(L,-1); - lua_pop(L,1); - - /*Optional Arguments */ - - //get bandwidth_trace value - lua_pushstring(L,"bandwidth_trace"); - lua_gettable(L, -2 ); - bandwidth_trace = lua_tostring(L,-1); - lua_pop(L,1); - - //get latency_trace value - lua_pushstring(L,"latency_trace"); - lua_gettable(L, -2 ); - latency_trace = lua_tostring(L,-1); - lua_pop(L,1); - - //get state_trace value - lua_pushstring(L,"state_trace"); - lua_gettable(L, -2 ); - state_trace = lua_tostring(L,-1); - lua_pop(L,1); - - //get state_initial value - lua_pushstring(L,"state_initial"); - lua_gettable(L, -2 ); - state_initial = lua_tonumber(L,-1); - lua_pop(L,1); - - - //get policy value - lua_pushstring(L,"policy"); - lua_gettable(L, -2 ); - policy = lua_tonumber(L,-1); - lua_pop(L,1); - - } else { - ERROR0("Bad Arguments to create link, Should be a table with named arguments"); - return -1; - } - - p_link_attr link = malloc(sizeof(link_attr)); - link->id = id; - link->bandwidth = bandwidth; - link->latency = latency; - link->bandwidth_trace = bandwidth_trace; - link->latency_trace = latency_trace; - link->state_trace = state_trace; - link->state_initial= state_initial; - link->policy = policy; - xbt_dynar_push(link_list_d,&link); - return 0; + if (xbt_dynar_is_empty(link_list_d)) + link_list_d = xbt_dynar_new(sizeof(p_link_attr), &xbt_free_ref); + + const char *id; + double bandwidth, latency; + const char *bandwidth_trace; + const char *latency_trace; + const char *state_trace; + int state_initial, policy; + + //get values from the table passed as argument + if (lua_istable(L, -1)) { + // get Id Value + lua_pushstring(L, "id"); + lua_gettable(L, -2); + id = lua_tostring(L, -1); + lua_pop(L, 1); + + // get bandwidth value + lua_pushstring(L, "bandwidth"); + lua_gettable(L, -2); + bandwidth = lua_tonumber(L, -1); + lua_pop(L, 1); + + //get latency value + lua_pushstring(L, "latency"); + lua_gettable(L, -2); + latency = lua_tonumber(L, -1); + lua_pop(L, 1); + + /*Optional Arguments */ + + //get bandwidth_trace value + lua_pushstring(L, "bandwidth_trace"); + lua_gettable(L, -2); + bandwidth_trace = lua_tostring(L, -1); + lua_pop(L, 1); + + //get latency_trace value + lua_pushstring(L, "latency_trace"); + lua_gettable(L, -2); + latency_trace = lua_tostring(L, -1); + lua_pop(L, 1); + + //get state_trace value + lua_pushstring(L, "state_trace"); + lua_gettable(L, -2); + state_trace = lua_tostring(L, -1); + lua_pop(L, 1); + + //get state_initial value + lua_pushstring(L, "state_initial"); + lua_gettable(L, -2); + state_initial = lua_tonumber(L, -1); + lua_pop(L, 1); + + + //get policy value + lua_pushstring(L, "policy"); + lua_gettable(L, -2); + policy = lua_tonumber(L, -1); + lua_pop(L, 1); + + } else { + ERROR0 + ("Bad Arguments to create link, Should be a table with named arguments"); + return -1; + } + + p_link_attr link = malloc(sizeof(link_attr)); + link->id = id; + link->bandwidth = bandwidth; + link->latency = latency; + link->bandwidth_trace = bandwidth_trace; + link->latency_trace = latency_trace; + link->state_trace = state_trace; + link->state_initial = state_initial; + link->policy = policy; + xbt_dynar_push(link_list_d, &link); + return 0; } /** * add route to platform routes list */ -static int Route_new(lua_State *L) // (src_id,dest_id,links_number,link_table) +static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_table) { - if(xbt_dynar_is_empty(route_list_d)) - route_list_d = xbt_dynar_new(sizeof(p_route_attr), &xbt_free_ref); - const char * link_id; - p_route_attr route = malloc(sizeof(route_attr)); - route->src_id = luaL_checkstring(L,1); - route->dest_id = luaL_checkstring(L,2); - route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref); - lua_pushnil(L); - while (lua_next(L,3) != 0) { - link_id = lua_tostring(L, -1); - xbt_dynar_push(route->links_id, &link_id); - DEBUG2("index = %f , Link_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1)); - lua_pop(L, 1); - } - lua_pop(L, 1); - - //add route to platform's route list - xbt_dynar_push(route_list_d,&route); - return 0; + if (xbt_dynar_is_empty(route_list_d)) + route_list_d = xbt_dynar_new(sizeof(p_route_attr), &xbt_free_ref); + const char *link_id; + p_route_attr route = malloc(sizeof(route_attr)); + route->src_id = luaL_checkstring(L, 1); + route->dest_id = luaL_checkstring(L, 2); + route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref); + lua_pushnil(L); + while (lua_next(L, 3) != 0) { + link_id = lua_tostring(L, -1); + xbt_dynar_push(route->links_id, &link_id); + DEBUG2("index = %f , Link_id = %s \n", lua_tonumber(L, -2), + lua_tostring(L, -1)); + lua_pop(L, 1); + } + lua_pop(L, 1); + + //add route to platform's route list + xbt_dynar_push(route_list_d, &route); + return 0; } /** * set function to process */ -static int Host_set_function(lua_State *L) //(host,function,nb_args,list_args) +static int Host_set_function(lua_State * L) //(host,function,nb_args,list_args) { - // look for the index of host in host_list - const char *host_id = luaL_checkstring(L,1); - const char* argument; - unsigned int i; - p_host_attr p_host; - - xbt_dynar_foreach(host_list_d,i,p_host) - { - if(p_host->id == host_id) - { - p_host->function = luaL_checkstring(L,2); - if(lua_istable(L,3)) - { - p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); - // fill the args list - lua_pushnil(L); - int j = 0; - while (lua_next(L,3) != 0) { - argument = lua_tostring(L, -1); - xbt_dynar_push(p_host->args_list, &argument); - DEBUG2("index = %f , Arg_id = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1)); - j++; - lua_pop(L, 1); - } - } - lua_pop(L, 1); - return 0; - } - } - ERROR1("Host : %s Not Found !!",host_id); - return 1; + // look for the index of host in host_list + const char *host_id = luaL_checkstring(L, 1); + const char *argument; + unsigned int i; + p_host_attr p_host; + + xbt_dynar_foreach(host_list_d, i, p_host) { + if (p_host->id == host_id) { + p_host->function = luaL_checkstring(L, 2); + if (lua_istable(L, 3)) { + p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); + // fill the args list + lua_pushnil(L); + int j = 0; + while (lua_next(L, 3) != 0) { + argument = lua_tostring(L, -1); + xbt_dynar_push(p_host->args_list, &argument); + DEBUG2("index = %f , Arg_id = %s \n", lua_tonumber(L, -2), + lua_tostring(L, -1)); + j++; + lua_pop(L, 1); + } + } + lua_pop(L, 1); + return 0; + } + } + ERROR1("Host : %s Not Found !!", host_id); + return 1; } /* @@ -770,46 +793,47 @@ static int Host_set_function(lua_State *L) //(host,function,nb_args,list_args) static int surf_parse_bypass_platform() { - unsigned int i; - p_host_attr p_host; - p_link_attr p_link; - p_route_attr p_route; - - // Init routing mode - create_AS(AS->id,AS->mode); - - - // Add Hosts - xbt_dynar_foreach(host_list_d,i,p_host) - { - create_host(p_host->id,p_host->power_peak,p_host->power_scale,p_host->power_trace, - p_host->state_initial,p_host->state_trace); - //add to routing model host list - surf_route_add_host((char*)p_host->id); - - } - - //add Links - xbt_dynar_foreach(link_list_d,i,p_link) - { - create_link(p_link->id,p_link->bandwidth,p_link->bandwidth_trace,p_link->latency, - p_link->latency_trace,p_link->state_initial,p_link->state_trace,p_link->policy); - } - // add route - xbt_dynar_foreach(route_list_d,i,p_route) - { - surf_routing_add_route((char*)p_route->src_id,(char*)p_route->dest_id,p_route->links_id); - } - /* */ - - // Finalize AS - surf_AS_finalize(AS->id); - - // add traces - surf_add_host_traces(); - surf_add_link_traces(); - - return 0; // must return 0 ?!! + unsigned int i; + p_host_attr p_host; + p_link_attr p_link; + p_route_attr p_route; + + // Init routing mode + create_AS(AS->id, AS->mode); + + + // Add Hosts + xbt_dynar_foreach(host_list_d, i, p_host) { + create_host(p_host->id, p_host->power_peak, p_host->power_scale, + p_host->power_trace, p_host->state_initial, + p_host->state_trace); + //add to routing model host list + surf_route_add_host((char *) p_host->id); + + } + + //add Links + xbt_dynar_foreach(link_list_d, i, p_link) { + create_link(p_link->id, p_link->bandwidth, p_link->bandwidth_trace, + p_link->latency, p_link->latency_trace, + p_link->state_initial, p_link->state_trace, + p_link->policy); + } + // add route + xbt_dynar_foreach(route_list_d, i, p_route) { + surf_routing_add_route((char *) p_route->src_id, + (char *) p_route->dest_id, p_route->links_id); + } + /* */ + + // Finalize AS + surf_AS_finalize(AS->id); + + // add traces + surf_add_host_traces(); + surf_add_link_traces(); + + return 0; // must return 0 ?!! } @@ -822,42 +846,43 @@ static int surf_parse_bypass_platform() static int surf_wsL07_parse_bypass_platform() { - unsigned int i; - p_host_attr p_host; - p_link_attr p_link; - p_route_attr p_route; - - // Init routing mode - create_AS(AS->id,AS->mode); - - // Add Hosts - xbt_dynar_foreach(host_list_d,i,p_host) - { - create_host_wsL07(p_host->id,p_host->power_peak,p_host->power_scale,p_host->power_trace, - p_host->state_initial,p_host->state_trace); - //add to routing model host list - surf_route_add_host((char*)p_host->id); - } - - //add Links - xbt_dynar_foreach(link_list_d,i,p_link) - { - create_link_wsL07(p_link->id,p_link->bandwidth,p_link->bandwidth_trace,p_link->latency, - p_link->latency_trace,p_link->state_initial,p_link->state_trace,p_link->policy); - } - // add route - xbt_dynar_foreach(route_list_d,i,p_route) - { - surf_routing_add_route((char*)p_route->src_id,(char*)p_route->dest_id,p_route->links_id); - } - /* */ - - // Finalize AS - surf_AS_finalize(AS->id); - // add traces - surf_wsL07_add_traces(); - - return 0; + unsigned int i; + p_host_attr p_host; + p_link_attr p_link; + p_route_attr p_route; + + // Init routing mode + create_AS(AS->id, AS->mode); + + // Add Hosts + xbt_dynar_foreach(host_list_d, i, p_host) { + create_host_wsL07(p_host->id, p_host->power_peak, p_host->power_scale, + p_host->power_trace, p_host->state_initial, + p_host->state_trace); + //add to routing model host list + surf_route_add_host((char *) p_host->id); + } + + //add Links + xbt_dynar_foreach(link_list_d, i, p_link) { + create_link_wsL07(p_link->id, p_link->bandwidth, + p_link->bandwidth_trace, p_link->latency, + p_link->latency_trace, p_link->state_initial, + p_link->state_trace, p_link->policy); + } + // add route + xbt_dynar_foreach(route_list_d, i, p_route) { + surf_routing_add_route((char *) p_route->src_id, + (char *) p_route->dest_id, p_route->links_id); + } + /* */ + + // Finalize AS + surf_AS_finalize(AS->id); + // add traces + surf_wsL07_add_traces(); + + return 0; } /* @@ -865,14 +890,13 @@ static int surf_wsL07_parse_bypass_platform() */ static int surf_parse_bypass_application() { - unsigned int i; - p_host_attr p_host; - xbt_dynar_foreach(host_list_d,i,p_host) - { - if(p_host->function) - MSG_set_function(p_host->id,p_host->function,p_host->args_list); - } - return 0; + unsigned int i; + p_host_attr p_host; + xbt_dynar_foreach(host_list_d, i, p_host) { + if (p_host->function) + MSG_set_function(p_host->id, p_host->function, p_host->args_list); + } + return 0; } @@ -895,50 +919,52 @@ void s_process_free(void *process) free(p->host); } -static int gras_add_process_function(lua_State *L) +static int gras_add_process_function(lua_State * L) { - const char * arg; - const char* process_host = luaL_checkstring(L,1); - const char *process_function = luaL_checkstring(L,2); - - 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_list = xbt_dynar_new(sizeof(s_process_t), s_process_free); - machine_set = xbt_dict_new(); - } - - xbt_dict_set(machine_set,process_host, NULL, NULL); - xbt_dict_set(process_function_set,process_function, NULL, NULL); - - process.argc = 1; - process.argv = xbt_new(char *, 1); - process.argv[0] = xbt_strdup(process_function); - process.host = strdup(process_host); - - lua_pushnil(L); - while (lua_next(L,3) != 0) { - arg = lua_tostring(L, -1); - process.argc++; - process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *)); - process.argv[(process.argc) - 1] = xbt_strdup(arg); - - DEBUG2("index = %f , arg = %s \n",lua_tonumber(L, -2),lua_tostring(L, -1)); - lua_pop(L, 1); - } - lua_pop(L, 1); - //add to the process list - xbt_dynar_push(process_list, &process); - - return 0; + const char *arg; + const char *process_host = luaL_checkstring(L, 1); + const char *process_function = luaL_checkstring(L, 2); + + 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_list = xbt_dynar_new(sizeof(s_process_t), s_process_free); + machine_set = xbt_dict_new(); + } + + xbt_dict_set(machine_set, process_host, NULL, NULL); + xbt_dict_set(process_function_set, process_function, NULL, NULL); + + process.argc = 1; + process.argv = xbt_new(char *, 1); + process.argv[0] = xbt_strdup(process_function); + process.host = strdup(process_host); + + lua_pushnil(L); + while (lua_next(L, 3) != 0) { + arg = lua_tostring(L, -1); + process.argc++; + process.argv = + xbt_realloc(process.argv, (process.argc) * sizeof(char *)); + process.argv[(process.argc) - 1] = xbt_strdup(arg); + + DEBUG2("index = %f , arg = %s \n", lua_tonumber(L, -2), + lua_tostring(L, -1)); + lua_pop(L, 1); + } + lua_pop(L, 1); + //add to the process list + xbt_dynar_push(process_list, &process); + + return 0; } -static int gras_generate(lua_State *L) +static int gras_generate(lua_State * L) { - const char *project_name = luaL_checkstring(L,1); + const char *project_name = luaL_checkstring(L, 1); generate_sim(project_name); generate_rl(project_name); generate_makefile_local(project_name); @@ -951,41 +977,42 @@ static int gras_generate(lua_State *L) * Host Methods */ static const luaL_reg Host_methods[] = { - {"getByName", Host_get_by_name}, - {"name", Host_get_name}, - {"number", Host_number}, - {"at", Host_at}, - // Bypass XML Methods - {"new", Host_new}, - {"setFunction", Host_set_function}, - {0,0} + {"getByName", Host_get_by_name}, + {"name", Host_get_name}, + {"number", Host_number}, + {"at", Host_at}, + // Bypass XML Methods + {"new", Host_new}, + {"setFunction", Host_set_function}, + {0, 0} }; -static int Host_gc(lua_State *L) +static int Host_gc(lua_State * L) { - m_host_t ht = checkHost(L,-1); - if (ht) ht = NULL; + m_host_t ht = checkHost(L, -1); + if (ht) + ht = NULL; return 0; } -static int Host_tostring(lua_State *L) +static int Host_tostring(lua_State * L) { - lua_pushfstring(L,"Host :%p",lua_touserdata(L,1)); + lua_pushfstring(L, "Host :%p", lua_touserdata(L, 1)); return 1; } static const luaL_reg Host_meta[] = { - {"__gc", Host_gc}, - {"__tostring", Host_tostring}, - {0,0} + {"__gc", Host_gc}, + {"__tostring", Host_tostring}, + {0, 0} }; /* * AS Methods */ static const luaL_reg AS_methods[] = { - {"new",AS_new}, - {0,0} + {"new", AS_new}, + {0, 0} }; @@ -993,15 +1020,16 @@ static const luaL_reg AS_methods[] = { * Link Methods */ static const luaL_reg Link_methods[] = { - {"new",Link_new}, - {0,0} + {"new", Link_new}, + {0, 0} }; + /* * Route Methods */ -static const luaL_reg Route_methods[] ={ - {"new",Route_new}, - {0,0} +static const luaL_reg Route_methods[] = { + {"new", Route_new}, + {0, 0} }; /* @@ -1010,71 +1038,84 @@ static const luaL_reg Route_methods[] ={ extern lua_State *simgrid_lua_state; -static int run_lua_code(int argc,char **argv) { - DEBUG1("Run lua code %s",argv[0]); +static int run_lua_code(int argc, char **argv) +{ + DEBUG1("Run lua code %s", argv[0]); lua_State *L = lua_newthread(simgrid_lua_state); - int ref = luaL_ref(simgrid_lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected + int ref = luaL_ref(simgrid_lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected int res = 1; /* Start the co-routine */ - lua_getglobal(L,argv[0]); - xbt_assert1(lua_isfunction(L,-1), - "The lua function %s does not seem to exist",argv[0]); + lua_getglobal(L, argv[0]); + xbt_assert1(lua_isfunction(L, -1), + "The lua function %s does not seem to exist", argv[0]); // push arguments onto the stack int i; - for(i=1;iptr; // name of process is the one of the class - return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"),3,fct_name,arguments,properties); + char *p_className = RSTRING(fct_name)->ptr; // name of process is the one of the class + return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)), + rb_intern("new"), 3, fct_name, arguments, properties); } // FIXME: don't mess with MSG internals here, use MSG_process_create_with_arguments() static void rb_process_create_with_args(VALUE fct_name, VALUE arguments, - VALUE properties, VALUE ht_name) { - - VALUE ruby_process = rb_process_instance(fct_name,arguments,properties); - m_process_t process; // Native Process to Create - const char * name ; // Name of C Native Processs + VALUE properties, VALUE ht_name) +{ + + VALUE ruby_process = + rb_process_instance(fct_name, arguments, properties); + m_process_t process; // Native Process to Create + const char *name; // Name of C Native Processs - if(!fct_name) - rb_raise(rb_eRuntimeError,"Internal error: Process name cannot be NULL"); + if (!fct_name) + rb_raise(rb_eRuntimeError, + "Internal error: Process name cannot be NULL"); name = RSTRING(fct_name)->ptr; - DEBUG1("Create native process %s",name); + DEBUG1("Create native process %s", name); // Allocate the data for the simulation - process = xbt_new0(s_m_process_t,1); - process->simdata = xbt_new0(s_simdata_process_t,1); + process = xbt_new0(s_m_process_t, 1); + process->simdata = xbt_new0(s_simdata_process_t, 1); // Bind The Ruby Process instance to The Native Process - rb_process_bind(ruby_process,process); + rb_process_bind(ruby_process, process); process->name = xbt_strdup(name); // Host m_host_t host = MSG_get_host_by_name(RSTRING(ht_name)->ptr); process->simdata->m_host = host; - - if(!(process->simdata->m_host)) { // Not Binded + + if (!(process->simdata->m_host)) { // Not Binded free(process->simdata); free(process->data); free(process); - rb_raise(rb_eRuntimeError,"Host not bound while creating native process"); + rb_raise(rb_eRuntimeError, + "Host not bound while creating native process"); } - process->simdata->PID = msg_global->PID++; + process->simdata->PID = msg_global->PID++; - DEBUG7("fill in process %s/%s (pid=%d) %p (sd=%p , host=%p, host->sd=%p)", - process->name , process->simdata->m_host->name,process->simdata->PID, - process,process->simdata, process->simdata->m_host, - process->simdata->m_host->simdata); + DEBUG7 + ("fill in process %s/%s (pid=%d) %p (sd=%p , host=%p, host->sd=%p)", + process->name, process->simdata->m_host->name, + process->simdata->PID, process, process->simdata, + process->simdata->m_host, process->simdata->m_host->simdata); /* FIXME: that's mainly for debugging. We could only allocate this if XBT_LOG_ISENABLED(ruby,debug) is true since I guess this leaks */ - char **argv=xbt_new(char*,2); - argv[0] = bprintf("%s@%s",process->name,process->simdata->m_host->simdata->smx_host->name); + char **argv = xbt_new(char *, 2); + argv[0] = + bprintf("%s@%s", process->name, + process->simdata->m_host->simdata->smx_host->name); argv[1] = NULL; process->simdata->s_process = SIMIX_process_create(process->name, - (xbt_main_func_t)ruby_process, - (void *) process, - process->simdata->m_host->simdata->smx_host->name, - 1,argv,NULL); + (xbt_main_func_t) ruby_process, + (void *) process, + process->simdata->m_host->simdata-> + smx_host->name, 1, argv, NULL); - DEBUG1("context created (s_process=%p)",process->simdata->s_process); + DEBUG1("context created (s_process=%p)", process->simdata->s_process); - if (SIMIX_process_self()) { // SomeOne Created Me !! - process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); + if (SIMIX_process_self()) { // SomeOne Created Me !! + process->simdata->PPID = + MSG_process_get_PID(SIMIX_process_self()->data); } else { process->simdata->PPID = -1; } process->simdata->last_errno = MSG_OK; // let's Add the Process to the list of the Simulation's Processes - xbt_fifo_unshift(msg_global->process_list,process); + xbt_fifo_unshift(msg_global->process_list, process); } -void rb_application_handler_on_start_document(void) { - +void rb_application_handler_on_start_document(void) +{ + - args = rb_ary_new(); // Max length = 16 !! - prop = rb_ary_new(); + args = rb_ary_new(); // Max length = 16 !! + prop = rb_ary_new(); } -void rb_application_handler_on_end_document(void) { +void rb_application_handler_on_end_document(void) +{ args = Qnil; prop = Qnil; function_name = Qnil; - host_name = Qnil; + host_name = Qnil; } -void rb_application_handler_on_begin_process(void) { - +void rb_application_handler_on_begin_process(void) +{ + host_name = rb_str_new2(A_surfxml_process_host); function_name = rb_str_new2(A_surfxml_process_function); - args = rb_ary_new(); // Max length = 16 ?! + args = rb_ary_new(); // Max length = 16 ?! prop = rb_ary_new(); } -void rb_application_handler_on_process_arg(void) { - +void rb_application_handler_on_process_arg(void) +{ + VALUE arg = rb_str_new2(A_surfxml_argument_value); - rb_ary_push(args,arg); + rb_ary_push(args, arg); } -void rb_application_handler_on_property(void) { +void rb_application_handler_on_property(void) +{ VALUE id = rb_str_new2(A_surfxml_prop_id); - VALUE val = rb_str_new2(A_surfxml_prop_value); - int i_id = NUM2INT (id); - rb_ary_store(prop,i_id,val); + VALUE val = rb_str_new2(A_surfxml_prop_value); + int i_id = NUM2INT(id); + rb_ary_store(prop, i_id, val); } -void rb_application_handler_on_end_process(void) { +void rb_application_handler_on_end_process(void) +{ + + rb_process_create_with_args(function_name, args, prop, host_name); - rb_process_create_with_args(function_name,args,prop,host_name); - } diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index 53b5d8d7e2..895ae1de19 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -9,23 +9,27 @@ #include "bindings/ruby_bindings.h" // Free Method -void rb_host_free(m_host_t ht) { +void rb_host_free(m_host_t ht) +{ //Nothing to do !!? } // New Method : return a Host -VALUE rb_host_get_by_name(VALUE class, VALUE name) { +VALUE rb_host_get_by_name(VALUE class, VALUE name) +{ - const char * h_name = RSTRING(name)->ptr; + const char *h_name = RSTRING(name)->ptr; m_host_t host = MSG_get_host_by_name(h_name); - if(!host) - rb_raise(rb_eRuntimeError,bprintf("No host called '%s' found",h_name)); + if (!host) + rb_raise(rb_eRuntimeError, + bprintf("No host called '%s' found", h_name)); - return Data_Wrap_Struct(class,0,rb_host_free,host); + return Data_Wrap_Struct(class, 0, rb_host_free, host); } //Get Name -VALUE rb_host_name(VALUE class,VALUE host) { +VALUE rb_host_name(VALUE class, VALUE host) +{ // Wrap Ruby Value to m_host_t struct m_host_t ht; @@ -35,64 +39,67 @@ VALUE rb_host_name(VALUE class,VALUE host) { } // Get Number -VALUE rb_host_number(VALUE class) { +VALUE rb_host_number(VALUE class) +{ return INT2NUM(MSG_get_host_number()); } // Host Speed ( Double ) -VALUE rb_host_speed(VALUE class,VALUE host) { - m_host_t ht ; - Data_Get_Struct(host,s_m_host_t,ht); +VALUE rb_host_speed(VALUE class, VALUE host) +{ + m_host_t ht; + Data_Get_Struct(host, s_m_host_t, ht); return MSG_get_host_speed(ht); } // Host is Avail -VALUE rb_host_is_avail(VALUE class,VALUE host) { +VALUE rb_host_is_avail(VALUE class, VALUE host) +{ m_host_t ht; - Data_Get_Struct(host,s_m_host_t,ht); + Data_Get_Struct(host, s_m_host_t, ht); if (!ht) { - rb_raise(rb_eRuntimeError,"Host not Bound"); + rb_raise(rb_eRuntimeError, "Host not Bound"); return Qnil; } - if(MSG_host_is_avail(ht)) + if (MSG_host_is_avail(ht)) return Qtrue; return Qfalse; } // getHost from process -VALUE rb_host_process(VALUE class,VALUE ruby_process) +VALUE rb_host_process(VALUE class, VALUE ruby_process) { - - m_process_t process = rb_process_to_native(ruby_process); + + m_process_t process = rb_process_to_native(ruby_process); m_host_t host; - + if (!process) { - rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); - return Qnil; // NULL + rb_raise(rb_eRuntimeError, "Process Not Bound...while getting Host"); + return Qnil; // NULL } - + host = MSG_process_get_host(process); - - return Data_Wrap_Struct(class, 0, rb_host_free, host); + + return Data_Wrap_Struct(class, 0, rb_host_free, host); } // get all hosts VALUE rb_host_get_all_hosts(VALUE class) { - int nb,index; - m_host_t *hosts; - VALUE rb_hosts; - nb = MSG_get_host_number(); - hosts = MSG_get_host_table(); - rb_hosts = rb_ary_new2(nb); - - for(index=0 ; index>> id_Bind Null"); + rb_raise(rb_eRuntimeError, "Process Not Bound >>> id_Bind Null"); return NULL; } - long l_id= FIX2LONG(id); - return (m_process_t)l_id; + long l_id = FIX2LONG(id); + return (m_process_t) l_id; } // Bind Process -void rb_process_bind(VALUE ruby_process,m_process_t process) { - long bind = (long)(process); - rb_process_setBind(ruby_process,bind); +void rb_process_bind(VALUE ruby_process, m_process_t process) +{ + long bind = (long) (process); + rb_process_setBind(ruby_process, bind); } // Process Management -void rb_process_suspend(VALUE class,VALUE ruby_process) { +void rb_process_suspend(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); if (!process) { - rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process"); - return; + rb_raise(rb_eRuntimeError, + "Process Not Bound...while suspending process"); + return; } - // Trying to suspend The Process - if ( MSG_OK != MSG_process_suspend(process)) - rb_raise(rb_eRuntimeError,"MSG_process_suspend() failed"); + if (MSG_OK != MSG_process_suspend(process)) + rb_raise(rb_eRuntimeError, "MSG_process_suspend() failed"); } -void rb_process_resume(VALUE class,VALUE ruby_process) { +void rb_process_resume(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); if (!process) { - rb_raise(rb_eRuntimeError,"Process not Bound...while resuming process"); - return ; + rb_raise(rb_eRuntimeError, + "Process not Bound...while resuming process"); + return; } - // Trying to resume the process - if ( MSG_OK != MSG_process_resume(process)) - rb_raise(rb_eRuntimeError,"MSG_process_resume() failed"); + if (MSG_OK != MSG_process_resume(process)) + rb_raise(rb_eRuntimeError, "MSG_process_resume() failed"); } -VALUE rb_process_isSuspended(VALUE class,VALUE ruby_process) { +VALUE rb_process_isSuspended(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); if (!process) { - rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended"); + rb_raise(rb_eRuntimeError, + "Process not Bound...while testing if suspended"); return Qfalse; } - if(MSG_process_is_suspended(process)) + if (MSG_process_is_suspended(process)) return Qtrue; return Qfalse; } -void rb_process_kill_down(VALUE class,VALUE ruby_process) { +void rb_process_kill_down(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); - if(!process) { - rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process"); + if (!process) { + rb_raise(rb_eRuntimeError, + "Process Not Bound...while killing process"); return; } // Delete The Global Reference / Ruby Process @@ -136,33 +153,36 @@ void rb_process_kill_down(VALUE class,VALUE ruby_process) { MSG_process_kill(process); } -VALUE rb_process_getHost(VALUE class,VALUE ruby_process) { +VALUE rb_process_getHost(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); m_host_t host; - + if (!process) { - rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); - return Qnil; // NULL + rb_raise(rb_eRuntimeError, "Process Not Bound...while getting Host"); + return Qnil; // NULL } - + host = MSG_process_get_host(process); - + return Data_Wrap_Struct(class, 0, rb_host_free, host); /*if(host->data) printf("Ok\n"); - - if(!host->data) { - rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed"); - return Qnil; - } - printf("Houuuuuuuuuuuuuuna3!!\n"); - return Data_Wrap_Struct(class, 0, rb_host_free, host);*/ + + if(!host->data) { + rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed"); + return Qnil; + } + printf("Houuuuuuuuuuuuuuna3!!\n"); + return Data_Wrap_Struct(class, 0, rb_host_free, host); */ } -void rb_process_exit(VALUE class,VALUE ruby_process) { +void rb_process_exit(VALUE class, VALUE ruby_process) +{ m_process_t process = rb_process_to_native(ruby_process); - if(!process) { - rb_raise(rb_eRuntimeError,"Process Not Bound...while exiting process"); + if (!process) { + rb_raise(rb_eRuntimeError, + "Process Not Bound...while exiting process"); return; } SIMIX_context_stop(SIMIX_process_self()->context); diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 3fe4d8ee73..692b185a60 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -12,23 +12,28 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby); // Free Method -void rb_task_free(m_task_t tk) { +void rb_task_free(m_task_t tk) +{ //MSG_task_destroy(tk); ( This cause a bug !! is it really necessary ?!! not really sure !! ) } // New Method -VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) { - m_task_t task = MSG_task_create(RSTRING(name)->ptr,NUM2INT(comp_size),NUM2INT(comm_size),NULL); +VALUE rb_task_new(VALUE class, VALUE name, VALUE comp_size, + VALUE comm_size) +{ + m_task_t task = MSG_task_create(RSTRING(name)->ptr, NUM2INT(comp_size), + NUM2INT(comm_size), NULL); rb_data_t data = malloc(sizeof(s_ruby_data_t)); data->ruby_task = NULL; data->user_data = NULL; - MSG_task_set_data(task,(void*)data); + MSG_task_set_data(task, (void *) data); // Wrap m_task_t to a Ruby Value return Data_Wrap_Struct(class, 0, rb_task_free, task); } //Get Computation Size -VALUE rb_task_comp(VALUE class,VALUE task) { +VALUE rb_task_comp(VALUE class, VALUE task) +{ double size; m_task_t tk; // Wrap Ruby Value to m_task_t struct @@ -38,16 +43,18 @@ VALUE rb_task_comp(VALUE class,VALUE task) { } //Get Name -VALUE rb_task_name(VALUE class,VALUE task) { +VALUE rb_task_name(VALUE class, VALUE task) +{ // Wrap Ruby Value to m_task_t struct - m_task_t tk; + m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); return rb_str_new2(MSG_task_get_name(tk)); } // Execute Task -VALUE rb_task_execute(VALUE class,VALUE task) { +VALUE rb_task_execute(VALUE class, VALUE task) +{ // Wrap Ruby Value to m_task_t struct m_task_t tk; @@ -56,7 +63,8 @@ VALUE rb_task_execute(VALUE class,VALUE task) { } // Sending Task -void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { +void rb_task_send(VALUE class, VALUE task, VALUE mailbox) +{ MSG_error_t rv; rb_data_t data; @@ -64,91 +72,98 @@ void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); data = MSG_task_get_data(tk); - data->ruby_task =(void*)task; - MSG_task_set_data(tk,(void*)data); - DEBUG1("Sending task %p",tk); - rv = MSG_task_send(tk,RSTRING(mailbox)->ptr); - if(rv != MSG_OK) - { - if (rv == MSG_TRANSFER_FAILURE ) - rb_raise(rb_eRuntimeError,"Transfer failure while Sending"); - else if ( rv == MSG_HOST_FAILURE ) - rb_raise(rb_eRuntimeError,"Host failure while Sending"); - else if ( rv == MSG_TIMEOUT ) - rb_raise(rb_eRuntimeError,"Timeout failure while Sending"); - else - rb_raise(rb_eRuntimeError,"MSG_task_send failed"); + data->ruby_task = (void *) task; + MSG_task_set_data(tk, (void *) data); + DEBUG1("Sending task %p", tk); + rv = MSG_task_send(tk, RSTRING(mailbox)->ptr); + if (rv != MSG_OK) { + if (rv == MSG_TRANSFER_FAILURE) + rb_raise(rb_eRuntimeError, "Transfer failure while Sending"); + else if (rv == MSG_HOST_FAILURE) + rb_raise(rb_eRuntimeError, "Host failure while Sending"); + else if (rv == MSG_TIMEOUT) + rb_raise(rb_eRuntimeError, "Timeout failure while Sending"); + else + rb_raise(rb_eRuntimeError, "MSG_task_send failed"); } } // Receiving Task (returns a Task) -VALUE rb_task_receive(VALUE class, VALUE mailbox) { +VALUE rb_task_receive(VALUE class, VALUE mailbox) +{ // We must put the location where we copy the task // pointer to on the heap, because the stack may move // during the context switches (damn ruby internals) m_task_t *ptask = malloc(sizeof(m_task_t)); m_task_t task; *ptask = NULL; - rb_data_t data =NULL; - DEBUG2("Receiving a task on mailbox '%s', store it into %p",RSTRING(mailbox)->ptr,&task); - MSG_task_receive(ptask,RSTRING(mailbox)->ptr); + rb_data_t data = NULL; + DEBUG2("Receiving a task on mailbox '%s', store it into %p", + RSTRING(mailbox)->ptr, &task); + MSG_task_receive(ptask, RSTRING(mailbox)->ptr); task = *ptask; free(ptask); data = MSG_task_get_data(task); - if(data==NULL) printf("Empty task while receving"); - return (VALUE)data->ruby_task; + if (data == NULL) + printf("Empty task while receving"); + return (VALUE) data->ruby_task; } // It Return a Native Process ( m_process_t ) -VALUE rb_task_sender(VALUE class,VALUE task) { +VALUE rb_task_sender(VALUE class, VALUE task) +{ m_task_t tk; - Data_Get_Struct(task,s_m_task_t,tk); + Data_Get_Struct(task, s_m_task_t, tk); THROW_UNIMPLEMENTED; - return 0;//MSG_task_get_sender(tk); + return 0; //MSG_task_get_sender(tk); } // it return a Host -VALUE rb_task_source(VALUE class,VALUE task) { +VALUE rb_task_source(VALUE class, VALUE task) +{ m_task_t tk; - Data_Get_Struct(task,s_m_task_t,tk); + Data_Get_Struct(task, s_m_task_t, tk); m_host_t host = MSG_task_get_source(tk); - if(!host->data) { - rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed"); + if (!host->data) { + rb_raise(rb_eRuntimeError, "MSG_task_get_source() failed"); return Qnil; } THROW_UNIMPLEMENTED; - return 0;//host; + return 0; //host; } // Return Boolean -VALUE rb_task_listen(VALUE class,VALUE task,VALUE alias) { +VALUE rb_task_listen(VALUE class, VALUE task, VALUE alias) +{ m_task_t tk; const char *p_alias; int rv; - Data_Get_Struct(task,s_m_task_t,tk); + Data_Get_Struct(task, s_m_task_t, tk); p_alias = RSTRING(alias)->ptr; rv = MSG_task_listen(p_alias); - if(rv) return Qtrue; + if (rv) + return Qtrue; return Qfalse; } // return Boolean -VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) { +VALUE rb_task_listen_host(VALUE class, VALUE task, VALUE alias, VALUE host) +{ m_task_t tk; m_host_t ht; const char *p_alias; int rv; - Data_Get_Struct(task,s_m_task_t,tk); - Data_Get_Struct(host,s_m_host_t,ht); + Data_Get_Struct(task, s_m_task_t, tk); + Data_Get_Struct(host, s_m_host_t, ht); p_alias = RSTRING(alias)->ptr; - rv = MSG_task_listen_from_host(p_alias,ht); + rv = MSG_task_listen_from_host(p_alias, ht); if (rv) return Qtrue; return Qfalse; @@ -156,54 +171,53 @@ VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) { // Set Priority -void rb_task_set_priority(VALUE class,VALUE task,VALUE priority) +void rb_task_set_priority(VALUE class, VALUE task, VALUE priority) { - + m_task_t tk; double prt = NUM2DBL(priority); - Data_Get_Struct(task,s_m_task_t,tk); - MSG_task_set_priority(tk,prt); - + Data_Get_Struct(task, s_m_task_t, tk); + MSG_task_set_priority(tk, prt); + } // Cancel -void rb_task_cancel(VALUE class,VALUE task) +void rb_task_cancel(VALUE class, VALUE task) { - m_task_t tk; - Data_Get_Struct(task,s_m_task_t,tk); - MSG_task_cancel(tk); + m_task_t tk; + Data_Get_Struct(task, s_m_task_t, tk); + MSG_task_cancel(tk); } -void rb_task_set_data(VALUE class,VALUE task,VALUE data) +void rb_task_set_data(VALUE class, VALUE task, VALUE data) { - m_task_t tk; - rb_data_t rb_data; - Data_Get_Struct(task,s_m_task_t,tk); - rb_data = MSG_task_get_data(tk); - rb_data->user_data = (void*)data; - MSG_task_set_data(tk,(void*)rb_data); + m_task_t tk; + rb_data_t rb_data; + Data_Get_Struct(task, s_m_task_t, tk); + rb_data = MSG_task_get_data(tk); + rb_data->user_data = (void *) data; + MSG_task_set_data(tk, (void *) rb_data); } -VALUE rb_task_get_data(VALUE class,VALUE task) +VALUE rb_task_get_data(VALUE class, VALUE task) { - m_task_t tk; - Data_Get_Struct(task,s_m_task_t,tk); - rb_data_t rb_data = MSG_task_get_data(tk); - if(!rb_data->user_data) - ERROR1("the task %s contain no user data",MSG_task_get_name(tk)); + m_task_t tk; + Data_Get_Struct(task, s_m_task_t, tk); + rb_data_t rb_data = MSG_task_get_data(tk); + if (!rb_data->user_data) + ERROR1("the task %s contain no user data", MSG_task_get_name(tk)); - return (VALUE)rb_data->user_data; + return (VALUE) rb_data->user_data; } -VALUE rb_task_has_data(VALUE class,VALUE task) +VALUE rb_task_has_data(VALUE class, VALUE task) { - m_task_t tk; - Data_Get_Struct(task,s_m_task_t,tk); - rb_data_t rb_data = MSG_task_get_data(tk); - if(!rb_data->user_data) - return Qfalse; - return Qtrue; + m_task_t tk; + Data_Get_Struct(task, s_m_task_t, tk); + rb_data_t rb_data = MSG_task_get_data(tk); + if (!rb_data->user_data) + return Qfalse; + return Qtrue; } - diff --git a/src/bindings/ruby/simgrid_ruby.c b/src/bindings/ruby/simgrid_ruby.c index 23c9d5c8b6..fd1ebf7f59 100644 --- a/src/bindings/ruby/simgrid_ruby.c +++ b/src/bindings/ruby/simgrid_ruby.c @@ -18,179 +18,216 @@ VALUE rb_task; VALUE rb_host; //Init Msg From Ruby -static void msg_init(VALUE Class,VALUE args) +static void msg_init(VALUE Class, VALUE args) { - char **argv=NULL; + char **argv = NULL; const char *tmp; - int argc,type,i; - VALUE *ptr ; + int argc, type, i; + VALUE *ptr; // Testing The Args Type - type = TYPE(args); - if (type != T_ARRAY ) { - rb_raise(rb_eRuntimeError,"Bad arguments to msg_init (expecting an array)"); + type = TYPE(args); + if (type != T_ARRAY) { + rb_raise(rb_eRuntimeError, + "Bad arguments to msg_init (expecting an array)"); return; } - ptr= RARRAY(args)->ptr; - argc= RARRAY(args)->len; + ptr = RARRAY(args)->ptr; + argc = RARRAY(args)->len; // Create C Array to Hold Data_Get_Struct argc++; argv = xbt_new0(char *, argc); argv[0] = strdup("ruby"); - for (i=0;iptr; - argv[i+1] = strdup(tmp); + argv[i + 1] = strdup(tmp); } // Calling C Msg_Init Method - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); // Cleanups - for (i=0;idata); + for (cpt = 0; cpt < host_count; cpt++) { + rbHost = (VALUE) ((hosts[cpt])->data); } return; } static void msg_clean(VALUE class) { - if (MSG_OK != MSG_clean()) - rb_raise(rb_eRuntimeError,"MSG_clean() failed"); - + if (MSG_OK != MSG_clean()) + rb_raise(rb_eRuntimeError, "MSG_clean() failed"); + } -static void msg_createEnvironment(VALUE class,VALUE plateformFile) { + +static void msg_createEnvironment(VALUE class, VALUE plateformFile) +{ int type = TYPE(plateformFile); - if ( type != T_STRING ) - rb_raise(rb_eRuntimeError,"Bad Argument's Type"); - const char * platform = RSTRING(plateformFile)->ptr; + if (type != T_STRING) + rb_raise(rb_eRuntimeError, "Bad Argument's Type"); + const char *platform = RSTRING(plateformFile)->ptr; MSG_create_environment(platform); - DEBUG1("Create Environment (%s)...Done",platform); + DEBUG1("Create Environment (%s)...Done", platform); } //deploy Application -static void msg_deployApplication(VALUE class,VALUE deploymentFile ) { +static void msg_deployApplication(VALUE class, VALUE deploymentFile) +{ int type = TYPE(deploymentFile); - if ( type != T_STRING ) - rb_raise(rb_eRuntimeError,"Bad Argument's Type for deployApplication "); + if (type != T_STRING) + rb_raise(rb_eRuntimeError, + "Bad Argument's Type for deployApplication "); const char *dep_file = RSTRING(deploymentFile)->ptr; surf_parse_reset_parser(); surfxml_add_callback(STag_surfxml_process_cb_list, - rb_application_handler_on_begin_process); + rb_application_handler_on_begin_process); surfxml_add_callback(ETag_surfxml_argument_cb_list, - rb_application_handler_on_process_arg); + rb_application_handler_on_process_arg); surfxml_add_callback(STag_surfxml_prop_cb_list, - rb_application_handler_on_property); + rb_application_handler_on_property); surfxml_add_callback(ETag_surfxml_process_cb_list, - rb_application_handler_on_end_process); + rb_application_handler_on_end_process); surf_parse_open(dep_file); rb_application_handler_on_start_document(); - if(surf_parse()) - rb_raise(rb_eRuntimeError,"surf_parse() failed"); + if (surf_parse()) + rb_raise(rb_eRuntimeError, "surf_parse() failed"); surf_parse_close(); - + rb_application_handler_on_end_document(); - DEBUG1("Deploy Application(%s)...Done",dep_file); + DEBUG1("Deploy Application(%s)...Done", dep_file); } // INFO -static void msg_info(VALUE class,VALUE msg) { +static void msg_info(VALUE class, VALUE msg) +{ const char *s = RSTRING(msg)->ptr; - INFO1("%s",s); + INFO1("%s", s); } -static void msg_debug(VALUE class,VALUE msg) { + +static void msg_debug(VALUE class, VALUE msg) +{ const char *s = RSTRING(msg)->ptr; - DEBUG1("%s",s); + DEBUG1("%s", s); } // get Clock -static VALUE msg_get_clock(VALUE class) { +static VALUE msg_get_clock(VALUE class) +{ return rb_float_new(MSG_get_clock()); } -extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */ +extern const char *xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */ -typedef VALUE(*rb_meth)(ANYARGS); -void Init_libsimgrid() { +typedef VALUE(*rb_meth) (ANYARGS); +void Init_libsimgrid() +{ xbt_ctx_factory_to_use = "ruby"; // Modules rb_msg = rb_define_module("MSG"); //Associated Environment Methods - rb_define_module_function(rb_msg,"init",(rb_meth)msg_init,1); - rb_define_module_function(rb_msg,"run",(rb_meth)msg_run,0); - rb_define_module_function(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1); - rb_define_module_function(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1); - rb_define_module_function(rb_msg,"info",(rb_meth)msg_info,1); - rb_define_module_function(rb_msg,"debug",(rb_meth)msg_debug,1); - rb_define_module_function(rb_msg,"getClock",(rb_meth)msg_get_clock,0); - rb_define_module_function(rb_msg,"exit",(rb_meth)msg_clean,0); + rb_define_module_function(rb_msg, "init", (rb_meth) msg_init, 1); + rb_define_module_function(rb_msg, "run", (rb_meth) msg_run, 0); + rb_define_module_function(rb_msg, "createEnvironment", + (rb_meth) msg_createEnvironment, 1); + rb_define_module_function(rb_msg, "deployApplication", + (rb_meth) msg_deployApplication, 1); + rb_define_module_function(rb_msg, "info", (rb_meth) msg_info, 1); + rb_define_module_function(rb_msg, "debug", (rb_meth) msg_debug, 1); + rb_define_module_function(rb_msg, "getClock", (rb_meth) msg_get_clock, + 0); + rb_define_module_function(rb_msg, "exit", (rb_meth) msg_clean, 0); //Associated Process Methods - rb_define_method(rb_msg,"processSuspend",(rb_meth)rb_process_suspend,1); - rb_define_method(rb_msg,"processResume",(rb_meth)rb_process_resume,1); - rb_define_method(rb_msg,"processIsSuspend",(rb_meth)rb_process_isSuspended,1); - rb_define_method(rb_msg,"processKill",(rb_meth)rb_process_kill_up,1); - rb_define_method(rb_msg,"processKillDown",(rb_meth)rb_process_kill_down,1); - rb_define_method(rb_msg,"processGetHost",(rb_meth)rb_process_getHost,1); - rb_define_method(rb_msg,"processExit",(rb_meth)rb_process_exit,1); + rb_define_method(rb_msg, "processSuspend", (rb_meth) rb_process_suspend, + 1); + rb_define_method(rb_msg, "processResume", (rb_meth) rb_process_resume, + 1); + rb_define_method(rb_msg, "processIsSuspend", + (rb_meth) rb_process_isSuspended, 1); + rb_define_method(rb_msg, "processKill", (rb_meth) rb_process_kill_up, 1); + rb_define_method(rb_msg, "processKillDown", + (rb_meth) rb_process_kill_down, 1); + rb_define_method(rb_msg, "processGetHost", (rb_meth) rb_process_getHost, + 1); + rb_define_method(rb_msg, "processExit", (rb_meth) rb_process_exit, 1); //Classes - rb_task = rb_define_class_under(rb_msg,"RbTask",rb_cObject); - rb_host = rb_define_class_under(rb_msg,"RbHost",rb_cObject); + rb_task = rb_define_class_under(rb_msg, "RbTask", rb_cObject); + rb_host = rb_define_class_under(rb_msg, "RbHost", rb_cObject); //Task Methods - rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3); - rb_define_module_function(rb_task,"compSize",(rb_meth)rb_task_comp,1); - rb_define_module_function(rb_task,"name",(rb_meth)rb_task_name,1); - rb_define_module_function(rb_task,"execute",(rb_meth)rb_task_execute,1); - rb_define_module_function(rb_task,"send",(rb_meth)rb_task_send,2); - rb_define_module_function(rb_task,"receive",(rb_meth)rb_task_receive,1); - rb_define_module_function(rb_task,"sender",(rb_meth)rb_task_sender,1); - rb_define_module_function(rb_task,"source",(rb_meth)rb_task_source,1); - rb_define_module_function(rb_task,"listen",(rb_meth)rb_task_listen,2); - rb_define_module_function(rb_task,"listenFromHost",(rb_meth)rb_task_listen_host,3); - rb_define_module_function(rb_task,"setPriority",(rb_meth)rb_task_set_priority,2); - rb_define_module_function(rb_task,"cancel",(rb_meth)rb_task_cancel,1); - rb_define_module_function(rb_task,"hasData",(rb_meth)rb_task_has_data,1); - rb_define_module_function(rb_task,"setData",(rb_meth)rb_task_set_data,2); - rb_define_module_function(rb_task,"data",(rb_meth)rb_task_get_data,1); + rb_define_module_function(rb_task, "new", (rb_meth) rb_task_new, 3); + rb_define_module_function(rb_task, "compSize", (rb_meth) rb_task_comp, + 1); + rb_define_module_function(rb_task, "name", (rb_meth) rb_task_name, 1); + rb_define_module_function(rb_task, "execute", (rb_meth) rb_task_execute, + 1); + rb_define_module_function(rb_task, "send", (rb_meth) rb_task_send, 2); + rb_define_module_function(rb_task, "receive", (rb_meth) rb_task_receive, + 1); + rb_define_module_function(rb_task, "sender", (rb_meth) rb_task_sender, + 1); + rb_define_module_function(rb_task, "source", (rb_meth) rb_task_source, + 1); + rb_define_module_function(rb_task, "listen", (rb_meth) rb_task_listen, + 2); + rb_define_module_function(rb_task, "listenFromHost", + (rb_meth) rb_task_listen_host, 3); + rb_define_module_function(rb_task, "setPriority", + (rb_meth) rb_task_set_priority, 2); + rb_define_module_function(rb_task, "cancel", (rb_meth) rb_task_cancel, + 1); + rb_define_module_function(rb_task, "hasData", (rb_meth) rb_task_has_data, + 1); + rb_define_module_function(rb_task, "setData", (rb_meth) rb_task_set_data, + 2); + rb_define_module_function(rb_task, "data", (rb_meth) rb_task_get_data, + 1); //Host Methods - rb_define_module_function(rb_host,"getByName",(rb_meth)rb_host_get_by_name,1); - rb_define_module_function(rb_host,"name",(rb_meth)rb_host_name,1); - rb_define_module_function(rb_host,"speed",(rb_meth)rb_host_speed,1); - rb_define_module_function(rb_host,"number",(rb_meth)rb_host_number,0); - rb_define_module_function(rb_host,"isAvail",(rb_meth)rb_host_is_avail,1); - rb_define_module_function(rb_host,"getHostProcess",(rb_meth)rb_host_process,1); - rb_define_module_function(rb_host,"all",(rb_meth)rb_host_get_all_hosts,0); + rb_define_module_function(rb_host, "getByName", + (rb_meth) rb_host_get_by_name, 1); + rb_define_module_function(rb_host, "name", (rb_meth) rb_host_name, 1); + rb_define_module_function(rb_host, "speed", (rb_meth) rb_host_speed, 1); + rb_define_module_function(rb_host, "number", (rb_meth) rb_host_number, + 0); + rb_define_module_function(rb_host, "isAvail", (rb_meth) rb_host_is_avail, + 1); + rb_define_module_function(rb_host, "getHostProcess", + (rb_meth) rb_host_process, 1); + rb_define_module_function(rb_host, "all", + (rb_meth) rb_host_get_all_hosts, 0); } diff --git a/src/bindings/rubyDag/rb_SD_task.c b/src/bindings/rubyDag/rb_SD_task.c index 740084b28c..2114e36dd8 100644 --- a/src/bindings/rubyDag/rb_SD_task.c +++ b/src/bindings/rubyDag/rb_SD_task.c @@ -8,44 +8,51 @@ #include "rb_SD_task.h" // Free Method -static void SD_task_free(SD_task_t tk) { +static void SD_task_free(SD_task_t tk) +{ // SD_task_destroy(tk); } -static void rb_SD_task_destroy(VALUE class,VALUE task) +static void rb_SD_task_destroy(VALUE class, VALUE task) { - SD_task_t tk ; - Data_Get_Struct(task, SD_task_t, tk); - SD_task_destroy(tk); + SD_task_t tk; + Data_Get_Struct(task, SD_task_t, tk); + SD_task_destroy(tk); } + // New Method -static VALUE rb_SD_task_new(VALUE class, VALUE name,VALUE amount) +static VALUE rb_SD_task_new(VALUE class, VALUE name, VALUE amount) { //data Set to NULL - SD_task_t task = SD_task_create(RSTRING(name)->ptr,NULL,NUM2DBL(amount)); + SD_task_t task = + SD_task_create(RSTRING(name)->ptr, NULL, NUM2DBL(amount)); // Wrap m_task_t to a Ruby Value return Data_Wrap_Struct(class, 0, SD_task_free, task); } //Get Name -static VALUE rb_SD_task_name(VALUE class,VALUE task) +static VALUE rb_SD_task_name(VALUE class, VALUE task) { // Wrap Ruby Value to m_task_t struct SD_task_t tk; Data_Get_Struct(task, SD_task_t, tk); return rb_str_new2(SD_task_get_name(tk)); - + } // Schedule Task -static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate) +static void rb_SD_task_schedule(VALUE class, VALUE task, + VALUE workstation_nb, + VALUE workstation_list, + VALUE computation_amount, + VALUE communication_amount, VALUE rate) { // Wrap Ruby Value to m_task_t struct - int i,wrk_nb,comp_nb,comm_nb; - double *comp_amount,*comm_amount; + int i, wrk_nb, comp_nb, comm_nb; + double *comp_amount, *comm_amount; double rt; - VALUE *ptr_wrk,*ptr_comp,*ptr_comm; + VALUE *ptr_wrk, *ptr_comp, *ptr_comm; SD_task_t tk; Data_Get_Struct(task, SD_task_t, tk); wrk_nb = NUM2INT(workstation_nb); @@ -53,125 +60,131 @@ static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALU comm_nb = RARRAY(communication_amount)->len; rt = NUM2DBL(rate); SD_workstation_t *wrk_list; - + ptr_wrk = RARRAY(workstation_list)->ptr; ptr_comp = RARRAY(computation_amount)->ptr; ptr_comm = RARRAY(communication_amount)->ptr; - - wrk_list = xbt_new0(SD_workstation_t,wrk_nb); - comp_amount = xbt_new0(double,wrk_nb); - comm_amount = xbt_new0(double,wrk_nb); - + + wrk_list = xbt_new0(SD_workstation_t, wrk_nb); + comp_amount = xbt_new0(double, wrk_nb); + comm_amount = xbt_new0(double, wrk_nb); + // wrk_nb == comp_nb == comm_nb ??? - for (i=0;iptr; ptr_comp = RARRAY(computation_amount)->ptr; ptr_comm = RARRAY(communication_amount)->ptr; - - wrk_list = xbt_new0(SD_workstation_t,wrk_nb); - comp_amount = xbt_new0(double,wrk_nb); - comm_amount = xbt_new0(double,wrk_nb); - - for (i=0;i #include -#include "xbt/sysdep.h" +#include "xbt/sysdep.h" // Free Method static void SD_task_free(SD_task_t tk); // needed by ruby while wrapping //destroy -static void rb_SD_task_destory(VALUE Class,VALUE task); +static void rb_SD_task_destory(VALUE Class, VALUE task); // New Method -static VALUE rb_SD_task_new(VALUE Class, VALUE name,VALUE amount); //data set to NULL +static VALUE rb_SD_task_new(VALUE Class, VALUE name, VALUE amount); //data set to NULL //Get Name -static VALUE rb_SD_task_name(VALUE Class,VALUE task); +static VALUE rb_SD_task_name(VALUE Class, VALUE task); // Schedule Task -static void rb_SD_task_schedule(VALUE Class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE comp_amount,VALUE comm_amount,VALUE rate); +static void rb_SD_task_schedule(VALUE Class, VALUE task, + VALUE workstation_nb, + VALUE workstation_list, VALUE comp_amount, + VALUE comm_amount, VALUE rate); // unschedule Task -static void rb_SD_task_unschedule(VALUE Class,VALUE task); +static void rb_SD_task_unschedule(VALUE Class, VALUE task); // task dependency Add ( name & data set to NULL) -static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst); +static void rb_SD_task_add_dependency(VALUE Class, VALUE task_src, + VALUE task_dst); // task execution time -static VALUE rb_SD_task_execution_time(VALUE Class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE comp_amount,VALUE comm_amount,VALUE rate); +static VALUE rb_SD_task_execution_time(VALUE Class, VALUE task, + VALUE workstation_nb, + VALUE workstation_list, + VALUE comp_amount, + VALUE comm_amount, VALUE rate); // task start time -static VALUE rb_SD_task_start_time(VALUE Class,VALUE task); +static VALUE rb_SD_task_start_time(VALUE Class, VALUE task); // task finish time -static VALUE rb_SD_task_finish_time(VALUE Class,VALUE task); +static VALUE rb_SD_task_finish_time(VALUE Class, VALUE task); // simulation -static VALUE rb_SD_simulate(VALUE Class,VALUE how_long); +static VALUE rb_SD_simulate(VALUE Class, VALUE how_long); -#endif \ No newline at end of file +#endif diff --git a/src/bindings/rubyDag/rb_SD_workstation.c b/src/bindings/rubyDag/rb_SD_workstation.c index 6b81d1bca1..cdea23bc18 100644 --- a/src/bindings/rubyDag/rb_SD_workstation.c +++ b/src/bindings/rubyDag/rb_SD_workstation.c @@ -12,19 +12,21 @@ static void SD_workstation_free(SD_workstation_t wrk) { //NOTHING TO DO } + // Workstation list static VALUE rb_SD_workstation_list(VALUE class) { - - int i,nb; + + int i, nb; nb = SD_workstation_get_number(); VALUE workstation_list = rb_ary_new2(nb); - for (i=0;iptr; - argc= RARRAY(args)->len; + argc = RARRAY(args)->len; argc++; - argv= xbt_new0(char*,argc); + argv = xbt_new0(char *, argc); argv[0] = strdup("ruby"); - for (i=0;iptr; - argv[i+1] = strdup(tmp); + for (i = 0; i < argc - 1; i++) { + VALUE value = ptr[i]; + type = TYPE(value); + tmp = RSTRING(value)->ptr; + argv[i + 1] = strdup(tmp); } - SD_init(&argc,argv); + SD_init(&argc, argv); free(argv); // INFO0("SD Init...Done"); printf("SD Init...Done\n"); return; - + } //Init Msg_Run From Ruby @@ -67,67 +65,76 @@ static void sd_reinit(VALUE class) { SD_application_reinit(); } - + //deploy Application -static void sd_createEnvironment(VALUE class,VALUE plateformFile ) -{ - int type = TYPE(plateformFile); - if ( type != T_STRING ) - rb_raise(rb_eRuntimeError,"Bad Argument's Type"); - const char * platform = RSTRING(plateformFile)->ptr; - SD_create_environment(platform); - printf("Create Environment...Done\n"); - - return; +static void sd_createEnvironment(VALUE class, VALUE plateformFile) +{ + int type = TYPE(plateformFile); + if (type != T_STRING) + rb_raise(rb_eRuntimeError, "Bad Argument's Type"); + const char *platform = RSTRING(plateformFile)->ptr; + SD_create_environment(platform); + printf("Create Environment...Done\n"); + + return; } - + // INFO -static void sd_info(VALUE class,VALUE msg) +static void sd_info(VALUE class, VALUE msg) { - const char *s = RSTRING(msg)->ptr; + const char *s = RSTRING(msg)->ptr; // INFO1("%s",s); - printf("%s\n",s); + printf("%s\n", s); } // Get Clock static VALUE sd_get_clock(VALUE class) { return rb_float_new(SD_get_clock()); -} +} void Init_dag() { - // Modules - rb_dag = rb_define_module("DAG"); - - // Classes - //Associated Environment Methods! - rb_define_method(rb_dag,"init",sd_init,1); - rb_define_method(rb_dag,"reinit",sd_reinit,0); - rb_define_method(rb_dag,"createEnvironment",sd_createEnvironment,1); - rb_define_method(rb_dag,"info",sd_info,1); - rb_define_method(rb_dag,"getClock",sd_get_clock,0); - - //Classes - rb_task = rb_define_class_under(rb_dag,"SdTask",rb_cObject); - rb_workstation = rb_define_class_under(rb_dag,"SdWorkstation",rb_cObject); + // Modules + rb_dag = rb_define_module("DAG"); + + // Classes + //Associated Environment Methods! + rb_define_method(rb_dag, "init", sd_init, 1); + rb_define_method(rb_dag, "reinit", sd_reinit, 0); + rb_define_method(rb_dag, "createEnvironment", sd_createEnvironment, 1); + rb_define_method(rb_dag, "info", sd_info, 1); + rb_define_method(rb_dag, "getClock", sd_get_clock, 0); + + //Classes + rb_task = rb_define_class_under(rb_dag, "SdTask", rb_cObject); + rb_workstation = + rb_define_class_under(rb_dag, "SdWorkstation", rb_cObject); // TODO Link Class - - //Task Methods - rb_define_module_function(rb_task,"new",rb_SD_task_new,2); + + //Task Methods + rb_define_module_function(rb_task, "new", rb_SD_task_new, 2); // rb_define_module_function(rb_task,"free",rb_SD_task_destroy,1); - rb_define_module_function(rb_task,"name",rb_SD_task_name,1); - rb_define_module_function(rb_task,"schedule",rb_SD_task_schedule,6); - rb_define_module_function(rb_task,"unschedule",rb_SD_task_unschedule,1); - rb_define_module_function(rb_task,"addDependency",rb_SD_task_add_dependency,2); - rb_define_module_function(rb_task,"executionTime",rb_SD_task_execution_time,6); - rb_define_module_function(rb_task,"startTime",rb_SD_task_start_time,1); - rb_define_module_function(rb_task,"finishTime",rb_SD_task_finish_time,1); - rb_define_module_function(rb_task,"simulate",rb_SD_simulate,1); - - //Worstation Methods - rb_define_module_function(rb_workstation,"getList",rb_SD_workstation_list,0); - rb_define_module_function(rb_workstation,"getNumber",rb_SD_workstation_number,0); - rb_define_module_function(rb_workstation,"name",rb_SD_workstation_name,1); -} + rb_define_module_function(rb_task, "name", rb_SD_task_name, 1); + rb_define_module_function(rb_task, "schedule", rb_SD_task_schedule, 6); + rb_define_module_function(rb_task, "unschedule", rb_SD_task_unschedule, + 1); + rb_define_module_function(rb_task, "addDependency", + rb_SD_task_add_dependency, 2); + rb_define_module_function(rb_task, "executionTime", + rb_SD_task_execution_time, 6); + rb_define_module_function(rb_task, "startTime", rb_SD_task_start_time, + 1); + rb_define_module_function(rb_task, "finishTime", rb_SD_task_finish_time, + 1); + rb_define_module_function(rb_task, "simulate", rb_SD_simulate, 1); + + //Worstation Methods + rb_define_module_function(rb_workstation, "getList", + rb_SD_workstation_list, 0); + rb_define_module_function(rb_workstation, "getNumber", + rb_SD_workstation_number, 0); + rb_define_module_function(rb_workstation, "name", rb_SD_workstation_name, + 1); +} diff --git a/src/bindings/ruby_bindings.h b/src/bindings/ruby_bindings.h index 7277ef4ab0..cfe8f5e614 100644 --- a/src/bindings/ruby_bindings.h +++ b/src/bindings/ruby_bindings.h @@ -44,14 +44,14 @@ * Context related stuff * * ********************* */ typedef struct s_smx_ctx_ruby { - s_smx_ctx_base_t super; /* Fields of super implementation */ - VALUE process; // The Ruby Process Instance + s_smx_ctx_base_t super; /* Fields of super implementation */ + VALUE process; // The Ruby Process Instance //... -}s_smx_ctx_ruby_t,*smx_ctx_ruby_t; -void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory); +} s_smx_ctx_ruby_t, *smx_ctx_ruby_t; +void SIMIX_ctx_ruby_factory_init(smx_context_factory_t * factory); -void Init_libsimgrid(void); /* Load the bindings */ -void initRuby(void); // Mandatory to call Ruby methods from C +void Init_libsimgrid(void); /* Load the bindings */ +void initRuby(void); // Mandatory to call Ruby methods from C /* *********************************************** * * Functions for Ruby Process Management (Up Call) * @@ -59,15 +59,15 @@ void initRuby(void); // Mandatory to call Ruby methods from C * Independent Methods * * *********************************************** */ -VALUE rb_process_getName( VALUE ruby_process ); +VALUE rb_process_getName(VALUE ruby_process); VALUE rb_process_getID(VALUE ruby_process); VALUE rb_process_getBind(VALUE ruby_class); -void rb_process_setBind(VALUE ruby_class,long bind); +void rb_process_setBind(VALUE ruby_class, long bind); VALUE rb_process_isAlive(VALUE ruby_process); -void rb_process_kill_up(VALUE ruby_process); -void rb_process_join( VALUE ruby_process ); -void rb_process_unschedule( VALUE ruby_process ); -void rb_process_schedule( VALUE ruby_process ); +void rb_process_kill_up(VALUE ruby_process); +void rb_process_join(VALUE ruby_process); +void rb_process_unschedule(VALUE ruby_process); +void rb_process_schedule(VALUE ruby_process); /* ********************************************** * * Function for Native Process (Bound) Management * @@ -80,52 +80,53 @@ void rb_process_schedule( VALUE ruby_process ); //friend Method // Not belong to the Class but Called within !! m_process_t rb_process_to_native(VALUE ruby_process); // Binding Process >> Friend Method -void rb_process_bind(VALUE ruby_class,m_process_t process); -void rb_process_create(VALUE Class,VALUE rb_process,VALUE host); -void rb_process_suspend(VALUE Class,VALUE ruby_process); -void rb_process_resume(VALUE Class,VALUE ruby_process); +void rb_process_bind(VALUE ruby_class, m_process_t process); +void rb_process_create(VALUE Class, VALUE rb_process, VALUE host); +void rb_process_suspend(VALUE Class, VALUE ruby_process); +void rb_process_resume(VALUE Class, VALUE ruby_process); // Returns Boolean ( Qtrue / Qfalse ) -VALUE rb_process_isSuspended(VALUE Class,VALUE ruby_process); -void rb_process_kill_down(VALUE Class,VALUE ruby_process); -VALUE rb_process_getHost(VALUE Class,VALUE ruby_process); -void rb_process_exit(VALUE Class,VALUE ruby_process); +VALUE rb_process_isSuspended(VALUE Class, VALUE ruby_process); +void rb_process_kill_down(VALUE Class, VALUE ruby_process); +VALUE rb_process_getHost(VALUE Class, VALUE ruby_process); +void rb_process_exit(VALUE Class, VALUE ruby_process); /* Functions related to hosts */ -void rb_host_free(m_host_t ht); +void rb_host_free(m_host_t ht); VALUE rb_host_get_by_name(VALUE Class, VALUE name); -VALUE rb_host_name(VALUE Class,VALUE host); +VALUE rb_host_name(VALUE Class, VALUE host); VALUE rb_host_number(VALUE Class); -VALUE rb_host_speed(VALUE Class,VALUE host); -void rb_host_set_data(VALUE Class,VALUE host,VALUE data); -VALUE rb_host_get_data(VALUE Class,VALUE host); -VALUE rb_host_is_avail(VALUE Class,VALUE host); -VALUE rb_host_process(VALUE Class,VALUE process); +VALUE rb_host_speed(VALUE Class, VALUE host); +void rb_host_set_data(VALUE Class, VALUE host, VALUE data); +VALUE rb_host_get_data(VALUE Class, VALUE host); +VALUE rb_host_is_avail(VALUE Class, VALUE host); +VALUE rb_host_process(VALUE Class, VALUE process); VALUE rb_host_get_all_hosts(VALUE Class); /* Functions related to tasks */ typedef struct ruby_data { - void *ruby_task; // Pointer to send the ruby_task - void *user_data; // Pointer on the user data -}s_ruby_data_t,*rb_data_t; + void *ruby_task; // Pointer to send the ruby_task + void *user_data; // Pointer on the user data +} s_ruby_data_t, *rb_data_t; void rb_task_free(m_task_t tk); -VALUE rb_task_new(VALUE Class, VALUE name,VALUE comp_size,VALUE comm_size); -VALUE rb_task_comp(VALUE Class,VALUE task); // Get Computation Size -VALUE rb_task_name(VALUE Class,VALUE task); -VALUE rb_task_execute(VALUE Class,VALUE task); -void rb_task_send(VALUE Class,VALUE task,VALUE mailbox); -VALUE rb_task_receive(VALUE Class,VALUE mailbox);// Receive : return a task -void rb_task_receive2(VALUE Class,VALUE task,VALUE mailbox);// Receive Task 2 << Not Appreciated -VALUE rb_task_sender(VALUE Class,VALUE task); -VALUE rb_task_source(VALUE Class,VALUE task); -VALUE rb_task_listen(VALUE Class,VALUE task,VALUE alias); //Listen From Alias (=mailbox) -VALUE rb_task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); //Listen from Host -void rb_task_set_priority(VALUE Class,VALUE task,VALUE priority); // Set Priority -void rb_task_cancel(VALUE Class,VALUE task); // Cancel -VALUE rb_task_has_data(VALUE Class,VALUE task); // check if the task contains a data -VALUE rb_task_get_data(VALUE Class,VALUE task); // get data -void rb_task_set_data(VALUE Class,VALUE task,VALUE data); // set data +VALUE rb_task_new(VALUE Class, VALUE name, VALUE comp_size, + VALUE comm_size); +VALUE rb_task_comp(VALUE Class, VALUE task); // Get Computation Size +VALUE rb_task_name(VALUE Class, VALUE task); +VALUE rb_task_execute(VALUE Class, VALUE task); +void rb_task_send(VALUE Class, VALUE task, VALUE mailbox); +VALUE rb_task_receive(VALUE Class, VALUE mailbox); // Receive : return a task +void rb_task_receive2(VALUE Class, VALUE task, VALUE mailbox); // Receive Task 2 << Not Appreciated +VALUE rb_task_sender(VALUE Class, VALUE task); +VALUE rb_task_source(VALUE Class, VALUE task); +VALUE rb_task_listen(VALUE Class, VALUE task, VALUE alias); //Listen From Alias (=mailbox) +VALUE rb_task_listen_host(VALUE Class, VALUE task, VALUE alias, VALUE host); //Listen from Host +void rb_task_set_priority(VALUE Class, VALUE task, VALUE priority); // Set Priority +void rb_task_cancel(VALUE Class, VALUE task); // Cancel +VALUE rb_task_has_data(VALUE Class, VALUE task); // check if the task contains a data +VALUE rb_task_get_data(VALUE Class, VALUE task); // get data +void rb_task_set_data(VALUE Class, VALUE task, VALUE data); // set data /* Upcalls for the application handler */ void rb_application_handler_on_start_document(void); @@ -135,4 +136,4 @@ void rb_application_handler_on_process_arg(void); void rb_application_handler_on_property(void); void rb_application_handler_on_end_process(void); -#endif /* RB_SG_BINDINGS */ +#endif /* RB_SG_BINDINGS */ diff --git a/src/config_unit.c b/src/config_unit.c index 34691661b9..c8ccce3947 100644 --- a/src/config_unit.c +++ b/src/config_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 1295 "xbt/config.c" +#line 1325 "xbt/config.c" #include "xbt.h" #include "xbt/ex.h" @@ -102,7 +102,8 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_dynar_t dyn; xbt_cfg_t myset = make_set(); - xbt_cfg_set_parse(myset, "peername:veloce user:foo\nuser:bar\tuser:toto"); + xbt_cfg_set_parse(myset, + "peername:veloce user:foo\nuser:bar\tuser:toto"); xbt_cfg_set_parse(myset, "speed:42"); xbt_cfg_check(myset); dyn = xbt_cfg_get_dynar(myset, "user"); @@ -112,16 +113,16 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_dynar_length(dyn)); if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo")) - xbt_test_fail1("Dynar[0] = %s, I expected foo", - xbt_dynar_get_as(dyn, 0, char *)); + xbt_test_fail1("Dynar[0] = %s, I expected foo", + xbt_dynar_get_as(dyn, 0, char *)); if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar")) - xbt_test_fail1("Dynar[1] = %s, I expected bar", - xbt_dynar_get_as(dyn, 1, char *)); + xbt_test_fail1("Dynar[1] = %s, I expected bar", + xbt_dynar_get_as(dyn, 1, char *)); if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto")) - xbt_test_fail1("Dynar[2] = %s, I expected toto", - xbt_dynar_get_as(dyn, 2, char *)); + xbt_test_fail1("Dynar[2] = %s, I expected toto", + xbt_dynar_get_as(dyn, 2, char *)); xbt_cfg_free(&myset); } diff --git a/src/cunit_unit.c b/src/cunit_unit.c index 13e797c400..d333278d4e 100644 --- a/src/cunit_unit.c +++ b/src/cunit_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 823 "xbt/cunit.c" +#line 835 "xbt/cunit.c" XBT_TEST_UNIT("expect", test_expected_failure, "expected failures") diff --git a/src/dict_unit.c b/src/dict_unit.c index 4fd6f8bc19..b3a0129dab 100644 --- a/src/dict_unit.c +++ b/src/dict_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 816 "xbt/dict.c" +#line 835 "xbt/dict.c" #include "xbt.h" #include "xbt/ex.h" #include "portable.h" @@ -27,7 +27,8 @@ static void debuged_add_ext(xbt_dict_t head, const char *key, { char *data = xbt_strdup(data_to_fill); - xbt_test_log2("Add %s under %s", PRINTF_STR(data_to_fill), PRINTF_STR(key)); + xbt_test_log2("Add %s under %s", PRINTF_STR(data_to_fill), + PRINTF_STR(key)); xbt_dict_set(head, key, data, &free); if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) { @@ -117,8 +118,8 @@ static void search_not_found(xbt_dict_t head, const char *data) TRY { data = xbt_dict_get(head, data); - THROW1(unknown_error, 0, "Found something which shouldn't be there (%s)", - data); + THROW1(unknown_error, 0, + "Found something which shouldn't be there (%s)", data); } CATCH(e) { if (e.category != not_found_error) xbt_test_exception(e); @@ -142,7 +143,7 @@ static void count(xbt_dict_t dict, int length) length); xbt_dict_foreach(dict, cursor, key, data) - effective++; + effective++; xbt_test_assert2(effective == length, "Effective length(%d) != %d.", effective, length); @@ -152,21 +153,24 @@ static void count(xbt_dict_t dict, int length) static void count_check_get_key(xbt_dict_t dict, int length) { xbt_dict_cursor_t cursor; - char *key,*key2; + char *key, *key2; void *data; int effective = 0; - xbt_test_add1("Count elements (expecting %d), and test the getkey function", length); + xbt_test_add1 + ("Count elements (expecting %d), and test the getkey function", + length); xbt_test_assert2(xbt_dict_length(dict) == length, "Announced length(%d) != %d.", xbt_dict_length(dict), length); xbt_dict_foreach(dict, cursor, key, data) { effective++; - key2 = xbt_dict_get_key(dict,data); - xbt_assert2(!strcmp(key,key2), - "The data was registered under %s instead of %s as expected",key2,key); + key2 = xbt_dict_get_key(dict, data); + xbt_assert2(!strcmp(key, key2), + "The data was registered under %s instead of %s as expected", + key2, key); } xbt_test_assert2(effective == length, "Effective length(%d) != %d.", @@ -179,7 +183,7 @@ xbt_dict_t head = NULL; char *data; -XBT_TEST_UNIT("basic", test_dict_basic,"Basic usage: change, retrieve, traverse") +XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse") { xbt_test_add0("Traversal the null dictionary"); traverse(head); @@ -281,7 +285,7 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") xbt_dict_free(&head); xbt_test_add0 - ("Remove each data manually (traversing the resulting dictionary each time)"); + ("Remove each data manually (traversing the resulting dictionary each time)"); fill(&head); debuged_remove(head, "12a"); traverse(head); @@ -320,7 +324,8 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") } traverse(head); - xbt_test_add0("Free dict, create new fresh one, and then reset the dict"); + xbt_test_add0 + ("Free dict, create new fresh one, and then reset the dict"); xbt_dict_free(&head); fill(&head); xbt_dict_reset(head); @@ -362,8 +367,9 @@ XBT_TEST_UNIT("nulldata", test_dict_nulldata, "NULL data management") xbt_dict_free(&head); } -static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) { - uintptr_t stored_data = 0; +static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) +{ + uintptr_t stored_data = 0; xbt_test_log2("Add %zu under %zu", data, key); xbt_dicti_set(head, key, data); @@ -372,8 +378,9 @@ static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) { fflush(stdout); } stored_data = xbt_dicti_get(head, key); - xbt_test_assert3(stored_data==data, - "Retrieved data (%zu) is not what I just stored (%zu) under key %zu",stored_data,data,key); + xbt_test_assert3(stored_data == data, + "Retrieved data (%zu) is not what I just stored (%zu) under key %zu", + stored_data, data, key); } XBT_TEST_UNIT("dicti", test_dict_scalar, "Scalar data and key management") @@ -428,9 +435,11 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") for (i = 0; i < 10; i++) { xbt_test_add2("CRASH test number %d (%d to go)", i + 1, 10 - i - 1); - xbt_test_log0("Fill the struct, count its elems and frees the structure"); - xbt_test_log1("using 1000 elements with %d chars long randomized keys.", - SIZEOFKEY); + xbt_test_log0 + ("Fill the struct, count its elems and frees the structure"); + xbt_test_log1 + ("using 1000 elements with %d chars long randomized keys.", + SIZEOFKEY); head = xbt_dict_new(); /* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */ nb = 0; @@ -474,7 +483,8 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") } /*xbt_dict_dump(head,(void (*)(void*))&printf); */ - xbt_test_add0("Count the elements (retrieving the key and data for each)"); + xbt_test_add0 + ("Count the elements (retrieving the key and data for each)"); i = countelems(head); xbt_test_log1("There is %d elements", i); @@ -490,7 +500,8 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") "with get, key=%s != data=%s", key, (char *) data); data = xbt_dict_get_ext(head, key, strlen(key)); xbt_test_assert2(!strcmp(key, (char *) data), - "with get_ext, key=%s != data=%s", key, (char *) data); + "with get_ext, key=%s != data=%s", key, + (char *) data); } } free(key); @@ -535,9 +546,10 @@ XBT_TEST_UNIT("multicrash", test_dict_multicrash, "Multi-dict crash test") xbt_test_add0("Generic multicache CRASH test"); - xbt_test_log4(" Fill the struct and frees it %d times, using %d elements, " - "depth of multicache=%d, key size=%d", - NB_TEST, NB_ELM, DEPTH, KEY_SIZE); + xbt_test_log4 + (" Fill the struct and frees it %d times, using %d elements, " + "depth of multicache=%d, key size=%d", NB_TEST, NB_ELM, DEPTH, + KEY_SIZE); for (l = 0; l < DEPTH; l++) { key = xbt_malloc(KEY_SIZE); diff --git a/src/dynar_unit.c b/src/dynar_unit.c index 6791935093..2800ad965e 100644 --- a/src/dynar_unit.c +++ b/src/dynar_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 716 "xbt/dynar.c" +#line 730 "xbt/dynar.c" #define NB_ELEM 5000 @@ -28,13 +28,13 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") xbt_dynar_foreach(d, cursor, i) { xbt_assert0(0, "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1 - ("==== Push %d int, set them again 3 times, traverse them, shift them", - NB_ELEM); + ("==== Push %d int, set them again 3 times, traverse them, shift them", + NB_ELEM); /* Populate_ints [doxygen cruft] */ /* 1. Populate the dynar */ d = xbt_dynar_new(sizeof(int), NULL); @@ -92,9 +92,9 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") } /* 5. Free the resources */ - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Unshift/pop %d int", NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); @@ -109,14 +109,14 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") i, cpt); xbt_test_log2("Pop %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1 - ("==== Push %d int, insert 1000 int in the middle, shift everything", - NB_ELEM); + ("==== Push %d int, insert 1000 int in the middle, shift everything", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) { xbt_dynar_push_as(d, int, cpt); @@ -146,11 +146,12 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") "The retrieved value is not the same than the injected one at the end (%d!=%d)", i, cpt); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ - xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest", NB_ELEM); + xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) xbt_dynar_push_as(d, int, cpt); @@ -161,9 +162,9 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") "Remove a bad value. Got %d, expected %d", i, cpt); DEBUG2("remove %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ } /*******************************************************************************/ @@ -179,11 +180,12 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") xbt_test_add0("==== Traverse the empty dynar"); d = xbt_dynar_new(sizeof(int), NULL); xbt_dynar_foreach(d, cursor, cpt) { - xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar"); + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Push/shift 5000 doubles"); d = xbt_dynar_new(sizeof(double), NULL); @@ -204,9 +206,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Unshift/pop 5000 doubles"); d = xbt_dynar_new(sizeof(double), NULL); @@ -221,14 +223,14 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0 - ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); + ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); d = xbt_dynar_new(sizeof(double), NULL); for (cpt = 0; cpt < 5000; cpt++) { d1 = (double) cpt; @@ -261,9 +263,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one at the end (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest"); @@ -278,9 +280,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") xbt_test_assert2(d1 == d2, "Remove a bad value. Got %f, expected %f", d2, d1); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ } @@ -300,11 +302,12 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") xbt_test_add0("==== Traverse the empty dynar"); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); xbt_dynar_foreach(d, iter, s1) { - xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar"); + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Push %d strings, set them again 3 times, shift them", NB_ELEM); @@ -339,9 +342,9 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") buf, s2); free(s2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Unshift, traverse and pop %d strings", NB_ELEM); d = xbt_dynar_new(sizeof(char **), &xbt_free_ref); @@ -367,14 +370,14 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") free(s2); } /* 4. Free the resources */ - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add2 - ("==== Push %d strings, insert %d strings in the middle, shift everything", - NB_ELEM, NB_ELEM / 5); + ("==== Push %d strings, insert %d strings in the middle, shift everything", + NB_ELEM, NB_ELEM / 5); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); for (cpt = 0; cpt < NB_ELEM; cpt++) { sprintf(buf, "%d", cpt); @@ -411,13 +414,13 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") buf, s2); free(s2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ - xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest", NB_ELEM, - 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5)); + xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest", + NB_ELEM, 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5)); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); for (cpt = 0; cpt < NB_ELEM; cpt++) { sprintf(buf, "%d", cpt); @@ -471,7 +474,7 @@ static void poper_f(void *a) } -XBT_TEST_UNIT("synchronized int", test_dynar_sync_int,"Synchronized dynars of integers") +XBT_TEST_UNIT("synchronized int", test_dynar_sync_int, "Synchronized dynars of integers") { /* Vars_decl [doxygen cruft] */ xbt_dynar_t d; @@ -479,8 +482,8 @@ XBT_TEST_UNIT("synchronized int", test_dynar_sync_int,"Synchronized dynars of in xbt_test_add0("==== Have a pusher and a popper on the dynar"); d = xbt_dynar_new_sync(sizeof(int), NULL); - pusher = xbt_thread_create("pusher", pusher_f, d,0/*not joinable*/); - poper = xbt_thread_create("poper", poper_f, d,0/*not joinable*/); + pusher = xbt_thread_create("pusher", pusher_f, d, 0 /*not joinable */ ); + poper = xbt_thread_create("poper", poper_f, d, 0 /*not joinable */ ); xbt_thread_join(pusher); xbt_thread_join(poper); xbt_dynar_free(&d); diff --git a/src/ex_unit.c b/src/ex_unit.c index d291c97fe6..1e43e35de6 100644 --- a/src/ex_unit.c +++ b/src/ex_unit.c @@ -203,7 +203,7 @@ static void good_example(void) cp3 = mallocex(SMALLAMOUNT); strcpy(cp1, "foo"); strcpy(cp2, "bar"); - } TRY_CLEANUP { /*04 */ + } TRY_CLEANUP { /*04 */ printf("cp3=%s", cp3 == NULL /*02 */ ? "" : cp3); if (cp3 != NULL) free(cp3); diff --git a/src/gras/DataDesc/cbps.c b/src/gras/DataDesc/cbps.c index b4867fa90a..94a5874d5f 100644 --- a/src/gras/DataDesc/cbps.c +++ b/src/gras/DataDesc/cbps.c @@ -120,7 +120,7 @@ void gras_cbps_v_pop(gras_cbps_t ps, const char *name, gras_datadesc_type_t * ddt, void **res) { - xbt_dynar_t varstack=NULL, frame=NULL; + xbt_dynar_t varstack = NULL, frame = NULL; gras_cbps_elm_t var = NULL; void *data = NULL; xbt_ex_t e; @@ -324,8 +324,8 @@ int gras_datadesc_cb_pop(gras_datadesc_type_t ignored, gras_cbps_t vars, /* ************************* */ /** \brief Cb to push an integer. Must be attached to the field you want to push */ -void gras_datadesc_cb_push_int(gras_datadesc_type_t ignored, gras_cbps_t vars, - void *data) +void gras_datadesc_cb_push_int(gras_datadesc_type_t ignored, + gras_cbps_t vars, void *data) { int *i = (int *) data; gras_cbps_i_push(vars, (int) *i); diff --git a/src/gras/DataDesc/datadesc.c b/src/gras/DataDesc/datadesc.c index 127d38681f..3c965c9283 100644 --- a/src/gras/DataDesc/datadesc.c +++ b/src/gras/DataDesc/datadesc.c @@ -122,30 +122,36 @@ void gras_datadesc_init(void) /* specific datatype: the exception type (for RPC) */ ddt = gras_datadesc_struct("ex_t"); gras_datadesc_struct_append(ddt, "msg", gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt, "category", gras_datadesc_by_name("int")); + gras_datadesc_struct_append(ddt, "category", + gras_datadesc_by_name("int")); gras_datadesc_struct_append(ddt, "value", gras_datadesc_by_name("int")); gras_datadesc_struct_append(ddt, "remote", gras_datadesc_by_name("short int")); - gras_datadesc_struct_append(ddt, "host", gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "host", + gras_datadesc_by_name("string")); gras_datadesc_struct_append(ddt, "procname", gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt, "pid", gras_datadesc_by_name("long int")); - gras_datadesc_struct_append(ddt, "file", gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "pid", + gras_datadesc_by_name("long int")); + gras_datadesc_struct_append(ddt, "file", + gras_datadesc_by_name("string")); gras_datadesc_struct_append(ddt, "line", gras_datadesc_by_name("int")); - gras_datadesc_struct_append(ddt, "func", gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "func", + gras_datadesc_by_name("string")); gras_datadesc_struct_append(ddt, "used", gras_datadesc_by_name("int")); gras_datadesc_cb_field_push(ddt, "used"); gras_datadesc_struct_append(ddt, "bt_strings", - gras_datadesc_ref_pop_arr(gras_datadesc_by_name - ("string"))); + gras_datadesc_ref_pop_arr + (gras_datadesc_by_name("string"))); gras_datadesc_struct_close(ddt); /* specific datatype: xbt_peer_t */ ddt = gras_datadesc_struct("s_xbt_peer_t"); - gras_datadesc_struct_append(ddt, "name", gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "name", + gras_datadesc_by_name("string")); gras_datadesc_struct_append(ddt, "port", gras_datadesc_by_name("int")); gras_datadesc_struct_close(ddt); diff --git a/src/gras/DataDesc/datadesc_interface.h b/src/gras/DataDesc/datadesc_interface.h index c4a5b31c22..d9bdfd5488 100644 --- a/src/gras/DataDesc/datadesc_interface.h +++ b/src/gras/DataDesc/datadesc_interface.h @@ -34,13 +34,13 @@ XBT_PUBLIC(void) gras_datadesc_recv(gras_socket_t sock, void *dst); /* Described data exchanges: IDL compilation FIXME: not implemented*/ - void gras_datadesc_gen_cpy(gras_datadesc_type_t type, void *src, - void **dst); - void gras_datadesc_gen_send(gras_socket_t sock, - gras_datadesc_type_t type, void *src); - void gras_datadesc_gen_recv(gras_socket_t sock, - gras_datadesc_type_t type, int r_arch, - void *dst); +void gras_datadesc_gen_cpy(gras_datadesc_type_t type, void *src, + void **dst); +void gras_datadesc_gen_send(gras_socket_t sock, + gras_datadesc_type_t type, void *src); +void gras_datadesc_gen_recv(gras_socket_t sock, + gras_datadesc_type_t type, int r_arch, + void *dst); -#endif /* GRAS_DATADESC_INTERFACE_H */ +#endif /* GRAS_DATADESC_INTERFACE_H */ diff --git a/src/gras/DataDesc/datadesc_private.h b/src/gras/DataDesc/datadesc_private.h index 97c0445470..1a10ad28d4 100644 --- a/src/gras/DataDesc/datadesc_private.h +++ b/src/gras/DataDesc/datadesc_private.h @@ -257,4 +257,4 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, ********************************************************************/ extern xbt_dict_t gras_dd_constants; /* lives in ddt_parse.c of course */ -#endif /* GRAS_DATADESC_PRIVATE_H */ +#endif /* GRAS_DATADESC_PRIVATE_H */ diff --git a/src/gras/DataDesc/ddt_convert.c b/src/gras/DataDesc/ddt_convert.c index 11e9f19fe1..dbc9becf68 100644 --- a/src/gras/DataDesc/ddt_convert.c +++ b/src/gras/DataDesc/ddt_convert.c @@ -79,7 +79,8 @@ const char *gras_datadesc_arch_name(int code) /** * Local function doing the grunt work */ -static void gras_dd_reverse_bytes(void *to, const void *from, size_t length); +static void gras_dd_reverse_bytes(void *to, const void *from, + size_t length); /** * gras_dd_convert_elm: @@ -109,7 +110,8 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, r_size = type->size[r_arch]; l_size = type->size[GRAS_THISARCH]; - DEBUG4("r_size=%lu l_size=%lu, src=%p dst=%p", r_size, l_size, src, dst); + DEBUG4("r_size=%lu l_size=%lu, src=%p dst=%p", r_size, l_size, src, + dst); DEBUG2("remote=%c local=%c", gras_arches[r_arch].endian ? 'B' : 'l', gras_arches[GRAS_THISARCH].endian ? 'B' : 'l'); @@ -137,7 +139,7 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, int padding; int sizeChange = l_size - r_size; int lowOrderFirst = !gras_arches[r_arch].endian || - gras_arches[r_arch].endian == gras_arches[GRAS_THISARCH].endian; + gras_arches[r_arch].endian == gras_arches[GRAS_THISARCH].endian; DEBUG5("Resize integer %d from %lu @%p to %lu @%p", cpt, r_size, r_data, l_size, l_data); @@ -157,11 +159,11 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, DEBUG0("This is signed"); /* Make sure the high order bit of r_data and l_data are the same */ l_sign = gras_arches[GRAS_THISARCH].endian - ? ((unsigned char *) l_data + l_size - 1) - : (unsigned char *) l_data; + ? ((unsigned char *) l_data + l_size - 1) + : (unsigned char *) l_data; r_sign = gras_arches[r_arch].endian - ? ((unsigned char *) r_data + r_size - 1) - : (unsigned char *) r_data; + ? ((unsigned char *) r_data + r_size - 1) + : (unsigned char *) r_data; DEBUG2("This is signed (r_sign=%c l_sign=%c", *r_sign, *l_sign); if ((*r_sign > 127) != (*l_sign > 127)) { @@ -179,9 +181,9 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, } else { /* extend sign */ r_sign = - gras_arches[r_arch].endian ? ((unsigned char *) r_data + r_size - - 1) - : (unsigned char *) r_data; + gras_arches[r_arch].endian ? ((unsigned char *) r_data + + r_size - 1) + : (unsigned char *) r_data; padding = (*r_sign > 127) ? 0xff : 0; } @@ -223,7 +225,8 @@ gras_dd_convert_elm(gras_datadesc_type_t type, int count, } -static void gras_dd_reverse_bytes(void *to, const void *from, size_t length) +static void gras_dd_reverse_bytes(void *to, const void *from, + size_t length) { char charBegin; diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 311917683f..77c19a5d83 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -41,7 +41,8 @@ static gras_datadesc_type_t gras_ddt_new(const char *name) res->name_len = strlen(name); res->cycle = 0; - xbt_set_add(gras_datadesc_set_local, (xbt_set_elm_t) res, gras_ddt_freev); + xbt_set_add(gras_datadesc_set_local, (xbt_set_elm_t) res, + gras_ddt_freev); XBT_OUT; return res; } @@ -71,8 +72,8 @@ gras_datadesc_type_t gras_datadesc_by_name(const char *name) volatile int found = 0; TRY { res = - (gras_datadesc_type_t) xbt_set_get_by_name(gras_datadesc_set_local, - name); + (gras_datadesc_type_t) xbt_set_get_by_name(gras_datadesc_set_local, + name); found = 1; } CATCH(e) { if (e.category != not_found_error) @@ -95,7 +96,8 @@ gras_datadesc_type_t gras_datadesc_by_id(long int code) gras_datadesc_type_t res = NULL; TRY { res = - (gras_datadesc_type_t) xbt_set_get_by_id(gras_datadesc_set_local, code); + (gras_datadesc_type_t) xbt_set_get_by_id(gras_datadesc_set_local, + code); } CATCH(e) { if (e.category != not_found_error) RETHROW; @@ -135,7 +137,7 @@ gras_datadesc_scalar(const char *name, res->size[arch] = gras_arches[arch].sizeofs[type]; res->alignment[arch] = gras_arches[arch].boundaries[type]; res->aligned_size[arch] = - ddt_aligned(res->size[arch], res->alignment[arch]); + ddt_aligned(res->size[arch], res->alignment[arch]); } res->category_code = e_gras_datadesc_type_cat_scalar; @@ -185,7 +187,7 @@ gras_datadesc_type_t gras_datadesc_struct(const char *name) } res->category_code = e_gras_datadesc_type_cat_struct; res->category.struct_data.fields = - xbt_dynar_new(sizeof(gras_dd_cat_field_t), gras_dd_cat_field_free); + xbt_dynar_new(sizeof(gras_dd_cat_field_t), gras_dd_cat_field_free); XBT_OUT; return res; @@ -194,7 +196,8 @@ gras_datadesc_type_t gras_datadesc_struct(const char *name) /** \brief Append a new field to a structure description */ void gras_datadesc_struct_append(gras_datadesc_type_t struct_type, - const char *name, gras_datadesc_type_t field_type) + const char *name, + gras_datadesc_type_t field_type) { gras_dd_cat_field_t field; @@ -206,8 +209,8 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, XBT_IN3("(%s %s.%s;)", field_type->name, struct_type->name, name); if (struct_type->category.struct_data.closed) { VERB1 - ("Ignoring request to add field to struct %s (closed. Redefinition?)", - struct_type->name); + ("Ignoring request to add field to struct %s (closed. Redefinition?)", + struct_type->name); return; } @@ -243,7 +246,8 @@ gras_datadesc_struct_append(gras_datadesc_type_t struct_type, xbt_dynar_push(struct_type->category.struct_data.fields, &field); DEBUG3("Push a %s into %s at offset %ld.", - field_type->name, struct_type->name, field->offset[GRAS_THISARCH]); + field_type->name, struct_type->name, + field->offset[GRAS_THISARCH]); DEBUG3(" f={size=%ld,align=%ld,asize=%ld}", field_type->size[GRAS_THISARCH], field_type->alignment[GRAS_THISARCH], @@ -333,7 +337,7 @@ gras_datadesc_union(const char *name, gras_datadesc_type_cb_int_t selector) res->category_code = e_gras_datadesc_type_cat_union; res->category.union_data.fields = - xbt_dynar_new(sizeof(gras_dd_cat_field_t *), gras_dd_cat_field_free); + xbt_dynar_new(sizeof(gras_dd_cat_field_t *), gras_dd_cat_field_free); res->category.union_data.selector = selector; return res; @@ -373,7 +377,8 @@ void gras_datadesc_union_append(gras_datadesc_type_t union_type, union_type->alignment[arch] = max(union_type->alignment[arch], field_type->alignment[arch]); union_type->aligned_size[arch] = ddt_aligned(union_type->size[arch], - union_type->alignment[arch]); + union_type->alignment + [arch]); } } @@ -409,7 +414,8 @@ gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type) { gras_datadesc_type_t res; - gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); + gras_datadesc_type_t pointer_type = + gras_datadesc_by_name("data pointer"); int arch; XBT_IN1("(%s)", name); @@ -449,11 +455,13 @@ gras_datadesc_ref(const char *name, gras_datadesc_type_t referenced_type) * callback and expects it to return the type description to use. */ gras_datadesc_type_t -gras_datadesc_ref_generic(const char *name, gras_datadesc_selector_t selector) +gras_datadesc_ref_generic(const char *name, + gras_datadesc_selector_t selector) { gras_datadesc_type_t res; - gras_datadesc_type_t pointer_type = gras_datadesc_by_name("data pointer"); + gras_datadesc_type_t pointer_type = + gras_datadesc_by_name("data pointer"); int arch; XBT_IN1("(%s)", name); @@ -504,8 +512,9 @@ gras_datadesc_array_fixed(const char *name, "Redefinition of type %s does not match", name); if (res->category.array_data.type != element_type) { - ERROR1("Redefinition of type %s does not match: array elements differ", - name); + ERROR1 + ("Redefinition of type %s does not match: array elements differ", + name); gras_datadesc_type_dump(res->category.array_data.type); gras_datadesc_type_dump(element_type); } @@ -609,8 +618,8 @@ gras_datadesc_type_t gras_datadesc_array_dyn(const char *name, gras_datadesc_type_t gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) { - int cpt=0; - gras_datadesc_type_t res,ddt2; + int cpt = 0; + gras_datadesc_type_t res, ddt2; char *name = (char *) xbt_malloc(strlen(element_type->name) + 4); sprintf(name, "%s[]", element_type->name); @@ -619,19 +628,19 @@ gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type) while (ddt2) { free(name); - name=bprintf("%s[]_%d",element_type->name,cpt++); - ddt2=gras_datadesc_by_name_or_null(name); + name = bprintf("%s[]_%d", element_type->name, cpt++); + ddt2 = gras_datadesc_by_name_or_null(name); } res = gras_datadesc_array_dyn(name, element_type, gras_datadesc_cb_pop); sprintf(name, "%s[]*", element_type->name); - cpt=0; + cpt = 0; ddt2 = gras_datadesc_by_name_or_null(name); while (ddt2) { free(name); - name=bprintf("%s[]*_%d",element_type->name,cpt++); - ddt2=gras_datadesc_by_name_or_null(name); + name = bprintf("%s[]*_%d", element_type->name, cpt++); + ddt2 = gras_datadesc_by_name_or_null(name); } res = gras_datadesc_ref(name, res); @@ -698,7 +707,8 @@ gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func) gras_datadesc_struct_append(res, "elmsize", gras_datadesc_by_name("unsigned long int")); - gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t)); + gras_datadesc_struct_append(res, "data", + gras_datadesc_ref_pop_arr(elm_t)); gras_datadesc_struct_append(res, "free_f", gras_datadesc_by_name("function pointer")); @@ -742,7 +752,8 @@ static void gras_datadesc_matrix_cb(gras_datadesc_type_t typedesc, } gras_datadesc_type_t -gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f) +gras_datadesc_matrix(gras_datadesc_type_t elm_t, + void_f_pvoid_t const free_f) { char *buffname; gras_datadesc_type_t res; @@ -758,7 +769,8 @@ gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f) gras_datadesc_struct_append(res, "elmsize", gras_datadesc_by_name("unsigned long int")); - gras_datadesc_struct_append(res, "data", gras_datadesc_ref_pop_arr(elm_t)); + gras_datadesc_struct_append(res, "data", + gras_datadesc_ref_pop_arr(elm_t)); gras_datadesc_struct_append(res, "free_f", gras_datadesc_by_name("function pointer")); gras_datadesc_struct_close(res); @@ -779,7 +791,8 @@ gras_datadesc_matrix(gras_datadesc_type_t elm_t, void_f_pvoid_t const free_f) gras_datadesc_type_t gras_datadesc_import_nws(const char *name, - const DataDescriptor * desc, unsigned long howmany) + const DataDescriptor * desc, + unsigned long howmany) { THROW_UNIMPLEMENTED; } @@ -872,8 +885,8 @@ void gras_datadesc_cb_field_push(gras_datadesc_type_t type, field->send = gras_datadesc_cb_push_ulint; } else { ERROR1 - ("Field %s is not an int, unsigned int, long int neither unsigned long int", - sub_type->name); + ("Field %s is not an int, unsigned int, long int neither unsigned long int", + sub_type->name); xbt_abort(); } } @@ -905,8 +918,8 @@ void gras_datadesc_cb_field_push_multiplier(gras_datadesc_type_t type, field->send = gras_datadesc_cb_push_ulint_mult; } else { ERROR1 - ("Field %s is not an int, unsigned int, long int neither unsigned long int", - sub_type->name); + ("Field %s is not an int, unsigned int, long int neither unsigned long int", + sub_type->name); xbt_abort(); } } @@ -1005,9 +1018,9 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, if (d1->aligned_size[cpt] != d2->aligned_size[cpt]) { DEBUG5 - ("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)", - d1->name, d1->aligned_size[cpt], d2->name, d2->aligned_size[cpt], - gras_arches[cpt].name); + ("ddt_cmp: %s->aligned_size=%ld != %s->aligned_size=%ld (on %s)", + d1->name, d1->aligned_size[cpt], d2->name, + d2->aligned_size[cpt], gras_arches[cpt].name); return d1->aligned_size[cpt] > d2->aligned_size[cpt] ? 1 : -1; } } @@ -1036,7 +1049,7 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, if (d1->category.scalar_data.encoding != d2->category.scalar_data.encoding) return d1->category.scalar_data.encoding > - d2->category.scalar_data.encoding ? 1 : -1; + d2->category.scalar_data.encoding ? 1 : -1; break; case e_gras_datadesc_type_cat_struct: @@ -1047,13 +1060,13 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, d2->name, xbt_dynar_length(d2->category.struct_data.fields)); return xbt_dynar_length(d1->category.struct_data.fields) > - xbt_dynar_length(d2->category.struct_data.fields) ? 1 : -1; + xbt_dynar_length(d2->category.struct_data.fields) ? 1 : -1; } xbt_dynar_foreach(d1->category.struct_data.fields, cpt, field1) { field2 = - xbt_dynar_get_as(d2->category.struct_data.fields, cpt, - gras_dd_cat_field_t); + xbt_dynar_get_as(d2->category.struct_data.fields, cpt, + gras_dd_cat_field_t); field_desc_1 = field1->type; field_desc_2 = field2->type; ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2); @@ -1067,19 +1080,20 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, break; case e_gras_datadesc_type_cat_union: - if (d1->category.union_data.selector != d2->category.union_data.selector) + if (d1->category.union_data.selector != + d2->category.union_data.selector) return 1; /* ISO C forbids ordered comparisons of pointers to functions */ if (xbt_dynar_length(d1->category.union_data.fields) != xbt_dynar_length(d2->category.union_data.fields)) return xbt_dynar_length(d1->category.union_data.fields) > - xbt_dynar_length(d2->category.union_data.fields) ? 1 : -1; + xbt_dynar_length(d2->category.union_data.fields) ? 1 : -1; xbt_dynar_foreach(d1->category.union_data.fields, cpt, field1) { field2 = - xbt_dynar_get_as(d2->category.union_data.fields, cpt, - gras_dd_cat_field_t); + xbt_dynar_get_as(d2->category.union_data.fields, cpt, + gras_dd_cat_field_t); field_desc_1 = field1->type; field_desc_2 = field2->type; ret = gras_datadesc_type_cmp(field_desc_1, field_desc_2); @@ -1095,18 +1109,19 @@ int gras_datadesc_type_cmp(const gras_datadesc_type_t d1, return 1; /* ISO C forbids ordered comparisons of pointers to functions */ if (d1->category.ref_data.type != d2->category.ref_data.type) - return d1->category.ref_data.type > d2->category.ref_data.type ? 1 : -1; + return d1->category.ref_data.type > + d2->category.ref_data.type ? 1 : -1; break; case e_gras_datadesc_type_cat_array: if (d1->category.array_data.type != d2->category.array_data.type) return d1->category.array_data.type > - d2->category.array_data.type ? 1 : -1; + d2->category.array_data.type ? 1 : -1; if (d1->category.array_data.fixed_size != d2->category.array_data.fixed_size) return d1->category.array_data.fixed_size > - d2->category.array_data.fixed_size ? 1 : -1; + d2->category.array_data.fixed_size ? 1 : -1; if (d1->category.array_data.dynamic_size != d2->category.array_data.dynamic_size) diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 97d1a41645..858d5f02cc 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -85,9 +85,10 @@ static XBT_INLINE void gras_dd_alloc_ref(xbt_dict_t refs, long int size, char ** l_data = xbt_malloc((size_t) size); *l_ref = l_data; - DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld", - (void *) l_data, (void *) &l_data, - (void *) r_ref, (void *) (r_ref ? *r_ref : NULL), r_len); + DEBUG5 + ("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld", + (void *) l_data, (void *) &l_data, (void *) r_ref, + (void *) (r_ref ? *r_ref : NULL), r_len); if (detect_cycle && r_ref && !gras_dd_is_r_null(r_ref, r_len)) { void *ptr = xbt_malloc(sizeof(void *)); @@ -105,7 +106,8 @@ static int gras_datadesc_memcpy_rec(gras_cbps_t state, xbt_dict_t refs, gras_datadesc_type_t type, - char *src, char *dst, int subsize, int detect_cycle) + char *src, char *dst, int subsize, + int detect_cycle) { @@ -149,22 +151,23 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, DEBUG1("Copy field %s", field->name); count += - gras_datadesc_memcpy_rec(state, refs, sub_type, field_src, - field_dst, 0, detect_cycle - || sub_type->cycle); + gras_datadesc_memcpy_rec(state, refs, sub_type, field_src, + field_dst, 0, detect_cycle + || sub_type->cycle); if (XBT_LOG_ISENABLED(gras_ddt_exchange, xbt_log_priority_verbose)) { if (sub_type == gras_datadesc_by_name("unsigned int")) { VERB2("Copied value for field '%s': %d (type: unsigned int)", field->name, *(unsigned int *) field_dst); } else if (sub_type == gras_datadesc_by_name("int")) { - VERB2("Copied value for field '%s': %d (type: int)", field->name, - *(int *) field_dst); + VERB2("Copied value for field '%s': %d (type: int)", + field->name, *(int *) field_dst); - } else if (sub_type == gras_datadesc_by_name("unsigned long int")) { + } else if (sub_type == + gras_datadesc_by_name("unsigned long int")) { VERB2 - ("Copied value for field '%s': %ld (type: unsigned long int)", - field->name, *(unsigned long int *) field_dst); + ("Copied value for field '%s': %ld (type: unsigned long int)", + field->name, *(unsigned long int *) field_dst); } else if (sub_type == gras_datadesc_by_name("long int")) { VERB2("Copied value for field '%s': %ld (type: long int)", field->name, *(long int *) field_dst); @@ -203,11 +206,13 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, xbt_assert3(field_num < xbt_dynar_length(union_data.fields), "union field selector of %s returned %d but there is only %lu fields", - type->name, field_num, xbt_dynar_length(union_data.fields)); + type->name, field_num, + xbt_dynar_length(union_data.fields)); /* Copy the content */ field = - xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + xbt_dynar_get_as(union_data.fields, field_num, + gras_dd_cat_field_t); sub_type = field->type; if (field->send) @@ -243,7 +248,9 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, reference_is_to_cpy = 1; if (detect_cycle && - (n_ref=xbt_dict_get_or_null_ext(refs, (char *) o_ref, sizeof(char *)))) { + (n_ref = + xbt_dict_get_or_null_ext(refs, (char *) o_ref, + sizeof(char *)))) { /* already known, no need to copy it */ //INFO0("Cycle detected"); reference_is_to_cpy = 0; @@ -268,12 +275,14 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, subsub_type = array_data.type; subsubcount = array_data.fixed_size; if (subsubcount == -1) - subsubcount = array_data.dynamic_size(subsub_type, state, *o_ref); + subsubcount = + array_data.dynamic_size(subsub_type, state, *o_ref); if (subsubcount != 0) gras_dd_alloc_ref(refs, - subsub_type->size[GRAS_THISARCH] * subsubcount, - o_ref, pointer_type->size[GRAS_THISARCH], + subsub_type->size[GRAS_THISARCH] * + subsubcount, o_ref, + pointer_type->size[GRAS_THISARCH], (char **) &l_referenced, detect_cycle); } else { gras_dd_alloc_ref(refs, sub_type->size[GRAS_THISARCH], @@ -292,8 +301,8 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, } else { VERB2 - ("NOT copying data previously referenced @%p (already done, @%p now)", - *(void **) o_ref, *(void **) n_ref); + ("NOT copying data previously referenced @%p (already done, @%p now)", + *(void **) o_ref, *(void **) n_ref); *(void **) dst = *n_ref; @@ -317,7 +326,8 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, if (array_count == -1) { array_count = array_data.dynamic_size(type, state, src); xbt_assert1(array_count >= 0, - "Invalid (negative) array size for type %s", type->name); + "Invalid (negative) array size for type %s", + type->name); } /* send the content */ @@ -325,21 +335,23 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, elm_size = sub_type->aligned_size[GRAS_THISARCH]; if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) { VERB1("Array of %ld scalars, copy it in one shot", array_count); - memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count); + memcpy(dst, src, + sub_type->aligned_size[GRAS_THISARCH] * array_count); count += sub_type->aligned_size[GRAS_THISARCH] * array_count; - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size > 0 && - sub_type->category.array_data.type->category_code == + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array + && sub_type->category.array_data.fixed_size > 0 + && sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { VERB1("Array of %ld fixed array of scalars, copy it in one shot", array_count); memcpy(dst, src, - sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] + sub_type->category.array_data. + type->aligned_size[GRAS_THISARCH] * array_count * sub_type->category.array_data.fixed_size); count += - sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] - * array_count * sub_type->category.array_data.fixed_size; + sub_type->category.array_data.type->aligned_size[GRAS_THISARCH] + * array_count * sub_type->category.array_data.fixed_size; } else { VERB1("Array of %ld stuff, copy it in one after the other", @@ -347,8 +359,9 @@ gras_datadesc_memcpy_rec(gras_cbps_t state, for (cpt = 0; cpt < array_count; cpt++) { VERB2("Copy the %dth stuff out of %ld", cpt, array_count); count += - gras_datadesc_memcpy_rec(state, refs, sub_type, src_ptr, dst_ptr, - 0, detect_cycle || sub_type->cycle); + gras_datadesc_memcpy_rec(state, refs, sub_type, src_ptr, + dst_ptr, 0, detect_cycle + || sub_type->cycle); src_ptr += elm_size; dst_ptr += elm_size; } @@ -387,7 +400,9 @@ int gras_datadesc_memcpy(gras_datadesc_type_t type, void *src, void *dst) } TRY { - size = gras_datadesc_memcpy_rec(state, refs, type, (char *) src, (char *) dst,0, type->cycle); + size = + gras_datadesc_memcpy_rec(state, refs, type, (char *) src, + (char *) dst, 0, type->cycle); } TRY_CLEANUP { xbt_dict_reset(refs); gras_cbps_reset(state); @@ -478,14 +493,16 @@ gras_datadesc_send_rec(gras_socket_t sock, xbt_assert3(field_num < xbt_dynar_length(union_data.fields), "union field selector of %s returned %d but there is only %lu fields", - type->name, field_num, xbt_dynar_length(union_data.fields)); + type->name, field_num, + xbt_dynar_length(union_data.fields)); /* Send the field number */ gras_dd_send_int(sock, &field_num, 0 /* not stable */ ); /* Send the content */ field = - xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + xbt_dynar_get_as(union_data.fields, field_num, + gras_dd_cat_field_t); sub_type = field->type; if (field->send) @@ -528,7 +545,9 @@ gras_datadesc_send_rec(gras_socket_t sock, reference_is_to_send = 1; /* return ignored. Just checking whether it's known or not */ - if (detect_cycle && xbt_dict_get_or_null_ext(refs, (char *) ref, sizeof(char *))) { + if (detect_cycle + && xbt_dict_get_or_null_ext(refs, (char *) ref, + sizeof(char *))) { //INFO0("Cycle detected"); reference_is_to_send = 0; } @@ -561,7 +580,8 @@ gras_datadesc_send_rec(gras_socket_t sock, if (count == -1) { count = array_data.dynamic_size(type, state, data); xbt_assert1(count >= 0, - "Invalid (negative) array size for type %s", type->name); + "Invalid (negative) array size for type %s", + type->name); gras_dd_send_int(sock, &count, 0 /*non-stable */ ); } @@ -573,9 +593,9 @@ gras_datadesc_send_rec(gras_socket_t sock, gras_trp_send(sock, data, sub_type->aligned_size[GRAS_THISARCH] * count, 0 /* not stable */ ); - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size > 0 && - sub_type->category.array_data.type->category_code == + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array + && sub_type->category.array_data.fixed_size > 0 + && sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { VERB1("Array of %d fixed array of scalars, send it in one shot", @@ -731,7 +751,8 @@ gras_datadesc_recv_rec(gras_socket_t sock, /* Recv the content */ field = - xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t); + xbt_dynar_get_as(union_data.fields, field_num, + gras_dd_cat_field_t); sub_type = field->type; gras_datadesc_recv_rec(sock, state, refs, sub_type, @@ -780,8 +801,9 @@ gras_datadesc_recv_rec(gras_socket_t sock, reference_is_to_recv = 1; if (detect_cycle && (l_ref = - xbt_dict_get_or_null_ext(refs, (char *) r_ref, - pointer_type->size[r_arch]))) { + xbt_dict_get_or_null_ext(refs, (char *) r_ref, + pointer_type->size + [r_arch]))) { reference_is_to_recv = 0; //INFO0("Cycle detected"); } @@ -805,8 +827,9 @@ gras_datadesc_recv_rec(gras_socket_t sock, if (subsubcount != 0) gras_dd_alloc_ref(refs, - subsub_type->size[GRAS_THISARCH] * subsubcount, - r_ref, pointer_type->size[r_arch], + subsub_type->size[GRAS_THISARCH] * + subsubcount, r_ref, + pointer_type->size[r_arch], (char **) &l_referenced, detect_cycle); else l_referenced = NULL; @@ -828,8 +851,8 @@ gras_datadesc_recv_rec(gras_socket_t sock, } else { VERB2 - ("NOT receiving data remotely referenced @%p (already done, @%p here)", - *(void **) r_ref, *(void **) l_ref); + ("NOT receiving data remotely referenced @%p (already done, @%p here)", + *(void **) r_ref, *(void **) l_ref); *(void **) l_data = *l_ref; @@ -868,14 +891,15 @@ gras_datadesc_recv_rec(gras_socket_t sock, } else { ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count); - gras_trp_recv(sock, (char *) ptr, sub_type->size[r_arch] * count); + gras_trp_recv(sock, (char *) ptr, + sub_type->size[r_arch] * count); if (r_arch != GRAS_THISARCH) gras_dd_convert_elm(sub_type, count, r_arch, ptr, l_data); free(ptr); } - } else if (sub_type->category_code == e_gras_datadesc_type_cat_array && - sub_type->category.array_data.fixed_size >= 0 && - sub_type->category.array_data.type->category_code == + } else if (sub_type->category_code == e_gras_datadesc_type_cat_array + && sub_type->category.array_data.fixed_size >= 0 + && sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) { gras_datadesc_type_t subsub_type; array_data = sub_type->category.array_data; @@ -893,8 +917,8 @@ gras_datadesc_recv_rec(gras_socket_t sock, r_arch, l_data, l_data); } else { ptr = - xbt_malloc(subsub_type->aligned_size[r_arch] * count * - array_data.fixed_size); + xbt_malloc(subsub_type->aligned_size[r_arch] * count * + array_data.fixed_size); gras_trp_recv(sock, (char *) ptr, subsub_type->size[r_arch] * count * diff --git a/src/gras/DataDesc/ddt_parse.c b/src/gras/DataDesc/ddt_parse.c index d6e2e82339..edc56daee8 100644 --- a/src/gras/DataDesc/ddt_parse.c +++ b/src/gras/DataDesc/ddt_parse.c @@ -256,8 +256,8 @@ static void parse_statement(char *definition, if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) PARSE_ERROR1 - ("Unparsable symbol: found a typeless statement (got '%s' instead)", - gras_ddt_parse_text); + ("Unparsable symbol: found a typeless statement (got '%s' instead)", + gras_ddt_parse_text); /**** get the type modifier of this statement ****/ parse_type_modifier(&identifier.tm); @@ -266,7 +266,7 @@ static void parse_statement(char *definition, if (identifier.tm.is_union || identifier.tm.is_enum || identifier.tm.is_struct) PARSE_ERROR0 - ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet"); + ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle recursive type definition yet"); /**** get the base type, giving "short a" the needed love ****/ if (!identifier.tm.is_union && @@ -290,11 +290,11 @@ static void parse_statement(char *definition, /**** build the base type for latter use ****/ if (identifier.tm.is_union) { PARSE_ERROR0 - ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)"); + ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle union yet (get callback from annotation?)"); } else if (identifier.tm.is_enum) { PARSE_ERROR0 - ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet"); + ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle enum yet"); } else if (identifier.tm.is_struct) { sprintf(buffname, "struct %s", identifier.type_name); @@ -380,7 +380,7 @@ static void parse_statement(char *definition, gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RB) { PARSE_ERROR0 - ("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)"); + ("Unimplemented feature: GRAS_DEFINE_TYPE cannot deal with [] constructs (yet)"); } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_WORD) { char *end; @@ -388,14 +388,14 @@ static void parse_statement(char *definition, if (end == gras_ddt_parse_text || *end != '\0') { /* Not a number. Get the constant value, if any */ - int *storage = - xbt_dict_get_or_null(gras_dd_constants, gras_ddt_parse_text); + int *storage = xbt_dict_get_or_null(gras_dd_constants, + gras_ddt_parse_text); if (storage) { size = *storage; } else { PARSE_ERROR1 - ("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?", - gras_ddt_parse_text); + ("Unparsable size of array. Found '%s', expected number or known constant. Need to use gras_datadesc_set_const(), huh?", + gras_ddt_parse_text); } } @@ -420,43 +420,50 @@ static void parse_statement(char *definition, char *keyval = NULL; memset(&array, 0, sizeof(array)); if (strcmp(gras_ddt_parse_text, "GRAS_ANNOTE")) - PARSE_ERROR1("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'", - gras_ddt_parse_text); + PARSE_ERROR1 + ("Unparsable symbol: Expected 'GRAS_ANNOTE', got '%s'", + gras_ddt_parse_text); gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LP) PARSE_ERROR1 - ("Unparsable annotation: Expected parenthesis, got '%s'", - gras_ddt_parse_text); + ("Unparsable annotation: Expected parenthesis, got '%s'", + gras_ddt_parse_text); while ((gras_ddt_parse_tok_num = - gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY); + gras_ddt_parse_lex_n_dump()) == + GRAS_DDT_PARSE_TOKEN_EMPTY); if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable annotation: Expected key name, got '%s'", - gras_ddt_parse_text); + PARSE_ERROR1 + ("Unparsable annotation: Expected key name, got '%s'", + gras_ddt_parse_text); keyname = (char *) strdup(gras_ddt_parse_text); while ((gras_ddt_parse_tok_num = - gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY); + gras_ddt_parse_lex_n_dump()) == + GRAS_DDT_PARSE_TOKEN_EMPTY); if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_COLON) PARSE_ERROR1 - ("Unparsable annotation: expected ',' after the key name, got '%s'", - gras_ddt_parse_text); + ("Unparsable annotation: expected ',' after the key name, got '%s'", + gras_ddt_parse_text); while ((gras_ddt_parse_tok_num = - gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY); + gras_ddt_parse_lex_n_dump()) == + GRAS_DDT_PARSE_TOKEN_EMPTY); /* get the value */ if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable annotation: Expected key value, got '%s'", - gras_ddt_parse_text); + PARSE_ERROR1 + ("Unparsable annotation: Expected key value, got '%s'", + gras_ddt_parse_text); keyval = (char *) strdup(gras_ddt_parse_text); while ((gras_ddt_parse_tok_num = - gras_ddt_parse_lex_n_dump()) == GRAS_DDT_PARSE_TOKEN_EMPTY); + gras_ddt_parse_lex_n_dump()) == + GRAS_DDT_PARSE_TOKEN_EMPTY); /* Done with parsing the annotation. Now deal with it by replacing previously pushed type with the right one */ @@ -464,7 +471,8 @@ static void parse_statement(char *definition, if (!strcmp(keyname, "size")) { free(keyname); if (!identifier.tm.is_ref) - PARSE_ERROR0("Size annotation for a field not being a reference"); + PARSE_ERROR0 + ("Size annotation for a field not being a reference"); identifier.tm.is_ref--; if (!strcmp(keyval, "1")) { @@ -496,16 +504,16 @@ static void parse_statement(char *definition, identifier.tm.is_dynar = -1; } else { PARSE_ERROR1 - ("subtype annotation only accepted for dynars and matrices, but passed to '%s'", - identifier.type_name); + ("subtype annotation only accepted for dynars and matrices, but passed to '%s'", + identifier.type_name); } free(keyval); } else if (!strcmp(keyname, "free_f")) { int *storage = xbt_dict_get_or_null(gras_dd_constants, keyval); if (!storage) PARSE_ERROR1 - ("value for free_f annotation of field %s is not a known constant", - identifier.name); + ("value for free_f annotation of field %s is not a known constant", + identifier.name); if (identifier.tm.is_matrix == -1) { add_free_f(identifiers, *(void_f_pvoid_t *) storage); identifier.tm.is_matrix = 0; @@ -514,8 +522,8 @@ static void parse_statement(char *definition, identifier.tm.is_dynar = 0; } else { PARSE_ERROR1 - ("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)", - identifier.name); + ("free_f annotation only accepted for dynars and matrices which subtype is already declared (field %s)", + identifier.name); } free(keyval); } else { @@ -530,8 +538,8 @@ static void parse_statement(char *definition, if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) PARSE_ERROR1 - ("Unparsable annotation: Expected field name after '*', got '%s'", - gras_ddt_parse_text); + ("Unparsable annotation: Expected field name after '*', got '%s'", + gras_ddt_parse_text); keyval = xbt_malloc(strlen(gras_ddt_parse_text) + 2); sprintf(keyval, "*%s", gras_ddt_parse_text); @@ -546,16 +554,16 @@ static void parse_statement(char *definition, if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RP) PARSE_ERROR1 - ("Unparsable annotation: Expected parenthesis, got '%s'", - gras_ddt_parse_text); + ("Unparsable annotation: Expected parenthesis, got '%s'", + gras_ddt_parse_text); continue; /* End of annotation handling */ } else { PARSE_ERROR1 - ("Unparsable symbol: Got '%s' instead of expected comma (',')", - gras_ddt_parse_text); + ("Unparsable symbol: Got '%s' instead of expected comma (',')", + gras_ddt_parse_text); } } else if (gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_COLON) { PARSE_ERROR0("Unparsable symbol: Unexpected comma (',')"); @@ -579,7 +587,7 @@ static void parse_statement(char *definition, } PARSE_ERROR0 - ("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)"); + ("Unparasable symbol (maybe a def struct in a def struct or a parser bug ;)"); } if (identifier.tm.is_matrix > 0) @@ -625,8 +633,8 @@ static gras_datadesc_type_t parse_struct(char *definition) if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_LA) PARSE_ERROR1 - ("Unparasable symbol: Expecting struct definition, but got %s instead of '{'", - gras_ddt_parse_text); + ("Unparasable symbol: Expecting struct definition, but got %s instead of '{'", + gras_ddt_parse_text); /* Parse the identifiers */ done = 0; @@ -647,8 +655,8 @@ static gras_datadesc_type_t parse_struct(char *definition) xbt_dynar_foreach(identifiers, iter, field) { if (field.tm.is_ref) PARSE_ERROR2 - ("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)", - field.name, field.tm.is_ref); + ("Not enough GRAS_ANNOTATE to deal with all dereferencing levels of %s (%d '*' left)", + field.name, field.tm.is_ref); VERB2("Append field '%s' to %p", field.name, (void *) struct_type); gras_datadesc_struct_append(struct_type, field.name, field.type); @@ -680,8 +688,8 @@ static gras_datadesc_type_t parse_struct(char *definition) /* terminates */ if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_RA) PARSE_ERROR1 - ("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'", - gras_ddt_parse_text); + ("Unparasable symbol: Expected '}' at the end of struct definition, got '%s'", + gras_ddt_parse_text); gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump(); @@ -713,16 +721,17 @@ static gras_datadesc_type_t parse_typedef(char *definition) if (tm.is_ref) PARSE_ERROR0 - ("GRAS_DEFINE_TYPE cannot handle reference without annotation"); + ("GRAS_DEFINE_TYPE cannot handle reference without annotation"); /* get the aliasing name */ if (gras_ddt_parse_tok_num != GRAS_DDT_PARSE_TOKEN_WORD) - PARSE_ERROR1("Unparsable typedef: Expected the alias name, and got '%s'", - gras_ddt_parse_text); + PARSE_ERROR1 + ("Unparsable typedef: Expected the alias name, and got '%s'", + gras_ddt_parse_text); /* (FIXME: should) build the alias */ PARSE_ERROR0 - ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet"); + ("Unimplemented feature: GRAS_DEFINE_TYPE cannot handle typedef yet"); XBT_OUT; return typedef_desc; @@ -776,8 +785,8 @@ gras_datadesc_parse(const char *name, const char *C_statement) } else { ERROR1 - ("Failed to parse the following symbol (not a struct neither a typedef) :\n%s", - definition); + ("Failed to parse the following symbol (not a struct neither a typedef) :\n%s", + definition); xbt_abort(); } @@ -787,8 +796,8 @@ gras_datadesc_parse(const char *name, const char *C_statement) /* register it under the name provided as symbol */ if (strcmp(res->name, name)) { ERROR2 - ("In GRAS_DEFINE_TYPE, the provided symbol (here %s) must be the C type name (here %s)", - name, res->name); + ("In GRAS_DEFINE_TYPE, the provided symbol (here %s) must be the C type name (here %s)", + name, res->name); xbt_abort(); } gras_ddt_parse_lex_destroy(); diff --git a/src/gras/Msg/gras_msg_exchange.c b/src/gras/Msg/gras_msg_exchange.c index ed0b3ddc63..e07793704b 100644 --- a/src/gras/Msg/gras_msg_exchange.c +++ b/src/gras/Msg/gras_msg_exchange.c @@ -16,7 +16,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg); char _GRAS_header[6]; const char *e_gras_msg_kind_names[e_gras_msg_kind_count] = - { "UNKNOWN", "ONEWAY", "RPC call", "RPC answer", "RPC error" }; + { "UNKNOWN", "ONEWAY", "RPC call", "RPC answer", "RPC error" }; /** \brief Waits for a message to come in over a given socket. @@ -43,7 +43,7 @@ gras_msg_wait_ext_(double timeout, s_gras_msg_t msg; double start, now; gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cpt; xbt_assert0(msg_got, "msg_got is an output parameter"); @@ -198,7 +198,8 @@ static int gras_msg_wait_or_filter(gras_msg_t msg, void *ctx) */ void gras_msg_wait_or(double timeout, xbt_dynar_t msgt_want, - gras_msg_cb_ctx_t * ctx, int *msgt_got, void *payload) + gras_msg_cb_ctx_t * ctx, int *msgt_got, + void *payload) { s_gras_msg_t msg; @@ -229,7 +230,8 @@ void gras_msg_wait_or(double timeout, /** \brief Send the data pointed by \a payload as a message of type * \a msgtype to the peer \a sock */ -void gras_msg_send_(gras_socket_t sock, gras_msgtype_t msgtype, void *payload) +void gras_msg_send_(gras_socket_t sock, gras_msgtype_t msgtype, + void *payload) { if (msgtype->ctn_type) { @@ -299,7 +301,7 @@ void gras_msg_handle(double timeOut) s_gras_msg_t msg; gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); gras_cblist_t *list = NULL; gras_msg_cb_t cb; s_gras_msg_cb_ctx_t ctx; @@ -353,8 +355,8 @@ void gras_msg_handle(double timeOut) xbt_assert1(untiltimer > 0, "Negative timer (%f). I'm 'puzzeled'", untiltimer); WARN1 - ("No timer elapsed, in contrary to expectations (next in %f sec)", - untiltimer); + ("No timer elapsed, in contrary to expectations (next in %f sec)", + untiltimer); THROW1(timeout_error, 0, "No timer elapsed, in contrary to expectations (next in %f sec)", untiltimer); @@ -378,9 +380,9 @@ void gras_msg_handle(double timeOut) } if (!list) { INFO4 - ("No callback for message '%s' (type:%s) from %s:%d. Queue it for later gras_msg_wait() use.", - msg.type->name, e_gras_msg_kind_names[msg.kind], - gras_socket_peer_name(msg.expe), gras_socket_peer_port(msg.expe)); + ("No callback for message '%s' (type:%s) from %s:%d. Queue it for later gras_msg_wait() use.", + msg.type->name, e_gras_msg_kind_names[msg.kind], + gras_socket_peer_name(msg.expe), gras_socket_peer_port(msg.expe)); xbt_dynar_push(pd->msg_waitqueue, &msg); return; /* FIXME: maybe we should call ourselves again until the end of the timer or a proper msg is got */ } @@ -398,8 +400,8 @@ void gras_msg_handle(double timeOut) xbt_dynar_foreach(list->cbs, cpt, cb) { if (!ran_ok) { DEBUG4 - ("Use the callback #%d (@%p) for incomming msg '%s' (payload_size=%d)", - cpt + 1, cb, msg.type->name, msg.payl_size); + ("Use the callback #%d (@%p) for incomming msg '%s' (payload_size=%d)", + cpt + 1, cb, msg.type->name, msg.payl_size); if (!(*cb) (&ctx, msg.payl)) { /* cb handled the message */ free(msg.payl); @@ -422,12 +424,11 @@ void gras_msg_handle(double timeOut) e.host = (char *) gras_os_myname(); xbt_ex_setup_backtrace(&e); } - INFO5("Propagate %s exception ('%s') from '%s' RPC cb back to %s:%d", - (e.remote ? "remote" : "local"), - e.msg, - msg.type->name, - gras_socket_peer_name(msg.expe), - gras_socket_peer_port(msg.expe)); + INFO5 + ("Propagate %s exception ('%s') from '%s' RPC cb back to %s:%d", + (e.remote ? "remote" : "local"), e.msg, msg.type->name, + gras_socket_peer_name(msg.expe), + gras_socket_peer_port(msg.expe)); if (XBT_LOG_ISENABLED(gras_msg, xbt_log_priority_verbose)) xbt_ex_display(&e); gras_msg_send_ext(msg.expe, e_gras_msg_kind_rpcerror, @@ -438,8 +439,8 @@ void gras_msg_handle(double timeOut) ran_ok = 1; } else { RETHROW4 - ("Callback #%d (@%p) to message '%s' (payload size: %d) raised an exception: %s", - cpt + 1, cb, msg.type->name, msg.payl_size); + ("Callback #%d (@%p) to message '%s' (payload size: %d) raised an exception: %s", + cpt + 1, cb, msg.type->name, msg.payl_size); } } @@ -448,9 +449,9 @@ void gras_msg_handle(double timeOut) msg.type->name); if (ctx.answer_due) CRITICAL1 - ("BUGS BOTH IN USER CODE (RPC callback to message '%s' didn't call gras_msg_rpcreturn) " - "AND IN SIMGRID (process wasn't killed by an assert)", - msg.type->name); + ("BUGS BOTH IN USER CODE (RPC callback to message '%s' didn't call gras_msg_rpcreturn) " + "AND IN SIMGRID (process wasn't killed by an assert)", + msg.type->name); if (!ran_ok) THROW1(mismatch_error, 0, "Message '%s' refused by all registered callbacks (maybe your callback misses a 'return 0' at the end)", @@ -463,14 +464,16 @@ void gras_msg_handle(double timeOut) INFO3("Unexpected RPC answer discarded (type: %s; from:%s:%d)", msg.type->name, gras_socket_peer_name(msg.expe), gras_socket_peer_port(msg.expe)); - WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload"); + WARN0 + ("FIXME: gras_datadesc_free not implemented => leaking the payload"); return; case e_gras_msg_kind_rpcerror: INFO3("Unexpected RPC error discarded (type: %s; from:%s:%d)", msg.type->name, gras_socket_peer_name(msg.expe), gras_socket_peer_port(msg.expe)); - WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload"); + WARN0 + ("FIXME: gras_datadesc_free not implemented => leaking the payload"); return; default: diff --git a/src/gras/Msg/gras_msg_listener.c b/src/gras/Msg/gras_msg_listener.c index e96f96d184..ef7057b055 100644 --- a/src/gras/Msg/gras_msg_listener.c +++ b/src/gras/Msg/gras_msg_listener.c @@ -18,12 +18,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_msg_read, gras_msg, #include "gras/Transport/transport_interface.h" /* gras_select */ typedef struct s_gras_msg_listener_ { - xbt_queue_t incomming_messages; /* messages received from the wire and still to be used by master */ + xbt_queue_t incomming_messages; /* messages received from the wire and still to be used by master */ xbt_queue_t socks_to_close; /* let the listener close the sockets, since it may be selecting on them. Darwin don't like this trick */ gras_socket_t wakeup_sock_listener_side; gras_socket_t wakeup_sock_master_side; - xbt_mutex_t init_mutex; /* both this mutex and condition are used at initialization to make sure that*/ - xbt_cond_t init_cond; /* the main thread speaks to the listener only once it is started (FIXME: It would be easier using a semaphore, if only semaphores were in xbt_synchro) */ + xbt_mutex_t init_mutex; /* both this mutex and condition are used at initialization to make sure that */ + xbt_cond_t init_cond; /* the main thread speaks to the listener only once it is started (FIXME: It would be easier using a semaphore, if only semaphores were in xbt_synchro) */ xbt_thread_t listener; } s_gras_msg_listener_t; @@ -33,11 +33,12 @@ static void listener_function(void *p) gras_msg_t msg; xbt_ex_t e; gras_msgtype_t msg_wakeup_listener_t = - gras_msgtype_by_name("_wakeup_listener"); + gras_msgtype_by_name("_wakeup_listener"); DEBUG0("I'm the listener"); /* get a free socket for the receiving part of the listener */ - me->wakeup_sock_listener_side = gras_socket_server_range(5000, 6000, -1, 0); + me->wakeup_sock_listener_side = + gras_socket_server_range(5000, 6000, -1, 0); /* wake up the launcher */ xbt_mutex_acquire(me->init_mutex); @@ -49,7 +50,7 @@ static void listener_function(void *p) msg = gras_msg_recv_any(); if (msg->type != msg_wakeup_listener_t) { VERB1("Got a '%s' message. Queue it for handling by main thread", - gras_msgtype_get_name(msg->type)); + gras_msgtype_get_name(msg->type)); xbt_queue_push(me->incomming_messages, msg); } else { char got = *(char *) msg->payl; @@ -72,7 +73,8 @@ static void listener_function(void *p) xbt_queue_shift_timed(me->socks_to_close, &sock, 0); if (tcp_close(sock) < 0) { #ifdef _XBT_WIN32 - WARN2("error while closing tcp socket %d: %d\n", sock, sock_errno); + WARN2("error while closing tcp socket %d: %d\n", sock, + sock_errno); #else WARN3("error while closing tcp socket %d: %d (%s)\n", sock, sock_errno, sock_errstr(sock_errno)); @@ -104,7 +106,9 @@ gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_received) /* actually start the thread, and */ /* wait for the listener to initialize before we connect to its socket */ xbt_mutex_acquire(arg->init_mutex); - arg->listener = xbt_thread_create("listener", listener_function, arg,1/*joinable*/); + arg->listener = + xbt_thread_create("listener", listener_function, arg, + 1 /*joinable */ ); xbt_cond_wait(arg->init_cond, arg->init_mutex); xbt_mutex_release(arg->init_mutex); xbt_cond_destroy(arg->init_cond); @@ -112,8 +116,9 @@ gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_received) /* Connect the other part of the socket */ arg->wakeup_sock_master_side = - gras_socket_client(gras_os_myname(), - gras_socket_my_port(arg->wakeup_sock_listener_side)); + gras_socket_client(gras_os_myname(), + gras_socket_my_port + (arg->wakeup_sock_listener_side)); return arg; } @@ -125,8 +130,8 @@ void gras_msg_listener_shutdown() DEBUG0("Listener quit"); if (pd->listener) - gras_msg_send(pd->listener->wakeup_sock_master_side, "_wakeup_listener", - &kill); + gras_msg_send(pd->listener->wakeup_sock_master_side, + "_wakeup_listener", &kill); xbt_thread_join(pd->listener->listener); @@ -144,8 +149,8 @@ void gras_msg_listener_awake() DEBUG0("Awaking the listener"); pd = gras_procdata_get(); if (pd->listener) { - gras_msg_send(pd->listener->wakeup_sock_master_side, "_wakeup_listener", - &c); + gras_msg_send(pd->listener->wakeup_sock_master_side, + "_wakeup_listener", &c); } } diff --git a/src/gras/Msg/gras_msg_mod.c b/src/gras/Msg/gras_msg_mod.c index d9a6322da1..fd330100b3 100644 --- a/src/gras/Msg/gras_msg_mod.c +++ b/src/gras/Msg/gras_msg_mod.c @@ -59,8 +59,8 @@ int gras_msg_libdata_id; void gras_msg_register() { gras_msg_libdata_id = - gras_procdata_add("gras_msg", gras_msg_procdata_new, - gras_msg_procdata_free); + gras_procdata_add("gras_msg", gras_msg_procdata_new, + gras_msg_procdata_free); } /* @@ -81,10 +81,10 @@ void gras_msg_init(void) _GRAS_header[5] = (char) GRAS_THISARCH; gras_msg_ctx_mallocator = - xbt_mallocator_new(1000, - gras_msg_ctx_mallocator_new_f, - gras_msg_ctx_mallocator_free_f, - gras_msg_ctx_mallocator_reset_f); + xbt_mallocator_new(1000, + gras_msg_ctx_mallocator_new_f, + gras_msg_ctx_mallocator_free_f, + gras_msg_ctx_mallocator_reset_f); } /* diff --git a/src/gras/Msg/gras_msg_types.c b/src/gras/Msg/gras_msg_types.c index 0ea75e4e6f..73f4a47d61 100644 --- a/src/gras/Msg/gras_msg_types.c +++ b/src/gras/Msg/gras_msg_types.c @@ -82,7 +82,8 @@ gras_msgtype_declare_ext(const char *name, xbt_ex_t e; TRY { - msgtype = (gras_msgtype_t) xbt_set_get_by_name(_gras_msgtype_set, namev); + msgtype = + (gras_msgtype_t) xbt_set_get_by_name(_gras_msgtype_set, namev); found = 1; } CATCH(e) { if (e.category != not_found_error) { @@ -94,18 +95,20 @@ gras_msgtype_declare_ext(const char *name, if (found) { VERB2 - ("Re-register version %d of message '%s' (same kind & payload, ignored).", - version, name); + ("Re-register version %d of message '%s' (same kind & payload, ignored).", + version, name); xbt_assert3(msgtype->kind == kind, "Message %s re-registered as a %s (it was known as a %s)", namev, e_gras_msg_kind_names[kind], e_gras_msg_kind_names[msgtype->kind]); - xbt_assert3(!gras_datadesc_type_cmp(msgtype->ctn_type, payload_request), + xbt_assert3(!gras_datadesc_type_cmp + (msgtype->ctn_type, payload_request), "Message %s re-registred with another payload (%s was %s)", namev, gras_datadesc_get_name(payload_request), gras_datadesc_get_name(msgtype->ctn_type)); - xbt_assert3(!gras_datadesc_type_cmp(msgtype->answer_type, payload_answer), + xbt_assert3(!gras_datadesc_type_cmp + (msgtype->answer_type, payload_answer), "Message %s re-registred with another answer payload (%s was %s)", namev, gras_datadesc_get_name(payload_answer), gras_datadesc_get_name(msgtype->answer_type)); @@ -127,7 +130,8 @@ gras_msgtype_declare_ext(const char *name, msgtype->ctn_type = payload_request; msgtype->answer_type = payload_answer; - xbt_set_add(_gras_msgtype_set, (xbt_set_elm_t) msgtype, &gras_msgtype_free); + xbt_set_add(_gras_msgtype_set, (xbt_set_elm_t) msgtype, + &gras_msgtype_free); } @@ -200,7 +204,8 @@ gras_msgtype_t gras_msgtype_by_namev(const char *name, short int version) xbt_ex_free(e); } if (!found) - THROW1(not_found_error, 0, "No registred message of that name: %s", name); + THROW1(not_found_error, 0, "No registred message of that name: %s", + name); free(namev); @@ -217,7 +222,8 @@ gras_msgtype_t gras_msgtype_by_id(int id) /* GETTERS */ /* ******************************************************************** */ -XBT_INLINE const char* gras_msgtype_get_name(gras_msgtype_t type) { +XBT_INLINE const char *gras_msgtype_get_name(gras_msgtype_t type) +{ return type->name; } @@ -244,7 +250,7 @@ void gras_cbl_free(void *data) void gras_cb_register_(gras_msgtype_t msgtype, gras_msg_cb_t cb) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); gras_cblist_t *list = NULL; unsigned int cpt; @@ -275,7 +281,7 @@ void gras_cb_unregister_(gras_msgtype_t msgtype, gras_msg_cb_t cb) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); gras_cblist_t *list; gras_msg_cb_t cb_cpt; unsigned int cpt; diff --git a/src/gras/Msg/msg_interface.h b/src/gras/Msg/msg_interface.h index 9e968a4624..2905b0cfda 100644 --- a/src/gras/Msg/msg_interface.h +++ b/src/gras/Msg/msg_interface.h @@ -53,4 +53,4 @@ void gras_msg_listener_close_socket(int sd); #define GRAS_PROTOCOL_VERSION '\1'; -#endif /* GRAS_MSG_INTERFACE_H */ +#endif /* GRAS_MSG_INTERFACE_H */ diff --git a/src/gras/Msg/msg_private.h b/src/gras/Msg/msg_private.h index 79321a2e13..b760e08724 100644 --- a/src/gras/Msg/msg_private.h +++ b/src/gras/Msg/msg_private.h @@ -65,7 +65,7 @@ void gras_msgtype_free(void *msgtype); /* functions to extract msg from socket or put it on wire (depend RL vs SG) */ -gras_msg_t gras_msg_recv_any(void); /* Get first message arriving */ +gras_msg_t gras_msg_recv_any(void); /* Get first message arriving */ void gras_msg_recv(gras_socket_t sock, gras_msg_t msg /*OUT*/); void gras_msg_send_ext(gras_socket_t sock, e_gras_msg_kind_t kind, @@ -134,4 +134,4 @@ void gras_msg_ctx_mallocator_free_f(void *dict); void gras_msg_ctx_mallocator_reset_f(void *dict); -#endif /* GRAS_MESSAGE_PRIVATE_H */ +#endif /* GRAS_MESSAGE_PRIVATE_H */ diff --git a/src/gras/Msg/rl_msg.c b/src/gras/Msg/rl_msg.c index c09210a7c1..25860b070c 100644 --- a/src/gras/Msg/rl_msg.c +++ b/src/gras/Msg/rl_msg.c @@ -17,8 +17,9 @@ XBT_LOG_DEFAULT_CATEGORY(gras_msg); void gras_msg_recv(gras_socket_t sock, gras_msg_t msg); -gras_msg_t gras_msg_recv_any(void) { - gras_msg_t msg = xbt_new0(s_gras_msg_t,1); +gras_msg_t gras_msg_recv_any(void) +{ + gras_msg_t msg = xbt_new0(s_gras_msg_t, 1); msg->expe = gras_trp_select(-1); DEBUG0("Select returned something"); gras_msg_recv(msg->expe, msg); @@ -117,7 +118,8 @@ void gras_msg_recv(gras_socket_t sock, gras_msg_t msg) msg->kind = (e_gras_msg_kind_t) c_kind; } CATCH(e) { - RETHROW0("Exception caught while trying to get the message header: %s"); + RETHROW0 + ("Exception caught while trying to get the message header: %s"); } for (cpt = 0; cpt < 4; cpt++) @@ -146,13 +148,13 @@ void gras_msg_recv(gras_socket_t sock, gras_msg_t msg) gras_datadesc_recv(sock, string_type, r_arch, &msg_name); DEBUG4 - ("Handle an incoming message '%s' (%s) using protocol %d (remote is %s)", - msg_name, e_gras_msg_kind_names[msg->kind], (int) header[4], - gras_datadesc_arch_name(r_arch)); + ("Handle an incoming message '%s' (%s) using protocol %d (remote is %s)", + msg_name, e_gras_msg_kind_names[msg->kind], (int) header[4], + gras_datadesc_arch_name(r_arch)); TRY { msg->type = - (gras_msgtype_t) xbt_set_get_by_name(_gras_msgtype_set, msg_name); + (gras_msgtype_t) xbt_set_get_by_name(_gras_msgtype_set, msg_name); } CATCH(e) { /* FIXME: Survive unknown messages */ if (e.category == not_found_error) { @@ -162,8 +164,8 @@ void gras_msg_recv(gras_socket_t sock, gras_msg_t msg) msg_name); } else RETHROW1 - ("Exception caught while retrieving the type associated to messages '%s' : %s", - msg_name); + ("Exception caught while retrieving the type associated to messages '%s' : %s", + msg_name); } free(msg_name); diff --git a/src/gras/Msg/rpc.c b/src/gras/Msg/rpc.c index 1bdad030cc..61dc2fda9f 100644 --- a/src/gras/Msg/rpc.c +++ b/src/gras/Msg/rpc.c @@ -69,16 +69,16 @@ static int msgfilter_rpcID(gras_msg_t msg, void *ctx) { unsigned long int ID = *(unsigned long int *) ctx; int res = msg->ID == ID && - (msg->kind == e_gras_msg_kind_rpcanswer - || msg->kind == e_gras_msg_kind_rpcerror); + (msg->kind == e_gras_msg_kind_rpcanswer + || msg->kind == e_gras_msg_kind_rpcerror); unsigned int cursor; gras_msg_cb_ctx_t rpc_ctx; DEBUG5 - ("Filter a message of ID %lu, type '%s' and kind '%s'. Waiting for ID=%lu. %s", - msg->ID, msg->type->name, e_gras_msg_kind_names[msg->kind], ID, - res ? "take it" : "reject"); + ("Filter a message of ID %lu, type '%s' and kind '%s'. Waiting for ID=%lu. %s", + msg->ID, msg->type->name, e_gras_msg_kind_names[msg->kind], ID, + res ? "take it" : "reject"); if (res && !_gras_rpc_cancelled) return res; @@ -87,8 +87,8 @@ static int msgfilter_rpcID(gras_msg_t msg, void *ctx) xbt_dynar_foreach(_gras_rpc_cancelled, cursor, rpc_ctx) { if (msg->ID == rpc_ctx->ID && msg->kind == e_gras_msg_kind_rpcanswer) { VERB1 - ("Got an answer to the already canceled (timeouted?) RPC %ld. Ignore it (leaking the payload!).", - msg->ID); + ("Got an answer to the already canceled (timeouted?) RPC %ld. Ignore it (leaking the payload!).", + msg->ID); xbt_dynar_cursor_rm(_gras_rpc_cancelled, &cursor); return 1; } @@ -128,7 +128,8 @@ gras_msg_rpc_async_call_(gras_socket_t server, msgtype->name); } else { xbt_assert1(!request, - "No payload was declared for RPC type '%s'", msgtype->name); + "No payload was declared for RPC type '%s'", + msgtype->name); } ctx->ID = last_msg_ID++; @@ -175,10 +176,11 @@ void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, void *answer) if (!_gras_rpc_cancelled) _gras_rpc_cancelled = xbt_dynar_new(sizeof(ctx), NULL); xbt_dynar_push(_gras_rpc_cancelled, &ctx); - INFO5("canceled RPC %ld pushed onto the stack (%s from %s:%d) Reason: %s", - ctx->ID, ctx->msgtype->name, - gras_socket_peer_name(ctx->expeditor), - gras_socket_peer_port(ctx->expeditor), e.msg); + INFO5 + ("canceled RPC %ld pushed onto the stack (%s from %s:%d) Reason: %s", + ctx->ID, ctx->msgtype->name, + gras_socket_peer_name(ctx->expeditor), + gras_socket_peer_port(ctx->expeditor), e.msg); RETHROW; } @@ -201,7 +203,8 @@ void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, void *answer) __xbt_ex_ctx()->ctx_ex.func = e.func; __xbt_ex_ctx()->ctx_ex.used = e.used; __xbt_ex_ctx()->ctx_ex.bt_strings = e.bt_strings; - memset(&__xbt_ex_ctx()->ctx_ex.bt, 0, sizeof(__xbt_ex_ctx()->ctx_ex.bt)); + memset(&__xbt_ex_ctx()->ctx_ex.bt, 0, + sizeof(__xbt_ex_ctx()->ctx_ex.bt)); DO_THROW(__xbt_ex_ctx()->ctx_ex); } memcpy(answer, received.payl, received.payl_size); @@ -227,7 +230,8 @@ void gras_msg_rpccall_(gras_socket_t server, * some cleanups before leaving. */ -void gras_msg_rpcreturn(double timeOut, gras_msg_cb_ctx_t ctx, void *answer) +void gras_msg_rpcreturn(double timeOut, gras_msg_cb_ctx_t ctx, + void *answer) { xbt_assert0(ctx->answer_due, "RPC return not allowed here. Either not a RPC message or already returned a result"); diff --git a/src/gras/Msg/sg_msg.c b/src/gras/Msg/sg_msg.c index 69dd85f5cb..f82f99afc9 100644 --- a/src/gras/Msg/sg_msg.c +++ b/src/gras/Msg/sg_msg.c @@ -20,26 +20,31 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg); typedef void *gras_trp_bufdata_; -gras_msg_t gras_msg_recv_any(void) { +gras_msg_t gras_msg_recv_any(void) +{ gras_trp_procdata_t trp_proc = (gras_trp_procdata_t) gras_libdata_by_name("gras_trp"); gras_msg_t msg; /* Build a dynar of all communications I could get something from */ - xbt_dynar_t comms = xbt_dynar_new(sizeof(smx_comm_t),NULL); + xbt_dynar_t comms = xbt_dynar_new(sizeof(smx_comm_t), NULL); unsigned int cursor = 0; int got = 0; smx_comm_t comm = NULL; gras_socket_t sock = NULL; gras_trp_sg_sock_data_t sock_data; - xbt_dynar_foreach(trp_proc->sockets,cursor,sock) { + xbt_dynar_foreach(trp_proc->sockets, cursor, sock) { sock_data = (gras_trp_sg_sock_data_t) sock->data; - DEBUG5("Consider socket %p (data:%p; Here rdv: %p; Remote rdv: %p; Comm %p) to get a message", - sock,sock_data, - (sock_data->server==SIMIX_process_self())?sock_data->rdv_server:sock_data->rdv_client, - (sock_data->server==SIMIX_process_self())?sock_data->rdv_client:sock_data->rdv_server, - sock_data->comm_recv); + DEBUG5 + ("Consider socket %p (data:%p; Here rdv: %p; Remote rdv: %p; Comm %p) to get a message", + sock, sock_data, + (sock_data->server == + SIMIX_process_self())? sock_data-> + rdv_server : sock_data->rdv_client, + (sock_data->server == + SIMIX_process_self())? sock_data-> + rdv_client : sock_data->rdv_server, sock_data->comm_recv); /* The following assert fails in some valid conditions, we need to @@ -70,28 +75,33 @@ gras_msg_t gras_msg_recv_any(void) { * when that iterator is equal to "got", the result of waitany. Not needed if B holds. */ xbt_assert1(sock_data->comm_recv, - "Comm_recv of socket %p is empty; please report that nasty bug",sock); + "Comm_recv of socket %p is empty; please report that nasty bug", + sock); /* End of paranoia */ VERB3("Copy comm_recv %p rdv:%p (other rdv:%p)", - sock_data->comm_recv, - (sock_data->server==SIMIX_process_self())?sock_data->rdv_server:sock_data->rdv_client, - (sock_data->server==SIMIX_process_self())?sock_data->rdv_client:sock_data->rdv_server); - xbt_dynar_push(comms,&(sock_data->comm_recv)); + sock_data->comm_recv, + (sock_data->server == + SIMIX_process_self())? sock_data-> + rdv_server : sock_data->rdv_client, + (sock_data->server == + SIMIX_process_self())? sock_data-> + rdv_client : sock_data->rdv_server); + xbt_dynar_push(comms, &(sock_data->comm_recv)); } - VERB1("Wait on %ld 'sockets'",xbt_dynar_length(comms)); + VERB1("Wait on %ld 'sockets'", xbt_dynar_length(comms)); /* Wait for the end of any of these communications */ got = SIMIX_network_waitany(comms); /* retrieve the message sent in that communication */ - xbt_dynar_get_cpy(comms,got,&(comm)); - msg=SIMIX_communication_get_data(comm); - VERB1("Got something. Communication %p's over",comm); + xbt_dynar_get_cpy(comms, got, &(comm)); + msg = SIMIX_communication_get_data(comm); + VERB1("Got something. Communication %p's over", comm); /* Reinstall a waiting communication on that rdv */ /* Get the sock again * For that, we use the fact that */ - sock=xbt_dynar_get_as(trp_proc->sockets,got,gras_socket_t); + sock = xbt_dynar_get_as(trp_proc->sockets, got, gras_socket_t); /* xbt_dynar_foreach(trp_proc->sockets,cursor,sock) { sock_data = (gras_trp_sg_sock_data_t) sock->data; if (sock_data->comm_recv && sock_data->comm_recv == comm) @@ -99,12 +109,11 @@ gras_msg_t gras_msg_recv_any(void) { } */ sock_data = (gras_trp_sg_sock_data_t) sock->data; - sock_data->comm_recv = SIMIX_network_irecv( - sock_data->rdv_server!=NULL? - //(sock_data->server==SIMIX_process_self())? - sock_data->rdv_server - :sock_data->rdv_client, - NULL,0); + sock_data->comm_recv = + SIMIX_network_irecv(sock_data->rdv_server != NULL ? + //(sock_data->server==SIMIX_process_self())? + sock_data->rdv_server + : sock_data->rdv_client, NULL, 0); return msg; } @@ -121,8 +130,10 @@ void gras_msg_send_ext(gras_socket_t sock, smx_comm_t comm; gras_trp_sg_sock_data_t sock_data = (gras_trp_sg_sock_data_t) sock->data; - smx_rdv_t target_rdv = (sock_data->server==SIMIX_process_self())?sock_data->rdv_client - :sock_data->rdv_server; + smx_rdv_t target_rdv = + (sock_data->server == + SIMIX_process_self())? sock_data-> + rdv_client : sock_data->rdv_server; /*initialize gras message */ msg = xbt_new(s_gras_msg_t, 1); @@ -131,14 +142,15 @@ void gras_msg_send_ext(gras_socket_t sock, msg->type = msgtype; msg->ID = ID; - VERB2("Send msg %s to rdv %p", msgtype->name,target_rdv); + VERB2("Send msg %s to rdv %p", msgtype->name, target_rdv); if (kind == e_gras_msg_kind_rpcerror) { /* error on remote host, careful, payload is an exception */ msg->payl_size = gras_datadesc_size(gras_datadesc_by_name("ex_t")); msg->payl = xbt_malloc(msg->payl_size); - whole_payload_size = gras_datadesc_memcpy(gras_datadesc_by_name("ex_t"), - payload, msg->payl); + whole_payload_size = + gras_datadesc_memcpy(gras_datadesc_by_name("ex_t"), payload, + msg->payl); } else if (kind == e_gras_msg_kind_rpcanswer) { msg->payl_size = gras_datadesc_size(msgtype->answer_type); if (msg->payl_size) @@ -157,9 +169,9 @@ void gras_msg_send_ext(gras_socket_t sock, payload, msg->payl); } - SIMIX_network_send(target_rdv, whole_payload_size,-1,-1,&msg,sizeof(void*),&comm,msg); + SIMIX_network_send(target_rdv, whole_payload_size, -1, -1, &msg, + sizeof(void *), &comm, msg); VERB0("Message sent"); } - diff --git a/src/gras/Msg/timer.c b/src/gras/Msg/timer.c index ca596c3d69..3860423cec 100644 --- a/src/gras/Msg/timer.c +++ b/src/gras/Msg/timer.c @@ -19,7 +19,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_timer, gras, void gras_timer_delay(double delay, void_f_void_t action) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); @@ -34,7 +34,7 @@ void gras_timer_delay(double delay, void_f_void_t action) void gras_timer_repeat(double interval, void_f_void_t action) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); gras_timer_t timer = xbt_dynar_push_ptr(pd->timers); @@ -49,7 +49,7 @@ void gras_timer_repeat(double interval, void_f_void_t action) void gras_timer_cancel_delay(double interval, void_f_void_t action) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cursor; int found; s_gras_timer_t timer; @@ -75,7 +75,7 @@ void gras_timer_cancel_delay(double interval, void_f_void_t action) void gras_timer_cancel_repeat(double interval, void_f_void_t action) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cursor; int found; s_gras_timer_t timer; @@ -100,7 +100,7 @@ void gras_timer_cancel_repeat(double interval, void_f_void_t action) void gras_timer_cancel_delay_all(void) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cursor; int found; s_gras_timer_t timer; @@ -123,7 +123,7 @@ void gras_timer_cancel_delay_all(void) void gras_timer_cancel_repeat_all(void) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cursor; int found; s_gras_timer_t timer; @@ -145,7 +145,7 @@ void gras_timer_cancel_repeat_all(void) void gras_timer_cancel_all(void) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); xbt_dynar_reset(pd->timers); } @@ -154,7 +154,7 @@ void gras_timer_cancel_all(void) double gras_msg_timer_handle(void) { gras_msg_procdata_t pd = - (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); + (gras_msg_procdata_t) gras_libdata_by_id(gras_msg_libdata_id); unsigned int cursor; gras_timer_t timer; double now = gras_os_time(); @@ -178,7 +178,8 @@ double gras_msg_timer_handle(void) if (timer->repeat) { timer->expiry = now + timer->period; DEBUG4("[%.0f] Re-arm repetitive action %p for %f (period=%f)", - gras_os_time(), timer->action, timer->expiry, timer->period); + gras_os_time(), timer->action, timer->expiry, + timer->period); } else { DEBUG2("[%.0f] Remove %p now that it's done", gras_os_time(), timer->action); diff --git a/src/gras/Transport/rl_transport.c b/src/gras/Transport/rl_transport.c index 7125039736..7b8ff2e416 100644 --- a/src/gras/Transport/rl_transport.c +++ b/src/gras/Transport/rl_transport.c @@ -27,7 +27,8 @@ gras_socket_t _gras_lastly_selected_socket = NULL; gras_socket_t gras_trp_select(double timeout) { xbt_dynar_t sockets = - ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets; + ((gras_trp_procdata_t) + gras_libdata_by_id(gras_trp_libdata_id))->sockets; int done = -1; double wakeup = gras_os_time() + timeout; double now = 0; @@ -47,9 +48,10 @@ gras_socket_t gras_trp_select(double timeout) /* Check whether there is more data to read from the socket we selected last time. This can happen with tcp buffered sockets since we try to get as much data as we can for them */ - if (_gras_lastly_selected_socket && _gras_lastly_selected_socket->moredata) { + if (_gras_lastly_selected_socket + && _gras_lastly_selected_socket->moredata) { VERB0 - ("Returning _gras_lastly_selected_socket since there is more data on it"); + ("Returning _gras_lastly_selected_socket since there is more data on it"); return _gras_lastly_selected_socket; } @@ -62,7 +64,7 @@ gras_socket_t gras_trp_select(double timeout) fd_setsize = getdtablesize(); # else fd_setsize = FD_SETSIZE; -# endif /* !USE_SYSCONF */ +# endif /* !USE_SYSCONF */ #endif } @@ -130,7 +132,7 @@ gras_socket_t gras_trp_select(double timeout) /* set the timeout */ tout.tv_sec = (unsigned long) (wakeup - now); tout.tv_usec = - ((wakeup - now) - ((unsigned long) (wakeup - now))) * 1000000; + ((wakeup - now) - ((unsigned long) (wakeup - now))) * 1000000; p_tout = &tout; } else if (timeout == 0) { /* polling only */ @@ -144,7 +146,8 @@ gras_socket_t gras_trp_select(double timeout) p_tout = NULL; } - DEBUG2("Selecting over %d socket(s); timeout=%f", max_fds - 1, timeout); + DEBUG2("Selecting over %d socket(s); timeout=%f", max_fds - 1, + timeout); ready = select(max_fds, &FDS, NULL, NULL, p_tout); DEBUG1("select returned %d", ready); if (ready == -1) { diff --git a/src/gras/Transport/sg_transport.c b/src/gras/Transport/sg_transport.c index 83586d21c1..6079f08acb 100644 --- a/src/gras/Transport/sg_transport.c +++ b/src/gras/Transport/sg_transport.c @@ -32,7 +32,7 @@ gras_socket_t gras_trp_select(double timeout) { gras_socket_t res; gras_trp_procdata_t pd = - (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); + (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); gras_trp_sg_sock_data_t *sockdata; gras_trp_plugin_t trp; gras_socket_t active_socket = NULL; @@ -103,7 +103,7 @@ gras_socket_t gras_trp_select(double timeout) res->peer_port = ((gras_trp_procdata_t) gras_libdata_by_name_from_remote("gras_trp", sockdata->to_process))-> - myport; + myport; sockdata->to_socket = active_socket; /*update the peer to_socket variable */ active_socket_data->to_socket = res; @@ -111,7 +111,7 @@ gras_socket_t gras_trp_select(double timeout) sockdata->mutex = SIMIX_mutex_init(); sockdata->to_host = - SIMIX_process_get_host(active_socket_data->from_process); + SIMIX_process_get_host(active_socket_data->from_process); res->data = sockdata; res->peer_name = strdup(SIMIX_host_get_name(sockdata->to_host)); diff --git a/src/gras/Transport/transport.c b/src/gras/Transport/transport.c index c993dceb9d..ed3f43eb46 100644 --- a/src/gras/Transport/transport.c +++ b/src/gras/Transport/transport.c @@ -218,10 +218,11 @@ gras_socket_server_ext(unsigned short port, } if (!measurement) - ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport = - port; + ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->myport + = port; xbt_dynar_push(((gras_trp_procdata_t) - gras_libdata_by_id(gras_trp_libdata_id))->sockets, &sock); + gras_libdata_by_id(gras_trp_libdata_id))->sockets, + &sock); gras_msg_listener_awake(); return sock; @@ -282,7 +283,8 @@ gras_socket_client_ext(const char *host, trp = gras_trp_plugin_get_by_name(gras_if_SG()? "sg" : "tcp"); - DEBUG1("Create a client socket from plugin %s", gras_if_RL()? "tcp" : "sg"); + DEBUG1("Create a client socket from plugin %s", + gras_if_RL()? "tcp" : "sg"); /* defaults settings */ gras_trp_socket_new(0, &sock); sock->plugin = trp; @@ -302,7 +304,8 @@ gras_socket_client_ext(const char *host, RETHROW; } xbt_dynar_push(((gras_trp_procdata_t) - gras_libdata_by_id(gras_trp_libdata_id))->sockets, &sock); + gras_libdata_by_id(gras_trp_libdata_id))->sockets, + &sock); gras_msg_listener_awake(); return sock; } @@ -332,15 +335,17 @@ gras_socket_t gras_socket_client_from_string(const char *host) return res; } -void gras_socket_close_voidp(void *sock) { - gras_socket_close((gras_socket_t)sock); +void gras_socket_close_voidp(void *sock) +{ + gras_socket_close((gras_socket_t) sock); } /** \brief Close socket */ void gras_socket_close(gras_socket_t sock) { xbt_dynar_t sockets = - ((gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id))->sockets; + ((gras_trp_procdata_t) + gras_libdata_by_id(gras_trp_libdata_id))->sockets; gras_socket_t sock_iter = NULL; unsigned int cursor; @@ -352,7 +357,7 @@ void gras_socket_close(gras_socket_t sock) if (sock->moredata) CRITICAL0 - ("Closing a socket having more data in buffer. Option nomoredata_on_close disabled, so continuing."); + ("Closing a socket having more data in buffer. Option nomoredata_on_close disabled, so continuing."); _gras_lastly_selected_socket = NULL; } @@ -378,8 +383,9 @@ void gras_socket_close(gras_socket_t sock) return; } } - WARN1("Ignoring request to free an unknown socket (%p). Execution stack:", - sock); + WARN1 + ("Ignoring request to free an unknown socket (%p). Execution stack:", + sock); xbt_backtrace_display_current(); } XBT_OUT; @@ -494,14 +500,15 @@ void gras_socket_meas_send(gras_socket_t peer, for (sent_sofar = 0; sent_sofar < msg_amount; sent_sofar++) { CDEBUG5(gras_trp_meas, - "Sent %lu msgs of %lu (size of each: %ld) to %s:%d", sent_sofar, - msg_amount, msg_size, gras_socket_peer_name(peer), + "Sent %lu msgs of %lu (size of each: %ld) to %s:%d", + sent_sofar, msg_amount, msg_size, gras_socket_peer_name(peer), gras_socket_peer_port(peer)); (*peer->plugin->raw_send) (peer, chunk, msg_size); } - CDEBUG5(gras_trp_meas, "Sent %lu msgs of %lu (size of each: %ld) to %s:%d", - sent_sofar, msg_amount, msg_size, - gras_socket_peer_name(peer), gras_socket_peer_port(peer)); + CDEBUG5(gras_trp_meas, + "Sent %lu msgs of %lu (size of each: %ld) to %s:%d", sent_sofar, + msg_amount, msg_size, gras_socket_peer_name(peer), + gras_socket_peer_port(peer)); if (gras_if_RL()) free(chunk); @@ -539,14 +546,14 @@ void gras_socket_meas_recv(gras_socket_t peer, for (got_sofar = 0; got_sofar < msg_amount; got_sofar++) { CDEBUG5(gras_trp_meas, - "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d", got_sofar, - msg_amount, msg_size, gras_socket_peer_name(peer), + "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d", + got_sofar, msg_amount, msg_size, gras_socket_peer_name(peer), gras_socket_peer_port(peer)); (peer->plugin->raw_recv) (peer, chunk, msg_size); } CDEBUG5(gras_trp_meas, - "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d", got_sofar, - msg_amount, msg_size, gras_socket_peer_name(peer), + "Recvd %ld msgs of %lu (size of each: %ld) from %s:%d", + got_sofar, msg_amount, msg_size, gras_socket_peer_name(peer), gras_socket_peer_port(peer)); if (gras_if_RL()) @@ -617,7 +624,7 @@ static void gras_trp_procdata_free(void *data) void gras_trp_socketset_dump(const char *name) { gras_trp_procdata_t procdata = - (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); + (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); unsigned int it; gras_socket_t s; @@ -638,8 +645,8 @@ int gras_trp_libdata_id; void gras_trp_register() { gras_trp_libdata_id = - gras_procdata_add("gras_trp", gras_trp_procdata_new, - gras_trp_procdata_free); + gras_procdata_add("gras_trp", gras_trp_procdata_new, + gras_trp_procdata_free); } int gras_os_myport(void) diff --git a/src/gras/Transport/transport_interface.h b/src/gras/Transport/transport_interface.h index dcd12dcef8..49223a49bb 100644 --- a/src/gras/Transport/transport_interface.h +++ b/src/gras/Transport/transport_interface.h @@ -26,7 +26,8 @@ extern int gras_opt_trp_nomoredata_on_close; /* stable if we know the storage will keep as is until the next trp_flush */ XBT_PUBLIC(void) gras_trp_send(gras_socket_t sd, char *data, long int size, int stable); -XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, long int size); +XBT_PUBLIC(void) gras_trp_recv(gras_socket_t sd, char *data, + long int size); XBT_PUBLIC(void) gras_trp_flush(gras_socket_t sd); /* Find which socket needs to be read next */ @@ -41,73 +42,73 @@ XBT_PUBLIC(void) gras_socket_peer_proc_set(gras_socket_t sock, ***/ /* A plugin type */ - typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t; +typedef struct gras_trp_plugin_ s_gras_trp_plugin_t, *gras_trp_plugin_t; /* A plugin type */ - struct gras_trp_plugin_ { - char *name; +struct gras_trp_plugin_ { + char *name; - /* dst pointers are created and initialized with default values - before call to socket_client/server. - Retrive the info you need from there. */ - void (*socket_client) (gras_trp_plugin_t self, gras_socket_t dst); - void (*socket_server) (gras_trp_plugin_t self, gras_socket_t dst); + /* dst pointers are created and initialized with default values + before call to socket_client/server. + Retrive the info you need from there. */ + void (*socket_client) (gras_trp_plugin_t self, gras_socket_t dst); + void (*socket_server) (gras_trp_plugin_t self, gras_socket_t dst); - gras_socket_t(*socket_accept) (gras_socket_t from); + gras_socket_t(*socket_accept) (gras_socket_t from); - /* socket_close() is responsible of telling the OS that the socket is over, - but should not free the socket itself (beside the specific part) */ - void (*socket_close) (gras_socket_t sd); + /* socket_close() is responsible of telling the OS that the socket is over, + but should not free the socket itself (beside the specific part) */ + void (*socket_close) (gras_socket_t sd); - /* send/recv may be buffered */ - void (*send) (gras_socket_t sd, - const char *data, - unsigned long int size, - int stable /* storage will survive until flush */ ); - int (*recv) (gras_socket_t sd, char *data, unsigned long int size); - /* raw_send/raw_recv is never buffered (use it for measurement stuff) */ - void (*raw_send) (gras_socket_t sd, - const char *data, unsigned long int size); - int (*raw_recv) (gras_socket_t sd, char *data, unsigned long int size); + /* send/recv may be buffered */ + void (*send) (gras_socket_t sd, + const char *data, + unsigned long int size, + int stable /* storage will survive until flush */ ); + int (*recv) (gras_socket_t sd, char *data, unsigned long int size); + /* raw_send/raw_recv is never buffered (use it for measurement stuff) */ + void (*raw_send) (gras_socket_t sd, + const char *data, unsigned long int size); + int (*raw_recv) (gras_socket_t sd, char *data, unsigned long int size); - /* flush has to make sure that the pending communications are achieved */ - void (*flush) (gras_socket_t sd); + /* flush has to make sure that the pending communications are achieved */ + void (*flush) (gras_socket_t sd); - void *data; /* plugin-specific data */ + void *data; /* plugin-specific data */ - /* exit is responsible for freeing data and telling to the OS that - this plugin is gone */ - /* exit=NULL, data gets brutally free()d by the generic interface. - (ie exit function needed only when data contains pointers) */ - void (*exit) (gras_trp_plugin_t); - }; + /* exit is responsible for freeing data and telling to the OS that + this plugin is gone */ + /* exit=NULL, data gets brutally free()d by the generic interface. + (ie exit function needed only when data contains pointers) */ + void (*exit) (gras_trp_plugin_t); +}; XBT_PUBLIC(gras_trp_plugin_t) - gras_trp_plugin_get_by_name(const char *name); + gras_trp_plugin_get_by_name(const char *name); /* Data of this module specific to each process * (used by sg_process.c to cleanup the SG channel cruft) */ - typedef struct { - /* set headers */ - unsigned int ID; - char *name; - unsigned int name_len; +typedef struct { + /* set headers */ + unsigned int ID; + char *name; + unsigned int name_len; - int myport; /* Port on which I listen myself */ + int myport; /* Port on which I listen myself */ - xbt_dynar_t sockets; /* all sockets known to this process */ + xbt_dynar_t sockets; /* all sockets known to this process */ - /* SG only elements. In RL, they are part of the OS ;) */ + /* SG only elements. In RL, they are part of the OS ;) */ - /* List of sockets ready to be select()ed */ - xbt_queue_t msg_selectable_sockets; /* regular sockets */ - xbt_queue_t meas_selectable_sockets; /* measurement ones */ + /* List of sockets ready to be select()ed */ + xbt_queue_t msg_selectable_sockets; /* regular sockets */ + xbt_queue_t meas_selectable_sockets; /* measurement ones */ - } s_gras_trp_procdata_t, *gras_trp_procdata_t; +} s_gras_trp_procdata_t, *gras_trp_procdata_t; /* Display the content of our socket set (debugging purpose) */ XBT_PUBLIC(void) gras_trp_socketset_dump(const char *name); -#endif /* GRAS_TRP_INTERFACE_H */ +#endif /* GRAS_TRP_INTERFACE_H */ diff --git a/src/gras/Transport/transport_plugin_file.c b/src/gras/Transport/transport_plugin_file.c index c112bb3d53..64859a574b 100644 --- a/src/gras/Transport/transport_plugin_file.c +++ b/src/gras/Transport/transport_plugin_file.c @@ -20,9 +20,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_trp_file, gras_trp, void gras_trp_file_close(gras_socket_t sd); void gras_trp_file_chunk_send_raw(gras_socket_t sd, - const char *data, unsigned long int size); -void gras_trp_file_chunk_send(gras_socket_t sd, - const char *data, + const char *data, + unsigned long int size); +void gras_trp_file_chunk_send(gras_socket_t sd, const char *data, unsigned long int size, int stable_ignored); int gras_trp_file_chunk_recv(gras_socket_t sd, @@ -81,8 +81,8 @@ gras_socket_t gras_socket_client_from_file(const char *path) if (strcmp("-", path)) { res->sd = - open(path, O_TRUNC | O_WRONLY | O_CREAT | O_BINARY, - S_IRUSR | S_IWUSR | S_IRGRP); + open(path, O_TRUNC | O_WRONLY | O_CREAT | O_BINARY, + S_IRUSR | S_IWUSR | S_IRGRP); if (res->sd < 0) { THROW2(system_error, 0, diff --git a/src/gras/Transport/transport_plugin_sg.c b/src/gras/Transport/transport_plugin_sg.c index 55bc0d240b..739a2a3c08 100644 --- a/src/gras/Transport/transport_plugin_sg.c +++ b/src/gras/Transport/transport_plugin_sg.c @@ -86,7 +86,8 @@ void gras_trp_sg_setup(gras_trp_plugin_t plug) } void gras_trp_sg_socket_client(gras_trp_plugin_t self, - /* OUT */ gras_socket_t sock) { + /* OUT */ gras_socket_t sock) +{ smx_host_t peer; gras_hostdata_t *hd; @@ -100,14 +101,15 @@ void gras_trp_sg_socket_client(gras_trp_plugin_t self, if (!(hd = (gras_hostdata_t *) SIMIX_host_get_data(peer))) THROW1(mismatch_error, 0, - "can't connect to %s: no process on this host", sock->peer_name); + "can't connect to %s: no process on this host", + sock->peer_name); pr = find_port(hd, sock->peer_port); if (pr == NULL) { THROW2(mismatch_error, 0, - "can't connect to %s:%d, no process listen on this port", - sock->peer_name, sock->peer_port); + "can't connect to %s:%d, no process listen on this port", + sock->peer_name, sock->peer_port); } /* Ensure that the listener is expecting the kind of stuff we want to send */ @@ -120,7 +122,8 @@ void gras_trp_sg_socket_client(gras_trp_plugin_t self, if (!pr->meas && sock->meas) { THROW2(mismatch_error, 0, "can't connect to %s:%d in measurement mode, the process listen " - "in regular mode on this port", sock->peer_name, sock->peer_port); + "in regular mode on this port", sock->peer_name, + sock->peer_port); } /* create simulation data of the socket */ @@ -131,7 +134,7 @@ void gras_trp_sg_socket_client(gras_trp_plugin_t self, /* initialize synchronization stuff on the socket */ data->rdv_server = pr->rdv; data->rdv_client = SIMIX_rdv_create(NULL); - data->comm_recv = SIMIX_network_irecv(data->rdv_client,NULL,0); + data->comm_recv = SIMIX_network_irecv(data->rdv_client, NULL, 0); /* connect that simulation data to the socket */ sock->data = data; @@ -139,14 +142,15 @@ void gras_trp_sg_socket_client(gras_trp_plugin_t self, DEBUG5("%s (PID %d) connects in %s mode to %s:%d", SIMIX_process_get_name(SIMIX_process_self()), gras_os_getpid(), - sock->meas ? "meas" : "regular", sock->peer_name, sock->peer_port); + sock->meas ? "meas" : "regular", sock->peer_name, + sock->peer_port); } void gras_trp_sg_socket_server(gras_trp_plugin_t self, gras_socket_t sock) { gras_hostdata_t *hd = - (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); + (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); gras_sg_portrec_t pr; gras_trp_sg_sock_data_t data; @@ -163,7 +167,7 @@ void gras_trp_sg_socket_server(gras_trp_plugin_t self, gras_socket_t sock) SIMIX_host_get_name(SIMIX_host_self()), sock->port); /* This port is free, let's take it */ - pr = xbt_new(s_gras_sg_portrec_t,1); + pr = xbt_new(s_gras_sg_portrec_t, 1); pr->port = sock->port; pr->meas = sock->meas; pr->server = SIMIX_process_self(); @@ -176,24 +180,27 @@ void gras_trp_sg_socket_server(gras_trp_plugin_t self, gras_socket_t sock) data->client = NULL; data->rdv_server = pr->rdv; data->rdv_client = NULL; - data->comm_recv = SIMIX_network_irecv(pr->rdv,NULL,0); + data->comm_recv = SIMIX_network_irecv(pr->rdv, NULL, 0); sock->data = data; - VERB10("'%s' (%d) ears on %s:%d%s (%p; data:%p); Here rdv: %p; Remote rdv: %p; Comm %p", - SIMIX_process_get_name(SIMIX_process_self()), gras_os_getpid(), - SIMIX_host_get_name(SIMIX_host_self()), sock->port, - sock->meas ? " (mode meas)" : "", sock,data, - (data->server==SIMIX_process_self())?data->rdv_server:data->rdv_client, - (data->server==SIMIX_process_self())?data->rdv_client:data->rdv_server, - data->comm_recv); + VERB10 + ("'%s' (%d) ears on %s:%d%s (%p; data:%p); Here rdv: %p; Remote rdv: %p; Comm %p", + SIMIX_process_get_name(SIMIX_process_self()), gras_os_getpid(), + SIMIX_host_get_name(SIMIX_host_self()), sock->port, + sock->meas ? " (mode meas)" : "", sock, data, + (data->server == + SIMIX_process_self())? data->rdv_server : data->rdv_client, + (data->server == + SIMIX_process_self())? data->rdv_client : data->rdv_server, + data->comm_recv); } void gras_trp_sg_socket_close(gras_socket_t sock) { gras_hostdata_t *hd = - (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); + (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); unsigned int cpt; gras_sg_portrec_t pr; @@ -219,8 +226,9 @@ void gras_trp_sg_socket_close(gras_socket_t sock) return; } } - WARN2("socket_close called on the unknown incoming socket %p (port=%d)", - sock, sock->port); + WARN2 + ("socket_close called on the unknown incoming socket %p (port=%d)", + sock, sock->port); } XBT_OUT; } @@ -257,13 +265,14 @@ void gras_trp_sg_chunk_send_raw(gras_socket_t sock, /* creates simix action and waits its ends, waits in the sender host condition */ - if (XBT_LOG_ISENABLED(gras_trp_sg,xbt_log_priority_debug)) { - smx_process_t remote_dude = (sock_data->server==SIMIX_process_self())?(sock_data->client):(sock_data->server); + if (XBT_LOG_ISENABLED(gras_trp_sg, xbt_log_priority_debug)) { + smx_process_t remote_dude = + (sock_data->server == + SIMIX_process_self())? (sock_data->client) : (sock_data->server); smx_host_t remote_host = SIMIX_process_get_host(remote_dude); DEBUG4("send chunk from %s to %s:%d (size=%ld)", - SIMIX_host_get_name(SIMIX_host_self()), - SIMIX_host_get_name(remote_host), - sock->peer_port, size); + SIMIX_host_get_name(SIMIX_host_self()), + SIMIX_host_get_name(remote_host), sock->peer_port, size); } //SIMIX_network_send(sock_data->rdv,size,1,-1,NULL,0,NULL,NULL); THROW_UNIMPLEMENTED; @@ -282,9 +291,9 @@ int gras_trp_sg_chunk_recv(gras_socket_t sock, gras_socket_t remote_socket = NULL; gras_msg_t msg_got; gras_msg_procdata_t msg_procdata = - (gras_msg_procdata_t) gras_libdata_by_name("gras_msg"); + (gras_msg_procdata_t) gras_libdata_by_name("gras_msg"); gras_trp_procdata_t trp_proc = - (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); + (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id); xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets"); diff --git a/src/gras/Transport/transport_plugin_tcp.c b/src/gras/Transport/transport_plugin_tcp.c index 114af0c5e3..ce5923d26e 100644 --- a/src/gras/Transport/transport_plugin_tcp.c +++ b/src/gras/Transport/transport_plugin_tcp.c @@ -63,7 +63,8 @@ struct gras_trp_bufdata_ { /*****************************/ /* we exchange port number on client side on socket creation, so we need to be able to talk right now. */ -static XBT_INLINE void gras_trp_tcp_send(gras_socket_t sock, const char *data, +static XBT_INLINE void gras_trp_tcp_send(gras_socket_t sock, + const char *data, unsigned long int size); static int gras_trp_tcp_recv(gras_socket_t sock, char *data, unsigned long int size); @@ -71,7 +72,8 @@ static int gras_trp_tcp_recv(gras_socket_t sock, char *data, static int _gras_tcp_proto_number(void); -static XBT_INLINE void gras_trp_sock_socket_client(gras_trp_plugin_t ignored, +static XBT_INLINE void gras_trp_sock_socket_client(gras_trp_plugin_t + ignored, gras_socket_t sock) { @@ -80,7 +82,8 @@ static XBT_INLINE void gras_trp_sock_socket_client(gras_trp_plugin_t ignored, struct in_addr *haddr; int size = sock->buf_size; uint32_t myport = htonl(((gras_trp_procdata_t) - gras_libdata_by_id(gras_trp_libdata_id))->myport); + gras_libdata_by_id + (gras_trp_libdata_id))->myport); sock->incoming = 1; /* TCP sockets are duplex'ed */ @@ -131,7 +134,8 @@ static XBT_INLINE void gras_trp_sock_socket_client(gras_trp_plugin_t ignored, * * Open a socket used to receive messages. */ -static XBT_INLINE void gras_trp_sock_socket_server(gras_trp_plugin_t ignored, +static XBT_INLINE void gras_trp_sock_socket_server(gras_trp_plugin_t + ignored, gras_socket_t sock) { int size = sock->buf_size; @@ -164,7 +168,8 @@ static XBT_INLINE void gras_trp_sock_socket_server(gras_trp_plugin_t ignored, if (bind(sock->sd, (struct sockaddr *) &server, sizeof(server)) == -1) { tcp_close(sock->sd); THROW2(system_error, 0, - "Cannot bind to port %d: %s", sock->port, sock_errstr(sock_errno)); + "Cannot bind to port %d: %s", sock->port, + sock_errstr(sock_errno)); } DEBUG2("Listen on port %d (sd=%d)", sock->port, sock->sd); @@ -175,7 +180,8 @@ static XBT_INLINE void gras_trp_sock_socket_server(gras_trp_plugin_t ignored, sock->port, sock_errstr(sock_errno)); } - VERB2("Openned a server socket on port %d (sd=%d)", sock->port, sock->sd); + VERB2("Openned a server socket on port %d (sd=%d)", sock->port, + sock->sd); } static gras_socket_t gras_trp_sock_socket_accept(gras_socket_t sock) @@ -217,7 +223,8 @@ static gras_socket_t gras_trp_sock_socket_accept(gras_socket_t sock) res->buf_size = sock->buf_size; size = sock->buf_size; if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof(size)) - || setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *) &size, sizeof(size))) + || setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *) &size, + sizeof(size))) VERB1("setsockopt failed, cannot set buffer size: %s", sock_errstr(tmp_errno)); @@ -338,8 +345,8 @@ gras_trp_tcp_recv_withbuffer(gras_socket_t sock, if (status < 0) { THROW7(system_error, 0, - "read(%d,%p,%d) from %s:%d failed: %s; got %d so far", sock->sd, - data + got, (int) size, gras_socket_peer_name(sock), + "read(%d,%p,%d) from %s:%d failed: %s; got %d so far", + sock->sd, data + got, (int) size, gras_socket_peer_name(sock), gras_socket_peer_port(sock), sock_errstr(sock_errno), got); } DEBUG2("Got %d more bytes (%s)", status, @@ -350,7 +357,8 @@ gras_trp_tcp_recv_withbuffer(gras_socket_t sock, got += status; } else { THROW1(system_error, errno, - "Socket closed by remote side (got %d bytes before this)", got); + "Socket closed by remote side (got %d bytes before this)", + got); } } @@ -433,7 +441,7 @@ gras_trp_buf_send(gras_socket_t sock, while (chunk_pos < size) { /* size of the chunk to receive in that shot */ long int thissize = - min(size - chunk_pos, data->buffsize - data->out_buf.size); + min(size - chunk_pos, data->buffsize - data->out_buf.size); DEBUG4("Set the chars %d..%ld into the buffer; size=%ld, ctn=(%s)", (int) data->out_buf.size, ((int) data->out_buf.size) + thissize - 1, size, @@ -476,15 +484,17 @@ gras_trp_buf_recv(gras_socket_t sock, char *chunk, unsigned long int size) data->in_buf.size = - gras_trp_tcp_recv_withbuffer(sock, data->in_buf.data, - MIN(size - chunk_pos, data->buffsize), - data->buffsize); + gras_trp_tcp_recv_withbuffer(sock, data->in_buf.data, + MIN(size - chunk_pos, + data->buffsize), + data->buffsize); data->in_buf.pos = 0; } thissize = min(size - chunk_pos, data->in_buf.size - data->in_buf.pos); - memcpy(chunk + chunk_pos, data->in_buf.data + data->in_buf.pos, thissize); + memcpy(chunk + chunk_pos, data->in_buf.data + data->in_buf.pos, + thissize); data->in_buf.pos += thissize; chunk_pos += thissize; @@ -573,8 +583,10 @@ gras_trp_iov_recv(gras_socket_t sock, char *chunk, unsigned long int size) *** Prototypes of BUFFERED ***/ -void gras_trp_buf_socket_client(gras_trp_plugin_t self, gras_socket_t sock); -void gras_trp_buf_socket_server(gras_trp_plugin_t self, gras_socket_t sock); +void gras_trp_buf_socket_client(gras_trp_plugin_t self, + gras_socket_t sock); +void gras_trp_buf_socket_server(gras_trp_plugin_t self, + gras_socket_t sock); gras_socket_t gras_trp_buf_socket_accept(gras_socket_t sock); void gras_trp_buf_socket_close(gras_socket_t sd); @@ -789,7 +801,7 @@ const char *gras_wsa_err2string(int err) RETSTR(WSA_E_NO_MORE); RETSTR(WSA_E_CANCELLED); RETSTR(WSAEREFUSED); -#endif /* HAVE_WINSOCK2 */ +#endif /* HAVE_WINSOCK2 */ RETSTR(WSAHOST_NOT_FOUND); RETSTR(WSATRY_AGAIN); @@ -798,7 +810,7 @@ const char *gras_wsa_err2string(int err) } return "unknown WSA error"; } -#endif /* HAVE_WINSOCK_H */ +#endif /* HAVE_WINSOCK_H */ /***********************************/ /****[ end of HELPER FUNCTIONS ]****/ diff --git a/src/gras/Transport/transport_private.h b/src/gras/Transport/transport_private.h index bf2dd522ed..d886c045ea 100644 --- a/src/gras/Transport/transport_private.h +++ b/src/gras/Transport/transport_private.h @@ -115,4 +115,4 @@ void gras_trp_sg_setup(gras_trp_plugin_t plug); gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock); -#endif /* GRAS_TRP_PRIVATE_H */ +#endif /* GRAS_TRP_PRIVATE_H */ diff --git a/src/gras/Virtu/gras_module.c b/src/gras/Virtu/gras_module.c index 7f8037e3ba..34d0a5c499 100644 --- a/src/gras/Virtu/gras_module.c +++ b/src/gras/Virtu/gras_module.c @@ -141,7 +141,8 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID, xbt_assert1(mod->datasize == datasize, "Module %s reregistered with a different datasize!", name); xbt_assert1(mod->p_id == ID, - "Module %s reregistered with a different p_id field!", name); + "Module %s reregistered with a different p_id field!", + name); DEBUG1("Module %s already registered. Ignoring re-registration", name); return; @@ -194,7 +195,7 @@ void gras_module_join(const char *name) gras_procdata_t *pd; void *moddata; gras_module_t mod = - (gras_module_t) xbt_set_get_by_name(_gras_modules, name); + (gras_module_t) xbt_set_get_by_name(_gras_modules, name); VERB2("Join to module %s (%p)", name, mod); @@ -229,7 +230,7 @@ void gras_module_leave(const char *name) { void *moddata; gras_module_t mod = - (gras_module_t) xbt_set_get_by_name(_gras_modules, name); + (gras_module_t) xbt_set_get_by_name(_gras_modules, name); VERB1("Leave module %s", name); diff --git a/src/gras/Virtu/process.c b/src/gras/Virtu/process.c index 2f2b31dc71..6ac3a17c7c 100644 --- a/src/gras/Virtu/process.c +++ b/src/gras/Virtu/process.c @@ -47,8 +47,9 @@ int gras_procdata_add(const char *name, pvoid_f_void_t constructor, if (!_gras_procdata_fabrics) { /* create the dynar if needed */ - _gras_procdata_fabrics = xbt_dynar_new(sizeof(s_gras_procdata_fabric_t), - gras_procdata_fabric_free); + _gras_procdata_fabrics = + xbt_dynar_new(sizeof(s_gras_procdata_fabric_t), + gras_procdata_fabric_free); } fab = xbt_dynar_push_ptr(_gras_procdata_fabrics); @@ -89,7 +90,8 @@ void *gras_libdata_by_name_from_procdata(const char *name, { void *res = NULL; xbt_ex_t e; - if (xbt_set_length(pd->libdata) < xbt_dynar_length(_gras_procdata_fabrics)) { + if (xbt_set_length(pd->libdata) < + xbt_dynar_length(_gras_procdata_fabrics)) { /* Damn, some new modules were added since procdata_init(). Amok? */ /* Get 'em all */ gras_procdata_init(); @@ -106,7 +108,8 @@ void *gras_libdata_by_name_from_procdata(const char *name, void *gras_libdata_by_id(int id) { gras_procdata_t *pd = gras_procdata_get(); - if (xbt_set_length(pd->libdata) < xbt_dynar_length(_gras_procdata_fabrics)) { + if (xbt_set_length(pd->libdata) < + xbt_dynar_length(_gras_procdata_fabrics)) { /* Damn, some new modules were added since procdata_init(). Amok? */ /* Get 'em all */ gras_procdata_init(); @@ -153,16 +156,16 @@ void gras_procdata_init() found = 0; } if (found) - THROW1(unknown_error, 0, "MayDay: two modules use '%s' as libdata name", - fab.name); + THROW1(unknown_error, 0, + "MayDay: two modules use '%s' as libdata name", fab.name); /* Add the data in place, after some more sanity checking */ elem = (*(fab.constructor)) (); if (elem->name_len && elem->name_len != strlen(elem->name)) { elem->name_len = strlen(elem->name); WARN1 - ("Module '%s' constructor is borken: it does not set elem->name_len", - fab.name); + ("Module '%s' constructor is borken: it does not set elem->name_len", + fab.name); } xbt_set_add(pd->libdata, elem, fab.destructor); } diff --git a/src/gras/Virtu/rl_emul.c b/src/gras/Virtu/rl_emul.c index d0409a5de9..5ed5a6515d 100644 --- a/src/gras/Virtu/rl_emul.c +++ b/src/gras/Virtu/rl_emul.c @@ -13,9 +13,10 @@ XBT_LOG_NEW_SUBCATEGORY(gras_virtu_emul, gras_virtu, "Emulation support"); /*** CPU burning */ -void gras_cpu_burn(double flops) { - while (flops>0) { - flops-=2; +void gras_cpu_burn(double flops) +{ + while (flops > 0) { + flops -= 2; } } diff --git a/src/gras/Virtu/rl_process.c b/src/gras/Virtu/rl_process.c index a2ba1a4ae5..e6a6672f6a 100644 --- a/src/gras/Virtu/rl_process.c +++ b/src/gras/Virtu/rl_process.c @@ -15,23 +15,23 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu_process); /* globals */ static gras_procdata_t *_gras_procdata = NULL; XBT_EXPORT_NO_IMPORT(char const *) _gras_procname = NULL; - static xbt_dict_t _process_properties = NULL; - static xbt_dict_t _host_properties = NULL; +static xbt_dict_t _process_properties = NULL; +static xbt_dict_t _host_properties = NULL; # ifdef __APPLE__ - /* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */ - # include - # define environ (*_NSGetEnviron()) + /* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */ +# include +# define environ (*_NSGetEnviron()) # else - #ifdef _XBT_WIN32 - /* the environment, as specified by the opengroup, used to initialize the process properties */ - extern char **wenviron; - #else - extern char **environ; - #endif +#ifdef _XBT_WIN32 + /* the environment, as specified by the opengroup, used to initialize the process properties */ +extern char **wenviron; +#else +extern char **environ; +#endif # endif - void gras_process_init() +void gras_process_init() { char **env_iter; _gras_procdata = xbt_new0(gras_procdata_t, 1); @@ -46,12 +46,13 @@ XBT_EXPORT_NO_IMPORT(char const *) _gras_procname = NULL; equal = strchr(buf, '='); if (!equal) { WARN1 - ("The environment contains an entry without '=' char: %s (ignore it)", - *env_iter); + ("The environment contains an entry without '=' char: %s (ignore it)", + *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), + xbt_free_f); free(buf); env_iter++; } diff --git a/src/gras/Virtu/sg_dns.c b/src/gras/Virtu/sg_dns.c index 8482497777..9269b0eeef 100644 --- a/src/gras/Virtu/sg_dns.c +++ b/src/gras/Virtu/sg_dns.c @@ -15,15 +15,15 @@ const char *gras_os_myname(void) smx_process_t process = SIMIX_process_self(); /*HACK: maestro used not have a simix process, now it does so - SIMIX_process_self will return something different to NULL. This breaks - the old xbt_log logic that assumed that NULL was equivalent to maestro, - thus when printing it searches for maestro host name (which doesn't exists) - and breaks the logging. - As a hack we check for maestro by looking to the assigned host, if it is - NULL then we are sure is maestro - */ + SIMIX_process_self will return something different to NULL. This breaks + the old xbt_log logic that assumed that NULL was equivalent to maestro, + thus when printing it searches for maestro host name (which doesn't exists) + and breaks the logging. + As a hack we check for maestro by looking to the assigned host, if it is + NULL then we are sure is maestro + */ if (process != NULL && (host = SIMIX_host_self()) != NULL) - return SIMIX_host_get_name(host); - - return ""; + return SIMIX_host_get_name(host); + + return ""; } diff --git a/src/gras/Virtu/sg_emul.c b/src/gras/Virtu/sg_emul.c index b6d371ffc7..4734db03c5 100644 --- a/src/gras/Virtu/sg_emul.c +++ b/src/gras/Virtu/sg_emul.c @@ -18,18 +18,18 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_virtu_emul, gras_virtu, "Emulation support"); /*** CPU burning */ -void gras_cpu_burn(double flops) { +void gras_cpu_burn(double flops) +{ smx_action_t act; smx_cond_t cond; smx_mutex_t mutex; - if (flops>0) { + if (flops > 0) { cond = SIMIX_cond_init(); mutex = SIMIX_mutex_init(); SIMIX_mutex_lock(mutex); - act = - SIMIX_action_execute(SIMIX_host_self(), "task", flops); + act = SIMIX_action_execute(SIMIX_host_self(), "task", flops); SIMIX_register_action_to_condition(act, cond); SIMIX_cond_wait(cond, mutex); @@ -42,6 +42,7 @@ void gras_cpu_burn(double flops) { SIMIX_mutex_destroy(mutex); } } + /*** Timing macros ***/ static xbt_os_timer_t timer; static int benchmarking = 0; @@ -98,13 +99,14 @@ int gras_bench_always_begin(const char *location, int line) return 0; } -int gras_bench_always_end(void) { +int gras_bench_always_end(void) +{ xbt_assert0(benchmarking, "Not benchmarking yet"); benchmarking = 0; xbt_os_timer_stop(timer); duration = xbt_os_timer_elapsed(timer); - gras_cpu_burn(duration/reference); + gras_cpu_burn(duration / reference); return 0; } @@ -133,7 +135,8 @@ int gras_bench_once_begin(const char *location, int line) } } -int gras_bench_once_end(void) { +int gras_bench_once_end(void) +{ xbt_assert0(benchmarking, "Not benchmarking yet"); benchmarking = 0; if (duration > 0) { @@ -144,7 +147,7 @@ int gras_bench_once_end(void) { duration = get_from_dict(benchmark_set, locbuf); } DEBUG2("Simulate the run of a task of %f sec for %s", duration, locbuf); - gras_cpu_burn(duration/reference); + gras_cpu_burn(duration / reference); return 0; } diff --git a/src/gras/Virtu/sg_process.c b/src/gras/Virtu/sg_process.c index 369cee6739..592de7e5ba 100644 --- a/src/gras/Virtu/sg_process.c +++ b/src/gras/Virtu/sg_process.c @@ -38,7 +38,7 @@ void gras_agent_spawn(const char *name, void *data, void gras_process_init() { gras_hostdata_t *hd = - (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); + (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); gras_procdata_t *pd = xbt_new0(gras_procdata_t, 1); gras_trp_procdata_t trp_pd; @@ -67,7 +67,8 @@ void gras_process_init() trp_pd->msg_selectable_sockets = xbt_queue_new(0, sizeof(gras_socket_t)); - trp_pd->meas_selectable_sockets = xbt_queue_new(0, sizeof(gras_socket_t)); + trp_pd->meas_selectable_sockets = + xbt_queue_new(0, sizeof(gras_socket_t)); VERB2("Creating process '%s' (%d)", SIMIX_process_get_name(SIMIX_process_self()), gras_os_getpid()); @@ -76,18 +77,18 @@ void gras_process_init() void gras_process_exit() { xbt_dynar_t sockets = - ((gras_trp_procdata_t) gras_libdata_by_name("gras_trp"))->sockets; + ((gras_trp_procdata_t) gras_libdata_by_name("gras_trp"))->sockets; gras_socket_t sock_iter; unsigned int cursor; gras_hostdata_t *hd = - (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); + (gras_hostdata_t *) SIMIX_host_get_data(SIMIX_host_self()); gras_procdata_t *pd = - (gras_procdata_t *) SIMIX_process_get_data(SIMIX_process_self()); + (gras_procdata_t *) SIMIX_process_get_data(SIMIX_process_self()); gras_msg_procdata_t msg_pd = - (gras_msg_procdata_t) gras_libdata_by_name("gras_msg"); + (gras_msg_procdata_t) gras_libdata_by_name("gras_msg"); gras_trp_procdata_t trp_pd = - (gras_trp_procdata_t) gras_libdata_by_name("gras_trp"); + (gras_trp_procdata_t) gras_libdata_by_name("gras_trp"); xbt_queue_free(&trp_pd->msg_selectable_sockets); @@ -102,11 +103,15 @@ void gras_process_exit() if (xbt_dynar_length(msg_pd->msg_queue)) { unsigned int cpt; s_gras_msg_t msg; - WARN2("process %d terminated, but %ld messages are still queued. Message list:", - gras_os_getpid(),xbt_dynar_length(msg_pd->msg_queue)); - xbt_dynar_foreach(msg_pd->msg_queue,cpt, msg) { - WARN5(" Message %s (%s) from %s@%s:%d",msg.type->name,e_gras_msg_kind_names[msg.kind], - gras_socket_peer_proc(msg.expe),gras_socket_peer_name(msg.expe),gras_socket_peer_port(msg.expe)); + WARN2 + ("process %d terminated, but %ld messages are still queued. Message list:", + gras_os_getpid(), xbt_dynar_length(msg_pd->msg_queue)); + xbt_dynar_foreach(msg_pd->msg_queue, cpt, msg) { + WARN5(" Message %s (%s) from %s@%s:%d", msg.type->name, + e_gras_msg_kind_names[msg.kind], + gras_socket_peer_proc(msg.expe), + gras_socket_peer_name(msg.expe), + gras_socket_peer_port(msg.expe)); } } @@ -132,7 +137,7 @@ void gras_process_exit() gras_procdata_t *gras_procdata_get(void) { gras_procdata_t *pd = - (gras_procdata_t *) SIMIX_process_get_data(SIMIX_process_self()); + (gras_procdata_t *) SIMIX_process_get_data(SIMIX_process_self()); xbt_assert0(pd, "Run gras_process_init! (ie, gras_init)"); @@ -155,8 +160,8 @@ void *gras_libdata_by_name_from_remote(const char *name, smx_process_t p) const char *gras_process_property_value(const char *name) { return - xbt_dict_get_or_null(SIMIX_process_get_properties(SIMIX_process_self()), - name); + xbt_dict_get_or_null(SIMIX_process_get_properties + (SIMIX_process_self()), name); } /** @brief retrieve the process properties dictionnary @@ -175,13 +180,13 @@ const char *xbt_procname(void) { smx_process_t process = SIMIX_process_self(); /*FIXME: maestro used not have a simix process, now it does so - SIMIX_process_self will return something different to NULL. This breaks - the old xbt_log logic that assumed that NULL was equivalent to maestro, - thus when printing it searches for maestro host name (which doesn't exists) - and breaks the logging. - As a hack we check for maestro by looking to the assigned host, if it is - NULL then we are sure is maestro - */ + SIMIX_process_self will return something different to NULL. This breaks + the old xbt_log logic that assumed that NULL was equivalent to maestro, + thus when printing it searches for maestro host name (which doesn't exists) + and breaks the logging. + As a hack we check for maestro by looking to the assigned host, if it is + NULL then we are sure is maestro + */ if (process != NULL && SIMIX_process_get_host(process)) return SIMIX_process_get_name(process); @@ -192,13 +197,13 @@ int gras_os_getpid(void) { gras_procdata_t *data; smx_process_t process = SIMIX_process_self(); - - if (process != NULL){ - data = (gras_procdata_t *)SIMIX_process_get_data(process); - if(data != NULL) + + if (process != NULL) { + data = (gras_procdata_t *) SIMIX_process_get_data(process); + if (data != NULL) return data->pid; } - + return 0; } @@ -206,9 +211,9 @@ int gras_os_getpid(void) const char *gras_os_host_property_value(const char *name) { return - xbt_dict_get_or_null(SIMIX_host_get_properties - (SIMIX_process_get_host(SIMIX_process_self())), - name); + xbt_dict_get_or_null(SIMIX_host_get_properties + (SIMIX_process_get_host(SIMIX_process_self())), + name); } /** @brief retrieve the host properties dictionnary @@ -217,7 +222,8 @@ const char *gras_os_host_property_value(const char *name) xbt_dict_t gras_os_host_properties(void) { return - SIMIX_host_get_properties(SIMIX_process_get_host(SIMIX_process_self())); + SIMIX_host_get_properties(SIMIX_process_get_host + (SIMIX_process_self())); } /* ************************************************************************** @@ -257,7 +263,7 @@ void gras_main() SIMIX_init(); while (SIMIX_solve(NULL, NULL) != -1.0); - + return; } @@ -266,20 +272,21 @@ void gras_launch_application(const char *file) SIMIX_launch_application(file); } -void gras_load_environment_script(const char* script_file) +void gras_load_environment_script(const char *script_file) { #ifdef HAVE_LUA - lua_State *L = lua_open(); - luaL_openlibs(L); + lua_State *L = lua_open(); + luaL_openlibs(L); - if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { - printf("error: %s\n", lua_tostring(L, -1)); - return; - } + if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { + printf("error: %s\n", lua_tostring(L, -1)); + return; + } #else - xbt_die("Lua is not available!! to call gras_load_environment_script, lua should be available..."); + xbt_die + ("Lua is not available!! to call gras_load_environment_script, lua should be available..."); #endif - return; + return; } void gras_clean() diff --git a/src/gras/Virtu/virtu_interface.h b/src/gras/Virtu/virtu_interface.h index 5623091198..8df85bc7e1 100644 --- a/src/gras/Virtu/virtu_interface.h +++ b/src/gras/Virtu/virtu_interface.h @@ -22,9 +22,9 @@ SG_BEGIN_DECL() /* shutdown the module mechanism (world-wide cleanups) */ - void gras_moddata_exit(void); +void gras_moddata_exit(void); /* shutdown this process wrt module mecanism (process-wide cleanups) */ - void gras_moddata_leave(void); +void gras_moddata_leave(void); /* Perform the various intialisations needed by gras. Each process must run it */ @@ -38,11 +38,11 @@ XBT_PUBLIC(void) gras_process_exit(void); /* declare a new process specific data (used by gras__register to make sure that gras_process_init will create it) */ - int gras_procdata_add(const char *name, pvoid_f_void_t creator, - void_f_pvoid_t destructor); +int gras_procdata_add(const char *name, pvoid_f_void_t creator, + void_f_pvoid_t destructor); - void *gras_libdata_by_name(const char *name); - void *gras_libdata_by_id(int id); +void *gras_libdata_by_name(const char *name); +void *gras_libdata_by_id(int id); SG_END_DECL() -#endif /* GRAS_VIRTU_INTERFACE_H */ +#endif /* GRAS_VIRTU_INTERFACE_H */ diff --git a/src/gras/Virtu/virtu_private.h b/src/gras/Virtu/virtu_private.h index f3f901ee1a..315214c046 100644 --- a/src/gras/Virtu/virtu_private.h +++ b/src/gras/Virtu/virtu_private.h @@ -44,4 +44,4 @@ gras_procdata_t *gras_procdata_get(void); void *gras_libdata_by_name_from_procdata(const char *name, gras_procdata_t * pd); -#endif /* GRAS_VIRTU_PRIVATE_H */ +#endif /* GRAS_VIRTU_PRIVATE_H */ diff --git a/src/gras/Virtu/virtu_rl.h b/src/gras/Virtu/virtu_rl.h index f8af952033..e402bc70a0 100644 --- a/src/gras/Virtu/virtu_rl.h +++ b/src/gras/Virtu/virtu_rl.h @@ -11,4 +11,4 @@ #include "gras/Virtu/virtu_private.h" -#endif /* VIRTU_RL_H */ +#endif /* VIRTU_RL_H */ diff --git a/src/gras/Virtu/virtu_sg.h b/src/gras/Virtu/virtu_sg.h index 94be34591b..16e4f00a30 100644 --- a/src/gras/Virtu/virtu_sg.h +++ b/src/gras/Virtu/virtu_sg.h @@ -34,10 +34,10 @@ typedef struct { smx_process_t server; smx_process_t client; - smx_rdv_t rdv_server; /* The rendez-vous point to use */ - smx_rdv_t rdv_client; /* The rendez-vous point to use */ - smx_comm_t comm_recv; /* The comm of irecv on receiver side */ -} s_gras_trp_sg_sock_data_t,*gras_trp_sg_sock_data_t; + smx_rdv_t rdv_server; /* The rendez-vous point to use */ + smx_rdv_t rdv_client; /* The rendez-vous point to use */ + smx_comm_t comm_recv; /* The comm of irecv on receiver side */ +} s_gras_trp_sg_sock_data_t, *gras_trp_sg_sock_data_t; void *gras_libdata_by_name_from_remote(const char *name, smx_process_t p); @@ -48,4 +48,4 @@ void *gras_libdata_by_name_from_remote(const char *name, smx_process_t p); * order. */ -#endif /* VIRTU_SG_H */ +#endif /* VIRTU_SG_H */ diff --git a/src/gras_modinter.h b/src/gras_modinter.h index 4de0a5ea09..e2b0b9f66c 100644 --- a/src/gras_modinter.h +++ b/src/gras_modinter.h @@ -26,4 +26,4 @@ void gras_datadesc_exit(void); void gras_procdata_init(void); void gras_procdata_exit(void); -#endif /* GRAS_MODINTER_H */ +#endif /* GRAS_MODINTER_H */ diff --git a/src/include/mc/datatypes.h b/src/include/mc/datatypes.h index 9c0e545e37..d9b8c01d6b 100644 --- a/src/include/mc/datatypes.h +++ b/src/include/mc/datatypes.h @@ -18,5 +18,4 @@ SG_BEGIN_DECL() typedef struct s_mc_transition *mc_transition_t; SG_END_DECL() - -#endif /* _MC_MC_H */ +#endif /* _MC_MC_H */ diff --git a/src/include/mc/mc.h b/src/include/mc/mc.h index 86cda3ee46..1d9f5210ef 100644 --- a/src/include/mc/mc.h +++ b/src/include/mc/mc.h @@ -23,7 +23,7 @@ XBT_PUBLIC(void) MC_init(int); XBT_PUBLIC(void) MC_exit(int); XBT_PUBLIC(void) MC_assert(int); XBT_PUBLIC(void) MC_modelcheck(int); -XBT_PUBLIC(int) MC_random(int,int); +XBT_PUBLIC(int) MC_random(int, int); /******************************* Transitions **********************************/ XBT_PUBLIC(void) MC_trans_intercept_isend(smx_rdv_t); @@ -31,10 +31,10 @@ XBT_PUBLIC(void) MC_trans_intercept_irecv(smx_rdv_t); XBT_PUBLIC(void) MC_trans_intercept_wait(smx_comm_t); XBT_PUBLIC(void) MC_trans_intercept_test(smx_comm_t); XBT_PUBLIC(void) MC_trans_intercept_waitany(xbt_dynar_t); -XBT_PUBLIC(void) MC_trans_intercept_random(int,int); +XBT_PUBLIC(void) MC_trans_intercept_random(int, int); /********************************* Memory *************************************/ -XBT_PUBLIC(void) MC_memory_init(void); /* Initialize the memory subsystem */ +XBT_PUBLIC(void) MC_memory_init(void); /* Initialize the memory subsystem */ XBT_PUBLIC(void) MC_memory_exit(void); /* @@ -44,5 +44,4 @@ extern int _surf_do_model_check; SG_END_DECL() - #endif /* _MC_MC_H */ diff --git a/src/include/simix/context.h b/src/include/simix/context.h index 178b418955..4d5b8d6b98 100644 --- a/src/include/simix/context.h +++ b/src/include/simix/context.h @@ -7,17 +7,21 @@ #ifndef XBT_CONTEXT_H #define XBT_CONTEXT_H -#include "xbt/misc.h" /* XBT_PUBLIC(), SG_BEGIN_DECL() and SG_END_DECL() definitions */ -#include "xbt/function_types.h" /* function pointer types declarations */ -#include "xbt_modinter.h" /* xbt_context_init() and xbt_context_exit() declarations */ - -SG_BEGIN_DECL() - +#include "xbt/misc.h" /* XBT_PUBLIC(), SG_BEGIN_DECL() and SG_END_DECL() definitions */ +#include "xbt/function_types.h" /* function pointer types declarations */ +#include "xbt_modinter.h" /* xbt_context_init() and xbt_context_exit() declarations */ + +SG_BEGIN_DECL() + typedef struct s_xbt_context *xbt_context_t; -XBT_PUBLIC(xbt_context_t) xbt_context_new(const char *name, xbt_main_func_t code, - void_f_pvoid_t startup_func, void *startup_arg, - void_f_pvoid_t cleanup_func, void *cleanup_arg, int argc, char *argv[]); +XBT_PUBLIC(xbt_context_t) xbt_context_new(const char *name, + xbt_main_func_t code, + void_f_pvoid_t startup_func, + void *startup_arg, + void_f_pvoid_t cleanup_func, + void *cleanup_arg, int argc, + char *argv[]); XBT_PUBLIC(void) xbt_context_kill(xbt_context_t context); @@ -26,13 +30,12 @@ XBT_PUBLIC(void) xbt_context_start(xbt_context_t context); XBT_PUBLIC(void) xbt_context_yield(void); XBT_PUBLIC(void) xbt_context_schedule(xbt_context_t context); - + void xbt_context_empty_trash(void); void xbt_context_stop(int exit_code); - + void xbt_context_free(xbt_context_t context); -SG_END_DECL() - -#endif /* !XBT_CONTEXT_H */ +SG_END_DECL() +#endif /* !XBT_CONTEXT_H */ diff --git a/src/include/simix/datatypes.h b/src/include/simix/datatypes.h index d318db2691..fde4f6fcd7 100644 --- a/src/include/simix/datatypes.h +++ b/src/include/simix/datatypes.h @@ -26,33 +26,33 @@ SG_BEGIN_DECL() \see m_host_management @{ */ - typedef struct s_smx_host *smx_host_t; +typedef struct s_smx_host *smx_host_t; /** @} */ /* ******************************** Syncro ************************************ */ - typedef struct s_smx_mutex { - xbt_swag_t sleeping; /* list of sleeping process */ - int refcount; - } s_smx_mutex_t; - typedef s_smx_mutex_t *smx_mutex_t; - - typedef struct s_smx_cond { - xbt_swag_t sleeping; /* list of sleeping process */ - smx_mutex_t mutex; - xbt_fifo_t actions; /* list of actions */ - } s_smx_cond_t; - typedef s_smx_cond_t *smx_cond_t; - - typedef struct s_smx_sem { - xbt_fifo_t sleeping; /* list of sleeping process */ - int capacity; - xbt_fifo_t actions; /* list of actions */ - } s_smx_sem_t; - typedef s_smx_sem_t *smx_sem_t; +typedef struct s_smx_mutex { + xbt_swag_t sleeping; /* list of sleeping process */ + int refcount; +} s_smx_mutex_t; +typedef s_smx_mutex_t *smx_mutex_t; + +typedef struct s_smx_cond { + xbt_swag_t sleeping; /* list of sleeping process */ + smx_mutex_t mutex; + xbt_fifo_t actions; /* list of actions */ +} s_smx_cond_t; +typedef s_smx_cond_t *smx_cond_t; + +typedef struct s_smx_sem { + xbt_fifo_t sleeping; /* list of sleeping process */ + int capacity; + xbt_fifo_t actions; /* list of actions */ +} s_smx_sem_t; +typedef s_smx_sem_t *smx_sem_t; /********************************** Action *************************************/ - typedef struct s_smx_action *smx_action_t; +typedef struct s_smx_action *smx_action_t; /* ****************************** Process *********************************** */ /** @brief Agent datatype @@ -62,17 +62,17 @@ SG_BEGIN_DECL() data, executing in a location. \see m_process_management @{ */ - typedef struct s_smx_process *smx_process_t; +typedef struct s_smx_process *smx_process_t; /** @} */ - typedef struct s_smx_context *smx_context_t; +typedef struct s_smx_context *smx_context_t; /******************************* Networking ***********************************/ - typedef struct s_smx_rvpoint *smx_rdv_t; - typedef struct s_smx_comm *smx_comm_t; - typedef enum {comm_send, - comm_recv - } smx_comm_type_t; +typedef struct s_smx_rvpoint *smx_rdv_t; +typedef struct s_smx_comm *smx_comm_t; +typedef enum { comm_send, + comm_recv +} smx_comm_type_t; diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index 6ce4cf178a..25fc374aca 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -23,14 +23,19 @@ XBT_PUBLIC(void) SIMIX_clean(void); XBT_PUBLIC(void) SIMIX_function_register(const char *name, xbt_main_func_t code); XBT_PUBLIC(void) SIMIX_function_register_default(xbt_main_func_t code); -XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name); +XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char + *name); XBT_PUBLIC(void) SIMIX_launch_application(const char *file); /* * Deployment (Bypass the parser) */ -XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host,const char *process_function,xbt_dynar_t arguments,double process_start_time,double process_kill_time); +XBT_PUBLIC(void) SIMIX_process_set_function(const char *process_host, + const char *process_function, + xbt_dynar_t arguments, + double process_start_time, + double process_kill_time); XBT_PUBLIC(double) SIMIX_get_clock(void); @@ -53,13 +58,13 @@ XBT_PUBLIC(void) __SIMIX_main(void); * int argc, char **argv: parameters passed to code * * */ - typedef void *(*smx_creation_func_t) ( /*name */ const char *, - /*code */ xbt_main_func_t, - /*userdata */ void *, - /*hostname */ char *, - /* argc */ int, - /* argv */ char **, - /* props */ xbt_dict_t); +typedef void *(*smx_creation_func_t) ( /*name */ const char *, + /*code */ xbt_main_func_t, + /*userdata */ void *, + /*hostname */ char *, + /* argc */ int, + /* argv */ char **, + /* props */ xbt_dict_t); XBT_PUBLIC(void) SIMIX_function_register_process_create(smx_creation_func_t function); XBT_PUBLIC(void) SIMIX_function_register_process_kill(void_f_pvoid_t @@ -94,8 +99,8 @@ XBT_PUBLIC(int) SIMIX_host_get_state(smx_host_t host); XBT_PUBLIC(smx_process_t) SIMIX_process_create(const char *name, xbt_main_func_t code, void *data, - const char *hostname, int argc, - char **argv, + const char *hostname, + int argc, char **argv, xbt_dict_t properties); XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process); @@ -108,7 +113,8 @@ XBT_PUBLIC(void) SIMIX_process_change_host(smx_process_t process, XBT_PUBLIC(void *) SIMIX_process_get_data(smx_process_t process); XBT_PUBLIC(void) SIMIX_process_set_data(smx_process_t process, void *data); -XBT_INLINE XBT_PUBLIC(smx_host_t) SIMIX_process_get_host(smx_process_t process); +XBT_INLINE XBT_PUBLIC(smx_host_t) SIMIX_process_get_host(smx_process_t + process); XBT_PUBLIC(const char *) SIMIX_process_get_name(smx_process_t process); XBT_INLINE XBT_PUBLIC(smx_process_t) SIMIX_process_self(void); @@ -135,7 +141,8 @@ XBT_PUBLIC(void) SIMIX_mutex_destroy(smx_mutex_t mutex); XBT_PUBLIC(smx_cond_t) SIMIX_cond_init(void); XBT_PUBLIC(void) SIMIX_cond_signal(smx_cond_t cond); XBT_PUBLIC(void) SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex); -XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, +XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond, + smx_mutex_t mutex, double max_duration); XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond); XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond); @@ -152,7 +159,8 @@ XBT_PUBLIC(void) SIMIX_sem_release_forever(smx_sem_t sem); XBT_PUBLIC(int) SIMIX_sem_would_block(smx_sem_t sem); XBT_PUBLIC(void) SIMIX_sem_block_onto(smx_sem_t sem); XBT_PUBLIC(void) SIMIX_sem_acquire(smx_sem_t sem); -XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration); +XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, + double max_duration); XBT_PUBLIC(unsigned int) SIMIX_sem_acquire_any(xbt_dynar_t sems); XBT_PUBLIC(int) SIMIX_sem_get_capacity(smx_sem_t sem); @@ -161,11 +169,13 @@ XBT_PUBLIC(int) SIMIX_sem_get_capacity(smx_sem_t sem); XBT_PUBLIC(smx_action_t) SIMIX_action_communicate(smx_host_t sender, smx_host_t receiver, const char *name, - double size, double rate); + double size, + double rate); XBT_PUBLIC(smx_action_t) SIMIX_action_execute(smx_host_t host, const char *name, double amount); -XBT_PUBLIC(smx_action_t) SIMIX_action_sleep(smx_host_t host, double amount); +XBT_PUBLIC(smx_action_t) SIMIX_action_sleep(smx_host_t host, + double amount); XBT_PUBLIC(void) SIMIX_action_cancel(smx_action_t action); XBT_PUBLIC(void) SIMIX_action_set_priority(smx_action_t action, double priority); @@ -179,8 +189,10 @@ XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond); XBT_PUBLIC(void) SIMIX_unregister_action_to_condition(smx_action_t action, smx_cond_t cond); -XBT_PUBLIC(void) SIMIX_register_action_to_semaphore(smx_action_t action, smx_sem_t sem); -XBT_INLINE XBT_PUBLIC(void) SIMIX_unregister_action_to_semaphore(smx_action_t action, smx_sem_t sem); +XBT_PUBLIC(void) SIMIX_register_action_to_semaphore(smx_action_t action, + smx_sem_t sem); +XBT_INLINE XBT_PUBLIC(void) +SIMIX_unregister_action_to_semaphore(smx_action_t action, smx_sem_t sem); XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action); @@ -188,19 +200,20 @@ XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action); XBT_PUBLIC(int) SIMIX_action_is_latency_bounded(smx_action_t action); #endif -XBT_PUBLIC(e_surf_action_state_t) SIMIX_action_get_state(smx_action_t action); +XBT_PUBLIC(e_surf_action_state_t) SIMIX_action_get_state(smx_action_t + action); XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char *name, int host_nb, - smx_host_t * host_list, - double + smx_host_t * + host_list, double *computation_amount, double *communication_amount, double amount, double rate); XBT_PUBLIC(char *) SIMIX_action_get_name(smx_action_t action); -XBT_PUBLIC(void) SIMIX_action_set_name(smx_action_t action,char *name); +XBT_PUBLIC(void) SIMIX_action_set_name(smx_action_t action, char *name); XBT_PUBLIC(void) SIMIX_action_signal_all(smx_action_t action); XBT_PUBLIC(void) SIMIX_display_process_status(void); /************************** Comunication Handling *****************************/ @@ -209,18 +222,20 @@ XBT_PUBLIC(void) SIMIX_display_process_status(void); /*****Rendez-vous points*****/ XBT_PUBLIC(smx_rdv_t) SIMIX_rdv_create(const char *name); XBT_PUBLIC(void) SIMIX_rdv_destroy(smx_rdv_t rvp); -XBT_PUBLIC(int) SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, smx_host_t host); +XBT_PUBLIC(int) SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, + smx_host_t host); XBT_PUBLIC(smx_comm_t) SIMIX_rdv_get_head(smx_rdv_t rdv); -XBT_PUBLIC(smx_comm_t) SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type); -XBT_PUBLIC(void) SIMIX_rdv_set_data(smx_rdv_t rdv,void *data); -XBT_PUBLIC(void*) SIMIX_rdv_get_data(smx_rdv_t rdv); +XBT_PUBLIC(smx_comm_t) SIMIX_rdv_get_request(smx_rdv_t rdv, + smx_comm_type_t type); +XBT_PUBLIC(void) SIMIX_rdv_set_data(smx_rdv_t rdv, void *data); +XBT_PUBLIC(void *) SIMIX_rdv_get_data(smx_rdv_t rdv); /*****Communication Requests*****/ XBT_INLINE XBT_PUBLIC(void) SIMIX_communication_cancel(smx_comm_t comm); XBT_PUBLIC(void) SIMIX_communication_destroy(smx_comm_t comm); XBT_PUBLIC(double) SIMIX_communication_get_remains(smx_comm_t comm); #ifdef HAVE_LATENCY_BOUND_TRACKING -XBT_PUBLIC(int) SIMIX_communication_is_latency_bounded(smx_comm_t comm); +XBT_PUBLIC(int) SIMIX_communication_is_latency_bounded(smx_comm_t comm); #endif XBT_PUBLIC(void *) SIMIX_communication_get_data(smx_comm_t comm); @@ -230,20 +245,30 @@ XBT_PUBLIC(size_t) SIMIX_communication_get_src_buf_size(smx_comm_t comm); XBT_PUBLIC(size_t) SIMIX_communication_get_dst_buf_size(smx_comm_t comm); /*****Networking*****/ -XBT_PUBLIC(void) SIMIX_network_set_copy_data_callback(void (*callback)(smx_comm_t, size_t)); -XBT_PUBLIC(void) SIMIX_network_copy_pointer_callback(smx_comm_t comm, size_t buff_size); -XBT_PUBLIC(void) SIMIX_network_copy_buffer_callback(smx_comm_t comm, size_t buff_size); -XBT_PUBLIC(void) SIMIX_network_send(smx_rdv_t rdv, double task_size, double rate, - double timeout, void *src_buff, - size_t src_buff_size, smx_comm_t *comm, void *data); -XBT_PUBLIC(void) SIMIX_network_recv(smx_rdv_t rdv, double timeout, void *dst_buff, - size_t *dst_buff_size, smx_comm_t *comm); -XBT_PUBLIC(smx_comm_t) SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate, - void *src_buff, size_t src_buff_size, void *data); -XBT_PUBLIC(smx_comm_t) SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size); +XBT_PUBLIC(void) SIMIX_network_set_copy_data_callback(void (*callback) + (smx_comm_t, + size_t)); +XBT_PUBLIC(void) SIMIX_network_copy_pointer_callback(smx_comm_t comm, + size_t buff_size); +XBT_PUBLIC(void) SIMIX_network_copy_buffer_callback(smx_comm_t comm, + size_t buff_size); +XBT_PUBLIC(void) SIMIX_network_send(smx_rdv_t rdv, double task_size, + double rate, double timeout, + void *src_buff, size_t src_buff_size, + smx_comm_t * comm, void *data); +XBT_PUBLIC(void) SIMIX_network_recv(smx_rdv_t rdv, double timeout, + void *dst_buff, size_t * dst_buff_size, + smx_comm_t * comm); +XBT_PUBLIC(smx_comm_t) SIMIX_network_isend(smx_rdv_t rdv, double task_size, + double rate, void *src_buff, + size_t src_buff_size, + void *data); +XBT_PUBLIC(smx_comm_t) SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, + size_t * dst_buff_size); XBT_PUBLIC(unsigned int) SIMIX_network_waitany(xbt_dynar_t comms); -XBT_INLINE XBT_PUBLIC(void) SIMIX_network_wait(smx_comm_t comm, double timeout); +XBT_INLINE XBT_PUBLIC(void) SIMIX_network_wait(smx_comm_t comm, + double timeout); XBT_PUBLIC(int) SIMIX_network_test(smx_comm_t comm); SG_END_DECL() -#endif /* _SIMIX_SIMIX_H */ +#endif /* _SIMIX_SIMIX_H */ diff --git a/src/include/surf/datatypes.h b/src/include/surf/datatypes.h index 994c96dffd..ff6bd66a09 100644 --- a/src/include/surf/datatypes.h +++ b/src/include/surf/datatypes.h @@ -33,4 +33,4 @@ typedef struct tmgr_trace *tmgr_trace_t; typedef struct tmgr_trace_event *tmgr_trace_event_t; -#endif /* MAXMIN_DATATYPES_H */ +#endif /* MAXMIN_DATATYPES_H */ diff --git a/src/include/surf/maxmin.h b/src/include/surf/maxmin.h index 383f11a826..a522198151 100644 --- a/src/include/surf/maxmin.h +++ b/src/include/surf/maxmin.h @@ -32,64 +32,63 @@ static XBT_INLINE int double_equals(double value1, double value2) XBT_PUBLIC(lmm_system_t) lmm_system_new(void); XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys); - void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var); +void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var); XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void *id, double bound_value); - void lmm_constraint_shared(lmm_constraint_t cnst); - int lmm_constraint_is_shared(lmm_constraint_t cnst); +void lmm_constraint_shared(lmm_constraint_t cnst); +int lmm_constraint_is_shared(lmm_constraint_t cnst); - void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst); +void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst); XBT_PUBLIC(lmm_variable_t) lmm_variable_new(lmm_system_t sys, void *id, double weight_value, double bound, int number_of_constraints); - void lmm_variable_free(lmm_system_t sys, lmm_variable_t var); +void lmm_variable_free(lmm_system_t sys, lmm_variable_t var); XBT_PUBLIC(double) lmm_variable_getvalue(lmm_variable_t var); XBT_PUBLIC(double) lmm_variable_getbound(lmm_variable_t var); XBT_PUBLIC(void) lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value); - void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, - lmm_variable_t var, double value); - void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst, - lmm_variable_t var, double value); - - lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, - lmm_variable_t var, int num); - int lmm_get_number_of_cnst_from_var(lmm_system_t sys, - lmm_variable_t var); - lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, - lmm_constraint_t cnst, - lmm_element_t * elem); - - lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys); - lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, - lmm_constraint_t cnst); +void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, + lmm_variable_t var, double value); +void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst, + lmm_variable_t var, double value); + +lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, + lmm_variable_t var, int num); +int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var); +lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, + lmm_constraint_t cnst, + lmm_element_t * elem); + +lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys); +lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, + lmm_constraint_t cnst); #ifdef HAVE_LATENCY_BOUND_TRACKING - XBT_PUBLIC(int) lmm_is_variable_limited_by_latency(lmm_variable_t var); +XBT_PUBLIC(int) lmm_is_variable_limited_by_latency(lmm_variable_t var); #endif - void *lmm_constraint_id(lmm_constraint_t cnst); - void *lmm_variable_id(lmm_variable_t var); +void *lmm_constraint_id(lmm_constraint_t cnst); +void *lmm_variable_id(lmm_variable_t var); - void lmm_update(lmm_system_t sys, lmm_constraint_t cnst, - lmm_variable_t var, double value); - void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, - double bound); +void lmm_update(lmm_system_t sys, lmm_constraint_t cnst, + lmm_variable_t var, double value); +void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, + double bound); XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight); - double lmm_get_variable_weight(lmm_variable_t var); +double lmm_get_variable_weight(lmm_variable_t var); XBT_PUBLIC(void) lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound); - int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst); +int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst); XBT_PUBLIC(void) lmm_solve(lmm_system_t sys); @@ -103,11 +102,14 @@ XBT_PUBLIC(void) bottleneck_solve(lmm_system_t sys); */ XBT_PUBLIC(void) lmm_set_default_protocol_function(double (*func_f) - (lmm_variable_t var, double x), + (lmm_variable_t var, + double x), double (*func_fp) - (lmm_variable_t var, double x), + (lmm_variable_t var, + double x), double (*func_fpi) - (lmm_variable_t var, double x)); + (lmm_variable_t var, + double x)); XBT_PUBLIC(double func_reno_f) (lmm_variable_t var, double x); XBT_PUBLIC(double func_reno_fp) (lmm_variable_t var, double x); @@ -122,4 +124,4 @@ XBT_PUBLIC(double func_vegas_fp) (lmm_variable_t var, double x); XBT_PUBLIC(double func_vegas_fpi) (lmm_variable_t var, double x); -#endif /* _SURF_MAXMIN_H */ +#endif /* _SURF_MAXMIN_H */ diff --git a/src/include/surf/random_mgr.h b/src/include/surf/random_mgr.h index 3a75dd4e8e..023abfd128 100644 --- a/src/include/surf/random_mgr.h +++ b/src/include/surf/random_mgr.h @@ -14,14 +14,14 @@ SG_BEGIN_DECL() - typedef enum { NONE, DRAND48, RAND } Generator; +typedef enum { NONE, DRAND48, RAND } Generator; - typedef struct random_data_desc { - long int seed; - double max, min; - double mean, std; /* note: mean and standard deviation are normalized */ - Generator generator; - } s_random_data_t, *random_data_t; +typedef struct random_data_desc { + long int seed; + double max, min; + double mean, std; /* note: mean and standard deviation are normalized */ + Generator generator; +} s_random_data_t, *random_data_t; XBT_PUBLIC_DATA(xbt_dict_t) random_data_list; @@ -31,4 +31,4 @@ XBT_PUBLIC(random_data_t) random_new(Generator generator, long int seed, double stdDeviation); SG_END_DECL() -#endif /* _SURF_RMGR_H */ +#endif /* _SURF_RMGR_H */ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 1c506017ef..973c64245a 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -17,15 +17,15 @@ SG_BEGIN_DECL() /* Actions and models are highly connected structures... */ - typedef enum { - SURF_RESOURCE_ON = 1, /**< Up & ready */ - SURF_RESOURCE_OFF = 0 /**< Down & broken */ - } e_surf_resource_state_t; +typedef enum { + SURF_RESOURCE_ON = 1, /**< Up & ready */ + SURF_RESOURCE_OFF = 0 /**< Down & broken */ +} e_surf_resource_state_t; - typedef enum { - SURF_LINK_SHARED = 1, - SURF_LINK_FATPIPE = 0 - } e_surf_link_sharing_policy_t; +typedef enum { + SURF_LINK_SHARED = 1, + SURF_LINK_FATPIPE = 0 +} e_surf_link_sharing_policy_t; /** @Brief Specify that we use that action */ XBT_PUBLIC(void) surf_action_ref(surf_action_t action); @@ -41,20 +41,21 @@ XBT_PUBLIC(void *) surf_action_new(size_t size, double cost, /** \brief Resource model description */ - typedef struct surf_model_description { - const char *name; - const char *description; - surf_model_t model; - void (*model_init_preparse) (const char *filename); - void (*model_init_postparse) (void); - } s_surf_model_description_t, *surf_model_description_t; +typedef struct surf_model_description { + const char *name; + const char *description; + surf_model_t model; + void (*model_init_preparse) (const char *filename); + void (*model_init_postparse) (void); +} s_surf_model_description_t, *surf_model_description_t; -XBT_PUBLIC(void) update_model_description(s_surf_model_description_t * table, - const char *name, +XBT_PUBLIC(void) update_model_description(s_surf_model_description_t * + table, const char *name, surf_model_t model); XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, const char *name); -XBT_PUBLIC(void) model_help(const char* category, s_surf_model_description_t * table); +XBT_PUBLIC(void) model_help(const char *category, + s_surf_model_description_t * table); /** \brief Action structure * \ingroup SURF_actions @@ -64,35 +65,35 @@ XBT_PUBLIC(void) model_help(const char* category, s_surf_model_description_t * t * * \see e_surf_action_state_t */ - typedef struct surf_action { - s_xbt_swag_hookup_t state_hookup; - xbt_swag_t state_set; - double cost; /**< cost */ - double priority; /**< priority (1.0 by default) */ - double max_duration; /**< max_duration (may fluctuate until +typedef struct surf_action { + s_xbt_swag_hookup_t state_hookup; + xbt_swag_t state_set; + double cost; /**< cost */ + double priority; /**< priority (1.0 by default) */ + double max_duration; /**< max_duration (may fluctuate until the task is completed) */ - double remains; /**< How much of that cost remains to + double remains; /**< How much of that cost remains to * be done in the currently running task */ #ifdef HAVE_LATENCY_BOUND_TRACKING - int latency_limited; /**< Set to 1 if is limited by latency, 0 otherwise */ + int latency_limited; /**< Set to 1 if is limited by latency, 0 otherwise */ #endif - double start; /**< start time */ - double finish; /**< finish time : this is modified during the run + double start; /**< start time */ + double finish; /**< finish time : this is modified during the run * and fluctuates until the task is completed */ - void *data; /**< for your convenience */ - int refcount; - surf_model_t model_type; + void *data; /**< for your convenience */ + int refcount; + surf_model_t model_type; #ifdef HAVE_TRACING - char *category; /**< tracing category for categorized resource utilization monitoring */ + char *category; /**< tracing category for categorized resource utilization monitoring */ #endif - } s_surf_action_t; +} s_surf_action_t; - typedef struct surf_action_lmm { - s_surf_action_t generic_action; - lmm_variable_t variable; - int suspended; - } s_surf_action_lmm_t, *surf_action_lmm_t; +typedef struct surf_action_lmm { + s_surf_action_t generic_action; + lmm_variable_t variable; + int suspended; +} s_surf_action_lmm_t, *surf_action_lmm_t; /** \brief Action states * \ingroup SURF_actions @@ -101,15 +102,15 @@ XBT_PUBLIC(void) model_help(const char* category, s_surf_model_description_t * t * * \see surf_action_t, surf_action_state_t */ - typedef enum { - SURF_ACTION_READY = 0, /**< Ready */ - SURF_ACTION_RUNNING, /**< Running */ - SURF_ACTION_FAILED, /**< Task Failure */ - SURF_ACTION_DONE, /**< Completed */ - SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */ - SURF_ACTION_NOT_IN_THE_SYSTEM +typedef enum { + SURF_ACTION_READY = 0, /**< Ready */ + SURF_ACTION_RUNNING, /**< Running */ + SURF_ACTION_FAILED, /**< Task Failure */ + SURF_ACTION_DONE, /**< Completed */ + SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */ + SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */ - } e_surf_action_state_t; +} e_surf_action_state_t; /** \brief Action state sets * \ingroup SURF_actions @@ -119,38 +120,38 @@ XBT_PUBLIC(void) model_help(const char* category, s_surf_model_description_t * t * * \see surf_action_t, e_surf_action_state_t */ - typedef struct surf_action_state { - xbt_swag_t ready_action_set; +typedef struct surf_action_state { + xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */ - xbt_swag_t running_action_set; + xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */ - xbt_swag_t failed_action_set; + xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */ - xbt_swag_t done_action_set; + xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */ - } s_surf_action_state_t, *surf_action_state_t; +} s_surf_action_state_t, *surf_action_state_t; /***************************/ /* Generic model object */ /***************************/ - typedef struct s_routing_global s_routing_global_t, *routing_global_t; +typedef struct s_routing_global s_routing_global_t, *routing_global_t; XBT_PUBLIC_DATA(routing_global_t) global_routing; /** \brief Private data available on all models * \ingroup SURF_models */ - typedef struct surf_model_private *surf_model_private_t; +typedef struct surf_model_private *surf_model_private_t; /** \brief Timer model extension public * \ingroup SURF_model * * Additionnal functions specific to the timer model */ - typedef struct surf_timer_model_extension_public { - void (*set) (double date, void *function, void *arg); - int (*get) (void **function, void **arg); - } s_surf_model_extension_timer_t; +typedef struct surf_timer_model_extension_public { + void (*set) (double date, void *function, void *arg); + int (*get) (void **function, void **arg); +} s_surf_model_extension_timer_t; /* Cpu model */ @@ -159,20 +160,20 @@ XBT_PUBLIC_DATA(routing_global_t) global_routing; * * Public functions specific to the CPU model. */ - typedef struct surf_cpu_model_extension_public { - surf_action_t(*execute) (void *cpu, double size); - surf_action_t(*sleep) (void *cpu, double duration); - e_surf_resource_state_t(*get_state) (void *cpu); - double (*get_speed) (void *cpu, double load); - double (*get_available_speed) (void *cpu); - void (*create_resource)(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties); - void (*add_traces)(void); - } s_surf_model_extension_cpu_t; +typedef struct surf_cpu_model_extension_public { + surf_action_t(*execute) (void *cpu, double size); + surf_action_t(*sleep) (void *cpu, double duration); + e_surf_resource_state_t(*get_state) (void *cpu); + double (*get_speed) (void *cpu, double load); + double (*get_available_speed) (void *cpu); + void (*create_resource) (char *name, double power_peak, + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties); + void (*add_traces) (void); +} s_surf_model_extension_cpu_t; /* Network model */ @@ -181,72 +182,72 @@ XBT_PUBLIC_DATA(routing_global_t) global_routing; * * Public functions specific to the network model */ - typedef struct surf_network_model_extension_public { - surf_action_t(*communicate) (const char *src_name, - const char *dst_name, - double size, double rate); - xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name); - double (*get_link_bandwidth) (const void *link); - double (*get_link_latency) (const void *link); - int (*link_shared) (const void *link); - void (*add_traces)(void); - void (*create_resource)(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t policy, - xbt_dict_t properties); - } s_surf_model_extension_network_t; +typedef struct surf_network_model_extension_public { + surf_action_t(*communicate) (const char *src_name, + const char *dst_name, + double size, double rate); + xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name); + double (*get_link_bandwidth) (const void *link); + double (*get_link_latency) (const void *link); + int (*link_shared) (const void *link); + void (*add_traces) (void); + void (*create_resource) (char *name, + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t policy, + xbt_dict_t properties); +} s_surf_model_extension_network_t; /** \brief Workstation model extension public * \ingroup SURF_models * * Public functions specific to the workstation model. */ - typedef struct surf_workstation_model_extension_public { - surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation +typedef struct surf_workstation_model_extension_public { + surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation and create the corresponding action */ - surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */ - e_surf_resource_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */ - double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */ - double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */ - surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */ - void *workstation_dst, double size, - double max_rate); - xbt_dynar_t(*get_route) (void *workstation_src, void *workstation_dst); /**< Get the list of links between two ws */ - - surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */ - void **workstation_list, - double *computation_amount, - double *communication_amount, - double amount, double rate); - double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */ - double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */ - int (*link_shared) (const void *link); - xbt_dict_t(*get_properties) (const void *resource); - void (*link_create_resource) (char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties); - void (*cpu_create_resource) (char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties); - void (*add_traces) (void); - - } s_surf_model_extension_workstation_t; + surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */ + e_surf_resource_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */ + double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */ + double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */ + surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */ + void *workstation_dst, double size, + double max_rate); + xbt_dynar_t(*get_route) (void *workstation_src, void *workstation_dst); /**< Get the list of links between two ws */ + + surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */ + void **workstation_list, + double *computation_amount, + double *communication_amount, + double amount, double rate); + double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */ + double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */ + int (*link_shared) (const void *link); + xbt_dict_t(*get_properties) (const void *resource); + void (*link_create_resource) (char *name, + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties); + void (*cpu_create_resource) (char *name, double power_peak, + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties); + void (*add_traces) (void); + +} s_surf_model_extension_workstation_t; @@ -257,76 +258,76 @@ XBT_PUBLIC_DATA(routing_global_t) global_routing; * Generic data structure for a model. The workstations, * the CPUs and the network links are examples of models. */ - typedef struct surf_model { - const char *name;/**< Name of this model */ - s_surf_action_state_t states; /**< Any living action on this model */ +typedef struct surf_model { + const char *name; /**< Name of this model */ + s_surf_action_state_t states; /**< Any living action on this model */ - e_surf_action_state_t(*action_state_get) (surf_action_t action); + e_surf_action_state_t(*action_state_get) (surf_action_t action); /**< Return the state of an action */ - void (*action_state_set) (surf_action_t action, - e_surf_action_state_t state); + void (*action_state_set) (surf_action_t action, + e_surf_action_state_t state); /**< Change an action state*/ - double (*action_get_start_time) (surf_action_t action);/**< Return the start time of an action */ - double (*action_get_finish_time) (surf_action_t action);/**< Return the finish time of an action */ - int (*action_unref) (surf_action_t action);/**< Specify that we don't use that action anymore */ - void (*action_cancel) (surf_action_t action);/**< Cancel a running action */ - void (*action_recycle) (surf_action_t action);/**< Recycle an action */ - void (*action_data_set) (surf_action_t action, void *data);/**< Set the user data of an action */ - void (*suspend) (surf_action_t action);/**< Suspend an action */ - void (*resume) (surf_action_t action);/**< Resume a suspended action */ - int (*is_suspended) (surf_action_t action);/**< Return whether an action is suspended */ - void (*set_max_duration) (surf_action_t action, double duration);/**< Set the max duration of an action*/ - void (*set_priority) (surf_action_t action, double priority);/**< Set the priority of an action */ - double (*get_remains) (surf_action_t action);/**< Get the remains of an action */ + double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */ + double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */ + int (*action_unref) (surf_action_t action); /**< Specify that we don't use that action anymore */ + void (*action_cancel) (surf_action_t action); /**< Cancel a running action */ + void (*action_recycle) (surf_action_t action); /**< Recycle an action */ + void (*action_data_set) (surf_action_t action, void *data); /**< Set the user data of an action */ + void (*suspend) (surf_action_t action); /**< Suspend an action */ + void (*resume) (surf_action_t action); /**< Resume a suspended action */ + int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */ + void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/ + void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */ + double (*get_remains) (surf_action_t action); /**< Get the remains of an action */ #ifdef HAVE_LATENCY_BOUND_TRACKING - int (*get_latency_limited) (surf_action_t action);/**< Return 1 if action is limited by latency, 0 otherwise */ + int (*get_latency_limited) (surf_action_t action); /**< Return 1 if action is limited by latency, 0 otherwise */ #endif - xbt_dict_t resource_set; + xbt_dict_t resource_set; - surf_model_private_t model_private; + surf_model_private_t model_private; - union extension { - s_surf_model_extension_timer_t timer; - s_surf_model_extension_cpu_t cpu; - s_surf_model_extension_network_t network; - s_surf_model_extension_workstation_t workstation; - } extension; - } s_surf_model_t; + union extension { + s_surf_model_extension_timer_t timer; + s_surf_model_extension_cpu_t cpu; + s_surf_model_extension_network_t network; + s_surf_model_extension_workstation_t workstation; + } extension; +} s_surf_model_t; - surf_model_t surf_model_init(void); - void surf_model_exit(surf_model_t model); +surf_model_t surf_model_init(void); +void surf_model_exit(surf_model_t model); - void *surf_model_resource_by_name(surf_model_t model, const char *name); +void *surf_model_resource_by_name(surf_model_t model, const char *name); #define surf_model_resource_set(model) (model)->resource_set - typedef struct surf_resource { - surf_model_t model; - char *name; - xbt_dict_t properties; - } s_surf_resource_t, *surf_resource_t; +typedef struct surf_resource { + surf_model_t model; + char *name; + xbt_dict_t properties; +} s_surf_resource_t, *surf_resource_t; /** * Resource which have a metric handled by a maxmin system */ - typedef struct { - double scale; - double peak; - tmgr_trace_event_t event; - } s_surf_metric_t; +typedef struct { + double scale; + double peak; + tmgr_trace_event_t event; +} s_surf_metric_t; - typedef struct surf_resource_lmm { - s_surf_resource_t generic_resource; - lmm_constraint_t constraint; - e_surf_resource_state_t state_current; - tmgr_trace_event_t state_event; - s_surf_metric_t power; - } s_surf_resource_lmm_t, *surf_resource_lmm_t; +typedef struct surf_resource_lmm { + s_surf_resource_t generic_resource; + lmm_constraint_t constraint; + e_surf_resource_state_t state_current; + tmgr_trace_event_t state_event; + s_surf_metric_t power; +} s_surf_resource_lmm_t, *surf_resource_lmm_t; /**************************************/ /* Implementations of model object */ @@ -418,7 +419,8 @@ XBT_PUBLIC(void) surf_network_model_init_SMPI(const char *filename); * * \see surf_workstation_model_init_LegrandVelho() */ -XBT_PUBLIC(void) surf_network_model_init_LegrandVelho(const char *filename); +XBT_PUBLIC(void) surf_network_model_init_LegrandVelho(const char + *filename); /** \brief Initializes the platform with the network model 'Constant' * \ingroup SURF_models @@ -450,7 +452,9 @@ XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename); /** * brief initialize the the network model bypassing the XML parser */ -XBT_PUBLIC(void) surf_network_model_init_bypass(const char* id,double initial_bw,double initial_lat); +XBT_PUBLIC(void) surf_network_model_init_bypass(const char *id, + double initial_bw, + double initial_lat); #ifdef HAVE_GTNETS /** \brief Initializes the platform with the network model GTNETS @@ -514,7 +518,8 @@ XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename); /** \brief The list of all available network model models * \ingroup SURF_models */ -XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[]; +XBT_PUBLIC_DATA(s_surf_model_description_t) + surf_network_model_description[]; /** \brief The workstation model @@ -535,7 +540,8 @@ XBT_PUBLIC_DATA(surf_model_t) surf_workstation_model; * network_model have been set up. * */ -XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename); +XBT_PUBLIC(void) surf_workstation_model_init_compound(const char + *filename); /** \brief Initializes the platform with the workstation model CLM03 * \ingroup SURF_models @@ -562,7 +568,8 @@ XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename); * SimDag. * */ -XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename); +XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char + *filename); /** \brief Initializes the platform with the model KCCFLN05 * \ingroup SURF_models @@ -573,13 +580,14 @@ XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename); * the model to each action. * */ -XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename); +XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char + *filename); /** \brief The list of all available workstation model models * \ingroup SURF_models */ XBT_PUBLIC_DATA(s_surf_model_description_t) - surf_workstation_model_description[]; + surf_workstation_model_description[]; /** \brief List of initialized models * \ingroup SURF_models @@ -683,48 +691,53 @@ XBT_PUBLIC(double) get_cpu_power(const char *power); * see surfxml_parse.c * */ XBT_PUBLIC(void) surf_host_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties); + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties); /*public interface to create resource bypassing the parser via workstation_ptask_L07 model * * see surfxml_parse.c * */ -XBT_PUBLIC(void) surf_wsL07_host_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties); +XBT_PUBLIC(void) surf_wsL07_host_create_resource(char *name, + double power_peak, + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + xbt_dict_t + cpu_properties); /** * create link resource * see surfxml_parse.c */ XBT_PUBLIC(void) surf_link_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t policy, - xbt_dict_t properties); + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties); XBT_PUBLIC(void) surf_wsL07_link_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties); + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, + xbt_dict_t properties); /** * add route element (link_ctn) bypassing the parser * @@ -754,14 +767,14 @@ XBT_PUBLIC(void) surf_wsL07_add_traces(void); * init AS from lua console * see surf_routing.c */ -XBT_PUBLIC(void) routing_AS_init(const char* id,const char *mode); -XBT_PUBLIC(void) routing_AS_end(const char* id); +XBT_PUBLIC(void) routing_AS_init(const char *id, const char *mode); +XBT_PUBLIC(void) routing_AS_end(const char *id); // add host to network element list -XBT_PUBLIC(void) routing_add_host(const char * host_id); +XBT_PUBLIC(void) routing_add_host(const char *host_id); //Set a new link on the actual list of link for a route or ASroute XBT_PUBLIC(void) routing_add_link(const char *link_id); //Set the endpoints for a route -XBT_PUBLIC(void) routing_set_route(const char* src_id,const char* dst_id); +XBT_PUBLIC(void) routing_set_route(const char *src_id, const char *dst_id); //Store the route XBT_PUBLIC(void) routing_store_route(void); @@ -769,13 +782,15 @@ XBT_PUBLIC(void) routing_store_route(void); * interface between surf and lua bindings * see surfxml_parse.c */ -XBT_PUBLIC(void) surf_AS_new(const char* id,const char *mode); -XBT_PUBLIC(void) surf_AS_finalize(const char*id); -XBT_PUBLIC(void) surf_route_add_host(const char*id); -XBT_PUBLIC(void) surf_routing_add_route(const char* src_id,const char *dest_id,xbt_dynar_t links_id); +XBT_PUBLIC(void) surf_AS_new(const char *id, const char *mode); +XBT_PUBLIC(void) surf_AS_finalize(const char *id); +XBT_PUBLIC(void) surf_route_add_host(const char *id); +XBT_PUBLIC(void) surf_routing_add_route(const char *src_id, + const char *dest_id, + xbt_dynar_t links_id); #include "surf/surf_resource.h" #include "surf/surf_resource_lmm.h" SG_END_DECL() -#endif /* _SURF_SURF_H */ +#endif /* _SURF_SURF_H */ diff --git a/src/include/surf/surf_resource.h b/src/include/surf/surf_resource.h index 78afcd72f4..625fd9ff9e 100644 --- a/src/include/surf/surf_resource.h +++ b/src/include/surf/surf_resource.h @@ -10,8 +10,10 @@ #define SURF_RESOURCE_H static XBT_INLINE -surf_resource_t surf_resource_new(size_t childsize, - surf_model_t model, char *name, xbt_dict_t props) { + surf_resource_t surf_resource_new(size_t childsize, + surf_model_t model, char *name, + xbt_dict_t props) +{ surf_resource_t res = xbt_malloc0(childsize); res->model = model; res->name = name; @@ -19,7 +21,8 @@ surf_resource_t surf_resource_new(size_t childsize, return res; } -static XBT_INLINE void surf_resource_free(void* r) { +static XBT_INLINE void surf_resource_free(void *r) +{ surf_resource_t resource = r; if (resource->name) free(resource->name); @@ -28,12 +31,14 @@ static XBT_INLINE void surf_resource_free(void* r) { free(resource); } -static XBT_INLINE const char *surf_resource_name(const void *resource) { - return ((surf_resource_t)resource)->name; +static XBT_INLINE const char *surf_resource_name(const void *resource) +{ + return ((surf_resource_t) resource)->name; } -static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource) { - return ((surf_resource_t)resource)->properties; +static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource) +{ + return ((surf_resource_t) resource)->properties; } -#endif /* SURF_RESOURCE_H */ +#endif /* SURF_RESOURCE_H */ diff --git a/src/include/surf/surf_resource_lmm.h b/src/include/surf/surf_resource_lmm.h index 37c437c02f..237c7b1bfd 100644 --- a/src/include/surf/surf_resource_lmm.h +++ b/src/include/surf/surf_resource_lmm.h @@ -11,30 +11,42 @@ #include "surf/trace_mgr.h" static XBT_INLINE -surf_resource_lmm_t surf_resource_lmm_new(size_t childsize, - /* for superclass */ surf_model_t model, char *name, xbt_dict_t props, - lmm_system_t system, double constraint_value, - tmgr_history_t history, - int state_init, tmgr_trace_t state_trace, - double metric_peak, tmgr_trace_t metric_trace) { - - surf_resource_lmm_t res = (surf_resource_lmm_t)surf_resource_new(childsize,model,name,props); + surf_resource_lmm_t surf_resource_lmm_new(size_t childsize, + /* for superclass */ + surf_model_t model, + char *name, xbt_dict_t props, + lmm_system_t system, + double constraint_value, + tmgr_history_t history, + int state_init, + tmgr_trace_t state_trace, + double metric_peak, + tmgr_trace_t metric_trace) +{ + + surf_resource_lmm_t res = + (surf_resource_lmm_t) surf_resource_new(childsize, model, name, + props); res->constraint = lmm_constraint_new(system, res, constraint_value); res->state_current = state_init; if (state_trace) - res->state_event = tmgr_history_add_trace(history, state_trace, 0.0, 0, res); + res->state_event = + tmgr_history_add_trace(history, state_trace, 0.0, 0, res); res->power.scale = 1.0; res->power.peak = metric_peak; if (metric_trace) - res->power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, res); + res->power.event = + tmgr_history_add_trace(history, metric_trace, 0.0, 0, res); return res; } -static XBT_INLINE e_surf_resource_state_t surf_resource_lmm_get_state(void *r) { - surf_resource_lmm_t resource = (surf_resource_lmm_t)r; +static XBT_INLINE e_surf_resource_state_t surf_resource_lmm_get_state(void + *r) +{ + surf_resource_lmm_t resource = (surf_resource_lmm_t) r; return (resource)->state_current; } -#endif /* SURF_RESOURCE_LMM_H */ +#endif /* SURF_RESOURCE_LMM_H */ diff --git a/src/include/surf/trace_mgr.h b/src/include/surf/trace_mgr.h index 51ed11d684..d8de2e75db 100644 --- a/src/include/surf/trace_mgr.h +++ b/src/include/surf/trace_mgr.h @@ -31,7 +31,8 @@ XBT_INLINE XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace); */ XBT_PUBLIC(int) tmgr_trace_event_free(tmgr_trace_event_t trace_event); -XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_add_trace(tmgr_history_t history, +XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_add_trace(tmgr_history_t + history, tmgr_trace_t trace, double start_time, unsigned int offset, @@ -39,12 +40,10 @@ XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_add_trace(tmgr_history_t history, /* Access functions */ XBT_PUBLIC(double) tmgr_history_next_date(tmgr_history_t history); -XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_get_next_event_leq(tmgr_history_t - history, - double date, - double *value, - void **model); +XBT_PUBLIC(tmgr_trace_event_t) + tmgr_history_get_next_event_leq(tmgr_history_t history, double date, + double *value, void **model); XBT_PUBLIC(void) tmgr_finalize(void); -#endif /* _SURF_TMGR_H */ +#endif /* _SURF_TMGR_H */ diff --git a/src/include/xbt/wine_dbghelp.h b/src/include/xbt/wine_dbghelp.h index 25339b56a9..2a42835218 100644 --- a/src/include/xbt/wine_dbghelp.h +++ b/src/include/xbt/wine_dbghelp.h @@ -719,21 +719,24 @@ extern "C" { #define SLMFLAG_VIRTUAL 0x1 #define SLMFLAG_NO_SYMBOLS 0x4 - typedef BOOL(CALLBACK * PENUMLOADED_MODULES_CALLBACK) (PSTR, ULONG, ULONG, - PVOID); + typedef BOOL(CALLBACK * PENUMLOADED_MODULES_CALLBACK) (PSTR, ULONG, + ULONG, PVOID); BOOL WINAPI EnumerateLoadedModules(HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID); typedef BOOL(CALLBACK * PENUMLOADED_MODULES_CALLBACK64) (PCSTR, DWORD64, ULONG, PVOID); - BOOL WINAPI EnumerateLoadedModules64(HANDLE, PENUMLOADED_MODULES_CALLBACK64, + BOOL WINAPI EnumerateLoadedModules64(HANDLE, + PENUMLOADED_MODULES_CALLBACK64, PVOID); - typedef BOOL(CALLBACK * PENUMLOADED_MODULES_CALLBACKW64) (PCWSTR, DWORD64, - ULONG, PVOID); + typedef BOOL(CALLBACK * PENUMLOADED_MODULES_CALLBACKW64) (PCWSTR, + DWORD64, ULONG, + PVOID); BOOL WINAPI EnumerateLoadedModulesW64(HANDLE, PENUMLOADED_MODULES_CALLBACKW64, PVOID); typedef BOOL(CALLBACK * PSYM_ENUMMODULES_CALLBACK) (PCSTR, ULONG, PVOID); - BOOL WINAPI SymEnumerateModules(HANDLE, PSYM_ENUMMODULES_CALLBACK, PVOID); + BOOL WINAPI SymEnumerateModules(HANDLE, PSYM_ENUMMODULES_CALLBACK, + PVOID); typedef BOOL(CALLBACK * PSYM_ENUMMODULES_CALLBACK64) (PCSTR, DWORD64, PVOID); BOOL WINAPI SymEnumerateModules64(HANDLE, PSYM_ENUMMODULES_CALLBACK64, @@ -751,8 +754,8 @@ extern "C" { DWORD WINAPI SymLoadModule(HANDLE, HANDLE, PCSTR, PCSTR, DWORD, DWORD); DWORD64 WINAPI SymLoadModule64(HANDLE, HANDLE, PCSTR, PCSTR, DWORD64, DWORD); - DWORD64 WINAPI SymLoadModuleEx(HANDLE, HANDLE, PCSTR, PCSTR, DWORD64, DWORD, - PMODLOAD_DATA, DWORD); + DWORD64 WINAPI SymLoadModuleEx(HANDLE, HANDLE, PCSTR, PCSTR, DWORD64, + DWORD, PMODLOAD_DATA, DWORD); DWORD64 WINAPI SymLoadModuleExW(HANDLE, HANDLE, PCWSTR, PCWSTR, DWORD64, DWORD, PMODLOAD_DATA, DWORD); BOOL WINAPI SymUnloadModule(HANDLE, DWORD); @@ -915,8 +918,8 @@ extern "C" { ULONG, PVOID); BOOL WINAPI SymEnumTypes(HANDLE, ULONG64, PSYM_ENUMERATESYMBOLS_CALLBACK, PVOID); - BOOL WINAPI SymEnumTypesW(HANDLE, ULONG64, PSYM_ENUMERATESYMBOLS_CALLBACKW, - PVOID); + BOOL WINAPI SymEnumTypesW(HANDLE, ULONG64, + PSYM_ENUMERATESYMBOLS_CALLBACKW, PVOID); BOOL WINAPI SymFromAddr(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFO *); BOOL WINAPI SymFromAddrW(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFOW *); BOOL WINAPI SymFromToken(HANDLE, DWORD64, DWORD, PSYMBOL_INFO); @@ -942,14 +945,14 @@ extern "C" { PSYM_ENUMERATESYMBOLS_CALLBACKW, PVOID); typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACK) (PCSTR, DWORD, ULONG, PVOID); - typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACKW) (PCWSTR, DWORD, ULONG, - PVOID); + typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACKW) (PCWSTR, DWORD, + ULONG, PVOID); BOOL WINAPI SymEnumerateSymbols(HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACK, PVOID); - BOOL WINAPI SymEnumerateSymbolsW(HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACKW, - PVOID); - typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACK64) (PCSTR, DWORD64, ULONG, - PVOID); + BOOL WINAPI SymEnumerateSymbolsW(HANDLE, ULONG, + PSYM_ENUMSYMBOLS_CALLBACKW, PVOID); + typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACK64) (PCSTR, DWORD64, + ULONG, PVOID); typedef BOOL(CALLBACK * PSYM_ENUMSYMBOLS_CALLBACK64W) (PCWSTR, DWORD64, ULONG, PVOID); BOOL WINAPI SymEnumerateSymbols64(HANDLE, ULONG64, @@ -959,12 +962,15 @@ extern "C" { BOOL WINAPI SymEnumSymbolsForAddr(HANDLE, DWORD64, PSYM_ENUMERATESYMBOLS_CALLBACK, PVOID); BOOL WINAPI SymEnumSymbolsForAddrW(HANDLE, DWORD64, - PSYM_ENUMERATESYMBOLS_CALLBACKW, PVOID); - typedef BOOL(CALLBACK * PSYMBOL_REGISTERED_CALLBACK) (HANDLE, ULONG, PVOID, - PVOID); - BOOL WINAPI SymRegisterCallback(HANDLE, PSYMBOL_REGISTERED_CALLBACK, PVOID); + PSYM_ENUMERATESYMBOLS_CALLBACKW, + PVOID); + typedef BOOL(CALLBACK * PSYMBOL_REGISTERED_CALLBACK) (HANDLE, ULONG, + PVOID, PVOID); + BOOL WINAPI SymRegisterCallback(HANDLE, PSYMBOL_REGISTERED_CALLBACK, + PVOID); typedef BOOL(CALLBACK * PSYMBOL_REGISTERED_CALLBACK64) (HANDLE, ULONG, - ULONG64, ULONG64); + ULONG64, + ULONG64); BOOL WINAPI SymRegisterCallback64(HANDLE, PSYMBOL_REGISTERED_CALLBACK64, ULONG64); BOOL WINAPI SymRegisterCallbackW64(HANDLE, PSYMBOL_REGISTERED_CALLBACK64, @@ -985,14 +991,16 @@ extern "C" { BOOL WINAPI SymFromIndex(HANDLE, ULONG64, DWORD, PSYMBOL_INFO); BOOL WINAPI SymFromIndexW(HANDLE, ULONG64, DWORD, PSYMBOL_INFOW); BOOL WINAPI SymAddSymbol(HANDLE, ULONG64, PCSTR, DWORD64, DWORD, DWORD); - BOOL WINAPI SymAddSymbolW(HANDLE, ULONG64, PCWSTR, DWORD64, DWORD, DWORD); + BOOL WINAPI SymAddSymbolW(HANDLE, ULONG64, PCWSTR, DWORD64, DWORD, + DWORD); BOOL WINAPI SymDeleteSymbol(HANDLE, ULONG64, PCSTR, DWORD64, DWORD); BOOL WINAPI SymDeleteSymbolW(HANDLE, ULONG64, PCWSTR, DWORD64, DWORD); /************************* * Source Files * *************************/ - typedef BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACK) (PSOURCEFILE, PVOID); + typedef BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACK) (PSOURCEFILE, + PVOID); typedef BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACKW) (PSOURCEFILEW, PVOID); @@ -1002,7 +1010,8 @@ extern "C" { PSYM_ENUMSOURCEFILES_CALLBACKW, PVOID); BOOL WINAPI SymGetLineFromAddr(HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE); BOOL WINAPI SymGetLineFromAddrW(HANDLE, DWORD, PDWORD, PIMAGEHLP_LINEW); - BOOL WINAPI SymGetLineFromAddr64(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64); + BOOL WINAPI SymGetLineFromAddr64(HANDLE, DWORD64, PDWORD, + PIMAGEHLP_LINE64); BOOL WINAPI SymGetLineFromAddrW64(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINEW64); BOOL WINAPI SymGetLinePrev(HANDLE, PIMAGEHLP_LINE); @@ -1019,19 +1028,22 @@ extern "C" { PIMAGEHLP_LINE64); BOOL WINAPI SymGetLineFromNameW64(HANDLE, PCWSTR, PCWSTR, DWORD, PLONG, PIMAGEHLP_LINEW64); - ULONG WINAPI SymGetFileLineOffsets64(HANDLE, PCSTR, PCSTR, PDWORD64, ULONG); + ULONG WINAPI SymGetFileLineOffsets64(HANDLE, PCSTR, PCSTR, PDWORD64, + ULONG); BOOL WINAPI SymGetSourceFile(HANDLE, ULONG64, PCSTR, PCSTR, PSTR, DWORD); BOOL WINAPI SymGetSourceFileW(HANDLE, ULONG64, PCWSTR, PCWSTR, PWSTR, DWORD); - BOOL WINAPI SymGetSourceFileToken(HANDLE, ULONG64, PCSTR, PVOID *, DWORD *); + BOOL WINAPI SymGetSourceFileToken(HANDLE, ULONG64, PCSTR, PVOID *, + DWORD *); BOOL WINAPI SymGetSourceFileTokenW(HANDLE, ULONG64, PCWSTR, PVOID *, DWORD *); BOOL WINAPI SymGetSourceFileFromToken(HANDLE, PVOID, PCSTR, PSTR, DWORD); - BOOL WINAPI SymGetSourceFileFromTokenW(HANDLE, PVOID, PCWSTR, PWSTR, DWORD); + BOOL WINAPI SymGetSourceFileFromTokenW(HANDLE, PVOID, PCWSTR, PWSTR, + DWORD); BOOL WINAPI SymGetSourceVarFromToken(HANDLE, PVOID, PCSTR, PCSTR, PSTR, DWORD); - BOOL WINAPI SymGetSourceVarFromTokenW(HANDLE, PVOID, PCWSTR, PCWSTR, PWSTR, - DWORD); + BOOL WINAPI SymGetSourceVarFromTokenW(HANDLE, PVOID, PCWSTR, PCWSTR, + PWSTR, DWORD); typedef struct _SRCCODEINFO { DWORD SizeOfStruct; @@ -1059,8 +1071,8 @@ extern "C" { PSYM_ENUMLINES_CALLBACK, PVOID); BOOL WINAPI SymEnumLinesW(HANDLE, ULONG64, PCWSTR, PCWSTR, PSYM_ENUMLINES_CALLBACKW, PVOID); - BOOL WINAPI SymEnumSourceLines(HANDLE, ULONG64, PCSTR, PCSTR, DWORD, DWORD, - PSYM_ENUMLINES_CALLBACK, PVOID); + BOOL WINAPI SymEnumSourceLines(HANDLE, ULONG64, PCSTR, PCSTR, DWORD, + DWORD, PSYM_ENUMLINES_CALLBACK, PVOID); BOOL WINAPI SymEnumSourceLinesW(HANDLE, ULONG64, PCWSTR, PCWSTR, DWORD, DWORD, PSYM_ENUMLINES_CALLBACKW, PVOID); @@ -1072,8 +1084,10 @@ extern "C" { BOOL WINAPI SymCleanup(HANDLE); HANDLE WINAPI FindDebugInfoFile(PCSTR, PCSTR, PSTR); - typedef BOOL(CALLBACK * PFIND_DEBUG_FILE_CALLBACK) (HANDLE, PCSTR, PVOID); - typedef BOOL(CALLBACK * PFIND_DEBUG_FILE_CALLBACKW) (HANDLE, PCWSTR, PVOID); + typedef BOOL(CALLBACK * PFIND_DEBUG_FILE_CALLBACK) (HANDLE, PCSTR, + PVOID); + typedef BOOL(CALLBACK * PFIND_DEBUG_FILE_CALLBACKW) (HANDLE, PCWSTR, + PVOID); HANDLE WINAPI FindDebugInfoFileEx(PCSTR, PCSTR, PSTR, PFIND_DEBUG_FILE_CALLBACK, PVOID); HANDLE WINAPI FindDebugInfoFileExW(PCWSTR, PCWSTR, PWSTR, @@ -1084,16 +1098,18 @@ extern "C" { PFIND_DEBUG_FILE_CALLBACKW, PVOID); typedef BOOL(CALLBACK * PFINDFILEINPATHCALLBACK) (PCSTR, PVOID); typedef BOOL(CALLBACK * PFINDFILEINPATHCALLBACKW) (PCWSTR, PVOID); - BOOL WINAPI FindFileInPath(HANDLE, PCSTR, PCSTR, PVOID, DWORD, DWORD, DWORD, - PSTR, PFINDFILEINPATHCALLBACK, PVOID); + BOOL WINAPI FindFileInPath(HANDLE, PCSTR, PCSTR, PVOID, DWORD, DWORD, + DWORD, PSTR, PFINDFILEINPATHCALLBACK, PVOID); BOOL WINAPI SymFindFileInPath(HANDLE, PCSTR, PCSTR, PVOID, DWORD, DWORD, - DWORD, PSTR, PFINDFILEINPATHCALLBACK, PVOID); - BOOL WINAPI SymFindFileInPathW(HANDLE, PCWSTR, PCWSTR, PVOID, DWORD, DWORD, - DWORD, PWSTR, PFINDFILEINPATHCALLBACKW, - PVOID); + DWORD, PSTR, PFINDFILEINPATHCALLBACK, + PVOID); + BOOL WINAPI SymFindFileInPathW(HANDLE, PCWSTR, PCWSTR, PVOID, DWORD, + DWORD, DWORD, PWSTR, + PFINDFILEINPATHCALLBACKW, PVOID); HANDLE WINAPI FindExecutableImage(PCSTR, PCSTR, PSTR); typedef BOOL(CALLBACK * PFIND_EXE_FILE_CALLBACK) (HANDLE, PCSTR, PVOID); - typedef BOOL(CALLBACK * PFIND_EXE_FILE_CALLBACKW) (HANDLE, PCWSTR, PVOID); + typedef BOOL(CALLBACK * PFIND_EXE_FILE_CALLBACKW) (HANDLE, PCWSTR, + PVOID); HANDLE WINAPI FindExecutableImageEx(PCSTR, PCSTR, PSTR, PFIND_EXE_FILE_CALLBACK, PVOID); HANDLE WINAPI FindExecutableImageExW(PCWSTR, PCWSTR, PWSTR, @@ -1120,8 +1136,8 @@ extern "C" { BOOL WINAPI SearchTreeForFileW(PCWSTR, PCWSTR, PWSTR); typedef BOOL(CALLBACK * PENUMDIRTREE_CALLBACK) (PCSTR, PVOID); typedef BOOL(CALLBACK * PENUMDIRTREE_CALLBACKW) (PCWSTR, PVOID); - BOOL WINAPI EnumDirTree(HANDLE, PCSTR, PCSTR, PSTR, PENUMDIRTREE_CALLBACK, - PVOID); + BOOL WINAPI EnumDirTree(HANDLE, PCSTR, PCSTR, PSTR, + PENUMDIRTREE_CALLBACK, PVOID); BOOL WINAPI EnumDirTreeW(HANDLE, PCWSTR, PCWSTR, PWSTR, PENUMDIRTREE_CALLBACKW, PVOID); BOOL WINAPI SymMatchFileName(PCSTR, PCSTR, PSTR *, PSTR *); @@ -1138,7 +1154,8 @@ extern "C" { /************************* * Context management * *************************/ - BOOL WINAPI SymSetContext(HANDLE, PIMAGEHLP_STACK_FRAME, PIMAGEHLP_CONTEXT); + BOOL WINAPI SymSetContext(HANDLE, PIMAGEHLP_STACK_FRAME, + PIMAGEHLP_CONTEXT); /************************* @@ -1196,7 +1213,7 @@ extern "C" { } STACKFRAME64, *LPSTACKFRAME64; typedef BOOL(CALLBACK * PREAD_PROCESS_MEMORY_ROUTINE) - (HANDLE, DWORD, PVOID, DWORD, PDWORD); + (HANDLE, DWORD, PVOID, DWORD, PDWORD); typedef PVOID(CALLBACK * PFUNCTION_TABLE_ACCESS_ROUTINE) (HANDLE, DWORD); typedef DWORD(CALLBACK * PGET_MODULE_BASE_ROUTINE) (HANDLE, DWORD); typedef DWORD(CALLBACK * PTRANSLATE_ADDRESS_ROUTINE) (HANDLE, HANDLE, @@ -1204,10 +1221,11 @@ extern "C" { BOOL WINAPI StackWalk(DWORD, HANDLE, HANDLE, LPSTACKFRAME, PVOID, PREAD_PROCESS_MEMORY_ROUTINE, PFUNCTION_TABLE_ACCESS_ROUTINE, - PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE); + PGET_MODULE_BASE_ROUTINE, + PTRANSLATE_ADDRESS_ROUTINE); typedef BOOL(CALLBACK * PREAD_PROCESS_MEMORY_ROUTINE64) - (HANDLE, DWORD64, PVOID, DWORD, PDWORD); + (HANDLE, DWORD64, PVOID, DWORD, PDWORD); typedef PVOID(CALLBACK * PFUNCTION_TABLE_ACCESS_ROUTINE64) (HANDLE, DWORD64); typedef DWORD64(CALLBACK * PGET_MODULE_BASE_ROUTINE64) (HANDLE, DWORD64); @@ -1222,7 +1240,8 @@ extern "C" { PVOID WINAPI SymFunctionTableAccess(HANDLE, DWORD); PVOID WINAPI SymFunctionTableAccess64(HANDLE, DWORD64); - typedef PVOID(CALLBACK * PSYMBOL_FUNCENTRY_CALLBACK) (HANDLE, DWORD, PVOID); + typedef PVOID(CALLBACK * PSYMBOL_FUNCENTRY_CALLBACK) (HANDLE, DWORD, + PVOID); typedef PVOID(CALLBACK * PSYMBOL_FUNCENTRY_CALLBACK64) (HANDLE, ULONG64, ULONG64); @@ -1298,8 +1317,8 @@ extern "C" { * Version, global stuff * *************************/ - typedef BOOL(WINAPI * PSYMBOLSERVERPROC) (PCSTR, PCSTR, PVOID, DWORD, DWORD, - PSTR); + typedef BOOL(WINAPI * PSYMBOLSERVERPROC) (PCSTR, PCSTR, PVOID, DWORD, + DWORD, PSTR); typedef BOOL(WINAPI * PSYMBOLSERVERPROCA) (PCSTR, PCSTR, PVOID, DWORD, DWORD, PSTR); typedef BOOL(WINAPI * PSYMBOLSERVERPROCW) (PCWSTR, PCWSTR, PVOID, DWORD, diff --git a/src/include/xbt/xbt_os_thread.h b/src/include/xbt/xbt_os_thread.h index 03f45a27a0..643eba31e2 100644 --- a/src/include/xbt/xbt_os_thread.h +++ b/src/include/xbt/xbt_os_thread.h @@ -24,11 +24,12 @@ SG_BEGIN_DECL() * @{ */ /** \brief Thread data type (opaque structure) */ - typedef struct xbt_os_thread_ *xbt_os_thread_t; +typedef struct xbt_os_thread_ *xbt_os_thread_t; XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name, pvoid_f_pvoid_t - start_routine, void *param); + start_routine, + void *param); XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode); XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void); XBT_PUBLIC(const char *) xbt_os_thread_self_name(void); @@ -42,7 +43,7 @@ XBT_PUBLIC(void *) xbt_os_thread_getparam(void); /** \brief Thread mutex data type (opaque structure) */ - typedef struct xbt_os_mutex_ *xbt_os_mutex_t; +typedef struct xbt_os_mutex_ *xbt_os_mutex_t; XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void); XBT_PUBLIC(void) xbt_os_mutex_acquire(xbt_os_mutex_t mutex); @@ -53,10 +54,11 @@ XBT_PUBLIC(void) xbt_os_mutex_destroy(xbt_os_mutex_t mutex); /** \brief Thread condition data type (opaque structure) */ - typedef struct xbt_os_cond_ *xbt_os_cond_t; +typedef struct xbt_os_cond_ *xbt_os_cond_t; XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void); -XBT_PUBLIC(void) xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex); +XBT_PUBLIC(void) xbt_os_cond_wait(xbt_os_cond_t cond, + xbt_os_mutex_t mutex); XBT_PUBLIC(void) xbt_os_cond_timedwait(xbt_os_cond_t cond, xbt_os_mutex_t mutex, double delay); XBT_PUBLIC(void) xbt_os_cond_signal(xbt_os_cond_t cond); @@ -64,7 +66,7 @@ XBT_PUBLIC(void) xbt_os_cond_broadcast(xbt_os_cond_t cond); XBT_PUBLIC(void) xbt_os_cond_destroy(xbt_os_cond_t cond); /** \brief Semaphore data type (opaque structure) */ - typedef struct xbt_os_sem_ *xbt_os_sem_t; +typedef struct xbt_os_sem_ *xbt_os_sem_t; XBT_PUBLIC(xbt_os_sem_t) xbt_os_sem_init(unsigned int value); XBT_PUBLIC(void) xbt_os_sem_acquire(xbt_os_sem_t sem); @@ -77,4 +79,4 @@ XBT_PUBLIC(void) xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue); /** @} */ SG_END_DECL() -#endif /* _XBT_OS_THREAD_H */ +#endif /* _XBT_OS_THREAD_H */ diff --git a/src/include/xbt/xbt_os_time.h b/src/include/xbt/xbt_os_time.h index e9f30e4433..ab5d51f56d 100644 --- a/src/include/xbt/xbt_os_time.h +++ b/src/include/xbt/xbt_os_time.h @@ -20,7 +20,7 @@ XBT_PUBLIC(double) xbt_os_time(void); XBT_PUBLIC(void) xbt_os_sleep(double sec); - typedef struct s_xbt_os_timer *xbt_os_timer_t; +typedef struct s_xbt_os_timer *xbt_os_timer_t; XBT_PUBLIC(xbt_os_timer_t) xbt_os_timer_new(void); XBT_PUBLIC(void) xbt_os_timer_free(xbt_os_timer_t timer); XBT_PUBLIC(void) xbt_os_timer_start(xbt_os_timer_t timer); diff --git a/src/instr/categories.c b/src/instr/categories.c index e34f83e388..f1e37b2273 100644 --- a/src/instr/categories.c +++ b/src/instr/categories.c @@ -10,44 +10,44 @@ static xbt_dict_t current_task_category = NULL; -void TRACE_category_alloc () +void TRACE_category_alloc() { current_task_category = xbt_dict_new(); } -void TRACE_category_release () +void TRACE_category_release() { - xbt_dict_free (¤t_task_category); + xbt_dict_free(¤t_task_category); } -void TRACE_category_set (smx_process_t proc, const char *category) +void TRACE_category_set(smx_process_t proc, const char *category) { char processid[100]; char *var_cpy = NULL; - snprintf (processid, 100, "%p", proc); - var_cpy = xbt_strdup (category); - xbt_dict_set (current_task_category, processid, var_cpy, xbt_free); + snprintf(processid, 100, "%p", proc); + var_cpy = xbt_strdup(category); + xbt_dict_set(current_task_category, processid, var_cpy, xbt_free); } -char *TRACE_category_get (smx_process_t proc) +char *TRACE_category_get(smx_process_t proc) { char processid[100]; - snprintf (processid, 100, "%p", proc); - return xbt_dict_get_or_null (current_task_category, processid); + snprintf(processid, 100, "%p", proc); + return xbt_dict_get_or_null(current_task_category, processid); } -void TRACE_category_unset (smx_process_t proc) +void TRACE_category_unset(smx_process_t proc) { char processid[100]; - snprintf (processid, 100, "%p", proc); - if (xbt_dict_get_or_null (current_task_category, processid) != NULL){ - xbt_dict_remove (current_task_category, processid); + snprintf(processid, 100, "%p", proc); + if (xbt_dict_get_or_null(current_task_category, processid) != NULL) { + xbt_dict_remove(current_task_category, processid); } } -void TRACE_msg_category_set (smx_process_t proc, m_task_t task) +void TRACE_msg_category_set(smx_process_t proc, m_task_t task) { - TRACE_category_set (proc, task->category); + TRACE_category_set(proc, task->category); } diff --git a/src/instr/general.c b/src/instr/general.c index cb90a7942c..85c7d5292b 100644 --- a/src/instr/general.c +++ b/src/instr/general.c @@ -9,83 +9,89 @@ #ifdef HAVE_TRACING -char *TRACE_paje_msg_container (m_task_t task, char *host, char *output, int len) +char *TRACE_paje_msg_container(m_task_t task, char *host, char *output, + int len) { - if (output){ - snprintf (output, len, "msg-%p-%s-%lld", task, host, task->counter); + if (output) { + snprintf(output, len, "msg-%p-%s-%lld", task, host, task->counter); return output; - }else{ + } else { return NULL; } } -char *TRACE_paje_smx_container (smx_action_t action, int seqnumber, char *host, char *output, int len) +char *TRACE_paje_smx_container(smx_action_t action, int seqnumber, + char *host, char *output, int len) { - if (output){ - snprintf (output, len, "smx-%p-%d", action, seqnumber); + if (output) { + snprintf(output, len, "smx-%p-%d", action, seqnumber); return output; - }else{ + } else { return NULL; } } -char *TRACE_paje_surf_container (void *action, int seqnumber, char *output, int len) +char *TRACE_paje_surf_container(void *action, int seqnumber, char *output, + int len) { - if (output){ - snprintf (output, len, "surf-%p-%d", action, seqnumber); + if (output) { + snprintf(output, len, "surf-%p-%d", action, seqnumber); return output; - }else{ + } else { return NULL; } } -char *TRACE_host_container (m_host_t host, char *output, int len) +char *TRACE_host_container(m_host_t host, char *output, int len) { - if (output){ - snprintf (output, len, "%s", MSG_host_get_name(host)); - return output; - }else{ - return NULL; + if (output) { + snprintf(output, len, "%s", MSG_host_get_name(host)); + return output; + } else { + return NULL; } } -char *TRACE_task_container (m_task_t task, char *output, int len) +char *TRACE_task_container(m_task_t task, char *output, int len) { - if (output){ - snprintf (output, len, "%p-%lld", task, task->counter); - return output; - }else{ - return NULL; + if (output) { + snprintf(output, len, "%p-%lld", task, task->counter); + return output; + } else { + return NULL; } } -char *TRACE_process_container (m_process_t process, char *output, int len) +char *TRACE_process_container(m_process_t process, char *output, int len) { - if (output){ - snprintf (output, len, "%s-%p", MSG_process_get_name(process), process); - return output; - }else{ - return NULL; + if (output) { + snprintf(output, len, "%s-%p", MSG_process_get_name(process), process); + return output; + } else { + return NULL; } } -char *TRACE_process_alias_container (m_process_t process, m_host_t host, char *output, int len) +char *TRACE_process_alias_container(m_process_t process, m_host_t host, + char *output, int len) { - if (output){ - snprintf (output, len, "%p-%p", process, host); - return output; - }else{ - return NULL; + if (output) { + snprintf(output, len, "%p-%p", process, host); + return output; + } else { + return NULL; } } -char *TRACE_task_alias_container (m_task_t task, m_process_t process, m_host_t host, char *output, int len) +char *TRACE_task_alias_container(m_task_t task, m_process_t process, + m_host_t host, char *output, int len) { - if (output){ - snprintf (output, len, "%p-%lld-%p-%p", task, task->counter, process, host); - return output; - }else{ - return NULL; + if (output) { + snprintf(output, len, "%p-%lld-%p-%p", task, task->counter, process, + host); + return output; + } else { + return NULL; } } diff --git a/src/instr/instr_config.c b/src/instr/instr_config.c index a7dadebaef..684b36c5a5 100644 --- a/src/instr/instr_config.c +++ b/src/instr/instr_config.c @@ -19,44 +19,44 @@ static int trace_configured = 0; -int TRACE_is_configured (void) +int TRACE_is_configured(void) { return trace_configured; } -int TRACE_smpi_is_enabled (void) +int TRACE_smpi_is_enabled(void) { return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI); } -int TRACE_platform_is_enabled (void) +int TRACE_platform_is_enabled(void) { return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM); } -int TRACE_msg_task_is_enabled (void) +int TRACE_msg_task_is_enabled(void) { return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK); } -int TRACE_msg_process_is_enabled (void) +int TRACE_msg_process_is_enabled(void) { return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS); } -int TRACE_msg_volume_is_enabled (void) +int TRACE_msg_volume_is_enabled(void) { return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME); } -char *TRACE_get_filename (void) +char *TRACE_get_filename(void) { - return xbt_cfg_get_string (_surf_cfg_set, OPT_TRACING_FILENAME); + return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME); } -char *TRACE_get_platform_method (void) +char *TRACE_get_platform_method(void) { - return xbt_cfg_get_string (_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD); + return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD); } void TRACE_global_init(int *argc, char **argv) @@ -64,9 +64,9 @@ void TRACE_global_init(int *argc, char **argv) /* name of the tracefile */ char *default_tracing_filename = xbt_strdup("simgrid.trace"); xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME, - "Trace file created by the instrumented SimGrid.", - xbt_cfgelm_string, &default_tracing_filename, 1, 1, - NULL, NULL); + "Trace file created by the instrumented SimGrid.", + xbt_cfgelm_string, &default_tracing_filename, 1, 1, + NULL, NULL); /* smpi */ int default_tracing_smpi = 0; @@ -83,11 +83,11 @@ void TRACE_global_init(int *argc, char **argv) NULL, NULL); /* platform method */ - char *default_tracing_platform_method = xbt_strdup ("b"); + char *default_tracing_platform_method = xbt_strdup("b"); xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD, "Tracing method used to register categorized resource behavior.", - xbt_cfgelm_string, &default_tracing_platform_method, 1, 1, - NULL, NULL); + xbt_cfgelm_string, &default_tracing_platform_method, 1, + 1, NULL, NULL); /* msg task */ int default_tracing_msg_task = 0; diff --git a/src/instr/interface.c b/src/instr/interface.c index b8877088a3..a405db26c6 100644 --- a/src/instr/interface.c +++ b/src/instr/interface.c @@ -10,37 +10,37 @@ #include "instr/private.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface"); +XBT_LOG_NEW_DEFAULT_CATEGORY(tracing, "Tracing Interface"); static xbt_dict_t defined_types; static xbt_dict_t created_categories; -int TRACE_start () +int TRACE_start() { - if (!TRACE_is_configured()){ - THROW0 (tracing_error, TRACE_ERROR_START, - "TRACE_start should be called after SimGrid initialization functions."); + if (!TRACE_is_configured()) { + THROW0(tracing_error, TRACE_ERROR_START, + "TRACE_start should be called after SimGrid initialization functions."); return 0; } - if (IS_TRACING) { /* what? trace is already active... ignore.. */ - THROW0 (tracing_error, TRACE_ERROR_START, - "TRACE_start called, but tracing is already active."); + if (IS_TRACING) { /* what? trace is already active... ignore.. */ + THROW0(tracing_error, TRACE_ERROR_START, + "TRACE_start called, but tracing is already active."); return 0; } - char *filename = TRACE_get_filename (); - if (!filename){ - THROW0 (tracing_error, TRACE_ERROR_START, - "Trace filename is not initialized."); + char *filename = TRACE_get_filename(); + if (!filename) { + THROW0(tracing_error, TRACE_ERROR_START, + "Trace filename is not initialized."); return 0; } FILE *file = fopen(filename, "w"); if (!file) { - THROW1 (tracing_error, TRACE_ERROR_START, - "Tracefile %s could not be opened for writing.", filename); + THROW1(tracing_error, TRACE_ERROR_START, + "Tracefile %s could not be opened for writing.", filename); } else { - TRACE_paje_start (file); + TRACE_paje_start(file); } TRACE_paje_create_header(); @@ -49,169 +49,195 @@ int TRACE_start () pajeDefineContainerType("HOST", "PLATFORM", "HOST"); pajeDefineContainerType("LINK", "PLATFORM", "LINK"); - if (IS_TRACING_PLATFORM){ - pajeDefineVariableType ("power", "HOST", "power"); - pajeDefineVariableType ("power_used", "HOST", "power_used"); - pajeDefineVariableType ("bandwidth", "LINK", "bandwidth"); - pajeDefineVariableType ("bandwidth_used", "LINK", "bandwidth_used"); - pajeDefineVariableType ("latency", "LINK", "latency"); - pajeDefineEventType ("source", "LINK", "source"); - pajeDefineEventType ("destination", "LINK", "destination"); + if (IS_TRACING_PLATFORM) { + pajeDefineVariableType("power", "HOST", "power"); + pajeDefineVariableType("power_used", "HOST", "power_used"); + pajeDefineVariableType("bandwidth", "LINK", "bandwidth"); + pajeDefineVariableType("bandwidth_used", "LINK", "bandwidth_used"); + pajeDefineVariableType("latency", "LINK", "latency"); + pajeDefineEventType("source", "LINK", "source"); + pajeDefineEventType("destination", "LINK", "destination"); } - if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){ + if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME) { //processes grouped by host pajeDefineContainerType("PROCESS", "HOST", "PROCESS"); } - if (IS_TRACING_PROCESSES){ + if (IS_TRACING_PROCESSES) { pajeDefineStateType("category", "PROCESS", "category"); pajeDefineStateType("presence", "PROCESS", "presence"); } - if (IS_TRACING_VOLUME){ - pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume"); + if (IS_TRACING_VOLUME) { + pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume"); } - if (IS_TRACING_TASKS){ + if (IS_TRACING_TASKS) { //tasks grouped by host pajeDefineContainerType("TASK", "HOST", "TASK"); pajeDefineStateType("category", "TASK", "category"); pajeDefineStateType("presence", "TASK", "presence"); } - if (IS_TRACING_SMPI){ - pajeDefineContainerType ("MPI_PROCESS", "HOST", "MPI_PROCESS"); - pajeDefineStateType ("MPI_STATE", "MPI_PROCESS", "MPI_STATE"); - pajeDefineLinkType ("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS", "MPI_LINK"); + if (IS_TRACING_SMPI) { + pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS"); + pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE"); + pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS", + "MPI_LINK"); } /* creating the platform */ - pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform"); + pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", + "simgrid-platform"); /* other trace initialization */ defined_types = xbt_dict_new(); created_categories = xbt_dict_new(); - TRACE_msg_task_alloc (); - TRACE_category_alloc (); - TRACE_surf_alloc (); - TRACE_msg_process_alloc (); - TRACE_smpi_alloc (); + TRACE_msg_task_alloc(); + TRACE_category_alloc(); + TRACE_surf_alloc(); + TRACE_msg_process_alloc(); + TRACE_smpi_alloc(); return 0; } -int TRACE_end() { - FILE *file = NULL; - if (!IS_TRACING) return 1; +int TRACE_end() +{ + FILE *file = NULL; + if (!IS_TRACING) + return 1; file = TRACE_paje_end(); - fclose (file); + fclose(file); return 0; } -int TRACE_category (const char *category) +int TRACE_category(const char *category) { static int first_time = 1; - if (!IS_TRACING) return 1; + if (!IS_TRACING) + return 1; - if (first_time){ - TRACE_define_type ("user_type", "0", 1); - first_time = 0; + if (first_time) { + TRACE_define_type("user_type", "0", 1); + first_time = 0; } - return TRACE_create_category (category, "user_type", "0"); + return TRACE_create_category(category, "user_type", "0"); } -void TRACE_define_type (const char *type, - const char *parent_type, int final) { - char *val_one = NULL; - if (!IS_TRACING) return; +void TRACE_define_type(const char *type, + const char *parent_type, int final) +{ + char *val_one = NULL; + if (!IS_TRACING) + return; //check if type is already defined - if (xbt_dict_get_or_null (defined_types, type)){ - THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type); + if (xbt_dict_get_or_null(defined_types, type)) { + THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, + "Type %s is already defined", type); } //check if parent_type is already defined - if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) { - THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type); + if (strcmp(parent_type, "0") + && !xbt_dict_get_or_null(defined_types, parent_type)) { + THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, + "Type (used as parent) %s is not defined", parent_type); } pajeDefineContainerType(type, parent_type, type); if (final) { //for m_process_t - if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process"); - if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state"); - - if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task"); - if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state"); - } - val_one = xbt_strdup ("1"); - xbt_dict_set (defined_types, type, &val_one, xbt_free); + if (IS_TRACING_PROCESSES) + pajeDefineContainerType("process", type, "process"); + if (IS_TRACING_PROCESSES) + pajeDefineStateType("process-state", "process", "process-state"); + + if (IS_TRACING_TASKS) + pajeDefineContainerType("task", type, "task"); + if (IS_TRACING_TASKS) + pajeDefineStateType("task-state", "task", "task-state"); + } + val_one = xbt_strdup("1"); + xbt_dict_set(defined_types, type, &val_one, xbt_free); } -int TRACE_create_category (const char *category, - const char *type, const char *parent_category) +int TRACE_create_category(const char *category, + const char *type, const char *parent_category) { char state[100]; char *val_one = NULL; - if (!IS_TRACING) return 1; + if (!IS_TRACING) + return 1; //check if type is defined - if (!xbt_dict_get_or_null (defined_types, type)) { - THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type); - return 1; + if (!xbt_dict_get_or_null(defined_types, type)) { + THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, + "Type %s is not defined", type); + return 1; } //check if parent_category exists - if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){ - THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category); - return 1; + if (strcmp(parent_category, "0") + && !xbt_dict_get_or_null(created_categories, parent_category)) { + THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, + "Category (used as parent) %s is not created", parent_category); + return 1; } //check if category is created - if (xbt_dict_get_or_null (created_categories, category)){ - return 1; + if (xbt_dict_get_or_null(created_categories, category)) { + return 1; } - pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category); + pajeCreateContainer(MSG_get_clock(), category, type, parent_category, + category); /* for registering application categories on top of platform */ - snprintf (state, 100, "b%s", category); - if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state); - snprintf (state, 100, "p%s", category); - if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state); + snprintf(state, 100, "b%s", category); + if (IS_TRACING_PLATFORM) + pajeDefineVariableType(state, "LINK", state); + snprintf(state, 100, "p%s", category); + if (IS_TRACING_PLATFORM) + pajeDefineVariableType(state, "HOST", state); - val_one = xbt_strdup ("1"); - xbt_dict_set (created_categories, category, &val_one, xbt_free); + val_one = xbt_strdup("1"); + xbt_dict_set(created_categories, category, &val_one, xbt_free); return 0; } -void TRACE_declare_mark (const char *mark_type) +void TRACE_declare_mark(const char *mark_type) { - if (!IS_TRACING) return; - if (!mark_type) return; + if (!IS_TRACING) + return; + if (!mark_type) + return; - pajeDefineEventType (mark_type, "0", mark_type); + pajeDefineEventType(mark_type, "0", mark_type); } -void TRACE_mark (const char *mark_type, const char *mark_value) +void TRACE_mark(const char *mark_type, const char *mark_value) { - if (!IS_TRACING) return; - if (!mark_type || !mark_value) return; + if (!IS_TRACING) + return; + if (!mark_type || !mark_value) + return; - pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value); + pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value); } -int TRACE_smpi_set_category (const char *category) +int TRACE_smpi_set_category(const char *category) { //if category is NULL, trace of platform is disabled - if (!IS_TRACING) return 1; - if (category != NULL){ - int ret = TRACE_category (category); - TRACE_category_set (SIMIX_process_self(), category); + if (!IS_TRACING) + return 1; + if (category != NULL) { + int ret = TRACE_category(category); + TRACE_category_set(SIMIX_process_self(), category); return ret; - }else{ - TRACE_category_unset (SIMIX_process_self()); + } else { + TRACE_category_unset(SIMIX_process_self()); return 0; } } -#endif /* HAVE_TRACING */ +#endif /* HAVE_TRACING */ diff --git a/src/instr/msg_process_instr.c b/src/instr/msg_process_instr.c index 44afeafa4e..d09b8f2a90 100644 --- a/src/instr/msg_process_instr.c +++ b/src/instr/msg_process_instr.c @@ -10,138 +10,159 @@ static xbt_dict_t process_containers = NULL; -void TRACE_msg_process_alloc (void) +void TRACE_msg_process_alloc(void) { process_containers = xbt_dict_new(); } -void TRACE_msg_process_release (void) +void TRACE_msg_process_release(void) { - xbt_dict_free (&process_containers); + xbt_dict_free(&process_containers); } -static void TRACE_msg_process_location (m_process_t process) +static void TRACE_msg_process_location(m_process_t process) { - char name[200], alias[200]; - m_host_t host = NULL; - if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME)) return; + char name[200], alias[200]; + m_host_t host = NULL; + if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME)) + return; - host = MSG_process_get_host (process); - TRACE_process_container (process, name, 200); - TRACE_process_alias_container (process, host, alias, 200); + host = MSG_process_get_host(process); + TRACE_process_container(process, name, 200); + TRACE_process_alias_container(process, host, alias, 200); //check if process_alias container is already created - if (!xbt_dict_get_or_null (process_containers, alias)){ - pajeCreateContainer (MSG_get_clock(), alias, "PROCESS", MSG_host_get_name(host), name); - if (IS_TRACING_PROCESSES) pajeSetState (MSG_get_clock(), "category", alias, process->category); - xbt_dict_set (process_containers, xbt_strdup(alias), xbt_strdup("1"), xbt_free); + if (!xbt_dict_get_or_null(process_containers, alias)) { + pajeCreateContainer(MSG_get_clock(), alias, "PROCESS", + MSG_host_get_name(host), name); + if (IS_TRACING_PROCESSES) + pajeSetState(MSG_get_clock(), "category", alias, process->category); + xbt_dict_set(process_containers, xbt_strdup(alias), xbt_strdup("1"), + xbt_free); } } -static void TRACE_msg_process_present (m_process_t process) +static void TRACE_msg_process_present(m_process_t process) { - char alias[200]; - m_host_t host = NULL; - if (!IS_TRACING_PROCESSES) return; + char alias[200]; + m_host_t host = NULL; + if (!IS_TRACING_PROCESSES) + return; //updating presence state of this process location - host = MSG_process_get_host (process); - TRACE_process_alias_container (process, host, alias, 200); - pajePushState (MSG_get_clock(), "presence", alias, "presence"); + host = MSG_process_get_host(process); + TRACE_process_alias_container(process, host, alias, 200); + pajePushState(MSG_get_clock(), "presence", alias, "presence"); } /* * TRACE_msg_set_process_category: tracing interface function */ -void TRACE_msg_set_process_category (m_process_t process, const char *category) +void TRACE_msg_set_process_category(m_process_t process, + const char *category) { - char name[200]; - if (!IS_TRACING) return; + char name[200]; + if (!IS_TRACING) + return; //set process category process->category = xbt_strdup(category); //create container of type "PROCESS" to indicate location - TRACE_msg_process_location (process); - TRACE_msg_process_present (process); + TRACE_msg_process_location(process); + TRACE_msg_process_present(process); //create container of type "process" to indicate behavior - TRACE_process_container (process, name, 200); - if (IS_TRACING_PROCESSES) pajeCreateContainer (MSG_get_clock(), name, "process", category, name); - if (IS_TRACING_PROCESSES) pajeSetState (MSG_get_clock(), "process-state", name, "executing"); + TRACE_process_container(process, name, 200); + if (IS_TRACING_PROCESSES) + pajeCreateContainer(MSG_get_clock(), name, "process", category, name); + if (IS_TRACING_PROCESSES) + pajeSetState(MSG_get_clock(), "process-state", name, "executing"); } /* * Instrumentation functions to trace MSG processes (m_process_t) */ -void TRACE_msg_process_change_host (m_process_t process, m_host_t old_host, m_host_t new_host) +void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, + m_host_t new_host) { - char alias[200]; - if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME) || !IS_TRACED(process)) return; + char alias[200]; + if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME) || !IS_TRACED(process)) + return; //disabling presence in old_host (__TRACE_msg_process_not_present) - TRACE_process_alias_container (process, old_host, alias, 200); - if (IS_TRACING_PROCESSES) pajePopState (MSG_get_clock(), "presence", alias); + TRACE_process_alias_container(process, old_host, alias, 200); + if (IS_TRACING_PROCESSES) + pajePopState(MSG_get_clock(), "presence", alias); - TRACE_msg_process_location (process); - TRACE_msg_process_present (process); + TRACE_msg_process_location(process); + TRACE_msg_process_present(process); } -void TRACE_msg_process_kill (m_process_t process) +void TRACE_msg_process_kill(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) return; + char name[200]; + if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) + return; - TRACE_process_container (process, name, 200); - pajeDestroyContainer (MSG_get_clock(), "process", name); + TRACE_process_container(process, name, 200); + pajeDestroyContainer(MSG_get_clock(), "process", name); } -void TRACE_msg_process_suspend (m_process_t process) -{ char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) return; +void TRACE_msg_process_suspend(m_process_t process) +{ + char name[200]; + if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) + return; - TRACE_process_container (process, name, 200); - pajeSetState (MSG_get_clock(), "process-state", name, "suspend"); + TRACE_process_container(process, name, 200); + pajeSetState(MSG_get_clock(), "process-state", name, "suspend"); } -void TRACE_msg_process_resume (m_process_t process) +void TRACE_msg_process_resume(m_process_t process) { char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) return; + if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) + return; - TRACE_process_container (process, name, 200); - pajeSetState (MSG_get_clock(), "process-state", name, "executing"); + TRACE_process_container(process, name, 200); + pajeSetState(MSG_get_clock(), "process-state", name, "executing"); } -void TRACE_msg_process_sleep_in (m_process_t process) +void TRACE_msg_process_sleep_in(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) return; + char name[200]; + if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) + return; - TRACE_process_container (process, name, 200); - pajeSetState (MSG_get_clock(), "process-state", name, "sleep"); + TRACE_process_container(process, name, 200); + pajeSetState(MSG_get_clock(), "process-state", name, "sleep"); } -void TRACE_msg_process_sleep_out (m_process_t process) +void TRACE_msg_process_sleep_out(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) return; + char name[200]; + if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) + return; - TRACE_process_container (process, name, 200); - pajeSetState (MSG_get_clock(), "process-state", name, "executing"); + TRACE_process_container(process, name, 200); + pajeSetState(MSG_get_clock(), "process-state", name, "executing"); } -void TRACE_msg_process_end (m_process_t process) +void TRACE_msg_process_end(m_process_t process) { - char name[200], alias[200]; - m_host_t host = NULL; - if (!IS_TRACED(process)) return; - - host = MSG_process_get_host (process); - TRACE_process_container (process, name, 200); - TRACE_process_alias_container (process, host, alias, 200); - if (IS_TRACING_PROCESSES) pajeDestroyContainer (MSG_get_clock(), "process", name); - if (IS_TRACING_PROCESSES) pajeDestroyContainer (MSG_get_clock(), "PROCESS", alias); + char name[200], alias[200]; + m_host_t host = NULL; + if (!IS_TRACED(process)) + return; + + host = MSG_process_get_host(process); + TRACE_process_container(process, name, 200); + TRACE_process_alias_container(process, host, alias, 200); + if (IS_TRACING_PROCESSES) + pajeDestroyContainer(MSG_get_clock(), "process", name); + if (IS_TRACING_PROCESSES) + pajeDestroyContainer(MSG_get_clock(), "PROCESS", alias); } #endif diff --git a/src/instr/msg_task_instr.c b/src/instr/msg_task_instr.c index ad1f3d2909..09e217a3a6 100644 --- a/src/instr/msg_task_instr.c +++ b/src/instr/msg_task_instr.c @@ -10,66 +10,69 @@ static xbt_dict_t task_containers = NULL; -void TRACE_msg_task_alloc (void) +void TRACE_msg_task_alloc(void) { task_containers = xbt_dict_new(); } -void TRACE_msg_task_release (void) +void TRACE_msg_task_release(void) { - xbt_dict_free (&task_containers); + xbt_dict_free(&task_containers); } -static void TRACE_task_location (m_task_t task) +static void TRACE_task_location(m_task_t task) { - char container[200]; - char name[200], alias[200]; - char *val_one = NULL; - m_process_t process = NULL; - m_host_t host = NULL; - if (!IS_TRACING_TASKS) return; + char container[200]; + char name[200], alias[200]; + char *val_one = NULL; + m_process_t process = NULL; + m_host_t host = NULL; + if (!IS_TRACING_TASKS) + return; process = MSG_process_self(); - host = MSG_process_get_host (process); + host = MSG_process_get_host(process); //tasks are grouped by host - TRACE_host_container (host, container, 200); - TRACE_task_container (task, name, 200); - TRACE_task_alias_container (task, process, host, alias, 200); + TRACE_host_container(host, container, 200); + TRACE_task_container(task, name, 200); + TRACE_task_alias_container(task, process, host, alias, 200); //check if task container is already created - if (!xbt_dict_get_or_null (task_containers, alias)){ - pajeCreateContainer (MSG_get_clock(), alias, "TASK", container, name); - pajeSetState (MSG_get_clock(), "category", alias, task->category); - val_one = xbt_strdup ("1"); - xbt_dict_set (task_containers, alias, val_one, xbt_free); + if (!xbt_dict_get_or_null(task_containers, alias)) { + pajeCreateContainer(MSG_get_clock(), alias, "TASK", container, name); + pajeSetState(MSG_get_clock(), "category", alias, task->category); + val_one = xbt_strdup("1"); + xbt_dict_set(task_containers, alias, val_one, xbt_free); } } -static void TRACE_task_location_present (m_task_t task) +static void TRACE_task_location_present(m_task_t task) { - char alias[200]; - m_process_t process = NULL; - m_host_t host = NULL; - if (!IS_TRACING_TASKS) return; + char alias[200]; + m_process_t process = NULL; + m_host_t host = NULL; + if (!IS_TRACING_TASKS) + return; //updating presence state of this task location process = MSG_process_self(); - host = MSG_process_get_host (process); + host = MSG_process_get_host(process); - TRACE_task_alias_container (task, process, host, alias, 200); - pajePushState (MSG_get_clock(), "presence", alias, "presence"); + TRACE_task_alias_container(task, process, host, alias, 200); + pajePushState(MSG_get_clock(), "presence", alias, "presence"); } -static void TRACE_task_location_not_present (m_task_t task) +static void TRACE_task_location_not_present(m_task_t task) { - char alias[200]; - m_process_t process = NULL; - m_host_t host = NULL; - if (!IS_TRACING_TASKS) return; + char alias[200]; + m_process_t process = NULL; + m_host_t host = NULL; + if (!IS_TRACING_TASKS) + return; //updating presence state of this task location process = MSG_process_self(); - host = MSG_process_get_host (process); + host = MSG_process_get_host(process); - TRACE_task_alias_container (task, process, host, alias, 200); - pajePopState (MSG_get_clock(), "presence", alias); + TRACE_task_alias_container(task, process, host, alias, 200); + pajePopState(MSG_get_clock(), "presence", alias); } /* @@ -77,25 +80,28 @@ static void TRACE_task_location_not_present (m_task_t task) */ void TRACE_msg_set_task_category(m_task_t task, const char *category) { - char name[200]; - if (!IS_TRACING) return; + char name[200]; + if (!IS_TRACING) + return; //set task category - task->category = xbt_new (char, strlen (category)+1); - strncpy(task->category, category, strlen(category)+1); + task->category = xbt_new(char, strlen(category) + 1); + strncpy(task->category, category, strlen(category) + 1); //tracing task location based on host - TRACE_task_location (task); - TRACE_task_location_present (task); + TRACE_task_location(task); + TRACE_task_location_present(task); - TRACE_task_container (task, name, 200); + TRACE_task_container(task, name, 200); //create container of type "task" to indicate behavior - if (IS_TRACING_TASKS) pajeCreateContainer (MSG_get_clock(), name, "task", category, name); - if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "created"); + if (IS_TRACING_TASKS) + pajeCreateContainer(MSG_get_clock(), name, "task", category, name); + if (IS_TRACING_TASKS) + pajePushState(MSG_get_clock(), "task-state", name, "created"); } /* MSG_task_create related function*/ -void TRACE_msg_task_create (m_task_t task) +void TRACE_msg_task_create(m_task_t task) { static long long counter = 0; task->counter = counter++; @@ -103,90 +109,103 @@ void TRACE_msg_task_create (m_task_t task) } /* MSG_task_execute related functions */ -void TRACE_msg_task_execute_start (m_task_t task) +void TRACE_msg_task_execute_start(m_task_t task) { - char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) return; + char name[200]; + if (!IS_TRACING || !IS_TRACED(task)) + return; - TRACE_task_container (task, name, 200); - if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "execute"); + TRACE_task_container(task, name, 200); + if (IS_TRACING_TASKS) + pajePushState(MSG_get_clock(), "task-state", name, "execute"); - TRACE_msg_category_set (SIMIX_process_self(), task); + TRACE_msg_category_set(SIMIX_process_self(), task); } -void TRACE_msg_task_execute_end (m_task_t task) +void TRACE_msg_task_execute_end(m_task_t task) { - char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) return; + char name[200]; + if (!IS_TRACING || !IS_TRACED(task)) + return; - TRACE_task_container (task, name, 200); - if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name); + TRACE_task_container(task, name, 200); + if (IS_TRACING_TASKS) + pajePopState(MSG_get_clock(), "task-state", name); TRACE_category_unset(SIMIX_process_self()); } /* MSG_task_destroy related functions */ -void TRACE_msg_task_destroy (m_task_t task) +void TRACE_msg_task_destroy(m_task_t task) { - char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) return; + char name[200]; + if (!IS_TRACING || !IS_TRACED(task)) + return; - TRACE_task_container (task, name, 200); - if (IS_TRACING_TASKS) pajeDestroyContainer (MSG_get_clock(), "task", name); + TRACE_task_container(task, name, 200); + if (IS_TRACING_TASKS) + pajeDestroyContainer(MSG_get_clock(), "task", name); //finish the location of this task - TRACE_task_location_not_present (task); + TRACE_task_location_not_present(task); //free category - xbt_free (task->category); + xbt_free(task->category); return; } /* MSG_task_get related functions */ -void TRACE_msg_task_get_start (void) +void TRACE_msg_task_get_start(void) { - if (!IS_TRACING) return; + if (!IS_TRACING) + return; } -void TRACE_msg_task_get_end (double start_time, m_task_t task) +void TRACE_msg_task_get_end(double start_time, m_task_t task) { - char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) return; + char name[200]; + if (!IS_TRACING || !IS_TRACED(task)) + return; - TRACE_task_container (task, name, 200); - if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name); + TRACE_task_container(task, name, 200); + if (IS_TRACING_TASKS) + pajePopState(MSG_get_clock(), "task-state", name); - TRACE_msg_volume_finish (task); + TRACE_msg_volume_finish(task); - TRACE_task_location (task); - TRACE_task_location_present (task); + TRACE_task_location(task); + TRACE_task_location_present(task); } /* MSG_task_put related functions */ -int TRACE_msg_task_put_start (m_task_t task) +int TRACE_msg_task_put_start(m_task_t task) { - char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) return 0; + char name[200]; + if (!IS_TRACING || !IS_TRACED(task)) + return 0; - TRACE_task_container (task, name, 200); - if (IS_TRACING_TASKS) pajePopState (MSG_get_clock(), "task-state", name); - if (IS_TRACING_TASKS) pajePushState (MSG_get_clock(), "task-state", name, "communicate"); + TRACE_task_container(task, name, 200); + if (IS_TRACING_TASKS) + pajePopState(MSG_get_clock(), "task-state", name); + if (IS_TRACING_TASKS) + pajePushState(MSG_get_clock(), "task-state", name, "communicate"); - TRACE_msg_volume_start (task); + TRACE_msg_volume_start(task); //trace task location grouped by host - TRACE_task_location_not_present (task); + TRACE_task_location_not_present(task); //set current category - TRACE_msg_category_set (SIMIX_process_self(), task); + TRACE_msg_category_set(SIMIX_process_self(), task); return 1; } -void TRACE_msg_task_put_end (void) +void TRACE_msg_task_put_end(void) { - if (!IS_TRACING) return; + if (!IS_TRACING) + return; - TRACE_category_unset (SIMIX_process_self()); + TRACE_category_unset(SIMIX_process_self()); } #endif diff --git a/src/instr/msg_volume.c b/src/instr/msg_volume.c index 8544449355..91a52acbe0 100644 --- a/src/instr/msg_volume.c +++ b/src/instr/msg_volume.c @@ -8,53 +8,61 @@ #ifdef HAVE_TRACING -void TRACE_msg_volume_start (m_task_t task) +void TRACE_msg_volume_start(m_task_t task) { - m_process_t process = NULL; - m_host_t host = NULL; - char process_name[200], process_alias[200]; - char task_name[200]; - double volume = 0; - if (!IS_TRACING_VOLUME) return; + m_process_t process = NULL; + m_host_t host = NULL; + char process_name[200], process_alias[200]; + char task_name[200]; + double volume = 0; + if (!IS_TRACING_VOLUME) + return; /* check if task is traced */ - if (!IS_TRACED(task)) return; + if (!IS_TRACED(task)) + return; /* check if process is traced */ - process = MSG_process_self (); - if (!IS_TRACED(process)) return; + process = MSG_process_self(); + if (!IS_TRACED(process)) + return; - host = MSG_process_get_host (process); - TRACE_process_container (process, process_name, 200); - TRACE_process_alias_container (process, host, process_alias, 200); - TRACE_task_container (task, task_name, 200); + host = MSG_process_get_host(process); + TRACE_process_container(process, process_name, 200); + TRACE_process_alias_container(process, host, process_alias, 200); + TRACE_task_container(task, task_name, 200); - volume = MSG_task_get_data_size (task); + volume = MSG_task_get_data_size(task); - pajeStartLinkWithVolume (MSG_get_clock(), "volume", "0", task->category, process_alias, task_name, volume); + pajeStartLinkWithVolume(MSG_get_clock(), "volume", "0", task->category, + process_alias, task_name, volume); } -void TRACE_msg_volume_finish (m_task_t task) +void TRACE_msg_volume_finish(m_task_t task) { - char process_name[200], process_alias[200]; - char task_name[200]; - m_process_t process = NULL; - m_host_t host = NULL; - if (!IS_TRACING_VOLUME) return; + char process_name[200], process_alias[200]; + char task_name[200]; + m_process_t process = NULL; + m_host_t host = NULL; + if (!IS_TRACING_VOLUME) + return; /* check if task is traced */ - if (!IS_TRACED(task)) return; + if (!IS_TRACED(task)) + return; /* check if process is traced */ - process = MSG_process_self (); - if (!IS_TRACED(process)) return; + process = MSG_process_self(); + if (!IS_TRACED(process)) + return; - host = MSG_process_get_host (process); - TRACE_process_container (process, process_name, 200); - TRACE_process_alias_container (process, host, process_alias, 200); - TRACE_task_container (task, task_name, 200); + host = MSG_process_get_host(process); + TRACE_process_container(process, process_name, 200); + TRACE_process_alias_container(process, host, process_alias, 200); + TRACE_task_container(task, task_name, 200); - pajeEndLink (MSG_get_clock(), "volume", "0", task->category, process_alias, task_name); + pajeEndLink(MSG_get_clock(), "volume", "0", task->category, + process_alias, task_name); } #endif diff --git a/src/instr/paje.c b/src/instr/paje.c index 63144a7fcf..9a9e98b331 100644 --- a/src/instr/paje.c +++ b/src/instr/paje.c @@ -42,25 +42,24 @@ static int pajeNewEventId = 27; #define TRACE_LINE_SIZE 1000 -void TRACE_paje_start (FILE *file) +void TRACE_paje_start(FILE * file) { tracing_file = file; tracing_active = 1; } -FILE *TRACE_paje_end (void) +FILE *TRACE_paje_end(void) { tracing_active = 0; return tracing_file; } -void TRACE_paje_create_header(void) { +void TRACE_paje_create_header(void) +{ if (!tracing_active) return; - fprintf( - tracing_file, - "\ + fprintf(tracing_file, "\ %%EventDef PajeDefineContainerType %d \n\ %% Alias string \n\ %% ContainerType string \n\ @@ -170,151 +169,183 @@ void TRACE_paje_create_header(void) { %% EntityType string \n\ %% Container string \n\ %% Value string \n\ -%%EndEventDef\n", - pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, - pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, - pajeDestroyContainerId, pajeSetStateId, - pajePopStateId, - pajeStartLinkId, pajeEndLinkId, - pajePushStateId, - pajeSetVariableId, - pajeAddVariableId, - pajeSubVariableId, - pajeDefineVariableTypeId, - pajeStartLinkWithVolumeId, - pajeNewEventId); +%%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeStartLinkWithVolumeId, pajeNewEventId); } /* internal to this file */ -static void __pajeCreateContainer (char *output, int len, int eventid, double time, const char *alias, const char *type, - const char *container, const char *name) +static void __pajeCreateContainer(char *output, int len, int eventid, + double time, const char *alias, + const char *type, const char *container, + const char *name) { - snprintf (output, len, "%d %lf %s %s %s %s", eventid, time, - alias, type, container, name); + snprintf(output, len, "%d %lf %s %s %s %s", eventid, time, + alias, type, container, name); } -static void __pajeSetState (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value) +static void __pajeSetState(char *output, int len, int eventid, double time, + const char *entityType, const char *container, + const char *value) { - snprintf (output, len, "%d %lf %s %s %s", eventid, time, entityType, container, value); + snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType, + container, value); } -static void __pajeSetVariable (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value) +static void __pajeSetVariable(char *output, int len, int eventid, + double time, const char *entityType, + const char *container, const char *value) { - snprintf (output, len, "%d %lf %s %s %s", eventid, time, entityType, container, value); + snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType, + container, value); } -static void __pajeStartLink (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value, -const char *sourceContainer, const char *key) +static void __pajeStartLink(char *output, int len, int eventid, + double time, const char *entityType, + const char *container, const char *value, + const char *sourceContainer, const char *key) { - snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType, container, value, sourceContainer, key); + snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType, + container, value, sourceContainer, key); } /* internal do the instrumentation module */ void pajeDefineContainerType(const char *alias, const char *containerType, - const char *name) { + const char *name) +{ fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias, - containerType, name); + containerType, name); } void pajeDefineStateType(const char *alias, const char *containerType, - const char *name) { + const char *name) +{ fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias, - containerType, name); + containerType, name); } void pajeDefineEventType(const char *alias, const char *containerType, - const char *name) { + const char *name) +{ fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias, - containerType, name); + containerType, name); } void pajeDefineLinkType(const char *alias, const char *containerType, - const char *sourceContainerType, const char *destContainerType, - const char *name) { + const char *sourceContainerType, + const char *destContainerType, const char *name) +{ fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias, - containerType, sourceContainerType, destContainerType, name); + containerType, sourceContainerType, destContainerType, name); } -void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name) { +void pajeCreateContainer(double time, const char *alias, const char *type, + const char *container, const char *name) +{ char line[TRACE_LINE_SIZE]; - __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerId, time, alias, type, container, name); - fprintf (tracing_file, "%s\n", line); + __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time, + alias, type, container, name); + fprintf(tracing_file, "%s\n", line); } -void pajeDestroyContainer (double time, const char *type, const char *container) +void pajeDestroyContainer(double time, const char *type, + const char *container) { - fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time, type, container); + fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time, + type, container); } -void pajeSetState (double time, const char *entityType, const char *container, const char *value) +void pajeSetState(double time, const char *entityType, + const char *container, const char *value) { char line[TRACE_LINE_SIZE]; - __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, container, value); + __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, + container, value); fprintf(tracing_file, "%s\n", line); } -void pajePushState (double time, const char *entityType, const char *container, const char *value) +void pajePushState(double time, const char *entityType, + const char *container, const char *value) { char line[TRACE_LINE_SIZE]; - __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, container, value); + __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, + container, value); fprintf(tracing_file, "%s\n", line); } -void pajePopState (double time, const char *entityType, const char *container) +void pajePopState(double time, const char *entityType, + const char *container) { - fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType, container); + fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType, + container); } -void pajeStartLink (double time, const char *entityType, const char *container, const char *value, - const char *sourceContainer, const char *key) +void pajeStartLink(double time, const char *entityType, + const char *container, const char *value, + const char *sourceContainer, const char *key) { char line[TRACE_LINE_SIZE]; - __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, container, value, sourceContainer, key); - fprintf (tracing_file, "%s\n", line); + __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, + container, value, sourceContainer, key); + fprintf(tracing_file, "%s\n", line); } -void pajeStartLinkWithVolume (double time, const char *entityType, const char *container, const char *value, - const char *sourceContainer, const char *key, double volume) +void pajeStartLinkWithVolume(double time, const char *entityType, + const char *container, const char *value, + const char *sourceContainer, const char *key, + double volume) { char line[TRACE_LINE_SIZE]; - __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, entityType, container, value, sourceContainer, key); - fprintf (tracing_file, "%s %f\n", line, volume); + __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, + entityType, container, value, sourceContainer, key); + fprintf(tracing_file, "%s %f\n", line, volume); } -void pajeEndLink (double time, const char *entityType, const char *container, const char *value, - const char *destContainer, const char *key) +void pajeEndLink(double time, const char *entityType, + const char *container, const char *value, + const char *destContainer, const char *key) { - fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time, entityType, container, value, destContainer, key); + fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time, + entityType, container, value, destContainer, key); } -void pajeDefineVariableType(const char *alias, const char *containerType, const char *name) { - fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, containerType, name); +void pajeDefineVariableType(const char *alias, const char *containerType, + const char *name) +{ + fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, + containerType, name); } -void pajeSetVariable (double time, const char *entityType, const char *container, const char *value) +void pajeSetVariable(double time, const char *entityType, + const char *container, const char *value) { char line[TRACE_LINE_SIZE]; - __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSetVariableId, time, entityType, container, value); + __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time, + entityType, container, value); fprintf(tracing_file, "%s\n", line); } -void pajeAddVariable (double time, const char *entityType, const char *container, const char *value) +void pajeAddVariable(double time, const char *entityType, + const char *container, const char *value) { char line[TRACE_LINE_SIZE]; - __pajeSetVariable (line, TRACE_LINE_SIZE, pajeAddVariableId, time, entityType, container, value); + __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time, + entityType, container, value); fprintf(tracing_file, "%s\n", line); } -void pajeSubVariable (double time, const char *entityType, const char *container, const char *value) +void pajeSubVariable(double time, const char *entityType, + const char *container, const char *value) { char line[TRACE_LINE_SIZE]; - __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSubVariableId, time, entityType, container, value); + __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time, + entityType, container, value); fprintf(tracing_file, "%s\n", line); } -void pajeNewEvent (double time, const char *entityType, const char *container, const char *value) +void pajeNewEvent(double time, const char *entityType, + const char *container, const char *value) { - fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time, entityType, container, value); + fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time, + entityType, container, value); } #endif diff --git a/src/instr/private.h b/src/instr/private.h index d81839df92..99eccbc12a 100644 --- a/src/instr/private.h +++ b/src/instr/private.h @@ -11,7 +11,7 @@ #ifdef HAVE_TRACING -extern int tracing_active; /* declared in paje.c */ +extern int tracing_active; /* declared in paje.c */ #define IS_TRACING (tracing_active) #define IS_TRACED(n) (n->category) @@ -28,133 +28,176 @@ extern int tracing_active; /* declared in paje.c */ /* from paje.c */ void TRACE_paje_create_header(void); -void TRACE_paje_start (FILE *file); -FILE *TRACE_paje_end (void); -void pajeDefineContainerType(const char *alias, const char *containerType, const char *name); -void pajeDefineStateType(const char *alias, const char *containerType, const char *name); -void pajeDefineEventType(const char *alias, const char *containerType, const char *name); -void pajeDefineLinkType(const char *alias, const char *containerType, const char *sourceContainerType, const char *destContainerType, const char *name); -void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name); -void pajeDestroyContainer (double time, const char *type, const char *container); -void pajeSetState (double time, const char *entityType, const char *container, const char *value); -void pajePushState (double time, const char *entityType, const char *container, const char *value); -void pajePopState (double time, const char *entityType, const char *container); -void pajeStartLink (double time, const char *entityType, const char *container, const char *value, const char *sourceContainer, const char *key); -void pajeStartLinkWithVolume (double time, const char *entityType, const char *container, const char *value, const char *sourceContainer, const char *key, double volume); -void pajeEndLink (double time, const char *entityType, const char *container, const char *value, const char *destContainer, const char *key); -void pajeDefineVariableType(const char *alias, const char *containerType, const char *name); -void pajeSetVariable (double time, const char *entityType, const char *container, const char *value); -void pajeAddVariable (double time, const char *entityType, const char *container, const char *value); -void pajeSubVariable (double time, const char *entityType, const char *container, const char *value); -void pajeNewEvent (double time, const char *entityType, const char *container, const char *value); +void TRACE_paje_start(FILE * file); +FILE *TRACE_paje_end(void); +void pajeDefineContainerType(const char *alias, const char *containerType, + const char *name); +void pajeDefineStateType(const char *alias, const char *containerType, + const char *name); +void pajeDefineEventType(const char *alias, const char *containerType, + const char *name); +void pajeDefineLinkType(const char *alias, const char *containerType, + const char *sourceContainerType, + const char *destContainerType, const char *name); +void pajeCreateContainer(double time, const char *alias, const char *type, + const char *container, const char *name); +void pajeDestroyContainer(double time, const char *type, + const char *container); +void pajeSetState(double time, const char *entityType, + const char *container, const char *value); +void pajePushState(double time, const char *entityType, + const char *container, const char *value); +void pajePopState(double time, const char *entityType, + const char *container); +void pajeStartLink(double time, const char *entityType, + const char *container, const char *value, + const char *sourceContainer, const char *key); +void pajeStartLinkWithVolume(double time, const char *entityType, + const char *container, const char *value, + const char *sourceContainer, const char *key, + double volume); +void pajeEndLink(double time, const char *entityType, + const char *container, const char *value, + const char *destContainer, const char *key); +void pajeDefineVariableType(const char *alias, const char *containerType, + const char *name); +void pajeSetVariable(double time, const char *entityType, + const char *container, const char *value); +void pajeAddVariable(double time, const char *entityType, + const char *container, const char *value); +void pajeSubVariable(double time, const char *entityType, + const char *container, const char *value); +void pajeNewEvent(double time, const char *entityType, + const char *container, const char *value); /* from general.c */ -char *TRACE_paje_msg_container (m_task_t task, char *host, char *output, int len); -char *TRACE_paje_smx_container (smx_action_t action, int seqnumber, char *host, char *output, int len); -char *TRACE_paje_surf_container (void *action, int seqnumber, char *output, int len); -char *TRACE_host_container (m_host_t host, char *output, int len); -char *TRACE_task_container (m_task_t task, char *output, int len); -char *TRACE_process_container (m_process_t process, char *output, int len); -char *TRACE_process_alias_container (m_process_t process, m_host_t host, char *output, int len); -char *TRACE_task_alias_container (m_task_t task, m_process_t process, m_host_t host, char *output, int len); +char *TRACE_paje_msg_container(m_task_t task, char *host, char *output, + int len); +char *TRACE_paje_smx_container(smx_action_t action, int seqnumber, + char *host, char *output, int len); +char *TRACE_paje_surf_container(void *action, int seqnumber, char *output, + int len); +char *TRACE_host_container(m_host_t host, char *output, int len); +char *TRACE_task_container(m_task_t task, char *output, int len); +char *TRACE_process_container(m_process_t process, char *output, int len); +char *TRACE_process_alias_container(m_process_t process, m_host_t host, + char *output, int len); +char *TRACE_task_alias_container(m_task_t task, m_process_t process, + m_host_t host, char *output, int len); /* from categories.c */ -void TRACE_category_alloc (void); -void TRACE_category_release (void); -void TRACE_category_set (smx_process_t proc, const char *category); -char *TRACE_category_get (smx_process_t proc); -void TRACE_category_unset (smx_process_t proc); -void TRACE_msg_category_set (smx_process_t proc, m_task_t task); +void TRACE_category_alloc(void); +void TRACE_category_release(void); +void TRACE_category_set(smx_process_t proc, const char *category); +char *TRACE_category_get(smx_process_t proc); +void TRACE_category_unset(smx_process_t proc); +void TRACE_msg_category_set(smx_process_t proc, m_task_t task); /* declaration of instrumentation functions from msg_task_instr.c */ -void TRACE_msg_task_alloc (void); -void TRACE_msg_task_release (void); -void TRACE_msg_task_create (m_task_t task); -void TRACE_msg_task_execute_start (m_task_t task); -void TRACE_msg_task_execute_end (m_task_t task); -void TRACE_msg_task_destroy (m_task_t task); +void TRACE_msg_task_alloc(void); +void TRACE_msg_task_release(void); +void TRACE_msg_task_create(m_task_t task); +void TRACE_msg_task_execute_start(m_task_t task); +void TRACE_msg_task_execute_end(m_task_t task); +void TRACE_msg_task_destroy(m_task_t task); void TRACE_msg_task_get_start(void); -void TRACE_msg_task_get_end (double start_time, m_task_t task); -int TRACE_msg_task_put_start (m_task_t task); //returns TRUE if the task_put_end must be called -void TRACE_msg_task_put_end (void); +void TRACE_msg_task_get_end(double start_time, m_task_t task); +int TRACE_msg_task_put_start(m_task_t task); //returns TRUE if the task_put_end must be called +void TRACE_msg_task_put_end(void); /* declaration of instrumentation functions from msg_process_instr.c */ -void TRACE_msg_process_alloc (void); -void TRACE_msg_process_release (void); -void TRACE_msg_process_change_host (m_process_t process, m_host_t old_host, m_host_t new_host); -void TRACE_msg_process_kill (m_process_t process); -void TRACE_msg_process_suspend (m_process_t process); -void TRACE_msg_process_resume (m_process_t process); -void TRACE_msg_process_sleep_in (m_process_t process); //called from msg/gos.c -void TRACE_msg_process_sleep_out (m_process_t process); -void TRACE_msg_process_end (m_process_t process); +void TRACE_msg_process_alloc(void); +void TRACE_msg_process_release(void); +void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, + m_host_t new_host); +void TRACE_msg_process_kill(m_process_t process); +void TRACE_msg_process_suspend(m_process_t process); +void TRACE_msg_process_resume(m_process_t process); +void TRACE_msg_process_sleep_in(m_process_t process); //called from msg/gos.c +void TRACE_msg_process_sleep_out(m_process_t process); +void TRACE_msg_process_end(m_process_t process); /* declaration of instrumentation functions from msg_volume.c */ -void TRACE_msg_volume_start (m_task_t task); -void TRACE_msg_volume_finish (m_task_t task); +void TRACE_msg_volume_start(m_task_t task); +void TRACE_msg_volume_finish(m_task_t task); /* from smx.c */ -void TRACE_smx_action_execute (smx_action_t act); -void TRACE_smx_action_communicate (smx_action_t act, smx_process_t proc); -void TRACE_smx_action_destroy (smx_action_t act); +void TRACE_smx_action_execute(smx_action_t act); +void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc); +void TRACE_smx_action_destroy(smx_action_t act); /* from surf_instr.c */ -void TRACE_surf_alloc (void); -void TRACE_surf_release (void); -void TRACE_surf_host_declaration (const char *name, double power); -void TRACE_surf_host_set_power (double date, const char *resource, double power); -void TRACE_surf_host_define_id (const char *name, int host_id); -void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h); -void TRACE_surf_link_declaration (void *link, char *name, double bw, double lat); -void TRACE_surf_link_set_bandwidth (double date, void *link, double bandwidth); -void TRACE_surf_link_set_latency (double date, void *link, double latency); -void TRACE_surf_save_onelink (void); -int TRACE_surf_link_is_traced (void *link); -void TRACE_surf_action (surf_action_t surf_action, const char *category); +void TRACE_surf_alloc(void); +void TRACE_surf_release(void); +void TRACE_surf_host_declaration(const char *name, double power); +void TRACE_surf_host_set_power(double date, const char *resource, + double power); +void TRACE_surf_host_define_id(const char *name, int host_id); +void TRACE_surf_host_vivaldi_parse(char *host, double x, double y, + double h); +void TRACE_surf_link_declaration(void *link, char *name, double bw, + double lat); +void TRACE_surf_link_set_bandwidth(double date, void *link, + double bandwidth); +void TRACE_surf_link_set_latency(double date, void *link, double latency); +void TRACE_surf_save_onelink(void); +int TRACE_surf_link_is_traced(void *link); +void TRACE_surf_action(surf_action_t surf_action, const char *category); //for tracing gtnets -void TRACE_surf_gtnets_communicate (void *action, int src, int dst); -int TRACE_surf_gtnets_get_src (void *action); -int TRACE_surf_gtnets_get_dst (void *action); -void TRACE_surf_gtnets_destroy (void *action); +void TRACE_surf_gtnets_communicate(void *action, int src, int dst); +int TRACE_surf_gtnets_get_src(void *action); +int TRACE_surf_gtnets_get_dst(void *action); +void TRACE_surf_gtnets_destroy(void *action); /* from smpi_instr.c */ -void TRACE_smpi_alloc (void); -void TRACE_smpi_release (void); -void TRACE_smpi_init (int rank); -void TRACE_smpi_finalize (int rank); -void TRACE_smpi_start (void); -void TRACE_smpi_collective_in (int rank, int root, const char *operation); -void TRACE_smpi_collective_out (int rank, int root, const char *operation); -void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation); -void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation); -void TRACE_smpi_send (int rank, int src, int dst); -void TRACE_smpi_recv (int rank, int src, int dst); +void TRACE_smpi_alloc(void); +void TRACE_smpi_release(void); +void TRACE_smpi_init(int rank); +void TRACE_smpi_finalize(int rank); +void TRACE_smpi_start(void); +void TRACE_smpi_collective_in(int rank, int root, const char *operation); +void TRACE_smpi_collective_out(int rank, int root, const char *operation); +void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation); +void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation); +void TRACE_smpi_send(int rank, int src, int dst); +void TRACE_smpi_recv(int rank, int src, int dst); /* from instr_config.c */ -int TRACE_is_configured (void); -int TRACE_smpi_is_enabled (void); -int TRACE_platform_is_enabled (void); -int TRACE_msg_task_is_enabled (void); -int TRACE_msg_process_is_enabled (void); -int TRACE_msg_volume_is_enabled (void); -char *TRACE_get_filename (void); -char *TRACE_get_platform_method (void); +int TRACE_is_configured(void); +int TRACE_smpi_is_enabled(void); +int TRACE_platform_is_enabled(void); +int TRACE_msg_task_is_enabled(void); +int TRACE_msg_process_is_enabled(void); +int TRACE_msg_volume_is_enabled(void); +char *TRACE_get_filename(void); +char *TRACE_get_platform_method(void); void TRACE_global_init(int *argc, char **argv); /* from resource_utilization.c */ -void TRACE_surf_host_set_utilization (const char *name, smx_action_t smx_action, surf_action_t surf_action, double value, double now, double delta); -void TRACE_surf_link_set_utilization (void *link, smx_action_t smx_action, surf_action_t surf_action, double value, double now, double delta); -void TRACE_surf_resource_utilization_start (smx_action_t action); -void TRACE_surf_resource_utilization_event (smx_action_t action, double now, double delta, const char *variable, const char *resource, double value); -void TRACE_surf_resource_utilization_end (smx_action_t action); -void TRACE_surf_resource_utilization_alloc (void); -void TRACE_surf_resource_utilization_release (void); +void TRACE_surf_host_set_utilization(const char *name, + smx_action_t smx_action, + surf_action_t surf_action, + double value, double now, + double delta); +void TRACE_surf_link_set_utilization(void *link, smx_action_t smx_action, + surf_action_t surf_action, + double value, double now, + double delta); +void TRACE_surf_resource_utilization_start(smx_action_t action); +void TRACE_surf_resource_utilization_event(smx_action_t action, double now, + double delta, + const char *variable, + const char *resource, + double value); +void TRACE_surf_resource_utilization_end(smx_action_t action); +void TRACE_surf_resource_utilization_alloc(void); +void TRACE_surf_resource_utilization_release(void); /* sd_instr.c */ -void TRACE_sd_task_create (SD_task_t task); -void TRACE_sd_task_destroy (SD_task_t task); +void TRACE_sd_task_create(SD_task_t task); +void TRACE_sd_task_destroy(SD_task_t task); #endif -#endif /* PRIVATE_H_ */ +#endif /* PRIVATE_H_ */ diff --git a/src/instr/resource_utilization.c b/src/instr/resource_utilization.c index b41c6b0dd5..03c49e292a 100644 --- a/src/instr/resource_utilization.c +++ b/src/instr/resource_utilization.c @@ -11,7 +11,7 @@ #define VARIABLE_SEPARATOR '#' //to check if variables were previously set to 0, otherwise paje won't simulate them -static xbt_dict_t platform_variables; /* host or link name -> array of categories */ +static xbt_dict_t platform_variables; /* host or link name -> array of categories */ //B static xbt_dict_t method_b_dict; @@ -20,61 +20,69 @@ static xbt_dict_t method_b_dict; static xbt_dict_t method_c_dict; /* auxiliary function for resource utilization tracing */ -static char *strsplit (char *input, int field, char del) //caller should free the returned string +static char *strsplit(char *input, int field, char del) //caller should free the returned string { char *ret = NULL; int length = strlen(input), i; - int s = 0, e = length+1; + int s = 0, e = length + 1; int current_field = 0; - for (i = 0; i < length; i++){ - if (input[i] == del){ - if (current_field == field){ - e = i-1; - break; - }else{ - s = i+1; - current_field++; - } - } + for (i = 0; i < length; i++) { + if (input[i] == del) { + if (current_field == field) { + e = i - 1; + break; + } else { + s = i + 1; + current_field++; + } + } } //copy string from s to e (with length equal to e-s) and return - ret = malloc ((e-s+2)*sizeof(char)); - strncpy (ret, input+s, e-s+1); - ret[e-s+1] = '\0'; + ret = malloc((e - s + 2) * sizeof(char)); + strncpy(ret, input + s, e - s + 1); + ret[e - s + 1] = '\0'; return ret; } //resource utilization tracing method -static void (*TRACE_method_alloc)(void) = NULL; -static void (*TRACE_method_release)(void) = NULL; -static void (*TRACE_method_start)(smx_action_t action) = NULL; -static void (*TRACE_method_event)(smx_action_t action, double now, double delta, const char *variable, const char *resource, double value) = NULL; -static void (*TRACE_method_end)(smx_action_t action) = NULL; +static void (*TRACE_method_alloc) (void) = NULL; +static void (*TRACE_method_release) (void) = NULL; +static void (*TRACE_method_start) (smx_action_t action) = NULL; +static void (*TRACE_method_event) (smx_action_t action, double now, + double delta, const char *variable, + const char *resource, double value) = + NULL; +static void (*TRACE_method_end) (smx_action_t action) = NULL; //used by all methods -static void __TRACE_surf_check_variable_set_to_zero (double now, const char *variable, const char *resource) +static void __TRACE_surf_check_variable_set_to_zero(double now, + const char *variable, + const char *resource) { /* check if we have to set it to 0 */ - if (!xbt_dict_get_or_null (platform_variables, resource)){ - xbt_dynar_t array = xbt_dynar_new(sizeof(char*), xbt_free); + if (!xbt_dict_get_or_null(platform_variables, resource)) { + xbt_dynar_t array = xbt_dynar_new(sizeof(char *), xbt_free); char *var_cpy = xbt_strdup(variable); - xbt_dynar_push (array, &var_cpy); - if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0"); - xbt_dict_set (platform_variables, resource, array, xbt_dynar_free_voidp); - }else{ - xbt_dynar_t array = xbt_dict_get (platform_variables, resource); + xbt_dynar_push(array, &var_cpy); + if (IS_TRACING_PLATFORM) + pajeSetVariable(now, variable, resource, "0"); + xbt_dict_set(platform_variables, resource, array, + xbt_dynar_free_voidp); + } else { + xbt_dynar_t array = xbt_dict_get(platform_variables, resource); unsigned int i; - char* cat; + char *cat; int flag = 0; - xbt_dynar_foreach (array, i, cat) { - if (strcmp(variable, cat)==0){ + xbt_dynar_foreach(array, i, cat) { + if (strcmp(variable, cat) == 0) { flag = 1; } } - if (flag==0){ + if (flag == 0) { char *var_cpy = xbt_strdup(variable); - xbt_dynar_push (array, &var_cpy); - if (IS_TRACING_PLATFORM) pajeSetVariable (now, variable, resource, "0"); + xbt_dynar_push(array, &var_cpy); + if (IS_TRACING_PLATFORM) + pajeSetVariable(now, variable, resource, "0"); } } /* end of check */ @@ -82,85 +90,109 @@ static void __TRACE_surf_check_variable_set_to_zero (double now, const char *var #define A_METHOD //A -static void __TRACE_A_alloc (void) {} -static void __TRACE_A_release (void) {} -static void __TRACE_A_start (smx_action_t action) {} -static void __TRACE_A_event (smx_action_t action, double now, double delta, const char *variable, const char *resource, double value) +static void __TRACE_A_alloc(void) +{ +} + +static void __TRACE_A_release(void) +{ +} + +static void __TRACE_A_start(smx_action_t action) +{ +} + +static void __TRACE_A_event(smx_action_t action, double now, double delta, + const char *variable, const char *resource, + double value) { - if (!IS_TRACING_PLATFORM) return; + if (!IS_TRACING_PLATFORM) + return; char valuestr[100]; - snprintf (valuestr, 100, "%f", value); + snprintf(valuestr, 100, "%f", value); - __TRACE_surf_check_variable_set_to_zero (now, variable, resource); - pajeAddVariable (now, variable, resource, valuestr); - pajeSubVariable (now+delta, variable, resource, valuestr); + __TRACE_surf_check_variable_set_to_zero(now, variable, resource); + pajeAddVariable(now, variable, resource, valuestr); + pajeSubVariable(now + delta, variable, resource, valuestr); +} + +static void __TRACE_A_end(smx_action_t action) +{ } -static void __TRACE_A_end (smx_action_t action) {} #define B_METHOD //B -static void __TRACE_B_alloc (void) +static void __TRACE_B_alloc(void) { - method_b_dict = xbt_dict_new(); + method_b_dict = xbt_dict_new(); } -static void __TRACE_B_release (void) +static void __TRACE_B_release(void) { xbt_dict_cursor_t cursor = NULL; unsigned int cursor_ar = 0; - char *key, *value, *res; - char *resource; - char *aux = NULL; - char *var_cpy = NULL; - xbt_dynar_t resources = NULL; - if (!IS_TRACING_PLATFORM) return; - if (!xbt_dict_length(method_b_dict)){ + char *key, *value, *res; + char *resource; + char *aux = NULL; + char *var_cpy = NULL; + xbt_dynar_t resources = NULL; + if (!IS_TRACING_PLATFORM) + return; + if (!xbt_dict_length(method_b_dict)) { return; - }else{ + } else { /* get all resources from method_b_dict */ - resources = xbt_dynar_new(sizeof(char*), xbt_free); + resources = xbt_dynar_new(sizeof(char *), xbt_free); xbt_dict_foreach(method_b_dict, cursor, key, value) { - res = strsplit (key, 0, VARIABLE_SEPARATOR); - aux = strsplit (key, 1, VARIABLE_SEPARATOR); - if (strcmp (aux, "Time") == 0){ //only need to add one of three - var_cpy = xbt_strdup (res); - xbt_dynar_push (resources, &var_cpy); + res = strsplit(key, 0, VARIABLE_SEPARATOR); + aux = strsplit(key, 1, VARIABLE_SEPARATOR); + if (strcmp(aux, "Time") == 0) { //only need to add one of three + var_cpy = xbt_strdup(res); + xbt_dynar_push(resources, &var_cpy); } - free (aux); - free (res); + free(aux); + free(res); } /* iterate through resources array */ - xbt_dynar_foreach (resources, cursor_ar, resource) { + xbt_dynar_foreach(resources, cursor_ar, resource) { char timekey[100], valuekey[100], variablekey[100]; char *time = NULL; char *value = NULL; char *variable = NULL; - snprintf (timekey, 100, "%s%cTime", resource, VARIABLE_SEPARATOR); - snprintf (valuekey, 100, "%s%cValue", resource, VARIABLE_SEPARATOR); - snprintf (variablekey, 100, "%s%cVariable", resource, VARIABLE_SEPARATOR); - - time = xbt_dict_get_or_null (method_b_dict, timekey); - if (!time) continue; - value = xbt_dict_get (method_b_dict, valuekey); - variable = xbt_dict_get (method_b_dict, variablekey); - pajeSubVariable (atof(time), variable, resource, value); - - xbt_dict_remove (method_b_dict, timekey); - xbt_dict_remove (method_b_dict, valuekey); - xbt_dict_remove (method_b_dict, variablekey); + snprintf(timekey, 100, "%s%cTime", resource, VARIABLE_SEPARATOR); + snprintf(valuekey, 100, "%s%cValue", resource, VARIABLE_SEPARATOR); + snprintf(variablekey, 100, "%s%cVariable", resource, + VARIABLE_SEPARATOR); + + time = xbt_dict_get_or_null(method_b_dict, timekey); + if (!time) + continue; + value = xbt_dict_get(method_b_dict, valuekey); + variable = xbt_dict_get(method_b_dict, variablekey); + pajeSubVariable(atof(time), variable, resource, value); + + xbt_dict_remove(method_b_dict, timekey); + xbt_dict_remove(method_b_dict, valuekey); + xbt_dict_remove(method_b_dict, variablekey); } } - xbt_dict_free (&method_b_dict); + xbt_dict_free(&method_b_dict); +} + +static void __TRACE_B_start(smx_action_t action) +{ } -static void __TRACE_B_start (smx_action_t action) {} -static void __TRACE_B_event (smx_action_t action, double now, double delta, const char *variable, const char *resource, double value) +static void __TRACE_B_event(smx_action_t action, double now, double delta, + const char *variable, const char *resource, + double value) { - if (!IS_TRACING_PLATFORM) return; + if (!IS_TRACING_PLATFORM) + return; char valuestr[100]; char nowstr[100], nowdeltastr[100]; @@ -178,237 +210,273 @@ static void __TRACE_B_event (smx_action_t action, double now, double delta, cons * variables. It should be re-checked before put in production. */ - snprintf (valuestr, 100, "%f", value); - snprintf (nowstr, 100, "%f", now); - snprintf (nowdeltastr, 100, "%f", now+delta); - snprintf (timekey, 100, "%s%cTime", resource, VARIABLE_SEPARATOR); - snprintf (valuekey, 100, "%s%cValue", resource, VARIABLE_SEPARATOR); - snprintf (variablekey, 100, "%s%cVariable", resource, VARIABLE_SEPARATOR); - - lastvariable = xbt_dict_get_or_null (method_b_dict, variablekey); - if (lastvariable == NULL){ - __TRACE_surf_check_variable_set_to_zero (now, variable, resource); - pajeAddVariable (now, variable, resource, valuestr); - nowdeltastr_cpy = xbt_strdup (nowdeltastr); - valuestr_cpy = xbt_strdup (valuestr); - variable_cpy = xbt_strdup (variable); - xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free); - xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free); - xbt_dict_set (method_b_dict, variablekey, variable_cpy, xbt_free); - }else{ - lasttime = xbt_dict_get_or_null (method_b_dict, timekey); - lastvalue = xbt_dict_get_or_null (method_b_dict, valuekey); + snprintf(valuestr, 100, "%f", value); + snprintf(nowstr, 100, "%f", now); + snprintf(nowdeltastr, 100, "%f", now + delta); + snprintf(timekey, 100, "%s%cTime", resource, VARIABLE_SEPARATOR); + snprintf(valuekey, 100, "%s%cValue", resource, VARIABLE_SEPARATOR); + snprintf(variablekey, 100, "%s%cVariable", resource, VARIABLE_SEPARATOR); + + lastvariable = xbt_dict_get_or_null(method_b_dict, variablekey); + if (lastvariable == NULL) { + __TRACE_surf_check_variable_set_to_zero(now, variable, resource); + pajeAddVariable(now, variable, resource, valuestr); + nowdeltastr_cpy = xbt_strdup(nowdeltastr); + valuestr_cpy = xbt_strdup(valuestr); + variable_cpy = xbt_strdup(variable); + xbt_dict_set(method_b_dict, timekey, nowdeltastr_cpy, xbt_free); + xbt_dict_set(method_b_dict, valuekey, valuestr_cpy, xbt_free); + xbt_dict_set(method_b_dict, variablekey, variable_cpy, xbt_free); + } else { + lasttime = xbt_dict_get_or_null(method_b_dict, timekey); + lastvalue = xbt_dict_get_or_null(method_b_dict, valuekey); /* check if it is the same variable */ - if (strcmp(lastvariable, variable) == 0){ /* same variable */ + if (strcmp(lastvariable, variable) == 0) { /* same variable */ /* check if lasttime equals now */ - if (atof(lasttime) == now){ /* lastime == now */ + if (atof(lasttime) == now) { /* lastime == now */ /* check if lastvalue equals valuestr */ - if (atof(lastvalue) == value){ /* lastvalue == value (good, just advance time) */ - char *nowdeltastr_cpy = xbt_strdup (nowdeltastr); - xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free); - }else{ /* value has changed */ + if (atof(lastvalue) == value) { /* lastvalue == value (good, just advance time) */ + char *nowdeltastr_cpy = xbt_strdup(nowdeltastr); + xbt_dict_set(method_b_dict, timekey, nowdeltastr_cpy, xbt_free); + } else { /* value has changed */ /* value has changed, subtract previous value, add new one */ - pajeSubVariable (atof(lasttime), variable, resource, lastvalue); - pajeAddVariable (atof(nowstr), variable, resource, valuestr); - nowdeltastr_cpy = xbt_strdup (nowdeltastr); - valuestr_cpy = xbt_strdup (valuestr); - xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free); - xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free); + pajeSubVariable(atof(lasttime), variable, resource, lastvalue); + pajeAddVariable(atof(nowstr), variable, resource, valuestr); + nowdeltastr_cpy = xbt_strdup(nowdeltastr); + valuestr_cpy = xbt_strdup(valuestr); + xbt_dict_set(method_b_dict, timekey, nowdeltastr_cpy, xbt_free); + xbt_dict_set(method_b_dict, valuekey, valuestr_cpy, xbt_free); } - }else{ /* lasttime != now */ + } else { /* lasttime != now */ /* the last time is different from new starting time, subtract to lasttime and add from nowstr */ - pajeSubVariable (atof(lasttime), variable, resource, lastvalue); - pajeAddVariable (atof(nowstr), variable, resource, valuestr); - nowdeltastr_cpy = xbt_strdup (nowdeltastr); - valuestr_cpy = xbt_strdup (valuestr); - xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free); - xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free); + pajeSubVariable(atof(lasttime), variable, resource, lastvalue); + pajeAddVariable(atof(nowstr), variable, resource, valuestr); + nowdeltastr_cpy = xbt_strdup(nowdeltastr); + valuestr_cpy = xbt_strdup(valuestr); + xbt_dict_set(method_b_dict, timekey, nowdeltastr_cpy, xbt_free); + xbt_dict_set(method_b_dict, valuekey, valuestr_cpy, xbt_free); } - }else{ /* variable has changed */ - pajeSubVariable (atof(lasttime), lastvariable, resource, lastvalue); - __TRACE_surf_check_variable_set_to_zero (now, variable, resource); - pajeAddVariable (now, variable, resource, valuestr); - nowdeltastr_cpy = xbt_strdup (nowdeltastr); - valuestr_cpy = xbt_strdup (valuestr); - variable_cpy = xbt_strdup (variable); - xbt_dict_set (method_b_dict, timekey, nowdeltastr_cpy, xbt_free); - xbt_dict_set (method_b_dict, valuekey, valuestr_cpy, xbt_free); - xbt_dict_set (method_b_dict, variablekey, variable_cpy, xbt_free); + } else { /* variable has changed */ + pajeSubVariable(atof(lasttime), lastvariable, resource, lastvalue); + __TRACE_surf_check_variable_set_to_zero(now, variable, resource); + pajeAddVariable(now, variable, resource, valuestr); + nowdeltastr_cpy = xbt_strdup(nowdeltastr); + valuestr_cpy = xbt_strdup(valuestr); + variable_cpy = xbt_strdup(variable); + xbt_dict_set(method_b_dict, timekey, nowdeltastr_cpy, xbt_free); + xbt_dict_set(method_b_dict, valuekey, valuestr_cpy, xbt_free); + xbt_dict_set(method_b_dict, variablekey, variable_cpy, xbt_free); } } return; } -static void __TRACE_B_end (smx_action_t action) {} + +static void __TRACE_B_end(smx_action_t action) +{ +} #define C_METHOD //C -static void __TRACE_C_alloc (void) +static void __TRACE_C_alloc(void) { method_c_dict = xbt_dict_new(); } -static void __TRACE_C_release (void) +static void __TRACE_C_release(void) { - xbt_dict_free (&method_c_dict); + xbt_dict_free(&method_c_dict); } -static void __TRACE_C_start (smx_action_t action) +static void __TRACE_C_start(smx_action_t action) { char key[100]; - snprintf (key, 100, "%p", action); + snprintf(key, 100, "%p", action); //check if exists - if (xbt_dict_get_or_null (method_c_dict, key)){ - xbt_dict_remove (method_c_dict, key); //should never execute here, but it does + if (xbt_dict_get_or_null(method_c_dict, key)) { + xbt_dict_remove(method_c_dict, key); //should never execute here, but it does } - xbt_dict_set (method_c_dict, key, xbt_dict_new(), xbt_free); + xbt_dict_set(method_c_dict, key, xbt_dict_new(), xbt_free); } -static void __TRACE_C_event (smx_action_t action, double now, double delta, const char *variable, const char *resource, double value) +static void __TRACE_C_event(smx_action_t action, double now, double delta, + const char *variable, const char *resource, + double value) { char key[100]; - snprintf (key, 100, "%p", action); + snprintf(key, 100, "%p", action); - xbt_dict_t action_dict = xbt_dict_get (method_c_dict, key); + xbt_dict_t action_dict = xbt_dict_get(method_c_dict, key); //setting start time - if (!xbt_dict_get_or_null (action_dict, "start")){ + if (!xbt_dict_get_or_null(action_dict, "start")) { char start_time[100]; - snprintf (start_time, 100, "%f", now); - xbt_dict_set (action_dict, "start", xbt_strdup (start_time), xbt_free); + snprintf(start_time, 100, "%f", now); + xbt_dict_set(action_dict, "start", xbt_strdup(start_time), xbt_free); } //updating end time char end_time[100]; - snprintf (end_time, 100, "%f", now+delta); - xbt_dict_set (action_dict, "end", xbt_strdup (end_time), xbt_free); + snprintf(end_time, 100, "%f", now + delta); + xbt_dict_set(action_dict, "end", xbt_strdup(end_time), xbt_free); //accumulate the value resource-variable char res_var[300]; - snprintf (res_var, 300, "%s %s", resource, variable); + snprintf(res_var, 300, "%s %s", resource, variable); double current_value_f; - char *current_value = xbt_dict_get_or_null (action_dict, res_var); - if (current_value){ - current_value_f = atof (current_value); - current_value_f += value*delta; - }else{ - current_value_f = value*delta; + char *current_value = xbt_dict_get_or_null(action_dict, res_var); + if (current_value) { + current_value_f = atof(current_value); + current_value_f += value * delta; + } else { + current_value_f = value * delta; } char new_current_value[100]; - snprintf (new_current_value, 100, "%f", current_value_f); - xbt_dict_set (action_dict, res_var, xbt_strdup (new_current_value), xbt_free); + snprintf(new_current_value, 100, "%f", current_value_f); + xbt_dict_set(action_dict, res_var, xbt_strdup(new_current_value), + xbt_free); } -static void __TRACE_C_end (smx_action_t action) +static void __TRACE_C_end(smx_action_t action) { char key[100]; - snprintf (key, 100, "%p", action); + snprintf(key, 100, "%p", action); - xbt_dict_t action_dict = xbt_dict_get (method_c_dict, key); - double start_time = atof(xbt_dict_get (action_dict, "start")); - double end_time = atof(xbt_dict_get (action_dict, "end")); + xbt_dict_t action_dict = xbt_dict_get(method_c_dict, key); + double start_time = atof(xbt_dict_get(action_dict, "start")); + double end_time = atof(xbt_dict_get(action_dict, "end")); - xbt_dict_cursor_t cursor=NULL; + xbt_dict_cursor_t cursor = NULL; char *action_dict_key, *action_dict_value; - xbt_dict_foreach(action_dict,cursor,action_dict_key,action_dict_value) { + xbt_dict_foreach(action_dict, cursor, action_dict_key, action_dict_value) { char resource[100], variable[100]; - if (sscanf (action_dict_key, "%s %s", resource, variable) != 2) continue; - __TRACE_surf_check_variable_set_to_zero (start_time, variable, resource); + if (sscanf(action_dict_key, "%s %s", resource, variable) != 2) + continue; + __TRACE_surf_check_variable_set_to_zero(start_time, variable, + resource); char value_str[100]; - if(end_time-start_time != 0){ - snprintf (value_str, 100, "%f", atof(action_dict_value)/(end_time-start_time)); - pajeAddVariable (start_time, variable, resource, value_str); - pajeSubVariable (end_time, variable, resource, value_str); + if (end_time - start_time != 0) { + snprintf(value_str, 100, "%f", + atof(action_dict_value) / (end_time - start_time)); + pajeAddVariable(start_time, variable, resource, value_str); + pajeSubVariable(end_time, variable, resource, value_str); } } - xbt_dict_remove (method_c_dict, key); + xbt_dict_remove(method_c_dict, key); } #define RESOURCE_UTILIZATION_INTERFACE /* * TRACE_surf_link_set_utilization: entry point from SimGrid */ -void TRACE_surf_link_set_utilization (void *link, smx_action_t smx_action, surf_action_t surf_action, double value, double now, double delta) +void TRACE_surf_link_set_utilization(void *link, smx_action_t smx_action, + surf_action_t surf_action, + double value, double now, + double delta) { - if (!IS_TRACING) return; - if (!value) return; + if (!IS_TRACING) + return; + if (!value) + return; //only trace link utilization if link is known by tracing mechanism - if (!TRACE_surf_link_is_traced (link)) return; - if (!value) return; + if (!TRACE_surf_link_is_traced(link)) + return; + if (!value) + return; //trace uncategorized link utilization char resource[100]; - snprintf (resource, 100, "%p", link); - TRACE_surf_resource_utilization_event (smx_action, now, delta, "bandwidth_used", resource, value); + snprintf(resource, 100, "%p", link); + TRACE_surf_resource_utilization_event(smx_action, now, delta, + "bandwidth_used", resource, value); //trace categorized utilization - if (!IS_TRACED(surf_action)) return; + if (!IS_TRACED(surf_action)) + return; char type[100]; - snprintf (type, 100, "b%s", surf_action->category); - TRACE_surf_resource_utilization_event (smx_action, now, delta, type, resource, value); + snprintf(type, 100, "b%s", surf_action->category); + TRACE_surf_resource_utilization_event(smx_action, now, delta, type, + resource, value); return; } /* * TRACE_surf_host_set_utilization: entry point from SimGrid */ -void TRACE_surf_host_set_utilization (const char *name, smx_action_t smx_action, surf_action_t surf_action, double value, double now, double delta) +void TRACE_surf_host_set_utilization(const char *name, + smx_action_t smx_action, + surf_action_t surf_action, + double value, double now, + double delta) { - if (!IS_TRACING) return; - if (!value) return; + if (!IS_TRACING) + return; + if (!value) + return; //trace uncategorized host utilization - TRACE_surf_resource_utilization_event (smx_action, now, delta, "power_used", name, value); + TRACE_surf_resource_utilization_event(smx_action, now, delta, + "power_used", name, value); //trace categorized utilization - if (!IS_TRACED(surf_action)) return; + if (!IS_TRACED(surf_action)) + return; char type[100]; - snprintf (type, 100, "p%s", surf_action->category); - TRACE_surf_resource_utilization_event (smx_action, now, delta, type, name, value); + snprintf(type, 100, "p%s", surf_action->category); + TRACE_surf_resource_utilization_event(smx_action, now, delta, type, name, + value); return; } /* * __TRACE_surf_resource_utilization_*: entry points from tracing functions */ -void TRACE_surf_resource_utilization_start (smx_action_t action) +void TRACE_surf_resource_utilization_start(smx_action_t action) { - if (!IS_TRACING) return; - TRACE_method_start (action); + if (!IS_TRACING) + return; + TRACE_method_start(action); } -void TRACE_surf_resource_utilization_event (smx_action_t action, double now, double delta, const char *variable, const char *resource, double value) +void TRACE_surf_resource_utilization_event(smx_action_t action, double now, + double delta, + const char *variable, + const char *resource, + double value) { - if (!IS_TRACING) return; - TRACE_method_event (action, now, delta, variable, resource, value); + if (!IS_TRACING) + return; + TRACE_method_event(action, now, delta, variable, resource, value); } -void TRACE_surf_resource_utilization_end (smx_action_t action) +void TRACE_surf_resource_utilization_end(smx_action_t action) { - if (!IS_TRACING) return; - TRACE_method_end (action); + if (!IS_TRACING) + return; + TRACE_method_end(action); } -void TRACE_surf_resource_utilization_release () +void TRACE_surf_resource_utilization_release() { - if (!IS_TRACING) return; - TRACE_method_release (); + if (!IS_TRACING) + return; + TRACE_method_release(); } -static void __TRACE_define_method (char *method) +static void __TRACE_define_method(char *method) { - if (!strcmp(method, "a")){ + if (!strcmp(method, "a")) { TRACE_method_alloc = __TRACE_A_alloc; TRACE_method_release = __TRACE_A_release; TRACE_method_start = __TRACE_A_start; TRACE_method_event = __TRACE_A_event; TRACE_method_end = __TRACE_A_end; - }else if (!strcmp(method, "c")){ + } else if (!strcmp(method, "c")) { TRACE_method_alloc = __TRACE_C_alloc; TRACE_method_release = __TRACE_C_release; TRACE_method_start = __TRACE_C_start; TRACE_method_event = __TRACE_C_event; TRACE_method_end = __TRACE_C_end; - }else{ //default is B + } else { //default is B TRACE_method_alloc = __TRACE_B_alloc; TRACE_method_release = __TRACE_B_release; TRACE_method_start = __TRACE_B_start; @@ -417,10 +485,10 @@ static void __TRACE_define_method (char *method) } } -void TRACE_surf_resource_utilization_alloc () +void TRACE_surf_resource_utilization_alloc() { platform_variables = xbt_dict_new(); - __TRACE_define_method (TRACE_get_platform_method()); - TRACE_method_alloc (); + __TRACE_define_method(TRACE_get_platform_method()); + TRACE_method_alloc(); } #endif diff --git a/src/instr/sd_instr.c b/src/instr/sd_instr.c index e2a18950a6..7355762a88 100644 --- a/src/instr/sd_instr.c +++ b/src/instr/sd_instr.c @@ -8,23 +8,27 @@ #ifdef HAVE_TRACING -void TRACE_sd_task_create (SD_task_t task) +void TRACE_sd_task_create(SD_task_t task) { - if (!IS_TRACING) return; + if (!IS_TRACING) + return; task->category = NULL; } -void TRACE_sd_task_destroy (SD_task_t task) +void TRACE_sd_task_destroy(SD_task_t task) { - if (!IS_TRACING) return; - if (task->category) xbt_free (task->category); + if (!IS_TRACING) + return; + if (task->category) + xbt_free(task->category); } void TRACE_sd_set_task_category(SD_task_t task, const char *category) { - if (!IS_TRACING) return; - task->category = xbt_new (char, strlen (category)+1); - strncpy(task->category, category, strlen(category)+1); + if (!IS_TRACING) + return; + task->category = xbt_new(char, strlen(category) + 1); + strncpy(task->category, category, strlen(category) + 1); } #endif diff --git a/src/instr/smpi_instr.c b/src/instr/smpi_instr.c index aa65cd644d..18ca3ebf9e 100644 --- a/src/instr/smpi_instr.c +++ b/src/instr/smpi_instr.c @@ -10,136 +10,143 @@ static xbt_dict_t keys; -static char *TRACE_smpi_container (int rank, char *container, int n) +static char *TRACE_smpi_container(int rank, char *container, int n) { - snprintf (container, n, "rank-%d", rank); + snprintf(container, n, "rank-%d", rank); return container; } -static char *TRACE_smpi_put_key (int src, int dst, char *key, int n) +static char *TRACE_smpi_put_key(int src, int dst, char *key, int n) { //get the dynar for src#dst char aux[100]; - snprintf (aux, 100, "%d#%d", src, dst); - xbt_dynar_t d = xbt_dict_get_or_null (keys, aux); - if (d == NULL){ - d = xbt_dynar_new (sizeof(char*), xbt_free); - xbt_dict_set (keys, aux, d, xbt_free); + snprintf(aux, 100, "%d#%d", src, dst); + xbt_dynar_t d = xbt_dict_get_or_null(keys, aux); + if (d == NULL) { + d = xbt_dynar_new(sizeof(char *), xbt_free); + xbt_dict_set(keys, aux, d, xbt_free); } //generate the key static long long counter = 0; - snprintf (key, n, "%d%d%lld", src, dst, counter++); + snprintf(key, n, "%d%d%lld", src, dst, counter++); - xbt_dynar_insert_at (d, 0, xbt_strdup (key)); + xbt_dynar_insert_at(d, 0, xbt_strdup(key)); return key; } -static char *TRACE_smpi_get_key (int src, int dst, char *key, int n) +static char *TRACE_smpi_get_key(int src, int dst, char *key, int n) { char aux[100]; - snprintf (aux, 100, "%d#%d", src, dst); - xbt_dynar_t d = xbt_dict_get_or_null (keys, aux); + snprintf(aux, 100, "%d#%d", src, dst); + xbt_dynar_t d = xbt_dict_get_or_null(keys, aux); - int length = xbt_dynar_length (d); + int length = xbt_dynar_length(d); char stored_key[n]; - xbt_dynar_remove_at (d, length-1, stored_key); - strncpy (key, stored_key, n); + xbt_dynar_remove_at(d, length - 1, stored_key); + strncpy(key, stored_key, n); return key; } -void TRACE_smpi_alloc () +void TRACE_smpi_alloc() { keys = xbt_dict_new(); } -void TRACE_smpi_start (void) +void TRACE_smpi_start(void) { - if (IS_TRACING_SMPI){ - TRACE_start (); + if (IS_TRACING_SMPI) { + TRACE_start(); } } -void TRACE_smpi_release (void) +void TRACE_smpi_release(void) { - TRACE_surf_release (); - if (IS_TRACING_SMPI){ + TRACE_surf_release(); + if (IS_TRACING_SMPI) { TRACE_end(); } } -void TRACE_smpi_init (int rank) +void TRACE_smpi_init(int rank) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - TRACE_smpi_container (rank, str, 100); - pajeCreateContainer (SIMIX_get_clock(), str, "MPI_PROCESS", - SIMIX_host_get_name(SIMIX_host_self()), str); + TRACE_smpi_container(rank, str, 100); + pajeCreateContainer(SIMIX_get_clock(), str, "MPI_PROCESS", + SIMIX_host_get_name(SIMIX_host_self()), str); } -void TRACE_smpi_finalize (int rank) +void TRACE_smpi_finalize(int rank) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - pajeDestroyContainer (SIMIX_get_clock(), "MPI_PROCESS", - TRACE_smpi_container (rank, str, 100)); + pajeDestroyContainer(SIMIX_get_clock(), "MPI_PROCESS", + TRACE_smpi_container(rank, str, 100)); } -void TRACE_smpi_collective_in (int rank, int root, const char *operation) +void TRACE_smpi_collective_in(int rank, int root, const char *operation) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - pajePushState (SIMIX_get_clock(), "MPI_STATE", - TRACE_smpi_container (rank, str, 100), operation); + pajePushState(SIMIX_get_clock(), "MPI_STATE", + TRACE_smpi_container(rank, str, 100), operation); } -void TRACE_smpi_collective_out (int rank, int root, const char *operation) +void TRACE_smpi_collective_out(int rank, int root, const char *operation) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - pajePopState (SIMIX_get_clock(), "MPI_STATE", - TRACE_smpi_container (rank, str, 100)); + pajePopState(SIMIX_get_clock(), "MPI_STATE", + TRACE_smpi_container(rank, str, 100)); } -void TRACE_smpi_ptp_in (int rank, int src, int dst, const char *operation) +void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - pajePushState (SIMIX_get_clock(), "MPI_STATE", - TRACE_smpi_container (rank, str, 100), operation); + pajePushState(SIMIX_get_clock(), "MPI_STATE", + TRACE_smpi_container(rank, str, 100), operation); } -void TRACE_smpi_ptp_out (int rank, int src, int dst, const char *operation) +void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char str[100]; - pajePopState (SIMIX_get_clock(), "MPI_STATE", - TRACE_smpi_container (rank, str, 100)); + pajePopState(SIMIX_get_clock(), "MPI_STATE", + TRACE_smpi_container(rank, str, 100)); } -void TRACE_smpi_send (int rank, int src, int dst) +void TRACE_smpi_send(int rank, int src, int dst) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char key[100], str[100]; - TRACE_smpi_put_key (src, dst, key, 100); - pajeStartLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP", - TRACE_smpi_container (src, str, 100), key); + TRACE_smpi_put_key(src, dst, key, 100); + pajeStartLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP", + TRACE_smpi_container(src, str, 100), key); } -void TRACE_smpi_recv (int rank, int src, int dst) +void TRACE_smpi_recv(int rank, int src, int dst) { - if (!IS_TRACING_SMPI) return; + if (!IS_TRACING_SMPI) + return; char key[100], str[100]; - TRACE_smpi_get_key (src, dst, key, 100); - pajeEndLink (SIMIX_get_clock(), "MPI_LINK", "0", "PTP", - TRACE_smpi_container (dst, str, 100), key); + TRACE_smpi_get_key(src, dst, key, 100); + pajeEndLink(SIMIX_get_clock(), "MPI_LINK", "0", "PTP", + TRACE_smpi_container(dst, str, 100), key); } #endif - diff --git a/src/instr/smx_instr.c b/src/instr/smx_instr.c index 1ff402b175..78bcb2937f 100644 --- a/src/instr/smx_instr.c +++ b/src/instr/smx_instr.c @@ -8,43 +8,46 @@ #ifdef HAVE_TRACING -static long long int counter = 0; /* to uniquely identify simix actions */ +static long long int counter = 0; /* to uniquely identify simix actions */ -void TRACE_smx_action_execute (smx_action_t act) +void TRACE_smx_action_execute(smx_action_t act) { - char *category = NULL; - if (!IS_TRACING) return; + char *category = NULL; + if (!IS_TRACING) + return; act->counter = counter++; - category = TRACE_category_get (SIMIX_process_self()); - if (category){ - act->category = xbt_new (char, strlen (category)+1); - strncpy (act->category, category, strlen(category)+1); + category = TRACE_category_get(SIMIX_process_self()); + if (category) { + act->category = xbt_new(char, strlen(category) + 1); + strncpy(act->category, category, strlen(category) + 1); } - TRACE_surf_resource_utilization_start (act); + TRACE_surf_resource_utilization_start(act); } -void TRACE_smx_action_communicate (smx_action_t act, smx_process_t proc) +void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc) { - char *category = NULL; - if (!IS_TRACING) return; + char *category = NULL; + if (!IS_TRACING) + return; act->counter = counter++; - category = TRACE_category_get (proc); - if (category){ - act->category = xbt_strdup (category); + category = TRACE_category_get(proc); + if (category) { + act->category = xbt_strdup(category); } - TRACE_surf_resource_utilization_start (act); + TRACE_surf_resource_utilization_start(act); } -void TRACE_smx_action_destroy (smx_action_t act) +void TRACE_smx_action_destroy(smx_action_t act) { - if (!IS_TRACING || !IS_TRACED(act)) return; + if (!IS_TRACING || !IS_TRACED(act)) + return; - if (act->category){ - xbt_free (act->category); + if (act->category) { + xbt_free(act->category); } - TRACE_surf_resource_utilization_end (act); + TRACE_surf_resource_utilization_end(act); } #endif diff --git a/src/instr/surf_instr.c b/src/instr/surf_instr.c index 0d582df3e7..6f48031679 100644 --- a/src/instr/surf_instr.c +++ b/src/instr/surf_instr.c @@ -9,30 +9,30 @@ #ifdef HAVE_TRACING -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf,tracing,"Tracing Surf"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(tracing_surf, tracing, "Tracing Surf"); #define VARIABLE_SEPARATOR '#' static xbt_dict_t created_links; static xbt_dict_t host_containers; -static xbt_dict_t resource_variables; /* (host|link)#variable -> value */ +static xbt_dict_t resource_variables; /* (host|link)#variable -> value */ /* to trace gtnets */ -static xbt_dict_t gtnets_src; /* %p (action) -> %s */ -static xbt_dict_t gtnets_dst; /* %p (action) -> %s */ +static xbt_dict_t gtnets_src; /* %p (action) -> %s */ +static xbt_dict_t gtnets_dst; /* %p (action) -> %s */ -void TRACE_surf_alloc (void) +void TRACE_surf_alloc(void) { created_links = xbt_dict_new(); host_containers = xbt_dict_new(); - resource_variables = xbt_dict_new (); - gtnets_src = xbt_dict_new (); - gtnets_dst = xbt_dict_new (); + resource_variables = xbt_dict_new(); + gtnets_src = xbt_dict_new(); + gtnets_dst = xbt_dict_new(); TRACE_surf_resource_utilization_alloc(); } -void TRACE_surf_release (void) +void TRACE_surf_release(void) { char *key, *value; xbt_dict_cursor_t cursor = NULL; @@ -40,29 +40,35 @@ void TRACE_surf_release (void) /* get all host from host_containers */ xbt_dict_foreach(host_containers, cursor, key, value) { - pajeDestroyContainer (MSG_get_clock(), "HOST", key); + pajeDestroyContainer(MSG_get_clock(), "HOST", key); } xbt_dict_foreach(created_links, cursor, key, value) { - pajeDestroyContainer (MSG_get_clock(), "LINK", key); + pajeDestroyContainer(MSG_get_clock(), "LINK", key); } } -static void TRACE_surf_set_resource_variable (double date, const char *variable, const char *resource, double value) +static void TRACE_surf_set_resource_variable(double date, + const char *variable, + const char *resource, + double value) { - char aux[100], key[100]; - char *last_value = NULL; - if (!IS_TRACING) return; - snprintf (aux, 100, "%f", value); - snprintf (key, 100, "%s%c%s", resource, VARIABLE_SEPARATOR, variable); + char aux[100], key[100]; + char *last_value = NULL; + if (!IS_TRACING) + return; + snprintf(aux, 100, "%f", value); + snprintf(key, 100, "%s%c%s", resource, VARIABLE_SEPARATOR, variable); last_value = xbt_dict_get_or_null(resource_variables, key); - if (last_value){ - if (atof(last_value) == value){ + if (last_value) { + if (atof(last_value) == value) { return; } } - if (IS_TRACING_PLATFORM) pajeSetVariable (date, variable, resource, aux); - xbt_dict_set (resource_variables, xbt_strdup(key), xbt_strdup(aux), xbt_free); + if (IS_TRACING_PLATFORM) + pajeSetVariable(date, variable, resource, aux); + xbt_dict_set(resource_variables, xbt_strdup(key), xbt_strdup(aux), + xbt_free); } /* @@ -74,19 +80,22 @@ static void TRACE_surf_set_resource_variable (double date, const char *variable, * main: create LINK container, set initial bandwidth and latency * return: void */ -void TRACE_surf_link_declaration (void *link, char *name, double bw, double lat) +void TRACE_surf_link_declaration(void *link, char *name, double bw, + double lat) { - if (!IS_TRACING) return; + if (!IS_TRACING) + return; //filter out loopback - if (!strcmp (name, "loopback") || !strcmp (name, "__loopback__")) return; + if (!strcmp(name, "loopback") || !strcmp(name, "__loopback__")) + return; char alias[100]; - snprintf (alias, 100, "%p", link); - pajeCreateContainer (SIMIX_get_clock(), alias, "LINK", "platform", name); - xbt_dict_set (created_links, alias, xbt_strdup ("1"), xbt_free); - TRACE_surf_link_set_bandwidth (SIMIX_get_clock(), link, bw); - TRACE_surf_link_set_latency (SIMIX_get_clock(), link, lat); + snprintf(alias, 100, "%p", link); + pajeCreateContainer(SIMIX_get_clock(), alias, "LINK", "platform", name); + xbt_dict_set(created_links, alias, xbt_strdup("1"), xbt_free); + TRACE_surf_link_set_bandwidth(SIMIX_get_clock(), link, bw); + TRACE_surf_link_set_latency(SIMIX_get_clock(), link, lat); } /* @@ -98,110 +107,123 @@ void TRACE_surf_link_declaration (void *link, char *name, double bw, double lat) * main: create HOST containers, set initial power value * return: void */ -void TRACE_surf_host_declaration (const char *name, double power) +void TRACE_surf_host_declaration(const char *name, double power) { - if (!IS_TRACING) return; - pajeCreateContainer (SIMIX_get_clock(), name, "HOST", "platform", name); - xbt_dict_set (host_containers, name, xbt_strdup("1"), xbt_free); - TRACE_surf_host_set_power (SIMIX_get_clock(), name, power); + if (!IS_TRACING) + return; + pajeCreateContainer(SIMIX_get_clock(), name, "HOST", "platform", name); + xbt_dict_set(host_containers, name, xbt_strdup("1"), xbt_free); + TRACE_surf_host_set_power(SIMIX_get_clock(), name, power); } -void TRACE_surf_host_set_power (double date, const char *resource, double power) +void TRACE_surf_host_set_power(double date, const char *resource, + double power) { - TRACE_surf_set_resource_variable (date, "power", resource, power); + TRACE_surf_set_resource_variable(date, "power", resource, power); } -void TRACE_surf_link_set_bandwidth (double date, void *link, double bandwidth) +void TRACE_surf_link_set_bandwidth(double date, void *link, + double bandwidth) { - if (!TRACE_surf_link_is_traced (link)) return; + if (!TRACE_surf_link_is_traced(link)) + return; char resource[100]; - snprintf (resource, 100, "%p", link); - TRACE_surf_set_resource_variable (date, "bandwidth", resource, bandwidth); + snprintf(resource, 100, "%p", link); + TRACE_surf_set_resource_variable(date, "bandwidth", resource, bandwidth); } -void TRACE_surf_link_set_latency (double date, void *link, double latency) +void TRACE_surf_link_set_latency(double date, void *link, double latency) { - if (!TRACE_surf_link_is_traced (link)) return; + if (!TRACE_surf_link_is_traced(link)) + return; char resource[100]; - snprintf (resource, 100, "%p", link); - TRACE_surf_set_resource_variable (date, "latency", resource, latency); + snprintf(resource, 100, "%p", link); + TRACE_surf_set_resource_variable(date, "latency", resource, latency); } /* to trace gtnets */ -void TRACE_surf_gtnets_communicate (void *action, int src, int dst) +void TRACE_surf_gtnets_communicate(void *action, int src, int dst) { - char key[100], aux[100]; - if (!IS_TRACING) return; - snprintf (key, 100, "%p", action); - - snprintf (aux, 100, "%d", src); - xbt_dict_set (gtnets_src, key, xbt_strdup(aux), xbt_free); - snprintf (aux, 100, "%d", dst); - xbt_dict_set (gtnets_dst, key, xbt_strdup(aux), xbt_free); + char key[100], aux[100]; + if (!IS_TRACING) + return; + snprintf(key, 100, "%p", action); + + snprintf(aux, 100, "%d", src); + xbt_dict_set(gtnets_src, key, xbt_strdup(aux), xbt_free); + snprintf(aux, 100, "%d", dst); + xbt_dict_set(gtnets_dst, key, xbt_strdup(aux), xbt_free); } -int TRACE_surf_gtnets_get_src (void *action) +int TRACE_surf_gtnets_get_src(void *action) { - char key[100]; - char *aux = NULL; - if (!IS_TRACING) return -1; - snprintf (key, 100, "%p", action); + char key[100]; + char *aux = NULL; + if (!IS_TRACING) + return -1; + snprintf(key, 100, "%p", action); - aux = xbt_dict_get_or_null (gtnets_src, key); - if (aux){ - return atoi(aux); - }else{ + aux = xbt_dict_get_or_null(gtnets_src, key); + if (aux) { + return atoi(aux); + } else { return -1; } } -int TRACE_surf_gtnets_get_dst (void *action) +int TRACE_surf_gtnets_get_dst(void *action) { - char key[100]; - char *aux = NULL; - if (!IS_TRACING) return -1; - snprintf (key, 100, "%p", action); + char key[100]; + char *aux = NULL; + if (!IS_TRACING) + return -1; + snprintf(key, 100, "%p", action); - aux = xbt_dict_get_or_null (gtnets_dst, key); - if (aux){ - return atoi(aux); - }else{ + aux = xbt_dict_get_or_null(gtnets_dst, key); + if (aux) { + return atoi(aux); + } else { return -1; } } -void TRACE_surf_gtnets_destroy (void *action) +void TRACE_surf_gtnets_destroy(void *action) { char key[100]; - if (!IS_TRACING) return; - snprintf (key, 100, "%p", action); - xbt_dict_remove (gtnets_src, key); - xbt_dict_remove (gtnets_dst, key); + if (!IS_TRACING) + return; + snprintf(key, 100, "%p", action); + xbt_dict_remove(gtnets_src, key); + xbt_dict_remove(gtnets_dst, key); } -void TRACE_surf_host_vivaldi_parse (char *host, double x, double y, double h) +void TRACE_surf_host_vivaldi_parse(char *host, double x, double y, + double h) { - char valuestr[100]; - if (!IS_TRACING || !IS_TRACING_PLATFORM) return; - - snprintf (valuestr, 100, "%g", x); - pajeSetVariable (0, "vivaldi_x", host, valuestr); - snprintf (valuestr, 100, "%g", y); - pajeSetVariable (0, "vivaldi_y", host, valuestr); - snprintf (valuestr, 100, "%g", h); - pajeSetVariable (0, "vivaldi_h", host, valuestr); + char valuestr[100]; + if (!IS_TRACING || !IS_TRACING_PLATFORM) + return; + + snprintf(valuestr, 100, "%g", x); + pajeSetVariable(0, "vivaldi_x", host, valuestr); + snprintf(valuestr, 100, "%g", y); + pajeSetVariable(0, "vivaldi_y", host, valuestr); + snprintf(valuestr, 100, "%g", h); + pajeSetVariable(0, "vivaldi_h", host, valuestr); } extern routing_global_t global_routing; -void TRACE_surf_save_onelink (void) +void TRACE_surf_save_onelink(void) { - if (!IS_TRACING) return; + if (!IS_TRACING) + return; //get the onelinks from the parsed platform xbt_dynar_t onelink_routes = global_routing->get_onelink_routes(); - if (!onelink_routes) return; + if (!onelink_routes) + return; //save them in trace file onelink_t onelink; @@ -211,35 +233,37 @@ void TRACE_surf_save_onelink (void) char *dst = onelink->dst; void *link = onelink->link_ptr; - if (TRACE_surf_link_is_traced (link)){ + if (TRACE_surf_link_is_traced(link)) { char resource[100]; - snprintf (resource, 100, "%p", link); + snprintf(resource, 100, "%p", link); - pajeNewEvent (0.1, "source", resource, src); - pajeNewEvent (0.1, "destination", resource, dst); + pajeNewEvent(0.1, "source", resource, src); + pajeNewEvent(0.1, "destination", resource, dst); } } } -int TRACE_surf_link_is_traced (void *link) +int TRACE_surf_link_is_traced(void *link) { char alias[100]; - snprintf (alias, 100, "%p", link); - if (xbt_dict_get_or_null (created_links, alias)){ + snprintf(alias, 100, "%p", link); + if (xbt_dict_get_or_null(created_links, alias)) { return 1; - }else{ + } else { return 0; } } -void TRACE_surf_action (surf_action_t surf_action, const char *category) +void TRACE_surf_action(surf_action_t surf_action, const char *category) { - if (!IS_TRACING) return; - if (!IS_TRACING_PLATFORM) return; - if (!category){ - xbt_die ("invalid tracing category"); + if (!IS_TRACING) + return; + if (!IS_TRACING_PLATFORM) + return; + if (!category) { + xbt_die("invalid tracing category"); } - surf_action->category = xbt_new (char, strlen (category)+1); - strncpy (surf_action->category, category, strlen(category)+1); + surf_action->category = xbt_new(char, strlen(category) + 1); + strncpy(surf_action->category, category, strlen(category) + 1); } #endif diff --git a/src/instr/variables_instr.c b/src/instr/variables_instr.c index aed99a1190..303eadaf8a 100644 --- a/src/instr/variables_instr.c +++ b/src/instr/variables_instr.c @@ -12,53 +12,59 @@ extern routing_global_t global_routing; -void TRACE_user_link_variable (double time, const char *src, const char *dst, const char *variable, double value, const char *what) +void TRACE_user_link_variable(double time, const char *src, + const char *dst, const char *variable, + double value, const char *what) { - if (!IS_TRACING || !IS_TRACING_PLATFORM) return; + if (!IS_TRACING || !IS_TRACING_PLATFORM) + return; char valuestr[100]; - snprintf (valuestr, 100, "%g", value); + snprintf(valuestr, 100, "%g", value); - if (strcmp (what, "declare") == 0){ - pajeDefineVariableType (variable, "LINK", variable); + if (strcmp(what, "declare") == 0) { + pajeDefineVariableType(variable, "LINK", variable); return; } - if (!global_routing) return; + if (!global_routing) + return; xbt_dynar_t route = global_routing->get_route(src, dst); unsigned int i; void *link_ptr; xbt_dynar_foreach(route, i, link_ptr) { char resource[100]; - snprintf (resource, 100, "%p", link_ptr); + snprintf(resource, 100, "%p", link_ptr); - if (strcmp (what, "set") == 0){ - pajeSetVariable (time, variable, resource, valuestr); - }else if (strcmp (what, "add") == 0){ - pajeAddVariable (time, variable, resource, valuestr); - }else if (strcmp (what, "sub") == 0){ - pajeSubVariable (time, variable, resource, valuestr); + if (strcmp(what, "set") == 0) { + pajeSetVariable(time, variable, resource, valuestr); + } else if (strcmp(what, "add") == 0) { + pajeAddVariable(time, variable, resource, valuestr); + } else if (strcmp(what, "sub") == 0) { + pajeSubVariable(time, variable, resource, valuestr); } } } -void TRACE_user_host_variable (double time, const char *variable, double value, const char *what) +void TRACE_user_host_variable(double time, const char *variable, + double value, const char *what) { char valuestr[100]; - if (!IS_TRACING || !IS_TRACING_PLATFORM) return; + if (!IS_TRACING || !IS_TRACING_PLATFORM) + return; - snprintf (valuestr, 100, "%g", value); + snprintf(valuestr, 100, "%g", value); - if (strcmp (what, "declare") == 0){ - pajeDefineVariableType (variable, "HOST", variable); - }else if (strcmp (what, "set") == 0){ - pajeSetVariable (time, variable, MSG_host_self()->name, valuestr); - }else if (strcmp (what, "add") == 0){ - pajeAddVariable (time, variable, MSG_host_self()->name, valuestr); - }else if (strcmp (what, "sub") == 0){ - pajeSubVariable (time, variable, MSG_host_self()->name, valuestr); + if (strcmp(what, "declare") == 0) { + pajeDefineVariableType(variable, "HOST", variable); + } else if (strcmp(what, "set") == 0) { + pajeSetVariable(time, variable, MSG_host_self()->name, valuestr); + } else if (strcmp(what, "add") == 0) { + pajeAddVariable(time, variable, MSG_host_self()->name, valuestr); + } else if (strcmp(what, "sub") == 0) { + pajeSubVariable(time, variable, MSG_host_self()->name, valuestr); } } -#endif /* HAVE_TRACING */ +#endif /* HAVE_TRACING */ diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 1432365b09..341473e3de 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -53,7 +53,8 @@ static jobject native_to_java_process(m_process_t process) JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, - jobject jprocess_arg, jobject jhost) + jobject jprocess_arg, + jobject jhost) { jobject jprocess; /* the global reference to the java process instance */ jstring jname; /* the name of the java process instance */ @@ -63,8 +64,8 @@ Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, msg_mailbox_t mailbox; DEBUG4 - ("Java_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,jhost=%p)", - env, cls, jprocess_arg, jhost); + ("Java_simgrid_msg_MsgNative_processCreate(env=%p,cls=%p,jproc=%p,jhost=%p)", + env, cls, jprocess_arg, jhost); /* get the name of the java process */ jname = jprocess_get_name(jprocess_arg, env); @@ -111,22 +112,23 @@ Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, /* create a new context */ DEBUG8 - ("fill in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p); env=%p", - process->name, process->simdata->m_host->name, process->simdata->PID, - process, process->simdata, process->simdata->m_host, - process->simdata->m_host->simdata, env); - - process->simdata->s_process = - SIMIX_process_create(process->name, (xbt_main_func_t)jprocess, - /*data */ (void *) process, - process->simdata->m_host->simdata->smx_host->name, - 0, NULL, NULL); - + ("fill in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p); env=%p", + process->name, process->simdata->m_host->name, + process->simdata->PID, process, process->simdata, + process->simdata->m_host, process->simdata->m_host->simdata, env); + + process->simdata->s_process = + SIMIX_process_create(process->name, (xbt_main_func_t) jprocess, + /*data */ (void *) process, + process->simdata->m_host->simdata-> + smx_host->name, 0, NULL, NULL); + DEBUG1("context created (s_process=%p)", process->simdata->s_process); if (SIMIX_process_self()) { /* someone created me */ - process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); + process->simdata->PPID = + MSG_process_get_PID(SIMIX_process_self()->data); } else { process->simdata->PPID = -1; } @@ -136,11 +138,12 @@ Java_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls, /* add the process to the list of the processes of the simulation */ xbt_fifo_unshift(msg_global->process_list, process); - sprintf(alias, "%s:%s", (process->simdata->m_host->simdata->smx_host)->name, + sprintf(alias, "%s:%s", + (process->simdata->m_host->simdata->smx_host)->name, process->name); mailbox = MSG_mailbox_new(alias); - + } JNIEXPORT void JNICALL @@ -156,10 +159,10 @@ Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls, /* try to suspend the process */ MSG_error_t rv = MSG_process_suspend(process); - - jxbt_check_res("MSG_process_suspend()",rv,MSG_OK, - bprintf("unexpected error , please report this bug")); - + + jxbt_check_res("MSG_process_suspend()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); + } JNIEXPORT void JNICALL @@ -169,15 +172,15 @@ Java_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls, m_process_t process = jprocess_to_native_process(jprocess, env); if (!process) { - jxbt_throw_notbound(env,"process", jprocess); + jxbt_throw_notbound(env, "process", jprocess); return; } /* try to resume the process */ - MSG_error_t rv = MSG_process_resume(process); - - jxbt_check_res("MSG_process_resume()",rv,MSG_OK, - bprintf("unexpected error , please report this bug")); + MSG_error_t rv = MSG_process_resume(process); + + jxbt_check_res("MSG_process_resume()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); } JNIEXPORT jboolean JNICALL @@ -242,7 +245,8 @@ Java_simgrid_msg_MsgNative_processGetHost(JNIEnv * env, jclass cls, } JNIEXPORT jobject JNICALL -Java_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls, jint PID) +Java_simgrid_msg_MsgNative_processFromPID(JNIEnv * env, jclass cls, + jint PID) { m_process_t process = MSG_process_from_PID(PID); @@ -322,8 +326,8 @@ Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv * env, jclass cls, /* try to change the host of the process */ MSG_error_t rv = MSG_process_change_host(host); - jxbt_check_res("MSG_process_change_host()",rv,MSG_OK, - bprintf("unexpected error , please report this bug")); + jxbt_check_res("MSG_process_change_host()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); } @@ -331,11 +335,12 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processWaitFor(JNIEnv * env, jclass cls, jdouble seconds) { - MSG_error_t rv= MSG_process_sleep((double) seconds); - - jxbt_check_res("MSG_process_sleep()",rv, MSG_HOST_FAILURE, - bprintf("while process was waiting for %f seconds",(double)seconds)); - + MSG_error_t rv = MSG_process_sleep((double) seconds); + + jxbt_check_res("MSG_process_sleep()", rv, MSG_HOST_FAILURE, + bprintf("while process was waiting for %f seconds", + (double) seconds)); + } @@ -364,7 +369,7 @@ Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls, return NULL; } - if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */ + if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */ /* instanciate a new java host */ jhost = jhost_new_instance(env); @@ -388,7 +393,7 @@ Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls, /* the native host data field is set with the global reference to the * java host returned by this function */ - MSG_host_set_data(host,(void *) jhost); + MSG_host_set_data(host, (void *) jhost); } /* return the global reference to the java host instance */ @@ -443,7 +448,7 @@ Java_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls) /* Bind & store it */ jhost_bind(jhost, host, env); - MSG_host_set_data(host,(void *) jhost); + MSG_host_set_data(host, (void *) jhost); } else { jhost = (jobject) MSG_host_get_data(host); } @@ -500,17 +505,19 @@ Java_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls, ***************************************************************************************/ JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, jobject jtask, - jstring jname, jdouble jcomputeDuration, +Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, + jobject jtask, jstring jname, + jdouble jcomputeDuration, jdouble jmessageSize) { m_task_t task; /* the native task to create */ - const char *name=NULL; /* the name of the task */ + const char *name = NULL; /* the name of the task */ if (jcomputeDuration < 0) { jxbt_throw_illegal(env, - bprintf("Task ComputeDuration (%f) cannot be negative", - (double) jcomputeDuration)); + bprintf + ("Task ComputeDuration (%f) cannot be negative", + (double) jcomputeDuration)); return; } @@ -529,24 +536,26 @@ Java_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls, jobject jtask, /* create the task */ task = - MSG_task_create(name, (double) jcomputeDuration, (double) jmessageSize, - NULL); + MSG_task_create(name, (double) jcomputeDuration, + (double) jmessageSize, NULL); if (jname) (*env)->ReleaseStringUTFChars(env, jname, name); /* bind & store the task */ jtask_bind(jtask, task, env); - MSG_task_set_data(task,jtask); + MSG_task_set_data(task, jtask); } JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls, - jobject jtask, jstring jname, + jobject jtask, + jstring jname, jobjectArray jhosts, jdoubleArray jcomputeDurations_arg, - jdoubleArray jmessageSizes_arg) + jdoubleArray + jmessageSizes_arg) { m_task_t task; /* the native parallel task to create */ @@ -571,7 +580,8 @@ Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls, if (!jmessageSizes_arg) { jxbt_throw_null(env, - xbt_strdup("Parallel task message sizes cannot be null")); + xbt_strdup + ("Parallel task message sizes cannot be null")); return; } @@ -588,8 +598,9 @@ Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls, messageSizes = xbt_new0(double, host_count * host_count); jcomputeDurations = - (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0); - jmessageSizes = (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0); + (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0); + jmessageSizes = + (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0); for (index = 0; index < host_count; index++) { jhost = (*env)->GetObjectArrayElement(env, jhosts, index); @@ -610,15 +621,15 @@ Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls, name = (*env)->GetStringUTFChars(env, jname, 0); task = - MSG_parallel_task_create(name, host_count, hosts, computeDurations, - messageSizes, NULL); + MSG_parallel_task_create(name, host_count, hosts, computeDurations, + messageSizes, NULL); (*env)->ReleaseStringUTFChars(env, jname, name); /* associate the java task object and the native task */ jtask_bind(jtask, task, env); - MSG_task_set_data(task,(void*) jtask); + MSG_task_set_data(task, (void *) jtask); if (!MSG_task_get_data(task)) jxbt_throw_jni(env, "global ref allocation failed"); @@ -679,7 +690,8 @@ Java_simgrid_msg_MsgNative_taskGetName(JNIEnv * env, jclass cls, } JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask) +Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, + jobject jtask) { m_task_t ptask = jtask_to_native_task(jtask, env); @@ -689,9 +701,9 @@ Java_simgrid_msg_MsgNative_taskCancel(JNIEnv * env, jclass cls, jobject jtask) } MSG_error_t rv = MSG_task_cancel(ptask); - - jxbt_check_res("MSG_task_cancel()",rv,MSG_OK, - bprintf("unexpected error , please report this bug")); + + jxbt_check_res("MSG_task_cancel()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); } JNIEXPORT jdouble JNICALL @@ -708,7 +720,8 @@ Java_simgrid_msg_MsgNative_taskGetComputeDuration(JNIEnv * env, jclass cls, } JNIEXPORT jdouble JNICALL -Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, jclass cls, +Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv * env, + jclass cls, jobject jtask) { m_task_t ptask = jtask_to_native_task(jtask, env); @@ -747,11 +760,11 @@ Java_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls, return; } jtask = (jobject) MSG_task_get_data(task); - + MSG_error_t rv = MSG_task_destroy(task); - - jxbt_check_res("MSG_task_destroy()",rv,MSG_OK, - bprintf("unexpected error , please report this bug")); + + jxbt_check_res("MSG_task_destroy()", rv, MSG_OK, + bprintf("unexpected error , please report this bug")); } JNIEXPORT void JNICALL @@ -766,9 +779,11 @@ Java_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls, } MSG_error_t rv = MSG_task_execute(task); - - jxbt_check_res("MSG_task_execute()",rv,MSG_HOST_FAILURE|MSG_TASK_CANCELLED, - bprintf("while executing task %s", MSG_task_get_name(task))); + + jxbt_check_res("MSG_task_execute()", rv, + MSG_HOST_FAILURE | MSG_TASK_CANCELLED, + bprintf("while executing task %s", + MSG_task_get_name(task))); } /*************************************************************************************** @@ -790,7 +805,8 @@ Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) JNIEXPORT void JNICALL -Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) { +Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) +{ char **argv = NULL; int index; int argc = 0; @@ -823,36 +839,38 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) { } JNIEXPORT void JNICALL - JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) { + JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls) +{ MSG_error_t rv; - int index;//xbt_fifo_item_t item = NULL; + int index; //xbt_fifo_item_t item = NULL; m_host_t *hosts; jobject jhost; /* Run everything */ - rv= MSG_main(); - jxbt_check_res("MSG_main()",rv,MSG_OK, - bprintf("unexpected error : MSG_main() failed .. please report this bug ")); + rv = MSG_main(); + jxbt_check_res("MSG_main()", rv, MSG_OK, + bprintf + ("unexpected error : MSG_main() failed .. please report this bug ")); DEBUG0 - ("MSG_main finished. Bail out before cleanup since there is a bug in this part."); + ("MSG_main finished. Bail out before cleanup since there is a bug in this part."); DEBUG0("Clean java world"); /* Cleanup java hosts */ hosts = MSG_get_host_table(); - for (index=0;indexdata; - if(jhost) - jhost_unref(env,jhost); + for (index = 0; index < MSG_get_host_number() - 1; index++) { + jhost = (jobject) hosts[index]->data; + if (jhost) + jhost_unref(env, jhost); } DEBUG0("Clean native world"); /* cleanup native stuff */ rv = MSG_OK != MSG_clean(); - jxbt_check_res("MSG_clean()",rv,MSG_OK, - bprintf("unexpected error : MSG_clean() failed .. please report this bug ")); + jxbt_check_res("MSG_clean()", rv, MSG_OK, + bprintf + ("unexpected error : MSG_clean() failed .. please report this bug ")); } @@ -868,7 +886,8 @@ Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, jstring jplatformFile) { - const char *platformFile = (*env)->GetStringUTFChars(env, jplatformFile, 0); + const char *platformFile = + (*env)->GetStringUTFChars(env, jplatformFile, 0); MSG_create_environment(platformFile); @@ -930,7 +949,8 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) if (!jhost) { jname = (*env)->NewStringUTF(env, MSG_host_get_name(host)); - jhost = Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname); + jhost = + Java_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname); /* FIXME: leak of jname ? */ } @@ -961,7 +981,8 @@ Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class, (*env)->ReleaseStringUTFChars(env, jname, name); if (errmsg) { - char *thrown = bprintf("xbt_select_context_factory() failed: %s", errmsg); + char *thrown = + bprintf("xbt_select_context_factory() failed: %s", errmsg); free(errmsg); jxbt_throw_jni(env, thrown); } @@ -986,13 +1007,15 @@ Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls, } /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */ - MSG_task_set_data(task,(void *) (*env)->NewGlobalRef(env, jtask)); + MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask)); rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout); (*env)->ReleaseStringUTFChars(env, jalias, alias); - jxbt_check_res("MSG_task_send_with_timeout()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT, - bprintf("while sending task %s to mailbox %s", MSG_task_get_name(task),alias)); + jxbt_check_res("MSG_task_send_with_timeout()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf("while sending task %s to mailbox %s", + MSG_task_get_name(task), alias)); } JNIEXPORT void JNICALL @@ -1012,14 +1035,17 @@ Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls, alias = (*env)->GetStringUTFChars(env, jalias, 0); /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */ - MSG_task_set_data(task,(void *) (*env)->NewGlobalRef(env, jtask)); + MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask)); rv = MSG_task_send_bounded(task, alias, (double) jmaxRate); (*env)->ReleaseStringUTFChars(env, jalias, alias); - jxbt_check_res("MSG_task_send_bounded()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT, - bprintf("while sending task %s to mailbox %s with max rate %f", MSG_task_get_name(task),alias,(double)jmaxRate)); - + jxbt_check_res("MSG_task_send_bounded()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf + ("while sending task %s to mailbox %s with max rate %f", + MSG_task_get_name(task), alias, (double) jmaxRate)); + } JNIEXPORT jobject JNICALL @@ -1050,12 +1076,13 @@ Java_simgrid_msg_MsgNative_taskReceive(JNIEnv * env, jclass cls, /* Convert the global ref into a local ref so that the JVM can free the stuff */ jtask_local = (*env)->NewLocalRef(env, jtask_global); (*env)->DeleteGlobalRef(env, jtask_global); - MSG_task_set_data(task,NULL); + MSG_task_set_data(task, NULL); (*env)->ReleaseStringUTFChars(env, jalias, alias); - jxbt_check_res("MSG_task_receive_ext()",rv, MSG_HOST_FAILURE|MSG_TRANSFER_FAILURE|MSG_TIMEOUT, - bprintf("while receiving from mailbox %s",alias)); + jxbt_check_res("MSG_task_receive_ext()", rv, + MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, + bprintf("while receiving from mailbox %s", alias)); return (jobject) jtask_local; } @@ -1079,7 +1106,8 @@ Java_simgrid_msg_MsgNative_taskListen(JNIEnv * env, jclass cls, JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_taskListenFromHost(JNIEnv * env, jclass cls, - jstring jalias, jobject jhost) + jstring jalias, + jobject jhost) { int rv; const char *alias; @@ -1120,7 +1148,7 @@ Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, { const char *deploymentFile = - (*env)->GetStringUTFChars(env, jdeploymentFile, 0); + (*env)->GetStringUTFChars(env, jdeploymentFile, 0); surf_parse_reset_parser(); @@ -1141,7 +1169,7 @@ Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, japplication_handler_on_start_document(); if (surf_parse()) - jxbt_throw_jni(env,"surf_parse() failed"); + jxbt_throw_jni(env, "surf_parse() failed"); surf_parse_close(); diff --git a/src/java/jmsg.h b/src/java/jmsg.h index 0d0d7a1d79..c6ff810748 100644 --- a/src/java/jmsg.h +++ b/src/java/jmsg.h @@ -41,7 +41,7 @@ Java_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls, * Signature (Lsimgrid/msg/Process;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processResume - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -49,7 +49,7 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processResume * Signature (Lsimgrid/msg/Process;)Z */ JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_processIsSuspended - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -57,7 +57,7 @@ JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_processIsSuspended * Signature (Lsimgrid/msg/Process;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processKill - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -65,7 +65,7 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processKill * Signature (Lsimgrid/msg/Process;)Lsimgrid/msg/Host; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processGetHost - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -73,7 +73,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processGetHost * Signature (I)Lsimgrid/msg/Process; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processFromPID - (JNIEnv *, jclass, jint); + (JNIEnv *, jclass, jint); /* * Class simgrid_msg_Msg @@ -81,7 +81,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processFromPID * Signature (Lsimgrid/msg/Process;)I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPID - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -89,7 +89,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPID * Signature (Lsimgrid/msg/Process;)I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPPID - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -97,7 +97,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processGetPPID * Signature ()Lsimgrid/msg/Process; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processSelf - (JNIEnv *, jclass); + (JNIEnv *, jclass); /* * Class simgrid_msg_Msg @@ -105,7 +105,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_processSelf * Signature ()I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPID - (JNIEnv *, jclass); + (JNIEnv *, jclass); /* * Class simgrid_msg_Msg @@ -113,7 +113,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPID * Signature ()I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPPID - (JNIEnv *, jclass); + (JNIEnv *, jclass); /* * Class simgrid_msg_Msg @@ -121,7 +121,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processSelfPPID * Signature (Lsimgrid/msg/Process;Lsimgrid/msg/Host;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processChangeHost - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -129,7 +129,7 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processChangeHost * Signature (D)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processWaitFor - (JNIEnv *, jclass, jdouble); + (JNIEnv *, jclass, jdouble); /* * Class simgrid_msg_Msg @@ -137,7 +137,7 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processWaitFor * Signature (Ljava/lang/String;)Lsimgrid/msg/Host; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostGetByName - (JNIEnv *, jclass, jstring); + (JNIEnv *, jclass, jstring); /* * Class simgrid_msg_Msg @@ -145,7 +145,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostGetByName * Signature (Lsimgrid/msg/Host;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_hostGetName - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -153,7 +153,7 @@ JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_hostGetName * Signature ()I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_hostGetNumber - (JNIEnv *, jclass); + (JNIEnv *, jclass); /* * Class simgrid_msg_Msg @@ -161,7 +161,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_hostGetNumber * Signature ()Lsimgrid/msg/Host; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostSelf - (JNIEnv *, jclass); + (JNIEnv *, jclass); /* * Class simgrid_msg_Msg @@ -169,7 +169,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_hostSelf * Signature (Lsimgrid/msg/Host;)D */ JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_hostGetSpeed - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls, @@ -181,7 +181,7 @@ Java_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls, * Signature (Lsimgrid/msg/Host;)Z */ JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_hostIsAvail - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -189,7 +189,7 @@ JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_hostIsAvail * Signature (Lsimgrid/msg/Task;Ljava/lang/String;DD)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskCreate - (JNIEnv *, jclass, jobject, jstring, jdouble, jdouble); + (JNIEnv *, jclass, jobject, jstring, jdouble, jdouble); JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv *, jclass, jobject, @@ -202,7 +202,7 @@ Java_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv *, jclass, jobject, * Signature (Lsimgrid/msg/Task;)Lsimgrid/msg/Process; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSender - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -210,7 +210,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSender * Signature (Lsimgrid/msg/Task;)Lsimgrid/msg/Host; */ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSource - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -218,7 +218,7 @@ JNIEXPORT jobject JNICALL Java_simgrid_msg_MsgNative_taskGetSource * Signature (Lsimgrid/msg/Task;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_taskGetName - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -226,7 +226,7 @@ JNIEXPORT jstring JNICALL Java_simgrid_msg_MsgNative_taskGetName * Signature (Lsimgrid/msg/Task;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskCancel - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -234,15 +234,16 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskCancel * Signature (Lsimgrid/msg/Task;)D */ JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_taskGetComputeDuration - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg * Method taskGetRemainingDuration * Signature (Lsimgrid/msg/Task;)D */ -JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_taskGetRemainingDuration - (JNIEnv *, jclass, jobject); +JNIEXPORT jdouble JNICALL +Java_simgrid_msg_MsgNative_taskGetRemainingDuration(JNIEnv *, jclass, + jobject); /* * Class simgrid_msg_Msg @@ -250,7 +251,7 @@ JNIEXPORT jdouble JNICALL Java_simgrid_msg_MsgNative_taskGetRemainingDuration * Signature (Lsimgrid/msg/Task;D)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSetPriority - (JNIEnv *, jclass, jobject, jdouble); + (JNIEnv *, jclass, jobject, jdouble); /* * Class simgrid_msg_Msg @@ -258,7 +259,7 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSetPriority * Signature (Lsimgrid/msg/Task;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskDestroy - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); /* * Class simgrid_msg_Msg @@ -266,15 +267,15 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskDestroy * Signature (Lsimgrid/msg/Task;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskExecute - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); JNIEXPORT jobject JNICALL - Java_simgrid_msg_MsgNative_taskReceive - (JNIEnv *, jclass, jstring, jdouble, jobject); + Java_simgrid_msg_MsgNative_taskReceive + (JNIEnv *, jclass, jstring, jdouble, jobject); JNIEXPORT void JNICALL - Java_simgrid_msg_MsgNative_taskSend - (JNIEnv *, jclass, jstring, jobject, jdouble); + Java_simgrid_msg_MsgNative_taskSend + (JNIEnv *, jclass, jstring, jobject, jdouble); /* * Class simgrid_msg_Msg @@ -291,7 +292,7 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_Msg_getErrCode(JNIEnv *, jclass); JNIEXPORT jdouble JNICALL Java_simgrid_msg_Msg_getClock(JNIEnv *, jclass); JNIEXPORT void JNICALL - JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls); + JNICALL Java_simgrid_msg_Msg_run(JNIEnv * env, jclass cls); JNIEXPORT void JNICALL Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs); @@ -302,7 +303,7 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs); * Signature (I)I */ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processKillAll - (JNIEnv *, jclass, jint); + (JNIEnv *, jclass, jint); /* * Class simgrid_msg_Msg @@ -310,9 +311,10 @@ JNIEXPORT jint JNICALL Java_simgrid_msg_MsgNative_processKillAll * Signature (Lsimgrid/msg/Process;)V */ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_processExit - (JNIEnv *, jclass, jobject); + (JNIEnv *, jclass, jobject); -JNIEXPORT void JNICALL Java_simgrid_msg_Msg_info(JNIEnv *, jclass, jstring); +JNIEXPORT void JNICALL Java_simgrid_msg_Msg_info(JNIEnv *, jclass, + jstring); JNIEXPORT jobjectArray JNICALL Java_simgrid_msg_MsgNative_allHosts(JNIEnv *, jclass); @@ -325,8 +327,8 @@ JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv *, jclass, jstring); JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring, jobject, - jdouble); +Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring, + jobject, jdouble); JNIEXPORT jboolean JNICALL Java_simgrid_msg_MsgNative_taskListen(JNIEnv *, jclass, jstring); @@ -342,4 +344,4 @@ JNIEXPORT void JNICALL Java_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls, jstring jdeploymentFile); -#endif /* !MSG4JAVA_H */ +#endif /* !MSG4JAVA_H */ diff --git a/src/java/jmsg_application_handler.c b/src/java/jmsg_application_handler.c index f3de817ea7..f22746424c 100644 --- a/src/java/jmsg_application_handler.c +++ b/src/java/jmsg_application_handler.c @@ -1,5 +1,5 @@ /* Upcalls to the Java functions used as callback to the FleXML parser. */ - + /* Copyright (c) 2008, 2009, 2010. The SimGrid Team. * All rights reserved. */ @@ -12,42 +12,48 @@ #include "surf/surfxml_parse.h" #include "jxbt_utilities.h" -void japplication_handler_on_start_document(void) { +void japplication_handler_on_start_document(void) +{ jclass cls; - JNIEnv * env = get_current_thread_env(); + JNIEnv *env = get_current_thread_env(); jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onStartDocument", "()V"); + "onStartDocument", "()V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; (*env)->CallStaticVoidMethod(env, cls, id); } -void japplication_handler_on_end_document(void) { +void japplication_handler_on_end_document(void) +{ jclass cls; - JNIEnv * env = get_current_thread_env(); + JNIEnv *env = get_current_thread_env(); jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onEndDocument", "()V"); + "onEndDocument", "()V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; (*env)->CallStaticVoidMethod(env, cls, id); } -void japplication_handler_on_begin_process(void) { +void japplication_handler_on_begin_process(void) +{ jstring jhostName; jstring jfunction; jclass cls; - JNIEnv * env = get_current_thread_env(); + JNIEnv *env = get_current_thread_env(); jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onBeginProcess", - "(Ljava/lang/String;Ljava/lang/String;)V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + "onBeginProcess", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; jhostName = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_host); jfunction = @@ -55,30 +61,34 @@ void japplication_handler_on_begin_process(void) { (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction); } -void japplication_handler_on_process_arg(void) { +void japplication_handler_on_process_arg(void) +{ jstring jarg; jclass cls; - JNIEnv * env = get_current_thread_env(); + JNIEnv *env = get_current_thread_env(); jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onProcessArg", "(Ljava/lang/String;)V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + "onProcessArg", "(Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; jarg = (jstring) (*env)->NewStringUTF(env, A_surfxml_argument_value); (*env)->CallStaticVoidMethod(env, cls, id, jarg); } -void japplication_handler_on_property(void) { +void japplication_handler_on_property(void) +{ jstring jid; jstring jvalue; jclass cls; - JNIEnv * env = get_current_thread_env(); + JNIEnv *env = get_current_thread_env(); jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onProperty", - "(Ljava/lang/String;Ljava/lang/String;)V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + "onProperty", + "(Ljava/lang/String;Ljava/lang/String;)V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; jid = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_id); @@ -86,13 +96,15 @@ void japplication_handler_on_property(void) { (*env)->CallStaticVoidMethod(env, cls, id, jid, jvalue); } -void japplication_handler_on_end_process(void) { - JNIEnv * env = get_current_thread_env(); +void japplication_handler_on_end_process(void) +{ + JNIEnv *env = get_current_thread_env(); jclass cls; jmethodID id = jxbt_get_static_smethod(env, "simgrid/msg/ApplicationHandler", - "onEndProcess", "()V"); - if (!id || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) + "onEndProcess", "()V"); + if (!id + || !(cls = jxbt_get_class(env, "simgrid/msg/ApplicationHandler"))) return; (*env)->CallStaticVoidMethod(env, cls, id); } diff --git a/src/java/jmsg_application_handler.h b/src/java/jmsg_application_handler.h index 71dcf36890..7d3a2159d3 100644 --- a/src/java/jmsg_application_handler.h +++ b/src/java/jmsg_application_handler.h @@ -1,5 +1,5 @@ /* Upcalls to the Java functions used as callback to the FleXML parser. */ - + /* Copyright (c) 2008, 2009, 2010. The SimGrid Team. * All rights reserved. */ @@ -8,7 +8,7 @@ #ifndef MSG_JAPPLICATION_HANDLER_H #define MSG_JAPPLICATION_HANDLER_H - + #include #include "msg/msg.h" void japplication_handler_on_start_document(void); @@ -18,4 +18,4 @@ void japplication_handler_on_process_arg(void); void japplication_handler_on_property(void); void japplication_handler_on_end_process(void); -#endif /* !MSG_JAPPLICATION_HANDLER_H */ +#endif /* !MSG_JAPPLICATION_HANDLER_H */ diff --git a/src/java/jmsg_host.h b/src/java/jmsg_host.h index e6574f1a76..1f40c13f38 100644 --- a/src/java/jmsg_host.h +++ b/src/java/jmsg_host.h @@ -107,4 +107,4 @@ void jhost_set_name(jobject jhost, jstring jname, JNIEnv * env); */ jboolean jhost_is_valid(jobject jhost, JNIEnv * env); -#endif /*!MSG_JHOST_H */ +#endif /*!MSG_JHOST_H */ diff --git a/src/java/jmsg_process.c b/src/java/jmsg_process.c index c42080fdc5..6ebb133fc8 100644 --- a/src/java/jmsg_process.c +++ b/src/java/jmsg_process.c @@ -27,7 +27,7 @@ void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env) jboolean jprocess_is_alive(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "isAlive", "()Z"); + jxbt_get_smethod(env, "simgrid/msg/Process", "isAlive", "()Z"); if (!id) return 0; @@ -37,7 +37,8 @@ jboolean jprocess_is_alive(jobject jprocess, JNIEnv * env) void jprocess_join(jobject jprocess, JNIEnv * env) { - jmethodID id = jxbt_get_smethod(env, "simgrid/msg/Process", "join", "()V"); + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "join", "()V"); if (!id) return; @@ -48,7 +49,7 @@ void jprocess_join(jobject jprocess, JNIEnv * env) void jprocess_exit(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "interrupt", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "interrupt", "()V"); if (!id) return; @@ -59,7 +60,7 @@ void jprocess_exit(jobject jprocess, JNIEnv * env) void jprocess_yield(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "switchProcess", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "switchProcess", "()V"); if (!id) return; @@ -70,7 +71,7 @@ void jprocess_yield(jobject jprocess, JNIEnv * env) void jprocess_lock_mutex(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "lockMutex", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "lockMutex", "()V"); if (!id) return; @@ -81,7 +82,7 @@ void jprocess_lock_mutex(jobject jprocess, JNIEnv * env) void jprocess_unlock_mutex(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "unlockMutex", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "unlockMutex", "()V"); if (!id) return; @@ -93,7 +94,7 @@ void jprocess_unlock_mutex(jobject jprocess, JNIEnv * env) void jprocess_signal_cond(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "signalCond", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "signalCond", "()V"); if (!id) return; @@ -104,7 +105,7 @@ void jprocess_signal_cond(jobject jprocess, JNIEnv * env) void jprocess_wait_cond(jobject jprocess, JNIEnv * env) { jmethodID id = - jxbt_get_smethod(env, "simgrid/msg/Process", "waitCond", "()V"); + jxbt_get_smethod(env, "simgrid/msg/Process", "waitCond", "()V"); if (!id) return; @@ -115,7 +116,8 @@ void jprocess_wait_cond(jobject jprocess, JNIEnv * env) void jprocess_start(jobject jprocess, JNIEnv * env) { - jmethodID id = jxbt_get_smethod(env, "simgrid/msg/Process", "start", "()V"); + jmethodID id = + jxbt_get_smethod(env, "simgrid/msg/Process", "start", "()V"); if (!id) return; @@ -157,8 +159,8 @@ jlong jprocess_get_id(jobject jprocess, JNIEnv * env) jstring jprocess_get_name(jobject jprocess, JNIEnv * env) { - jfieldID id = - jxbt_get_sfield(env, "simgrid/msg/Process", "name", "Ljava/lang/String;"); + jfieldID id = jxbt_get_sfield(env, "simgrid/msg/Process", "name", + "Ljava/lang/String;"); jobject jname; if (!id) diff --git a/src/java/jmsg_process.h b/src/java/jmsg_process.h index 8a2aef871c..8d3862a90d 100644 --- a/src/java/jmsg_process.h +++ b/src/java/jmsg_process.h @@ -239,4 +239,4 @@ void jprocess_schedule(smx_context_t context); void jprocess_unschedule(smx_context_t context); -#endif /* !MSG_JPROCESS_H */ +#endif /* !MSG_JPROCESS_H */ diff --git a/src/java/jmsg_task.h b/src/java/jmsg_task.h index 30c014e2b6..7b07a55c0d 100644 --- a/src/java/jmsg_task.h +++ b/src/java/jmsg_task.h @@ -75,4 +75,4 @@ m_task_t jtask_to_native_task(jobject jtask, JNIEnv * env); */ jboolean jtask_is_valid(jobject jtask, JNIEnv * env); -#endif /* !MSG_JTASK_H */ +#endif /* !MSG_JTASK_H */ diff --git a/src/java/jxbt_utilities.c b/src/java/jxbt_utilities.c index af7153ce10..6b11b8b0c2 100644 --- a/src/java/jxbt_utilities.c +++ b/src/java/jxbt_utilities.c @@ -42,13 +42,13 @@ jmethodID jxbt_get_jmethod(JNIEnv * env, jclass cls, if (!id) { jmethodID tostr_id = - (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); jstring jclassname = - (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); + (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); - char *m = - bprintf("Cannot find method %s(%s) in %s", name, signature, classname); + char *m = bprintf("Cannot find method %s(%s) in %s", name, signature, + classname); (*env)->ReleaseStringUTFChars(env, jclassname, classname); @@ -73,14 +73,14 @@ jmethodID jxbt_get_static_jmethod(JNIEnv * env, jclass cls, if (!id) { jmethodID tostr_id = - (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); jstring jclassname = - (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); + (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL); const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); char *m = - bprintf("Cannot find static method %s(%s) in %s", name, signature, - classname); + bprintf("Cannot find static method %s(%s) in %s", name, signature, + classname); (*env)->ReleaseStringUTFChars(env, jclassname, classname); @@ -108,8 +108,8 @@ jmethodID jxbt_get_static_smethod(JNIEnv * env, const char *classname, if (!id) { char *m = - bprintf("Cannot find static method %s(%s) in %s", name, signature, - classname); + bprintf("Cannot find static method %s(%s) in %s", name, signature, + classname); jxbt_throw_jni(env, m); @@ -133,8 +133,8 @@ jmethodID jxbt_get_smethod(JNIEnv * env, const char *classname, id = (*env)->GetMethodID(env, cls, name, signature); if (!id) { - char *m = - bprintf("Cannot find method %s(%s) in %s", name, signature, classname); + char *m = bprintf("Cannot find method %s(%s) in %s", name, signature, + classname); jxbt_throw_jni(env, m); @@ -156,12 +156,12 @@ jfieldID jxbt_get_jfield(JNIEnv * env, jclass cls, if (!id) { jmethodID getname_id = - (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); + (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;"); jstring jclassname = - (jstring) (*env)->CallObjectMethod(env, cls, getname_id, NULL); + (jstring) (*env)->CallObjectMethod(env, cls, getname_id, NULL); const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0); - char *m = - bprintf("Cannot find field %s %s in %s", signature, name, classname); + char *m = bprintf("Cannot find field %s %s in %s", signature, name, + classname); (*env)->ReleaseStringUTFChars(env, jclassname, classname); @@ -186,8 +186,8 @@ jfieldID jxbt_get_sfield(JNIEnv * env, const char *classname, id = (*env)->GetFieldID(env, cls, name, signature); if (!id) { - char *m = - bprintf("Cannot find field %s %s in %s", signature, name, classname); + char *m = bprintf("Cannot find field %s %s in %s", signature, name, + classname); jxbt_throw_jni(env, m); @@ -205,7 +205,8 @@ static void jxbt_throw_by_name(JNIEnv * env, const char *name, char *msg) { jclass cls = (*env)->FindClass(env, name); - xbt_assert2(cls, "%s (Plus severe error: class %s not found)\n", msg, name); + xbt_assert2(cls, "%s (Plus severe error: class %s not found)\n", msg, + name); (*env)->ThrowNew(env, cls, msg); @@ -261,38 +262,35 @@ void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name) } // tranfert failure -void jxbt_throw_transfer_failure(JNIEnv *env,char *details) { - - jxbt_throw_by_name(env, - "simgrid/msg/TransferFailureException", - details); - +void jxbt_throw_transfer_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, "simgrid/msg/TransferFailureException", details); + } // host failure Exception -void jxbt_throw_host_failure(JNIEnv *env,char *details) { - - jxbt_throw_by_name(env, - "simgrid/msg/HostFailureException", - bprintf("Host Failure %s",details)); - +void jxbt_throw_host_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, + "simgrid/msg/HostFailureException", + bprintf("Host Failure %s", details)); + } // time out failure Exception -void jxbt_throw_time_out_failure(JNIEnv *env,char *details) { - - jxbt_throw_by_name(env, - "simgrid/msg/TimeoutException", - details); - +void jxbt_throw_time_out_failure(JNIEnv * env, char *details) +{ + + jxbt_throw_by_name(env, "simgrid/msg/TimeoutException", details); + } // task Cancelled exception -void jxbt_throw_task_cancelled(JNIEnv *env,char *details) +void jxbt_throw_task_cancelled(JNIEnv * env, char *details) { - - jxbt_throw_by_name(env, - "simgrid/msg/TaskCancelledException", - details); - -} \ No newline at end of file + + jxbt_throw_by_name(env, "simgrid/msg/TaskCancelledException", details); + +} diff --git a/src/java/jxbt_utilities.h b/src/java/jxbt_utilities.h index 6563f56229..08bd391873 100644 --- a/src/java/jxbt_utilities.h +++ b/src/java/jxbt_utilities.h @@ -83,12 +83,12 @@ void jxbt_throw_host_not_found(JNIEnv * env, const char *invalid_name); /** Thrown when looking for an host from name does not lead to anything */ void jxbt_throw_process_not_found(JNIEnv * env, const char *invalid_name); /** Thrown when a transfer failure accure while Sending task */ -void jxbt_throw_transfer_failure(JNIEnv * env,char *detail); +void jxbt_throw_transfer_failure(JNIEnv * env, char *detail); /** Thrown when a host failure accures while Sending task*/ -void jxbt_throw_host_failure(JNIEnv *env,char *details); +void jxbt_throw_host_failure(JNIEnv * env, char *details); /** Thrown when a time out accures While Sending task */ -void jxbt_throw_time_out_failure(JNIEnv *env,char *details); +void jxbt_throw_time_out_failure(JNIEnv * env, char *details); /**Thrown when a task is canceled */ -void jxbt_throw_task_cancelled(JNIEnv *env,char *details); +void jxbt_throw_task_cancelled(JNIEnv * env, char *details); -#endif /* ! JXBT_UTILITY_H */ +#endif /* ! JXBT_UTILITY_H */ diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.c index 5abffdad14..de1ec3a143 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.c @@ -1,23 +1,23 @@ #include "private.h" void MC_take_snapshot(mc_snapshot_t snapshot) -{ +{ /* Save the heap! */ - snapshot->heap_size = MC_save_heap(&(snapshot->heap)); + snapshot->heap_size = MC_save_heap(&(snapshot->heap)); /* Save data and bss that */ snapshot->data_size = MC_save_dataseg(&(snapshot->data)); } void MC_restore_snapshot(mc_snapshot_t snapshot) -{ +{ MC_restore_heap(snapshot->heap, snapshot->heap_size); - MC_restore_dataseg(snapshot->data, snapshot->data_size); + MC_restore_dataseg(snapshot->data, snapshot->data_size); } void MC_free_snapshot(mc_snapshot_t snapshot) { xbt_free(snapshot->heap); xbt_free(snapshot->data); - xbt_free(snapshot); + xbt_free(snapshot); } diff --git a/src/mc/mc_dfs.c b/src/mc/mc_dfs.c index d578540631..a3dec04801 100644 --- a/src/mc/mc_dfs.c +++ b/src/mc/mc_dfs.c @@ -1,42 +1,46 @@ #include "private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dfs, mc, - "Logging specific to MC DFS exploration"); + "Logging specific to MC DFS exploration"); void MC_dfs_init() { - mc_transition_t trans = NULL; + mc_transition_t trans = NULL; mc_state_t initial_state = NULL; xbt_setset_cursor_t cursor = NULL; - + MC_SET_RAW_MEM; initial_state = MC_state_new(); /* Add the state data structure for the initial state */ xbt_fifo_unshift(mc_stack, initial_state); MC_UNSET_RAW_MEM; - - DEBUG0("**************************************************"); + + DEBUG0("**************************************************"); DEBUG0("Initial state"); - + /* Schedule all the processes to detect the transitions from the initial state */ MC_schedule_enabled_processes(); MC_SET_RAW_MEM; - xbt_setset_add(initial_state->enabled_transitions, initial_state->transitions); - xbt_setset_foreach(initial_state->enabled_transitions, cursor, trans){ - if(trans->type == mc_wait - && (trans->wait.comm->src_proc == NULL || trans->wait.comm->dst_proc == NULL)){ + xbt_setset_add(initial_state->enabled_transitions, + initial_state->transitions); + xbt_setset_foreach(initial_state->enabled_transitions, cursor, trans) { + if (trans->type == mc_wait + && (trans->wait.comm->src_proc == NULL + || trans->wait.comm->dst_proc == NULL)) { xbt_setset_set_remove(initial_state->enabled_transitions, trans); } } /* Fill the interleave set of the initial state with all enabled transitions */ - xbt_setset_add(initial_state->interleave, initial_state->enabled_transitions); + xbt_setset_add(initial_state->interleave, + initial_state->enabled_transitions); /* Update Statistics */ - mc_stats->state_size += xbt_setset_set_size(initial_state->enabled_transitions); - + mc_stats->state_size += + xbt_setset_set_size(initial_state->enabled_transitions); + MC_UNSET_RAW_MEM; } @@ -48,32 +52,34 @@ void MC_dfs_init() */ void MC_dfs(void) { - mc_transition_t trans = NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; mc_state_t next_state = NULL; xbt_setset_cursor_t cursor = NULL; - - while(xbt_fifo_size(mc_stack) > 0){ + + while (xbt_fifo_size(mc_stack) > 0) { DEBUG0("**************************************************"); /* FIXME: Think about what happens if there are no transitions but there are some actions on the models. (ex. all the processes do a sleep(0) in a round). */ /* Get current state */ - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); - + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + /* If there are transitions to execute and the maximun depth has not been reached then perform one step of the exploration algorithm */ - if(xbt_setset_set_size(current_state->interleave) > 0 && xbt_fifo_size(mc_stack) < MAX_DEPTH){ + if (xbt_setset_set_size(current_state->interleave) > 0 + && xbt_fifo_size(mc_stack) < MAX_DEPTH) { - DEBUG3("Exploration detph=%d (state=%p)(%d transitions)", xbt_fifo_size(mc_stack), - current_state, xbt_setset_set_size(current_state->interleave)); + DEBUG3("Exploration detph=%d (state=%p)(%d transitions)", + xbt_fifo_size(mc_stack), current_state, + xbt_setset_set_size(current_state->interleave)); /* Update statistics */ mc_stats->visited_states++; mc_stats->executed_transitions++; - + /* Choose a transition to execute from the interleave set of the current state, and create the data structures for the new expanded state in the exploration stack. */ @@ -95,45 +101,50 @@ void MC_dfs(void) /* Schedule every process that got enabled due to the executed transition */ MC_schedule_enabled_processes(); - + /* Calculate the enabled transitions set of the next state: - -add the transition sets of the current state and the next state - -remove the executed transition from that set - -remove all the transitions that are disabled (mc_wait only) - -use the resulting set as the enabled transitions of the next state */ + -add the transition sets of the current state and the next state + -remove the executed transition from that set + -remove all the transitions that are disabled (mc_wait only) + -use the resulting set as the enabled transitions of the next state */ MC_SET_RAW_MEM; xbt_setset_add(next_state->transitions, current_state->transitions); xbt_setset_set_remove(next_state->transitions, trans); - xbt_setset_add(next_state->enabled_transitions, next_state->transitions); - xbt_setset_foreach(next_state->enabled_transitions, cursor, trans){ - if(trans->type == mc_wait - && (trans->wait.comm->src_proc == NULL || trans->wait.comm->dst_proc == NULL)){ + xbt_setset_add(next_state->enabled_transitions, + next_state->transitions); + xbt_setset_foreach(next_state->enabled_transitions, cursor, trans) { + if (trans->type == mc_wait + && (trans->wait.comm->src_proc == NULL + || trans->wait.comm->dst_proc == NULL)) { xbt_setset_set_remove(next_state->enabled_transitions, trans); } } - + /* Fill the interleave set of the new state with all enabled transitions */ - xbt_setset_add(next_state->interleave, next_state->enabled_transitions); + xbt_setset_add(next_state->interleave, + next_state->enabled_transitions); MC_UNSET_RAW_MEM; /* Update Statistics */ - mc_stats->state_size += xbt_setset_set_size(next_state->enabled_transitions); + mc_stats->state_size += + xbt_setset_set_size(next_state->enabled_transitions); /* Let's loop again */ - - /* The interleave set is empty or the maximum depth is reached, let's back-track */ - }else{ + + /* The interleave set is empty or the maximum depth is reached, let's back-track */ + } else { DEBUG0("There are no more actions to run"); - + MC_SET_RAW_MEM; xbt_fifo_shift(mc_stack); - MC_state_delete(current_state); + MC_state_delete(current_state); /* Go backwards in the stack until we find a state with transitions in the interleave set */ - while(xbt_fifo_size(mc_stack) > 0 && (current_state = (mc_state_t)xbt_fifo_shift(mc_stack))){ - if(xbt_setset_set_size(current_state->interleave) == 0){ + while (xbt_fifo_size(mc_stack) > 0 + && (current_state = (mc_state_t) xbt_fifo_shift(mc_stack))) { + if (xbt_setset_set_size(current_state->interleave) == 0) { MC_state_delete(current_state); - }else{ + } else { xbt_fifo_unshift(mc_stack, current_state); DEBUG1("Back-tracking to depth %d", xbt_fifo_size(mc_stack)); MC_replay(mc_stack); @@ -147,4 +158,4 @@ void MC_dfs(void) MC_UNSET_RAW_MEM; /* We are done, show the statistics and return */ MC_print_statistics(mc_stats); -} \ No newline at end of file +} diff --git a/src/mc/mc_dpor.c b/src/mc/mc_dpor.c index bdc859e6e5..93e7d07bdd 100644 --- a/src/mc/mc_dpor.c +++ b/src/mc/mc_dpor.c @@ -7,7 +7,7 @@ #include "private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dpor, mc, - "Logging specific to MC DPOR exploration"); + "Logging specific to MC DPOR exploration"); /** * \brief Initialize the DPOR exploration algorithm @@ -17,7 +17,7 @@ void MC_dpor_init() mc_state_t initial_state = NULL; mc_transition_t trans, trans_tmp = NULL; xbt_setset_cursor_t cursor = NULL; - + /* Create the initial state and push it into the exploration stack */ MC_SET_RAW_MEM; initial_state = MC_state_new(); @@ -25,10 +25,10 @@ void MC_dpor_init() MC_UNSET_RAW_MEM; /* Schedule all the processes to detect the transitions of the initial state */ - DEBUG0("**************************************************"); + DEBUG0("**************************************************"); DEBUG0("Initial state"); - while(xbt_swag_size(simix_global->process_to_run)){ + while (xbt_swag_size(simix_global->process_to_run)) { MC_schedule_enabled_processes(); MC_execute_surf_actions(); } @@ -38,18 +38,21 @@ void MC_dpor_init() initial_state->transitions); /* Fill the interleave set of the initial state with an enabled process */ - trans = xbt_setset_set_choose(initial_state->enabled_transitions); - if(trans){ - DEBUG1("Choosing process %s for next interleave", trans->process->name); - xbt_setset_foreach(initial_state->enabled_transitions, cursor, trans_tmp){ - if(trans_tmp->process == trans->process) - xbt_setset_set_insert(initial_state->interleave, trans_tmp); + trans = xbt_setset_set_choose(initial_state->enabled_transitions); + if (trans) { + DEBUG1("Choosing process %s for next interleave", + trans->process->name); + xbt_setset_foreach(initial_state->enabled_transitions, cursor, + trans_tmp) { + if (trans_tmp->process == trans->process) + xbt_setset_set_insert(initial_state->interleave, trans_tmp); } } MC_UNSET_RAW_MEM; /* Update Statistics */ - mc_stats->state_size += xbt_setset_set_size(initial_state->enabled_transitions); + mc_stats->state_size += + xbt_setset_set_size(initial_state->enabled_transitions); } @@ -59,32 +62,35 @@ void MC_dpor_init() */ void MC_dpor(void) { - mc_transition_t trans, trans_tmp = NULL; + mc_transition_t trans, trans_tmp = NULL; mc_state_t next_state = NULL; xbt_setset_cursor_t cursor = NULL; - - while(xbt_fifo_size(mc_stack) > 0){ - + + while (xbt_fifo_size(mc_stack) > 0) { + DEBUG0("**************************************************"); /* FIXME: Think about what happen if there are no transitions but there are some actions on the models. (ex. all the processes do a sleep(0) in a round). */ /* Get current state */ - mc_current_state = (mc_state_t) xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); - + mc_current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + /* If there are transitions to execute and the maximun depth has not been reached then perform one step of the exploration algorithm */ - if(xbt_setset_set_size(mc_current_state->interleave) > 0 && xbt_fifo_size(mc_stack) < MAX_DEPTH){ + if (xbt_setset_set_size(mc_current_state->interleave) > 0 + && xbt_fifo_size(mc_stack) < MAX_DEPTH) { + + DEBUG4("Exploration detph=%d (state=%p)(%d interleave) (%d enabled)", + xbt_fifo_size(mc_stack), mc_current_state, + xbt_setset_set_size(mc_current_state->interleave), + xbt_setset_set_size(mc_current_state->enabled_transitions)); - DEBUG4("Exploration detph=%d (state=%p)(%d interleave) (%d enabled)", xbt_fifo_size(mc_stack), - mc_current_state, xbt_setset_set_size(mc_current_state->interleave), - xbt_setset_set_size(mc_current_state->enabled_transitions)); - /* Update statistics */ mc_stats->visited_states++; mc_stats->executed_transitions++; - + /* Choose a transition to execute from the interleave set of the current state, and create the data structures for the new expanded state in the exploration stack. */ @@ -93,10 +99,10 @@ void MC_dpor(void) /* Add the transition in the done set of the current state */ xbt_setset_set_insert(mc_current_state->done, trans); - + next_state = MC_state_new(); xbt_fifo_unshift(mc_stack, next_state); - + /* Set it as the executed transition of the current state */ mc_current_state->executed_transition = trans; MC_UNSET_RAW_MEM; @@ -107,118 +113,125 @@ void MC_dpor(void) DEBUG1("Executing transition %s", trans->name); SIMIX_process_schedule(trans->process); MC_execute_surf_actions(); - - while(xbt_swag_size(simix_global->process_to_run)){ + + while (xbt_swag_size(simix_global->process_to_run)) { MC_schedule_enabled_processes(); MC_execute_surf_actions(); } - + /* Calculate the enabled transitions set of the next state */ MC_SET_RAW_MEM; - xbt_setset_foreach(mc_current_state->transitions, cursor, trans_tmp){ - if(trans_tmp->process != trans->process){ + xbt_setset_foreach(mc_current_state->transitions, cursor, trans_tmp) { + if (trans_tmp->process != trans->process) { xbt_setset_set_insert(next_state->transitions, trans_tmp); } } - - MC_trans_compute_enabled(next_state->enabled_transitions, next_state->transitions); - - /* Choose one transition to interleave from the enabled transition set */ + + MC_trans_compute_enabled(next_state->enabled_transitions, + next_state->transitions); + + /* Choose one transition to interleave from the enabled transition set */ trans = xbt_setset_set_choose(next_state->enabled_transitions); - if(trans){ - DEBUG1("Choosing process %s for next interleave", trans->process->name); - xbt_setset_foreach(next_state->enabled_transitions, cursor, trans_tmp){ - if(trans_tmp->process == trans->process) - xbt_setset_set_insert(next_state->interleave, trans_tmp); + if (trans) { + DEBUG1("Choosing process %s for next interleave", + trans->process->name); + xbt_setset_foreach(next_state->enabled_transitions, cursor, + trans_tmp) { + if (trans_tmp->process == trans->process) + xbt_setset_set_insert(next_state->interleave, trans_tmp); } } MC_UNSET_RAW_MEM; /* Update Statistics */ - mc_stats->state_size += xbt_setset_set_size(next_state->enabled_transitions); + mc_stats->state_size += + xbt_setset_set_size(next_state->enabled_transitions); /* Let's loop again */ - - /* The interleave set is empty or the maximum depth is reached, let's back-track */ - }else{ + + /* The interleave set is empty or the maximum depth is reached, let's back-track */ + } else { DEBUG0("There are no more transitions to interleave."); - + /* Check for deadlocks */ - xbt_setset_substract(mc_current_state->transitions, mc_current_state->done); - if(xbt_setset_set_size(mc_current_state->transitions) > 0){ + xbt_setset_substract(mc_current_state->transitions, + mc_current_state->done); + if (xbt_setset_set_size(mc_current_state->transitions) > 0) { INFO0("**************************"); INFO0("*** DEAD-LOCK DETECTED ***"); INFO0("**************************"); INFO0("Locked transitions:"); - xbt_setset_foreach(mc_current_state->transitions, cursor, trans){ - INFO3("%s [src=%p, dst=%p]", trans->name, trans->wait.comm->src_proc, - trans->wait.comm->dst_proc); + xbt_setset_foreach(mc_current_state->transitions, cursor, trans) { + INFO3("%s [src=%p, dst=%p]", trans->name, + trans->wait.comm->src_proc, trans->wait.comm->dst_proc); } INFO0("Counter-example execution trace:"); MC_dump_stack(mc_stack); - + MC_print_statistics(mc_stats); xbt_abort(); } - + mc_transition_t q = NULL; xbt_fifo_item_t item = NULL; mc_state_t state = NULL; /* - INFO0("*********************************"); - MC_show_stack(mc_stack);*/ - + INFO0("*********************************"); + MC_show_stack(mc_stack); */ + /* Trash the current state, no longer needed */ MC_SET_RAW_MEM; xbt_fifo_shift(mc_stack); MC_state_delete(mc_current_state); - + /* Traverse the stack backwards until a state with a non empty interleave set is found, deleting all the states that have it empty in the way. For each deleted state, check if the transition that has generated it (from it's predecesor state), depends on any other previous transition executed before it. If it does then add it to the interleave set of the state that executed that previous transition. */ - while((mc_current_state = xbt_fifo_shift(mc_stack)) != NULL){ + while ((mc_current_state = xbt_fifo_shift(mc_stack)) != NULL) { q = mc_current_state->executed_transition; - xbt_fifo_foreach(mc_stack, item, state, mc_state_t){ - if(MC_transition_depend(q, state->executed_transition)){ - xbt_setset_foreach(state->enabled_transitions, cursor, trans){ - if((trans->process == q->process) && !xbt_setset_set_belongs(state->done, trans)){ - DEBUG3("%s depend with %s at %p", q->name, + xbt_fifo_foreach(mc_stack, item, state, mc_state_t) { + if (MC_transition_depend(q, state->executed_transition)) { + xbt_setset_foreach(state->enabled_transitions, cursor, trans) { + if ((trans->process == q->process) + && !xbt_setset_set_belongs(state->done, trans)) { + DEBUG3("%s depend with %s at %p", q->name, state->executed_transition->name, state); - xbt_setset_foreach(state->enabled_transitions, cursor, trans){ - if(trans->process == q->process) - xbt_setset_set_insert(state->interleave, trans); + xbt_setset_foreach(state->enabled_transitions, cursor, + trans) { + if (trans->process == q->process) + xbt_setset_set_insert(state->interleave, trans); } - /* FIXME: hack to make it work*/ + /* FIXME: hack to make it work */ trans = q; break; } } - if(trans) + if (trans) break; } } - if(xbt_setset_set_size(mc_current_state->interleave) > 0){ + if (xbt_setset_set_size(mc_current_state->interleave) > 0) { /* We found a back-tracking point, let's loop */ xbt_fifo_unshift(mc_stack, mc_current_state); DEBUG1("Back-tracking to depth %d", xbt_fifo_size(mc_stack)); MC_replay(mc_stack); MC_UNSET_RAW_MEM; break; - }else{ + } else { MC_state_delete(mc_current_state); - } + } } } } DEBUG0("We are done"); /* We are done, show the statistics and return */ MC_print_statistics(mc_stats); -} \ No newline at end of file +} diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index e924d16857..9cd6c7f6db 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -4,7 +4,7 @@ #include "private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, - "Logging specific to MC (global)"); + "Logging specific to MC (global)"); /* MC global data structures */ mc_snapshot_t initial_snapshot = NULL; @@ -18,39 +18,39 @@ char mc_replay_mode = FALSE; * \brief Initialize the model-checker data structures */ void MC_init(int method) -{ +{ /* Check if MC is already initialized */ - if(initial_snapshot) + if (initial_snapshot) return; - + /* Initialize the data structures that must be persistent across every iteration of the model-checker (in RAW memory) */ MC_SET_RAW_MEM; - + /* Initialize statistics */ mc_stats = xbt_new0(s_mc_stats_t, 1); mc_stats->state_size = 1; - + /* Create exploration stack */ mc_stack = xbt_fifo_new(); /* Create the container for the sets */ mc_setset = xbt_setset_new(20); - - switch(method){ - case 0: - MC_dfs_init(); - break; - case 1: - MC_dpor_init(); - break; - default: - break; + + switch (method) { + case 0: + MC_dfs_init(); + break; + case 1: + MC_dpor_init(); + break; + default: + break; } - + /* Save the initial state */ MC_SET_RAW_MEM; - initial_snapshot = xbt_new(s_mc_snapshot_t,1); + initial_snapshot = xbt_new(s_mc_snapshot_t, 1); MC_take_snapshot(initial_snapshot); MC_UNSET_RAW_MEM; } @@ -60,15 +60,15 @@ void MC_modelcheck(int method) MC_init(method); - switch(method){ - case 0: - MC_dfs(); - break; - case 1: - MC_dpor(); - break; - default: - break; + switch (method) { + case 0: + MC_dfs(); + break; + case 1: + MC_dpor(); + break; + default: + break; } MC_exit(method); @@ -77,25 +77,25 @@ void MC_modelcheck(int method) void MC_exit(int method) { mc_state_t state; - - switch(method){ - case 0: - //MC_dfs_exit(); - break; - case 1: - //MC_dpor_exit(); - break; - default: - break; + + switch (method) { + case 0: + //MC_dfs_exit(); + break; + case 1: + //MC_dpor_exit(); + break; + default: + break; } - + /* Destroy MC data structures (in RAW memory) */ MC_SET_RAW_MEM; xbt_free(mc_stats); - while( (state = (mc_state_t)xbt_fifo_pop(mc_stack)) != NULL ) + while ((state = (mc_state_t) xbt_fifo_pop(mc_stack)) != NULL) MC_state_delete(state); - + xbt_fifo_free(mc_stack); xbt_setset_destroy(mc_setset); MC_UNSET_RAW_MEM; @@ -123,13 +123,13 @@ void MC_replay(xbt_fifo_t stack) MC_restore_snapshot(initial_snapshot); mc_replay_mode = TRUE; - + MC_UNSET_RAW_MEM; /* Traverse the stack from the initial state and re-execute the transitions */ - for(item = xbt_fifo_get_last_item(stack); - item != xbt_fifo_get_first_item(stack); - item = xbt_fifo_get_prev_item(item)){ + for (item = xbt_fifo_get_last_item(stack); + item != xbt_fifo_get_first_item(stack); + item = xbt_fifo_get_prev_item(item)) { mc_current_state = (mc_state_t) xbt_fifo_get_item_content(item); trans = mc_current_state->executed_transition; @@ -161,9 +161,9 @@ void MC_dump_stack(xbt_fifo_t stack) mc_state_t state; MC_show_stack(stack); - + MC_SET_RAW_MEM; - while( (state = (mc_state_t)xbt_fifo_pop(stack)) != NULL ) + while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL) MC_state_delete(state); MC_UNSET_RAW_MEM; } @@ -174,12 +174,12 @@ void MC_show_stack(xbt_fifo_t stack) mc_transition_t trans; xbt_fifo_item_t item; - for(item=xbt_fifo_get_last_item(stack); - (item?(state=(mc_state_t)(xbt_fifo_get_item_content(item))):(NULL)); - item=xbt_fifo_get_prev_item(item)){ + for (item = xbt_fifo_get_last_item(stack); + (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item))) + : (NULL)); item = xbt_fifo_get_prev_item(item)) { trans = state->executed_transition; - if(trans){ - INFO1("%s", trans->name); + if (trans) { + INFO1("%s", trans->name); } } } @@ -208,8 +208,8 @@ void MC_schedule_enabled_processes(void) */ mc_state_t MC_state_new(void) { - mc_state_t state = NULL; - + mc_state_t state = NULL; + state = xbt_new0(s_mc_state_t, 1); state->created_transitions = xbt_setset_new_set(mc_setset); state->transitions = xbt_setset_new_set(mc_setset); @@ -219,9 +219,10 @@ mc_state_t MC_state_new(void) state->executed_transition = NULL; mc_stats->expanded_states++; - + return state; } + /** * \brief Deletes a state data structure * \param trans The state to be deleted @@ -229,9 +230,9 @@ mc_state_t MC_state_new(void) void MC_state_delete(mc_state_t state) { xbt_setset_cursor_t cursor; - mc_transition_t trans; - - xbt_setset_foreach(state->created_transitions, cursor, trans){ + mc_transition_t trans; + + xbt_setset_foreach(state->created_transitions, cursor, trans) { xbt_setset_elm_remove(mc_setset, trans); MC_transition_delete(trans); } @@ -262,32 +263,33 @@ void MC_execute_surf_actions(void) smx_action_t smx_action = NULL; /* Execute all the actions in every model */ - xbt_dynar_foreach(model_list, iter, model){ - while ((action = xbt_swag_extract(model->states.running_action_set))){ + xbt_dynar_foreach(model_list, iter, model) { + while ((action = xbt_swag_extract(model->states.running_action_set))) { /* FIXME: timeouts are not calculated correctly */ - if(NOW >= action->max_duration){ + if (NOW >= action->max_duration) { surf_action_state_set(action, SURF_ACTION_DONE); smx_action = action->data; - DEBUG5("Resource [%s] (%d): Executing RUNNING action \"%s\" (%p) MaxDuration %lf", - model->name, xbt_swag_size(model->states.running_action_set), - smx_action->name, smx_action, action->max_duration); - - if(smx_action) + DEBUG5 + ("Resource [%s] (%d): Executing RUNNING action \"%s\" (%p) MaxDuration %lf", + model->name, xbt_swag_size(model->states.running_action_set), + smx_action->name, smx_action, action->max_duration); + + if (smx_action) SIMIX_action_signal_all(smx_action); } } /*FIXME: check if this is always empty or not */ while ((action = xbt_swag_extract(model->states.failed_action_set))) { smx_action = action->data; - DEBUG4("Resource [%s] (%d): Executing FAILED action \"%s\" (%p)", - model->name, xbt_swag_size(model->states.running_action_set), - smx_action->name, smx_action); + DEBUG4("Resource [%s] (%d): Executing FAILED action \"%s\" (%p)", + model->name, xbt_swag_size(model->states.running_action_set), + smx_action->name, smx_action); if (smx_action) - SIMIX_action_signal_all(smx_action); + SIMIX_action_signal_all(smx_action); } } /* That's it, now go one step deeper into the model-checking process! */ - NOW += 0.5; /* FIXME: Check time increases*/ + NOW += 0.5; /* FIXME: Check time increases */ } /****************************** Statistics ************************************/ @@ -298,15 +300,15 @@ void MC_print_statistics(mc_stats_t stats) INFO1("Visited states = %lu", stats->visited_states); INFO1("Executed transitions = %lu", stats->executed_transitions); INFO1("Expanded / Visited = %lf", - (double)stats->visited_states / stats->expanded_states); + (double) stats->visited_states / stats->expanded_states); /*INFO1("Exploration coverage = %lf", - (double)stats->expanded_states / stats->state_size);*/ + (double)stats->expanded_states / stats->state_size); */ } /************************* Assertion Checking *********************************/ void MC_assert(int prop) { - if(!prop){ + if (!prop) { INFO0("**************************"); INFO0("*** PROPERTY NOT VALID ***"); INFO0("**************************"); @@ -316,4 +318,3 @@ void MC_assert(int prop) xbt_abort(); } } - diff --git a/src/mc/mc_memory.c b/src/mc/mc_memory.c index 970f00fc00..7b191a9348 100644 --- a/src/mc/mc_memory.c +++ b/src/mc/mc_memory.c @@ -7,16 +7,16 @@ #include #define _GNU_SOURCE -extern char *basename (__const char *__filename); +extern char *basename(__const char *__filename); -#define STD_HEAP_SIZE 20480000 /* Maximum size of the system's heap */ +#define STD_HEAP_SIZE 20480000 /* Maximum size of the system's heap */ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_memory, mc, - "Logging specific to MC (memory)"); + "Logging specific to MC (memory)"); /* Pointers to each of the heap regions to use */ -void *std_heap=NULL; /* memory erased each time the MC stuff rollbacks to the beginning. Almost everything goes here */ -void *raw_heap=NULL; /* memory persistent over the MC rollbacks. Only MC stuff should go there */ +void *std_heap = NULL; /* memory erased each time the MC stuff rollbacks to the beginning. Almost everything goes here */ +void *raw_heap = NULL; /* memory persistent over the MC rollbacks. Only MC stuff should go there */ /* Pointers to the beginning and end of the .data and .bss segment of libsimgrid */ /* They are initialized once at memory_init */ @@ -32,7 +32,9 @@ void MC_memory_init() xbt_assert(std_heap != NULL); /* Create the second region a page after the first one ends */ - raw_heap = mmalloc_attach(-1, (char *)(std_heap) + STD_HEAP_SIZE + getpagesize()); + raw_heap = + mmalloc_attach(-1, + (char *) (std_heap) + STD_HEAP_SIZE + getpagesize()); xbt_assert(raw_heap != NULL); MC_SET_RAW_MEM; @@ -46,43 +48,46 @@ void MC_memory_init() /* Get memory map */ memory_map_t maps; maps = get_memory_map(); - - for(i=0; i < maps->mapsize; i++){ - - if(maps->regions[i].inode != 0){ - + + for (i = 0; i < maps->mapsize; i++) { + + if (maps->regions[i].inode != 0) { + tmp = xbt_strdup(maps->regions[i].pathname); libname = basename(tmp); - + #if 0 - if (maps->regions[i].perms & MAP_WRITE && - maps->regions[i].pathname[0] != '\0' && /* do not take anonymous segments: what are they? */ - strcmp("[heap]",maps->regions[i].pathname) && /* do not take standard heap: mmalloc saves it already */ - strcmp("[stack]",maps->regions[i].pathname) /* this is maestro's stack. No need to save it */ + if (maps->regions[i].perms & MAP_WRITE && maps->regions[i].pathname[0] != '\0' && /* do not take anonymous segments: what are they? */ + strcmp("[heap]", maps->regions[i].pathname) && /* do not take standard heap: mmalloc saves it already */ + strcmp("[stack]", maps->regions[i].pathname) /* this is maestro's stack. No need to save it */ ) { /* FIXME: we should save the data of more segments, in a list of block to save */ } #endif /* for now, we only save the data of libsimgrid (FIXME) */ - if( strncmp("libsimgrid.so.", libname, 14) == 0 && maps->regions[i].perms & MAP_WRITE){ + if (strncmp("libsimgrid.so.", libname, 14) == 0 + && maps->regions[i].perms & MAP_WRITE) { libsimgrid_data_addr_start = maps->regions[i].start_addr; - libsimgrid_data_size = (size_t)((char *)maps->regions[i+1].start_addr - (char *)maps->regions[i].start_addr); + libsimgrid_data_size = + (size_t) ((char *) maps->regions[i + 1].start_addr - + (char *) maps->regions[i].start_addr); xbt_free(tmp); break; - } + } xbt_free(tmp); } } - - xbt_assert0(libsimgrid_data_addr_start != NULL, - "Cannot determine libsimgrid's .data segment address"); - + + xbt_assert0(libsimgrid_data_addr_start != NULL, + "Cannot determine libsimgrid's .data segment address"); + MC_UNSET_RAW_MEM; } /* Finish the memory subsystem */ #include "xbt_modinter.h" -void MC_memory_exit(void) { +void MC_memory_exit(void) +{ if (raw_heap) mmalloc_detach(raw_heap); } @@ -92,28 +97,27 @@ void MC_memory_exit(void) { /* an API to query about the status of a heap, we simply call mmstats and */ /* because I now how does structure looks like, then I redefine it here */ -struct mstats - { - size_t bytes_total; /* Total size of the heap. */ - size_t chunks_used; /* Chunks allocated by the user. */ - size_t bytes_used; /* Byte total of user-allocated chunks. */ - size_t chunks_free; /* Chunks in the free list. */ - size_t bytes_free; /* Byte total of chunks in the free list. */ - }; +struct mstats { + size_t bytes_total; /* Total size of the heap. */ + size_t chunks_used; /* Chunks allocated by the user. */ + size_t bytes_used; /* Byte total of user-allocated chunks. */ + size_t chunks_free; /* Chunks in the free list. */ + size_t bytes_free; /* Byte total of chunks in the free list. */ +}; extern struct mstats mmstats(void *); /* Copy std_heap to "to_heap" allocating the required space for it */ size_t MC_save_heap(void **to_heap) -{ +{ size_t heap_size = mmstats(std_heap).bytes_total; - + *to_heap = calloc(heap_size, 1); xbt_assert(*to_heap != NULL); - + memcpy(*to_heap, std_heap, heap_size); - + return heap_size; } @@ -127,7 +131,7 @@ size_t MC_save_dataseg(void **data) /* Restore std_heap from "src_heap" */ void MC_restore_heap(void *src_heap, size_t size) -{ +{ memcpy(std_heap, src_heap, size); } @@ -136,8 +140,3 @@ void MC_restore_dataseg(void *src_data, size_t size) { memcpy(libsimgrid_data_addr_start, src_data, size); } - - - - - diff --git a/src/mc/mc_transition.c b/src/mc/mc_transition.c index e4587a34c4..d9e8b010aa 100644 --- a/src/mc/mc_transition.c +++ b/src/mc/mc_transition.c @@ -1,7 +1,7 @@ #include "private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans, mc, - "Logging specific to MC transitions"); + "Logging specific to MC transitions"); /* Creates a new iSend transition */ mc_transition_t MC_trans_isend_new(smx_rdv_t rdv) @@ -11,7 +11,8 @@ mc_transition_t MC_trans_isend_new(smx_rdv_t rdv) trans->type = mc_isend; trans->process = SIMIX_process_self(); trans->isend.rdv = rdv; - trans->name = bprintf("[%s]\t iSend (%p)", trans->process->smx_host->name, trans); + trans->name = + bprintf("[%s]\t iSend (%p)", trans->process->smx_host->name, trans); return trans; } @@ -23,7 +24,8 @@ mc_transition_t MC_trans_irecv_new(smx_rdv_t rdv) trans->type = mc_irecv; trans->process = SIMIX_process_self(); trans->irecv.rdv = rdv; - trans->name = bprintf("[%s]\t iRecv (%p)", trans->process->smx_host->name, trans); + trans->name = + bprintf("[%s]\t iRecv (%p)", trans->process->smx_host->name, trans); return trans; } @@ -35,7 +37,8 @@ mc_transition_t MC_trans_wait_new(smx_comm_t comm) trans->type = mc_wait; trans->process = SIMIX_process_self(); trans->wait.comm = comm; - trans->name = bprintf("[%s]\t Wait (%p)", trans->process->smx_host->name, trans); + trans->name = + bprintf("[%s]\t Wait (%p)", trans->process->smx_host->name, trans); return trans; } @@ -47,7 +50,8 @@ mc_transition_t MC_trans_test_new(smx_comm_t comm) trans->type = mc_test; trans->process = SIMIX_process_self(); trans->test.comm = comm; - trans->name = bprintf("[%s]\t Test (%p)", trans->process->smx_host->name, trans); + trans->name = + bprintf("[%s]\t Test (%p)", trans->process->smx_host->name, trans); return trans; } @@ -59,7 +63,9 @@ mc_transition_t MC_trans_waitany_new(xbt_dynar_t comms) trans->type = mc_waitany; trans->process = SIMIX_process_self(); trans->waitany.comms = comms; - trans->name = bprintf("[%s]\t WaitAny (%p)", trans->process->smx_host->name, trans); + trans->name = + bprintf("[%s]\t WaitAny (%p)", trans->process->smx_host->name, + trans); return trans; } @@ -71,7 +77,9 @@ mc_transition_t MC_trans_random_new(int value) trans->type = mc_random; trans->process = SIMIX_process_self(); trans->random.value = value; - trans->name = bprintf("[%s]\t Random %d (%p)", trans->process->smx_host->name, value, trans); + trans->name = + bprintf("[%s]\t Random %d (%p)", trans->process->smx_host->name, + value, trans); return trans; } @@ -103,18 +111,18 @@ void MC_transition_delete(mc_transition_t trans) */ void MC_trans_intercept_isend(smx_rdv_t rdv) { - mc_transition_t trans=NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; trans = MC_trans_isend_new(rdv); - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); MC_UNSET_RAW_MEM; } - SIMIX_process_yield(); + SIMIX_process_yield(); } /** @@ -123,13 +131,13 @@ void MC_trans_intercept_isend(smx_rdv_t rdv) */ void MC_trans_intercept_irecv(smx_rdv_t rdv) { - mc_transition_t trans=NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; trans = MC_trans_irecv_new(rdv); - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); MC_UNSET_RAW_MEM; @@ -143,13 +151,13 @@ void MC_trans_intercept_irecv(smx_rdv_t rdv) */ void MC_trans_intercept_wait(smx_comm_t comm) { - mc_transition_t trans=NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; trans = MC_trans_wait_new(comm); - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); MC_UNSET_RAW_MEM; @@ -163,13 +171,13 @@ void MC_trans_intercept_wait(smx_comm_t comm) */ void MC_trans_intercept_test(smx_comm_t comm) { - mc_transition_t trans=NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; trans = MC_trans_test_new(comm); - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); MC_UNSET_RAW_MEM; @@ -187,11 +195,11 @@ void MC_trans_intercept_waitany(xbt_dynar_t comms) smx_comm_t comm = NULL; mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); - xbt_dynar_foreach(comms, index, comm){ + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + xbt_dynar_foreach(comms, index, comm) { trans = MC_trans_wait_new(comm); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); @@ -209,13 +217,13 @@ void MC_trans_intercept_waitany(xbt_dynar_t comms) void MC_trans_intercept_random(int min, int max) { int i; - mc_transition_t trans=NULL; + mc_transition_t trans = NULL; mc_state_t current_state = NULL; - if(!mc_replay_mode){ + if (!mc_replay_mode) { MC_SET_RAW_MEM; - current_state = (mc_state_t) - xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); - for(i=min; i <= max; i++){ + current_state = (mc_state_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack)); + for (i = min; i <= max; i++) { trans = MC_trans_random_new(i); xbt_setset_set_insert(current_state->created_transitions, trans); xbt_setset_set_insert(current_state->transitions, trans); @@ -226,41 +234,42 @@ void MC_trans_intercept_random(int min, int max) } /* Compute the subset of enabled transitions of the transition set */ -void MC_trans_compute_enabled(xbt_setset_set_t enabled, xbt_setset_set_t transitions) +void MC_trans_compute_enabled(xbt_setset_set_t enabled, + xbt_setset_set_t transitions) { unsigned int index = 0; smx_comm_t comm = NULL; mc_transition_t trans = NULL; xbt_setset_cursor_t cursor = NULL; - xbt_setset_foreach(transitions, cursor, trans){ - switch(trans->type){ + xbt_setset_foreach(transitions, cursor, trans) { + switch (trans->type) { /* Wait transitions are enabled only if the communication has both a sender and receiver */ - case mc_wait: - if(trans->wait.comm->src_proc && trans->wait.comm->dst_proc){ - xbt_setset_set_insert(enabled, trans); - DEBUG1("Transition %p is enabled for next state", trans); - } - break; + case mc_wait: + if (trans->wait.comm->src_proc && trans->wait.comm->dst_proc) { + xbt_setset_set_insert(enabled, trans); + DEBUG1("Transition %p is enabled for next state", trans); + } + break; /* WaitAny transitions are enabled if any of it's communications has both a sender and a receiver */ - case mc_waitany: - xbt_dynar_foreach(trans->waitany.comms, index, comm){ - if(comm->src_proc && comm->dst_proc){ - xbt_setset_set_insert(enabled, trans); - DEBUG1("Transition %p is enabled for next state", trans); - break; - } + case mc_waitany: + xbt_dynar_foreach(trans->waitany.comms, index, comm) { + if (comm->src_proc && comm->dst_proc) { + xbt_setset_set_insert(enabled, trans); + DEBUG1("Transition %p is enabled for next state", trans); + break; } - break; + } + break; /* The rest of the transitions cannot be disabled */ - default: - xbt_setset_set_insert(enabled, trans); - DEBUG1("Transition %p is enabled for next state", trans); - break; - } + default: + xbt_setset_set_insert(enabled, trans); + DEBUG1("Transition %p is enabled for next state", trans); + break; + } } } @@ -272,40 +281,43 @@ void MC_trans_compute_enabled(xbt_setset_set_t enabled, xbt_setset_set_t transit */ int MC_transition_depend(mc_transition_t t1, mc_transition_t t2) { - if(t1->process == t2->process) + if (t1->process == t2->process) return FALSE; - if(t1->type != t2->type) + if (t1->type != t2->type) return FALSE; - + /* if(t1->type == mc_isend && t2->type == mc_irecv) return FALSE; if(t1->type == mc_irecv && t2->type == mc_isend) return FALSE;*/ - - if(t1->type == mc_random || t2->type == mc_random) + + if (t1->type == mc_random || t2->type == mc_random) return FALSE; - - if(t1->type == mc_isend && t2->type == mc_isend && t1->isend.rdv != t2->isend.rdv) + + if (t1->type == mc_isend && t2->type == mc_isend + && t1->isend.rdv != t2->isend.rdv) return FALSE; - if(t1->type == mc_irecv && t2->type == mc_irecv && t1->irecv.rdv != t2->irecv.rdv) + if (t1->type == mc_irecv && t2->type == mc_irecv + && t1->irecv.rdv != t2->irecv.rdv) return FALSE; - if(t1->type == mc_wait && t2->type == mc_wait && t1->wait.comm == t2->wait.comm) + if (t1->type == mc_wait && t2->type == mc_wait + && t1->wait.comm == t2->wait.comm) return FALSE; - - if(t1->type == mc_wait && t2->type == mc_wait - && t1->wait.comm->src_buff != NULL - && t1->wait.comm->dst_buff != NULL - && t2->wait.comm->src_buff != NULL - && t2->wait.comm->dst_buff != NULL - && t1->wait.comm->dst_buff != t2->wait.comm->src_buff - && t1->wait.comm->dst_buff != t2->wait.comm->dst_buff - && t2->wait.comm->dst_buff != t1->wait.comm->src_buff) + + if (t1->type == mc_wait && t2->type == mc_wait + && t1->wait.comm->src_buff != NULL + && t1->wait.comm->dst_buff != NULL + && t2->wait.comm->src_buff != NULL + && t2->wait.comm->dst_buff != NULL + && t1->wait.comm->dst_buff != t2->wait.comm->src_buff + && t1->wait.comm->dst_buff != t2->wait.comm->dst_buff + && t2->wait.comm->dst_buff != t1->wait.comm->src_buff) return FALSE; - - + + return TRUE; -} \ No newline at end of file +} diff --git a/src/mc/memory_map.c b/src/mc/memory_map.c index 0868ccc537..7a5175e2fc 100644 --- a/src/mc/memory_map.c +++ b/src/mc/memory_map.c @@ -4,27 +4,28 @@ memory_map_t get_memory_map(void) { - FILE *fp; /* File pointer to process's proc maps file */ - char *line = NULL; /* Temporal storage for each line that is readed */ - ssize_t read; /* Number of bytes readed */ - size_t n = 0; /* Amount of bytes to read by getline */ - memory_map_t ret = NULL; /* The memory map to return */ - + FILE *fp; /* File pointer to process's proc maps file */ + char *line = NULL; /* Temporal storage for each line that is readed */ + ssize_t read; /* Number of bytes readed */ + size_t n = 0; /* Amount of bytes to read by getline */ + memory_map_t ret = NULL; /* The memory map to return */ + /* The following variables are used during the parsing of the file "maps" */ - s_map_region memreg; /* temporal map region used for creating the map */ + s_map_region memreg; /* temporal map region used for creating the map */ char *lfields[6], *tok, *endptr; int i; - + /* Open the actual process's proc maps file and create the memory_map_t */ /* to be returned. */ - fp = fopen("/proc/self/maps","r"); + fp = fopen("/proc/self/maps", "r"); + + xbt_assert0(fp, + "Cannot open /proc/self/maps to investigate the memory map of the process. Please report this bug."); - xbt_assert0(fp,"Cannot open /proc/self/maps to investigate the memory map of the process. Please report this bug."); - - ret = xbt_new0(s_memory_map_t,1); - - /* Read one line at the time, parse it and add it to the memory map to be returned */ - while((read = getline(&line, &n, fp)) != -1) { + ret = xbt_new0(s_memory_map_t, 1); + + /* Read one line at the time, parse it and add it to the memory map to be returned */ + while ((read = getline(&line, &n, fp)) != -1) { /* Wipeout the new line character */ line[read - 1] = '\0'; @@ -32,93 +33,94 @@ memory_map_t get_memory_map(void) /* Tokenize the line using spaces as delimiters and store each token */ /* in lfields array. We expect 5 tokens/fields */ lfields[0] = strtok(line, " "); - - for(i=1; i < 6 && lfields[i - 1] != NULL; i++){ - lfields[i] = strtok(NULL, " "); + + for (i = 1; i < 6 && lfields[i - 1] != NULL; i++) { + lfields[i] = strtok(NULL, " "); } /* Check to see if we got the expected amount of columns */ - if(i < 6) + if (i < 6) xbt_abort(); /* Ok we are good enough to try to get the info we need */ /* First get the start and the end address of the map */ - tok = strtok(lfields[0], "-"); - if(tok == NULL) + tok = strtok(lfields[0], "-"); + if (tok == NULL) xbt_abort(); - - memreg.start_addr = (void *)strtoul(tok, &endptr, 16); + + memreg.start_addr = (void *) strtoul(tok, &endptr, 16); /* Make sure that the entire string was an hex number */ - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); - + tok = strtok(NULL, "-"); - if(tok == NULL) + if (tok == NULL) xbt_abort(); - - memreg.end_addr = (void *)strtoul(tok, &endptr, 16); + + memreg.end_addr = (void *) strtoul(tok, &endptr, 16); /* Make sure that the entire string was an hex number */ - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); - + /* Get the permissions flags */ - if(strlen(lfields[1]) < 4) + if (strlen(lfields[1]) < 4) xbt_abort(); - + memreg.perms = 0; - - for(i=0; i<3; i++) - if(lfields[1][i] != '-') + + for (i = 0; i < 3; i++) + if (lfields[1][i] != '-') memreg.perms |= 1 << i; - if(lfields[1][4] == 'p') + if (lfields[1][4] == 'p') memreg.perms |= MAP_PRIV; - + else if (lfields[1][4] == 's') - memreg.perms |= MAP_SHARED; - + memreg.perms |= MAP_SHARED; + /* Get the offset value */ - memreg.offset = (void *)strtoul(lfields[2], &endptr, 16); + memreg.offset = (void *) strtoul(lfields[2], &endptr, 16); /* Make sure that the entire string was an hex number */ - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); - + /* Get the device major:minor bytes */ tok = strtok(lfields[3], ":"); - if(tok == NULL) + if (tok == NULL) xbt_abort(); - memreg.dev_major = (char)strtoul(tok, &endptr, 16); + memreg.dev_major = (char) strtoul(tok, &endptr, 16); /* Make sure that the entire string was an hex number */ - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); tok = strtok(NULL, ":"); - if(tok == NULL) + if (tok == NULL) xbt_abort(); - memreg.dev_minor = (char)strtoul(tok, &endptr, 16); + memreg.dev_minor = (char) strtoul(tok, &endptr, 16); /* Make sure that the entire string was an hex number */ - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); - - /* Get the inode number and make sure that the entire string was a long int*/ + + /* Get the inode number and make sure that the entire string was a long int */ memreg.inode = strtoul(lfields[4], &endptr, 10); - if(*endptr != '\0') + if (*endptr != '\0') xbt_abort(); /* And finally get the pathname */ memreg.pathname = xbt_strdup(lfields[5]); - + /* Create space for a new map region in the region's array and copy the */ /* parsed stuff from the temporal memreg variable */ - ret->regions = xbt_realloc(ret->regions, sizeof(memreg) * (ret->mapsize + 1)); - memcpy(ret->regions + ret->mapsize, &memreg, sizeof(memreg)); - ret->mapsize++; + ret->regions = + xbt_realloc(ret->regions, sizeof(memreg) * (ret->mapsize + 1)); + memcpy(ret->regions + ret->mapsize, &memreg, sizeof(memreg)); + ret->mapsize++; } - - if(line) + + if (line) free(line); - + return ret; } diff --git a/src/mc/private.h b/src/mc/private.h index 6b4e47d68e..ec005ad8f4 100644 --- a/src/mc/private.h +++ b/src/mc/private.h @@ -28,8 +28,8 @@ typedef struct s_mc_snapshot { size_t heap_size; size_t data_size; - void* data; - void* heap; + void *data; + void *heap; } s_mc_snapshot_t, *mc_snapshot_t; @@ -76,19 +76,19 @@ typedef enum { mc_random } mc_trans_type_t; -typedef struct s_mc_transition{ +typedef struct s_mc_transition { XBT_SETSET_HEADERS; - char* name; + char *name; smx_process_t process; mc_trans_type_t type; union { struct { - smx_rdv_t rdv; + smx_rdv_t rdv; } isend; struct { - smx_rdv_t rdv; + smx_rdv_t rdv; } irecv; struct { @@ -120,13 +120,13 @@ int MC_transition_depend(mc_transition_t, mc_transition_t); void MC_trans_compute_enabled(xbt_setset_set_t, xbt_setset_set_t); /******************************** States **************************************/ -typedef struct mc_state{ - xbt_setset_set_t created_transitions; /* created in this state */ - xbt_setset_set_t transitions; /* created in this state + inherited */ - xbt_setset_set_t enabled_transitions; /* they can be executed by the mc */ - xbt_setset_set_t interleave; /* the ones to be executed by the mc */ - xbt_setset_set_t done; /* already executed transitions */ - mc_transition_t executed_transition; /* last executed transition */ +typedef struct mc_state { + xbt_setset_set_t created_transitions; /* created in this state */ + xbt_setset_set_t transitions; /* created in this state + inherited */ + xbt_setset_set_t enabled_transitions; /* they can be executed by the mc */ + xbt_setset_set_t interleave; /* the ones to be executed by the mc */ + xbt_setset_set_t done; /* already executed transitions */ + mc_transition_t executed_transition; /* last executed transition */ } s_mc_state_t, *mc_state_t; extern xbt_fifo_t mc_stack; @@ -137,12 +137,12 @@ mc_state_t MC_state_new(void); void MC_state_delete(mc_state_t); /****************************** Statistics ************************************/ -typedef struct mc_stats{ +typedef struct mc_stats { unsigned long state_size; unsigned long visited_states; unsigned long expanded_states; unsigned long executed_transitions; -}s_mc_stats_t, *mc_stats_t; +} s_mc_stats_t, *mc_stats_t; extern mc_stats_t mc_stats; @@ -169,26 +169,26 @@ extern size_t libsimgrid_data_size; #define MAP_WRITE 1 << 1 #define MAP_EXEC 1 << 2 #define MAP_SHARED 1 << 3 -#define MAP_PRIV 1 << 4 +#define MAP_PRIV 1 << 4 /* Each field is defined as documented in proc's manual page */ typedef struct s_map_region { - void *start_addr; /* Start address of the map */ - void *end_addr; /* End address of the map */ - int perms; /* Set of permissions */ - void *offset; /* Offset in the file/whatever */ - char dev_major; /* Major of the device */ - char dev_minor; /* Minor of the device */ - unsigned long inode; /* Inode in the device */ - char *pathname; /* Path name of the mapped file */ + void *start_addr; /* Start address of the map */ + void *end_addr; /* End address of the map */ + int perms; /* Set of permissions */ + void *offset; /* Offset in the file/whatever */ + char dev_major; /* Major of the device */ + char dev_minor; /* Minor of the device */ + unsigned long inode; /* Inode in the device */ + char *pathname; /* Path name of the mapped file */ } s_map_region; typedef struct s_memory_map { - s_map_region *regions; /* Pointer to an array of regions */ - int mapsize; /* Number of regions in the memory */ + s_map_region *regions; /* Pointer to an array of regions */ + int mapsize; /* Number of regions in the memory */ } s_memory_map_t, *memory_map_t; diff --git a/src/msg/deployment.c b/src/msg/deployment.c index 984792cb9c..29e5235558 100644 --- a/src/msg/deployment.c +++ b/src/msg/deployment.c @@ -75,7 +75,8 @@ xbt_main_func_t MSG_get_registered_function(const char *name) * \brief register functions bypassing the parser */ -void MSG_set_function(const char* host_id,const char *function_name,xbt_dynar_t arguments) +void MSG_set_function(const char *host_id, const char *function_name, + xbt_dynar_t arguments) { - SIMIX_process_set_function(host_id,function_name,arguments,-1,-1); + SIMIX_process_set_function(host_id, function_name, arguments, -1, -1); } diff --git a/src/msg/environment.c b/src/msg/environment.c index 0f7d6dce34..9599a0176e 100644 --- a/src/msg/environment.c +++ b/src/msg/environment.c @@ -37,11 +37,11 @@ m_host_t MSG_get_host_by_name(const char *name) { smx_host_t simix_h = NULL; simix_h = SIMIX_host_get_by_name(name); - + if (simix_h == NULL) return NULL; - return (m_host_t)SIMIX_host_get_data(simix_h); + return (m_host_t) SIMIX_host_get_data(simix_h); } /** \ingroup msg_easier_life @@ -83,17 +83,19 @@ void MSG_create_environment(const char *file) * and the routing table */ -void MSG_load_platform_script(const char *script_file) { +void MSG_load_platform_script(const char *script_file) +{ #ifdef HAVE_LUA - lua_State *L = lua_open(); - luaL_openlibs(L); + lua_State *L = lua_open(); + luaL_openlibs(L); - if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { - printf("error: %s\n", lua_tostring(L, -1)); - return; - } + if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { + printf("error: %s\n", lua_tostring(L, -1)); + return; + } #else - xbt_die("Lua is not available!! to call MSG_load_platform_script, lua should be available..."); + xbt_die + ("Lua is not available!! to call MSG_load_platform_script, lua should be available..."); #endif - return; + return; } diff --git a/src/msg/global.c b/src/msg/global.c index a3e8ae6b04..bee130881d 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -49,7 +49,7 @@ XBT_LOG_EXTERNAL_CATEGORY(msg_process); void MSG_global_init(int *argc, char **argv) { #ifdef HAVE_TRACING - TRACE_global_init (argc, argv); + TRACE_global_init(argc, argv); #endif xbt_getpid = MSG_process_self_PID; @@ -150,7 +150,7 @@ MSG_error_t MSG_main(void) else #endif while (SIMIX_solve(NULL, NULL) != -1.0); - + return MSG_OK; } @@ -190,7 +190,7 @@ MSG_error_t MSG_clean(void) m_process_t p = NULL; #ifdef HAVE_TRACING - TRACE_surf_release (); + TRACE_surf_release(); #endif while ((p = xbt_fifo_pop(msg_global->process_list))) { diff --git a/src/msg/gos.c b/src/msg/gos.c index d7a2e3ac10..24e98d7f7d 100644 --- a/src/msg/gos.c +++ b/src/msg/gos.c @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg, - "Logging specific to MSG (gos)"); + "Logging specific to MSG (gos)"); /** \ingroup msg_gos_functions * @@ -22,7 +22,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg, */ MSG_error_t MSG_get_errno(void) { - return PROCESS_GET_ERRNO(); + return PROCESS_GET_ERRNO(); } /** \ingroup msg_gos_functions @@ -37,79 +37,81 @@ MSG_error_t MSG_get_errno(void) */ MSG_error_t MSG_task_execute(m_task_t task) { - simdata_task_t simdata = NULL; - m_process_t self = MSG_process_self(); - e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; - CHECK_HOST(); + simdata_task_t simdata = NULL; + m_process_t self = MSG_process_self(); + e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; + CHECK_HOST(); - simdata = task->simdata; + simdata = task->simdata; - xbt_assert0(simdata->host_nb==0, "This is a parallel task. Go to hell."); + xbt_assert0(simdata->host_nb == 0, + "This is a parallel task. Go to hell."); #ifdef HAVE_TRACING - TRACE_msg_task_execute_start (task); + TRACE_msg_task_execute_start(task); #endif - xbt_assert1((!simdata->compute) && (task->simdata->refcount == 1), - "This task is executed somewhere else. Go fix your code! %d", task->simdata->refcount); + xbt_assert1((!simdata->compute) && (task->simdata->refcount == 1), + "This task is executed somewhere else. Go fix your code! %d", + task->simdata->refcount); - DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); + DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - if (simdata->computation_amount == 0) { + if (simdata->computation_amount == 0) { #ifdef HAVE_TRACING - TRACE_msg_task_execute_end (task); + TRACE_msg_task_execute_end(task); #endif - return MSG_OK; - } - simdata->refcount++; - SIMIX_mutex_lock(simdata->mutex); - simdata->compute = - SIMIX_action_execute(SIMIX_host_self(), task->name, - simdata->computation_amount); - SIMIX_action_set_priority(simdata->compute, simdata->priority); - - /* changed to waiting action since we are always waiting one action (execute, communicate or sleep) */ - self->simdata->waiting_action = simdata->compute; - SIMIX_register_action_to_condition(simdata->compute, simdata->cond); - do { - SIMIX_cond_wait(simdata->cond, simdata->mutex); - state = SIMIX_action_get_state(simdata->compute); - } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); - SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); - self->simdata->waiting_action = NULL; - - SIMIX_mutex_unlock(simdata->mutex); - simdata->refcount--; - - if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->computation_amount = 0.0; - simdata->comm = NULL; - simdata->compute = NULL; + return MSG_OK; + } + simdata->refcount++; + SIMIX_mutex_lock(simdata->mutex); + simdata->compute = + SIMIX_action_execute(SIMIX_host_self(), task->name, + simdata->computation_amount); + SIMIX_action_set_priority(simdata->compute, simdata->priority); + + /* changed to waiting action since we are always waiting one action (execute, communicate or sleep) */ + self->simdata->waiting_action = simdata->compute; + SIMIX_register_action_to_condition(simdata->compute, simdata->cond); + do { + SIMIX_cond_wait(simdata->cond, simdata->mutex); + state = SIMIX_action_get_state(simdata->compute); + } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); + SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); + self->simdata->waiting_action = NULL; + + SIMIX_mutex_unlock(simdata->mutex); + simdata->refcount--; + + if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->computation_amount = 0.0; + simdata->comm = NULL; + simdata->compute = NULL; #ifdef HAVE_TRACING - TRACE_msg_task_execute_end (task); + TRACE_msg_task_execute_end(task); #endif - MSG_RETURN(MSG_OK); - } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->comm = NULL; - simdata->compute = NULL; + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; #ifdef HAVE_TRACING - TRACE_msg_task_execute_end (task); + TRACE_msg_task_execute_end(task); #endif - MSG_RETURN(MSG_HOST_FAILURE); - } else { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->comm = NULL; - simdata->compute = NULL; + MSG_RETURN(MSG_HOST_FAILURE); + } else { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; #ifdef HAVE_TRACING - TRACE_msg_task_execute_end (task); + TRACE_msg_task_execute_end(task); #endif - MSG_RETURN(MSG_TASK_CANCELLED); - } + MSG_RETURN(MSG_TASK_CANCELLED); + } } /** \ingroup m_task_management @@ -131,104 +133,106 @@ MSG_error_t MSG_task_execute(m_task_t task) * \see m_task_t * \return The new corresponding object. */ - m_task_t +m_task_t MSG_parallel_task_create(const char *name, int host_nb, - const m_host_t * host_list, - double *computation_amount, - double *communication_amount, void *data) -{ - int i; - simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1); - m_task_t task = xbt_new0(s_m_task_t, 1); - task->simdata = simdata; - - /* Task structure */ - task->name = xbt_strdup(name); - task->data = data; - - /* Simulator Data */ - simdata->computation_amount = 0; - simdata->message_size = 0; - simdata->cond = SIMIX_cond_init(); - simdata->mutex = SIMIX_mutex_init(); - simdata->compute = NULL; - simdata->comm = NULL; - simdata->rate = -1.0; - simdata->refcount = 1; - simdata->sender = NULL; - simdata->receiver = NULL; - simdata->source = NULL; - - simdata->host_nb = host_nb; - simdata->host_list = xbt_new0(smx_host_t, host_nb); - simdata->comp_amount = computation_amount; - simdata->comm_amount = communication_amount; - - for (i = 0; i < host_nb; i++) - simdata->host_list[i] = host_list[i]->simdata->smx_host; - - return task; + const m_host_t * host_list, + double *computation_amount, + double *communication_amount, void *data) +{ + int i; + simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1); + m_task_t task = xbt_new0(s_m_task_t, 1); + task->simdata = simdata; + + /* Task structure */ + task->name = xbt_strdup(name); + task->data = data; + + /* Simulator Data */ + simdata->computation_amount = 0; + simdata->message_size = 0; + simdata->cond = SIMIX_cond_init(); + simdata->mutex = SIMIX_mutex_init(); + simdata->compute = NULL; + simdata->comm = NULL; + simdata->rate = -1.0; + simdata->refcount = 1; + simdata->sender = NULL; + simdata->receiver = NULL; + simdata->source = NULL; + + simdata->host_nb = host_nb; + simdata->host_list = xbt_new0(smx_host_t, host_nb); + simdata->comp_amount = computation_amount; + simdata->comm_amount = communication_amount; + + for (i = 0; i < host_nb; i++) + simdata->host_list[i] = host_list[i]->simdata->smx_host; + + return task; } MSG_error_t MSG_parallel_task_execute(m_task_t task) { - simdata_task_t simdata = NULL; - m_process_t self = MSG_process_self(); - e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; - CHECK_HOST(); + simdata_task_t simdata = NULL; + m_process_t self = MSG_process_self(); + e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; + CHECK_HOST(); - simdata = task->simdata; + simdata = task->simdata; - xbt_assert0((!simdata->compute) - && (task->simdata->refcount == 1), - "This task is executed somewhere else. Go fix your code!"); + xbt_assert0((!simdata->compute) + && (task->simdata->refcount == 1), + "This task is executed somewhere else. Go fix your code!"); - xbt_assert0(simdata->host_nb, "This is not a parallel task. Go to hell."); + xbt_assert0(simdata->host_nb, + "This is not a parallel task. Go to hell."); - DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); + DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name); - simdata->refcount++; + simdata->refcount++; - SIMIX_mutex_lock(simdata->mutex); - simdata->compute = - SIMIX_action_parallel_execute(task->name, simdata->host_nb, - simdata->host_list, simdata->comp_amount, - simdata->comm_amount, 1.0, -1.0); + SIMIX_mutex_lock(simdata->mutex); + simdata->compute = + SIMIX_action_parallel_execute(task->name, simdata->host_nb, + simdata->host_list, + simdata->comp_amount, + simdata->comm_amount, 1.0, -1.0); - self->simdata->waiting_action = simdata->compute; - SIMIX_register_action_to_condition(simdata->compute, simdata->cond); - do { - SIMIX_cond_wait(simdata->cond, simdata->mutex); - state = SIMIX_action_get_state(task->simdata->compute); - } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); + self->simdata->waiting_action = simdata->compute; + SIMIX_register_action_to_condition(simdata->compute, simdata->cond); + do { + SIMIX_cond_wait(simdata->cond, simdata->mutex); + state = SIMIX_action_get_state(task->simdata->compute); + } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); - SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); - self->simdata->waiting_action = NULL; + SIMIX_unregister_action_to_condition(simdata->compute, simdata->cond); + self->simdata->waiting_action = NULL; - SIMIX_mutex_unlock(simdata->mutex); - simdata->refcount--; + SIMIX_mutex_unlock(simdata->mutex); + simdata->refcount--; - if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->computation_amount = 0.0; - simdata->comm = NULL; - simdata->compute = NULL; - MSG_RETURN(MSG_OK); - } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->comm = NULL; - simdata->compute = NULL; - MSG_RETURN(MSG_HOST_FAILURE); - } else { - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - SIMIX_action_destroy(task->simdata->compute); - simdata->comm = NULL; - simdata->compute = NULL; - MSG_RETURN(MSG_TASK_CANCELLED); - } + if (SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->computation_amount = 0.0; + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(SIMIX_host_self()) == 0) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_HOST_FAILURE); + } else { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_TASK_CANCELLED); + } } @@ -242,62 +246,62 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) */ MSG_error_t MSG_process_sleep(double nb_sec) { - smx_action_t act_sleep; - m_process_t proc = MSG_process_self(); - e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; - smx_mutex_t mutex; - smx_cond_t cond; + smx_action_t act_sleep; + m_process_t proc = MSG_process_self(); + e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; + smx_mutex_t mutex; + smx_cond_t cond; #ifdef HAVE_TRACING - TRACE_msg_process_sleep_in (MSG_process_self()); + TRACE_msg_process_sleep_in(MSG_process_self()); #endif - /* create action to sleep */ - act_sleep = - SIMIX_action_sleep(SIMIX_process_get_host(proc->simdata->s_process), - nb_sec); - - mutex = SIMIX_mutex_init(); - SIMIX_mutex_lock(mutex); - - /* create conditional and register action to it */ - cond = SIMIX_cond_init(); - - proc->simdata->waiting_action = act_sleep; - SIMIX_register_action_to_condition(act_sleep, cond); - do { - SIMIX_cond_wait(cond, mutex); - state = SIMIX_action_get_state(act_sleep); - } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); - proc->simdata->waiting_action = NULL; - SIMIX_unregister_action_to_condition(act_sleep, cond); - SIMIX_mutex_unlock(mutex); - - /* remove variables */ - SIMIX_cond_destroy(cond); - SIMIX_mutex_destroy(mutex); - - if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { - if (SIMIX_host_get_state(SIMIX_host_self()) == SURF_RESOURCE_OFF) { - SIMIX_action_destroy(act_sleep); + /* create action to sleep */ + act_sleep = + SIMIX_action_sleep(SIMIX_process_get_host(proc->simdata->s_process), + nb_sec); + + mutex = SIMIX_mutex_init(); + SIMIX_mutex_lock(mutex); + + /* create conditional and register action to it */ + cond = SIMIX_cond_init(); + + proc->simdata->waiting_action = act_sleep; + SIMIX_register_action_to_condition(act_sleep, cond); + do { + SIMIX_cond_wait(cond, mutex); + state = SIMIX_action_get_state(act_sleep); + } while (state == SURF_ACTION_READY || state == SURF_ACTION_RUNNING); + proc->simdata->waiting_action = NULL; + SIMIX_unregister_action_to_condition(act_sleep, cond); + SIMIX_mutex_unlock(mutex); + + /* remove variables */ + SIMIX_cond_destroy(cond); + SIMIX_mutex_destroy(mutex); + + if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { + if (SIMIX_host_get_state(SIMIX_host_self()) == SURF_RESOURCE_OFF) { + SIMIX_action_destroy(act_sleep); #ifdef HAVE_TRACING - TRACE_msg_process_sleep_out (MSG_process_self()); + TRACE_msg_process_sleep_out(MSG_process_self()); #endif - MSG_RETURN(MSG_HOST_FAILURE); - } - } else { - SIMIX_action_destroy(act_sleep); + MSG_RETURN(MSG_HOST_FAILURE); + } + } else { + SIMIX_action_destroy(act_sleep); #ifdef HAVE_TRACING - TRACE_msg_process_sleep_out (MSG_process_self()); + TRACE_msg_process_sleep_out(MSG_process_self()); #endif - MSG_RETURN(MSG_HOST_FAILURE); - } + MSG_RETURN(MSG_HOST_FAILURE); + } - SIMIX_action_destroy(act_sleep); + SIMIX_action_destroy(act_sleep); #ifdef HAVE_TRACING - TRACE_msg_process_sleep_out (MSG_process_self()); + TRACE_msg_process_sleep_out(MSG_process_self()); #endif - MSG_RETURN(MSG_OK); + MSG_RETURN(MSG_OK); } /** \ingroup msg_gos_functions @@ -315,10 +319,10 @@ MSG_error_t MSG_process_sleep(double nb_sec) * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING if \a *task is not equal to \c NULL, and #MSG_OK otherwise. */ - MSG_error_t +MSG_error_t MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host) { - return MSG_task_get_ext(task, channel, -1, host); + return MSG_task_get_ext(task, channel, -1, host); } /** \ingroup msg_gos_functions @@ -337,7 +341,7 @@ MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host) */ MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel) { - return MSG_task_get_with_timeout(task, channel, -1); + return MSG_task_get_with_timeout(task, channel, -1); } /** \ingroup msg_gos_functions @@ -358,11 +362,11 @@ MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel) * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING if \a *task is not equal to \c NULL, and #MSG_OK otherwise. */ - MSG_error_t +MSG_error_t MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, - double max_duration) + double max_duration) { - return MSG_task_get_ext(task, channel, max_duration, NULL); + return MSG_task_get_ext(task, channel, max_duration, NULL); } /** \defgroup msg_gos_functions MSG Operating System Functions @@ -370,44 +374,48 @@ MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel, * by an agent for handling some task. */ - MSG_error_t +MSG_error_t MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout, - m_host_t host) + m_host_t host) { - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - return - MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel - (MSG_host_self(), channel), task, host, timeout); + return + MSG_mailbox_get_task_ext(MSG_mailbox_get_by_channel + (MSG_host_self(), channel), task, host, + timeout); } - MSG_error_t -MSG_task_receive_from_host(m_task_t * task, const char *alias, m_host_t host) +MSG_error_t +MSG_task_receive_from_host(m_task_t * task, const char *alias, + m_host_t host) { - return MSG_task_receive_ext(task, alias, -1, host); + return MSG_task_receive_ext(task, alias, -1, host); } MSG_error_t MSG_task_receive(m_task_t * task, const char *alias) { - return MSG_task_receive_with_timeout(task, alias, -1); + return MSG_task_receive_with_timeout(task, alias, -1); } - MSG_error_t +MSG_error_t MSG_task_receive_with_timeout(m_task_t * task, const char *alias, - double timeout) + double timeout) { - return MSG_task_receive_ext(task, alias, timeout, NULL); + return MSG_task_receive_ext(task, alias, timeout, NULL); } - MSG_error_t +MSG_error_t MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout, - m_host_t host) + m_host_t host) { - DEBUG1("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",alias); - return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task, host, - timeout); + DEBUG1 + ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'", + alias); + return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task, + host, timeout); } /** \ingroup msg_gos_functions @@ -420,35 +428,37 @@ MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout, channels fixed with MSG_set_channel_number(). * \return the msg_comm_t communication. */ -msg_comm_t MSG_task_isend(m_task_t task, const char *alias) { - simdata_task_t t_simdata = NULL; - m_process_t process = MSG_process_self(); - msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); +msg_comm_t MSG_task_isend(m_task_t task, const char *alias) +{ + simdata_task_t t_simdata = NULL; + m_process_t process = MSG_process_self(); + msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); - CHECK_HOST(); + CHECK_HOST(); - /* FIXME: these functions are not tracable */ + /* FIXME: these functions are not tracable */ - /* Prepare the task to send */ - t_simdata = task->simdata; - t_simdata->sender = process; - t_simdata->source = MSG_host_self(); + /* Prepare the task to send */ + t_simdata = task->simdata; + t_simdata->sender = process; + t_simdata->source = MSG_host_self(); - xbt_assert0(t_simdata->refcount == 1, - "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); + xbt_assert0(t_simdata->refcount == 1, + "This task is still being used somewhere else. You cannot send it now. Go fix your code!"); - t_simdata->refcount++; - msg_global->sent_msg++; - process->simdata->waiting_task = task; + t_simdata->refcount++; + msg_global->sent_msg++; + process->simdata->waiting_task = task; - /* Send it by calling SIMIX network layer */ + /* Send it by calling SIMIX network layer */ - /* Kept for semantical compatibility with older implementation */ - if(mailbox->cond) - SIMIX_cond_signal(mailbox->cond); + /* Kept for semantical compatibility with older implementation */ + if (mailbox->cond) + SIMIX_cond_signal(mailbox->cond); - return SIMIX_network_isend(mailbox->rdv, t_simdata->message_size, t_simdata->rate, - task, sizeof(void*), &t_simdata->comm); + return SIMIX_network_isend(mailbox->rdv, t_simdata->message_size, + t_simdata->rate, task, sizeof(void *), + &t_simdata->comm); } /** \ingroup msg_gos_functions @@ -461,31 +471,34 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias) { number of channels fixed with MSG_set_channel_number(). * \return the msg_comm_t communication. */ -msg_comm_t MSG_task_irecv(m_task_t * task, const char *alias) { - smx_comm_t comm; - smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias)->rdv; - msg_mailbox_t mailbox=MSG_mailbox_get_by_alias(alias); +msg_comm_t MSG_task_irecv(m_task_t * task, const char *alias) +{ + smx_comm_t comm; + smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias)->rdv; + msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); - CHECK_HOST(); + CHECK_HOST(); - /* FIXME: these functions are not tracable */ + /* FIXME: these functions are not tracable */ - memset(&comm,0,sizeof(comm)); + memset(&comm, 0, sizeof(comm)); - /* Kept for compatibility with older implementation */ - xbt_assert1(!MSG_mailbox_get_cond(mailbox), - "A process is already blocked on this channel %s", - MSG_mailbox_get_alias(mailbox)); + /* Kept for compatibility with older implementation */ + xbt_assert1(!MSG_mailbox_get_cond(mailbox), + "A process is already blocked on this channel %s", + MSG_mailbox_get_alias(mailbox)); - /* Sanity check */ - xbt_assert0(task, "Null pointer for the task storage"); + /* Sanity check */ + xbt_assert0(task, "Null pointer for the task storage"); - if (*task) - CRITICAL0("MSG_task_get() was asked to write in a non empty task struct."); + if (*task) + CRITICAL0 + ("MSG_task_get() was asked to write in a non empty task struct."); - /* Try to receive it by calling SIMIX network layer */ - return SIMIX_network_irecv(rdv, task, NULL); + /* Try to receive it by calling SIMIX network layer */ + return SIMIX_network_irecv(rdv, task, NULL); } + /** \ingroup msg_gos_functions * \brief Test the status of a communication. * @@ -496,23 +509,25 @@ msg_comm_t MSG_task_irecv(m_task_t * task, const char *alias) { * FALSE: the communication is incompleted * If the status is FALSE, don't forget to use MSG_process_sleep() after the test. */ -int MSG_comm_test(msg_comm_t comm) { - return SIMIX_network_test(comm); +int MSG_comm_test(msg_comm_t comm) +{ + return SIMIX_network_test(comm); } + /** \ingroup msg_gos_functions * \brief After received TRUE to MSG_comm_test(), the communication must be destroyed. * * It takes one parameter. * \param comm the communication to destroy. */ -void MSG_comm_destroy(msg_comm_t comm) { - if(!(comm->src_proc == SIMIX_process_self())) - { - m_task_t task; - task = (m_task_t) SIMIX_communication_get_src_buf(comm); - task->simdata->refcount--; - } - SIMIX_communication_destroy(comm); +void MSG_comm_destroy(msg_comm_t comm) +{ + if (!(comm->src_proc == SIMIX_process_self())) { + m_task_t task; + task = (m_task_t) SIMIX_communication_get_src_buf(comm); + task->simdata->refcount--; + } + SIMIX_communication_destroy(comm); } /** \ingroup msg_gos_functions @@ -523,37 +538,38 @@ void MSG_comm_destroy(msg_comm_t comm) { * \param timeout Wait until the communication terminates or the timeout occurs * \return MSG_error_t */ -MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) { - xbt_ex_t e; - MSG_error_t res = MSG_OK; - TRY { - SIMIX_network_wait(comm,timeout); - - if(!(comm->src_proc == SIMIX_process_self())) - { - m_task_t task; - task = (m_task_t) SIMIX_communication_get_src_buf(comm); - task->simdata->refcount--; - } - - /* FIXME: these functions are not tracable */ - } CATCH(e){ - switch(e.category){ - case host_error: - res = MSG_HOST_FAILURE; - break; - case network_error: - res = MSG_TRANSFER_FAILURE; - break; - case timeout_error: - res = MSG_TIMEOUT; - break; - default: - xbt_die(bprintf("Unhandled SIMIX network exception: %s",e.msg)); - } - xbt_ex_free(e); - } - return res; +MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) +{ + xbt_ex_t e; + MSG_error_t res = MSG_OK; + TRY { + SIMIX_network_wait(comm, timeout); + + if (!(comm->src_proc == SIMIX_process_self())) { + m_task_t task; + task = (m_task_t) SIMIX_communication_get_src_buf(comm); + task->simdata->refcount--; + } + + /* FIXME: these functions are not tracable */ + } + CATCH(e) { + switch (e.category) { + case host_error: + res = MSG_HOST_FAILURE; + break; + case network_error: + res = MSG_TRANSFER_FAILURE; + break; + case timeout_error: + res = MSG_TIMEOUT; + break; + default: + xbt_die(bprintf("Unhandled SIMIX network exception: %s", e.msg)); + } + xbt_ex_free(e); + } + return res; } /** \ingroup msg_gos_functions @@ -564,13 +580,14 @@ MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout) { * \param nb_elem is the size of the comm vector * \param timeout for each call of MSG_comm_wait */ -void MSG_comm_waitall(msg_comm_t *comm,int nb_elem, double timeout) { - int i=0; - for(i=0; isimdata->rate = maxrate; - return MSG_task_put(task, dest, channel); + task->simdata->rate = maxrate; + return MSG_task_put(task, dest, channel); } /** \ingroup msg_gos_functions \brief Put a task on a channel of an @@ -661,46 +680,47 @@ this function was called was shut down. Returns #MSG_TRANSFER_FAILURE if the transfer could not be properly done (network failure, dest failure, timeout...) */ - MSG_error_t -MSG_task_put_with_timeout(m_task_t task, m_host_t dest, m_channel_t channel, - double timeout) +MSG_error_t +MSG_task_put_with_timeout(m_task_t task, m_host_t dest, + m_channel_t channel, double timeout) { - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - return - MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel(dest, channel), - task, timeout); + return + MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel + (dest, channel), task, timeout); } MSG_error_t MSG_task_send(m_task_t task, const char *alias) { - DEBUG1("MSG_task_send: Trying to send a message on mailbox '%s'",alias); - return MSG_task_send_with_timeout(task, alias, -1); + DEBUG1("MSG_task_send: Trying to send a message on mailbox '%s'", alias); + return MSG_task_send_with_timeout(task, alias, -1); } - MSG_error_t +MSG_error_t MSG_task_send_bounded(m_task_t task, const char *alias, double maxrate) { - task->simdata->rate = maxrate; - return MSG_task_send(task, alias); + task->simdata->rate = maxrate; + return MSG_task_send(task, alias); } - MSG_error_t -MSG_task_send_with_timeout(m_task_t task, const char *alias, double timeout) +MSG_error_t +MSG_task_send_with_timeout(m_task_t task, const char *alias, + double timeout) { - return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), task, - timeout); + return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias), + task, timeout); } int MSG_task_listen(const char *alias) { - CHECK_HOST(); + CHECK_HOST(); - return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias)); + return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias)); } /** \ingroup msg_gos_functions @@ -714,15 +734,15 @@ int MSG_task_listen(const char *alias) */ int MSG_task_Iprobe(m_channel_t channel) { - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - CHECK_HOST(); + CHECK_HOST(); - return - !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel - (MSG_host_self(), channel)); + return + !MSG_mailbox_is_empty(MSG_mailbox_get_by_channel + (MSG_host_self(), channel)); } /** \ingroup msg_gos_functions @@ -740,26 +760,26 @@ int MSG_task_Iprobe(m_channel_t channel) */ int MSG_task_probe_from_host(int channel, m_host_t host) { - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - CHECK_HOST(); + CHECK_HOST(); - return - MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel - (MSG_host_self(), channel), - host); + return + MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_channel + (MSG_host_self(), channel), + host); } int MSG_task_listen_from_host(const char *alias, m_host_t host) { - CHECK_HOST(); + CHECK_HOST(); - return - MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias(alias), - host); + return + MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias + (alias), host); } /** \ingroup msg_gos_functions @@ -773,33 +793,34 @@ int MSG_task_listen_from_host(const char *alias, m_host_t host) */ int MSG_task_probe_from(m_channel_t channel) { - m_task_t task; + m_task_t task; - CHECK_HOST(); + CHECK_HOST(); - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - if (NULL == - (task = - MSG_mailbox_get_head(MSG_mailbox_get_by_channel - (MSG_host_self(), channel)))) - return -1; + if (NULL == + (task = + MSG_mailbox_get_head(MSG_mailbox_get_by_channel + (MSG_host_self(), channel)))) + return -1; - return MSG_process_get_PID(task->simdata->sender); + return MSG_process_get_PID(task->simdata->sender); } int MSG_task_listen_from(const char *alias) { - m_task_t task; + m_task_t task; - CHECK_HOST(); + CHECK_HOST(); - if (NULL == (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias)))) - return -1; + if (NULL == + (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias)))) + return -1; - return MSG_process_get_PID(task->simdata->sender); + return MSG_process_get_PID(task->simdata->sender); } /** \ingroup msg_gos_functions @@ -819,146 +840,148 @@ int MSG_task_listen_from(const char *alias) * \return #MSG_HOST_FAILURE if the host is shut down in the meantime and #MSG_OK otherwise. */ - MSG_error_t +MSG_error_t MSG_channel_select_from(m_channel_t channel, double timeout, int *PID) { - m_host_t h = NULL; - simdata_host_t h_simdata = NULL; - m_task_t t; - int first_time = 1; - smx_cond_t cond; - msg_mailbox_t mailbox; + m_host_t h = NULL; + simdata_host_t h_simdata = NULL; + m_task_t t; + int first_time = 1; + smx_cond_t cond; + msg_mailbox_t mailbox; - xbt_assert1((channel >= 0) - && (channel < msg_global->max_channel), "Invalid channel %d", - channel); + xbt_assert1((channel >= 0) + && (channel < msg_global->max_channel), "Invalid channel %d", + channel); - if (PID) { - *PID = -1; - } + if (PID) { + *PID = -1; + } - if (timeout == 0.0) { - *PID = MSG_task_probe_from(channel); - MSG_RETURN(MSG_OK); - } else { - CHECK_HOST(); - h = MSG_host_self(); - h_simdata = h->simdata; + if (timeout == 0.0) { + *PID = MSG_task_probe_from(channel); + MSG_RETURN(MSG_OK); + } else { + CHECK_HOST(); + h = MSG_host_self(); + h_simdata = h->simdata; - mailbox = MSG_mailbox_get_by_channel(MSG_host_self(), channel); + mailbox = MSG_mailbox_get_by_channel(MSG_host_self(), channel); - while (MSG_mailbox_is_empty(mailbox)) { - if (timeout > 0) { - if (!first_time) { - MSG_RETURN(MSG_OK); - } - } + while (MSG_mailbox_is_empty(mailbox)) { + if (timeout > 0) { + if (!first_time) { + MSG_RETURN(MSG_OK); + } + } - SIMIX_mutex_lock(h_simdata->mutex); + SIMIX_mutex_lock(h_simdata->mutex); - xbt_assert1(!MSG_mailbox_get_cond(mailbox), - "A process is already blocked on this channel %d", channel); + xbt_assert1(!MSG_mailbox_get_cond(mailbox), + "A process is already blocked on this channel %d", + channel); - cond = SIMIX_cond_init(); + cond = SIMIX_cond_init(); - MSG_mailbox_set_cond(mailbox, cond); + MSG_mailbox_set_cond(mailbox, cond); - if (timeout > 0) { - SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); - } else { - SIMIX_cond_wait(cond, h_simdata->mutex); - } + if (timeout > 0) { + SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); + } else { + SIMIX_cond_wait(cond, h_simdata->mutex); + } - SIMIX_cond_destroy(cond); - SIMIX_mutex_unlock(h_simdata->mutex); + SIMIX_cond_destroy(cond); + SIMIX_mutex_unlock(h_simdata->mutex); - if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { - MSG_RETURN(MSG_HOST_FAILURE); - } + if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { + MSG_RETURN(MSG_HOST_FAILURE); + } - MSG_mailbox_set_cond(mailbox, NULL); - first_time = 0; - } + MSG_mailbox_set_cond(mailbox, NULL); + first_time = 0; + } - if (NULL == (t = MSG_mailbox_get_head(mailbox))) - MSG_RETURN(MSG_OK); + if (NULL == (t = MSG_mailbox_get_head(mailbox))) + MSG_RETURN(MSG_OK); - if (PID) { - *PID = MSG_process_get_PID(t->simdata->sender); - } + if (PID) { + *PID = MSG_process_get_PID(t->simdata->sender); + } - MSG_RETURN(MSG_OK); - } + MSG_RETURN(MSG_OK); + } } -MSG_error_t MSG_alias_select_from(const char *alias, double timeout, int *PID) +MSG_error_t MSG_alias_select_from(const char *alias, double timeout, + int *PID) { - m_host_t h = NULL; - simdata_host_t h_simdata = NULL; - m_task_t t; - int first_time = 1; - smx_cond_t cond; - msg_mailbox_t mailbox; + m_host_t h = NULL; + simdata_host_t h_simdata = NULL; + m_task_t t; + int first_time = 1; + smx_cond_t cond; + msg_mailbox_t mailbox; - if (PID) { - *PID = -1; - } + if (PID) { + *PID = -1; + } - if (timeout == 0.0) { - *PID = MSG_task_listen_from(alias); - MSG_RETURN(MSG_OK); - } else { - CHECK_HOST(); - h = MSG_host_self(); - h_simdata = h->simdata; + if (timeout == 0.0) { + *PID = MSG_task_listen_from(alias); + MSG_RETURN(MSG_OK); + } else { + CHECK_HOST(); + h = MSG_host_self(); + h_simdata = h->simdata; - DEBUG2("Probing on alias %s (%s)", alias, h->name); + DEBUG2("Probing on alias %s (%s)", alias, h->name); - mailbox = MSG_mailbox_get_by_alias(alias); + mailbox = MSG_mailbox_get_by_alias(alias); - while (MSG_mailbox_is_empty(mailbox)) { - if (timeout > 0) { - if (!first_time) { - MSG_RETURN(MSG_OK); - } - } + while (MSG_mailbox_is_empty(mailbox)) { + if (timeout > 0) { + if (!first_time) { + MSG_RETURN(MSG_OK); + } + } - SIMIX_mutex_lock(h_simdata->mutex); + SIMIX_mutex_lock(h_simdata->mutex); - xbt_assert1(!MSG_mailbox_get_cond(mailbox), - "A process is already blocked on this alias %s", alias); + xbt_assert1(!MSG_mailbox_get_cond(mailbox), + "A process is already blocked on this alias %s", alias); - cond = SIMIX_cond_init(); + cond = SIMIX_cond_init(); - MSG_mailbox_set_cond(mailbox, cond); + MSG_mailbox_set_cond(mailbox, cond); - if (timeout > 0) { - SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); - } else { - SIMIX_cond_wait(cond, h_simdata->mutex); - } + if (timeout > 0) { + SIMIX_cond_wait_timeout(cond, h_simdata->mutex, timeout); + } else { + SIMIX_cond_wait(cond, h_simdata->mutex); + } - SIMIX_cond_destroy(cond); - SIMIX_mutex_unlock(h_simdata->mutex); + SIMIX_cond_destroy(cond); + SIMIX_mutex_unlock(h_simdata->mutex); - if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { - MSG_RETURN(MSG_HOST_FAILURE); - } + if (SIMIX_host_get_state(h_simdata->smx_host) == 0) { + MSG_RETURN(MSG_HOST_FAILURE); + } - MSG_mailbox_set_cond(mailbox, NULL); - first_time = 0; - } + MSG_mailbox_set_cond(mailbox, NULL); + first_time = 0; + } - if (NULL == (t = MSG_mailbox_get_head(mailbox))) - MSG_RETURN(MSG_OK); + if (NULL == (t = MSG_mailbox_get_head(mailbox))) + MSG_RETURN(MSG_OK); - if (PID) { - *PID = MSG_process_get_PID(t->simdata->sender); - } + if (PID) { + *PID = MSG_process_get_PID(t->simdata->sender); + } - MSG_RETURN(MSG_OK); - } + MSG_RETURN(MSG_OK); + } } diff --git a/src/msg/m_process.c b/src/msg/m_process.c index 185a1ed652..cfdd55708d 100644 --- a/src/msg/m_process.c +++ b/src/msg/m_process.c @@ -32,7 +32,7 @@ void __MSG_process_cleanup(void *arg) /* arg is a pointer to a simix process, we can get the msg process with the field data */ m_process_t proc = ((smx_process_t) arg)->data; #ifdef HAVE_TRACING - TRACE_msg_process_end (proc); + TRACE_msg_process_end(proc); #endif xbt_fifo_remove(msg_global->process_list, proc); SIMIX_process_cleanup(arg); @@ -56,8 +56,9 @@ void *_MSG_process_create_from_SIMIX(const char *name, xbt_dict_t properties) { m_host_t host = MSG_get_host_by_name(hostname); - return (void *) MSG_process_create_with_environment(name, code, data, host, - argc, argv, properties); + return (void *) MSG_process_create_with_environment(name, code, data, + host, argc, argv, + properties); } /** \ingroup m_process_management @@ -186,7 +187,7 @@ m_process_t MSG_process_create_with_environment(const char *name, void _MSG_process_kill_from_SIMIX(void *p) { #ifdef HAVE_TRACING - TRACE_msg_process_kill ((m_process_t) p); + TRACE_msg_process_kill((m_process_t) p); #endif MSG_process_kill((m_process_t) p); } @@ -201,22 +202,22 @@ void MSG_process_kill(m_process_t process) simdata_process_t p_simdata = process->simdata; #ifdef HAVE_TRACING - TRACE_msg_process_kill (process); + TRACE_msg_process_kill(process); #endif DEBUG3("Killing %s(%d) on %s", process->name, p_simdata->PID, p_simdata->m_host->name); if (p_simdata->waiting_task && p_simdata->waiting_task->simdata->comm) { - SIMIX_communication_cancel(p_simdata->waiting_task->simdata->comm); + SIMIX_communication_cancel(p_simdata->waiting_task->simdata->comm); } - + if (p_simdata->waiting_action) { DEBUG1("Canceling waiting task %s", SIMIX_action_get_name(p_simdata->waiting_action)); SIMIX_action_cancel(p_simdata->waiting_action); - } - + } + xbt_fifo_remove(msg_global->process_list, process); SIMIX_process_kill(process->simdata->s_process); @@ -235,7 +236,7 @@ MSG_error_t MSG_process_change_host(m_host_t host) m_host_t now = process->simdata->m_host; process->simdata->m_host = host; #ifdef HAVE_TRACING - TRACE_msg_process_change_host (process, now, host); + TRACE_msg_process_change_host(process, now, host); #endif SIMIX_process_change_host(process->simdata->s_process, now->name, host->name); @@ -428,7 +429,7 @@ MSG_error_t MSG_process_suspend(m_process_t process) CHECK_HOST(); #ifdef HAVE_TRACING - TRACE_msg_process_suspend (process); + TRACE_msg_process_suspend(process); #endif SIMIX_process_suspend(process->simdata->s_process); @@ -449,7 +450,7 @@ MSG_error_t MSG_process_resume(m_process_t process) CHECK_HOST(); #ifdef HAVE_TRACING - TRACE_msg_process_resume (process); + TRACE_msg_process_resume(process); #endif SIMIX_process_resume(process->simdata->s_process); diff --git a/src/msg/mailbox.h b/src/msg/mailbox.h index ffb8c3c877..3deb371785 100644 --- a/src/msg/mailbox.h +++ b/src/msg/mailbox.h @@ -17,12 +17,12 @@ SG_BEGIN_DECL() /* * Initialization of the mailbox module. */ - void MSG_mailbox_mod_init(void); +void MSG_mailbox_mod_init(void); /* * Terminaison of the mailbox module. */ - void MSG_mailbox_mod_exit(void); +void MSG_mailbox_mod_exit(void); /*! \brief MSG_mailbox_new - create a new mailbox. @@ -35,7 +35,7 @@ SG_BEGIN_DECL() * \return The newly created mailbox. */ XBT_PUBLIC(msg_mailbox_t) - MSG_mailbox_new(const char *alias); + MSG_mailbox_new(const char *alias); /*! \brief MSG_mailbox_create - create a new mailbox. * @@ -48,7 +48,7 @@ XBT_PUBLIC(msg_mailbox_t) * * \return The newly created mailbox. */ - msg_mailbox_t MSG_mailbox_create(const char *alias); +msg_mailbox_t MSG_mailbox_create(const char *alias); /* \brief MSG_mailbox_free - release a mailbox from the memory. * @@ -59,7 +59,7 @@ XBT_PUBLIC(msg_mailbox_t) * * \see MSG_mailbox_destroy. */ - void MSG_mailbox_free(void *mailbox); +void MSG_mailbox_free(void *mailbox); /* \brief MSG_mailbox_get_by_alias - get a mailbox from its alias. * @@ -73,7 +73,7 @@ XBT_PUBLIC(msg_mailbox_t) * or a new mailbox if the key does not match. */ XBT_PUBLIC(msg_mailbox_t) - MSG_mailbox_get_by_alias(const char *alias); + MSG_mailbox_get_by_alias(const char *alias); /* \brief MSG_mailbox_get_by_channel - get a mailbox of the specified host from its channel. * @@ -89,7 +89,7 @@ XBT_PUBLIC(msg_mailbox_t) * */ XBT_PUBLIC(msg_mailbox_t) - MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel); + MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel); /*! \brief MSG_mailbox_get_alias - get the alias associated with the mailbox. * @@ -112,7 +112,7 @@ XBT_PUBLIC(const char *) MSG_mailbox_get_alias(msg_mailbox_t mailbox); * \return The simix condition of the mailbox specified by the parameter mailbox. */ XBT_PUBLIC(smx_cond_t) - MSG_mailbox_get_cond(msg_mailbox_t mailbox); + MSG_mailbox_get_cond(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_set_cond - set the simix condition of a mailbox. * @@ -123,7 +123,8 @@ XBT_PUBLIC(smx_cond_t) * \param cond The new simix condition of the mailbox. * */ -XBT_PUBLIC(void) MSG_mailbox_set_cond(msg_mailbox_t mailbox, smx_cond_t cond); +XBT_PUBLIC(void) MSG_mailbox_set_cond(msg_mailbox_t mailbox, + smx_cond_t cond); /*! \brief MSG_mailbox_is_empty - test if a mailbox is empty. * @@ -148,7 +149,7 @@ XBT_PUBLIC(int) MSG_mailbox_is_empty(msg_mailbox_t mailbox); * \return The task at the head of the mailbox. */ XBT_PUBLIC(m_task_t) - MSG_mailbox_get_head(msg_mailbox_t mailbox); + MSG_mailbox_get_head(msg_mailbox_t mailbox); /*! \brief MSG_mailbox_get_count_host_waiting_tasks - Return the number of tasks waiting to be received in a mailbox and sent by a host. @@ -167,4 +168,4 @@ MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, SG_END_DECL() -#endif /* !SMX_MAILBOX_H */ +#endif /* !SMX_MAILBOX_H */ diff --git a/src/msg/msg_actions.c b/src/msg/msg_actions.c index c4da3ff3ab..685eaa850f 100644 --- a/src/msg/msg_actions.c +++ b/src/msg/msg_actions.c @@ -9,13 +9,14 @@ #include "xbt/str.h" #include "xbt/dynar.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action,msg,"MSG actions for trace driven simulation"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action, msg, + "MSG actions for trace driven simulation"); static xbt_dict_t action_funs; static xbt_dict_t action_queues; /* To split the file if a unique one is given (specific variable for the other case live in runner()) */ -static FILE *action_fp=NULL; +static FILE *action_fp = NULL; static char *action_line = NULL; static size_t action_len = 0; @@ -47,15 +48,16 @@ void MSG_action_unregister(const char *action_name) xbt_dict_remove(action_funs, action_name); } -static int MSG_action_runner(int argc, char *argv[]) { - xbt_dynar_t evt=NULL; +static int MSG_action_runner(int argc, char *argv[]) +{ + xbt_dynar_t evt = NULL; char *line = NULL; size_t line_len = 0; FILE *fp = NULL; char *comment = NULL; char *evtname = NULL; ssize_t read; - if (action_fp) { // A unique trace file + if (action_fp) { // A unique trace file while ((evt = action_get_action(argv[0]))) { msg_action_fun function = @@ -63,14 +65,16 @@ static int MSG_action_runner(int argc, char *argv[]) { (*function) (evt); xbt_dynar_free(&evt); } - } else { // Should have got my trace file in argument - xbt_assert1(argc>=2, - "No '%s' agent function provided, no simulation-wide trace file provided to MSG_action_trace_run(), " - "and no process-wide trace file provided in deployment file. Aborting.",argv[0] - ); + } else { // Should have got my trace file in argument + xbt_assert1(argc >= 2, + "No '%s' agent function provided, no simulation-wide trace file provided to MSG_action_trace_run(), " + "and no process-wide trace file provided in deployment file. Aborting.", + argv[0] + ); fp = fopen(argv[1], "r"); - xbt_assert2(fp != NULL, "Cannot open %s: %s", argv[1], strerror(errno)); + xbt_assert2(fp != NULL, "Cannot open %s: %s", argv[1], + strerror(errno)); // Read lines and execute them until I reach the end of file while ((read = getline(&line, &line_len, fp)) != -1) { @@ -84,12 +88,13 @@ static int MSG_action_runner(int argc, char *argv[]) { evt = xbt_str_split_quoted(line); evtname = xbt_dynar_get_as(evt, 0, char *); - if (!strcmp(argv[0],evtname)) { + if (!strcmp(argv[0], evtname)) { msg_action_fun function = xbt_dict_get(action_funs, xbt_dynar_get_as(evt, 1, char *)); (*function) (evt); } else { - WARN1("Ignore trace element not for me: %s",xbt_str_join(evt," ")); + WARN1("Ignore trace element not for me: %s", + xbt_str_join(evt, " ")); } xbt_dynar_free(&evt); } @@ -105,24 +110,25 @@ void _MSG_action_init() MSG_function_register_default(MSG_action_runner); } -void _MSG_action_exit() { +void _MSG_action_exit() +{ xbt_dict_free(&action_queues); xbt_dict_free(&action_funs); } -static xbt_dynar_t action_get_action(char *name) { +static xbt_dynar_t action_get_action(char *name) +{ ssize_t read; - xbt_dynar_t evt=NULL; + xbt_dynar_t evt = NULL; char *evtname = NULL; - xbt_dynar_t myqueue = xbt_dict_get_or_null(action_queues,name); - if (myqueue==NULL || xbt_dynar_length(myqueue)==0) { // nothing stored for me. Read the file further + xbt_dynar_t myqueue = xbt_dict_get_or_null(action_queues, name); + if (myqueue == NULL || xbt_dynar_length(myqueue) == 0) { // nothing stored for me. Read the file further - if (action_fp==NULL) { // File closed now. There's nothing more to read. I'm out of here + if (action_fp == NULL) { // File closed now. There's nothing more to read. I'm out of here goto todo_done; } - // Read lines until I reach something for me (which breaks in loop body) // or end of file reached while ((read = getline(&action_line, &action_len, action_fp)) != -1) { @@ -137,32 +143,34 @@ static xbt_dynar_t action_get_action(char *name) { // if it's for me, I'm done evtname = xbt_dynar_get_as(evt, 0, char *); - if (!strcmp(name,evtname)) { + if (!strcmp(name, evtname)) { return evt; } else { // Else, I have to store it for the relevant colleague - xbt_dynar_t otherqueue = xbt_dict_get_or_null(action_queues,evtname); - if (otherqueue == NULL) { // Damn. Create the queue of that guy - otherqueue = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp); - xbt_dict_set(action_queues ,evtname, otherqueue, NULL); + xbt_dynar_t otherqueue = + xbt_dict_get_or_null(action_queues, evtname); + if (otherqueue == NULL) { // Damn. Create the queue of that guy + otherqueue = + xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp); + xbt_dict_set(action_queues, evtname, otherqueue, NULL); } - xbt_dynar_push(otherqueue,&evt); + xbt_dynar_push(otherqueue, &evt); } } - goto todo_done; // end of file reached while searching in vain for more work + goto todo_done; // end of file reached while searching in vain for more work } else { // Get something from my queue and return it - xbt_dynar_shift(myqueue,&evt); + xbt_dynar_shift(myqueue, &evt); return evt; } // I did all my actions for me in the file (either I closed the file, or a colleague did) // Let's cleanup before leaving - todo_done: +todo_done: if (myqueue != NULL) { xbt_dynar_free(&myqueue); - xbt_dict_remove(action_queues,name); + xbt_dict_remove(action_queues, name); } return NULL; } @@ -176,22 +184,24 @@ static xbt_dynar_t action_get_action(char *name) { MSG_error_t MSG_action_trace_run(char *path) { MSG_error_t res; - char *name; - xbt_dynar_t todo; - xbt_dict_cursor_t cursor; + char *name; + xbt_dynar_t todo; + xbt_dict_cursor_t cursor; if (path) { action_fp = fopen(path, "r"); - xbt_assert2(action_fp != NULL, "Cannot open %s: %s", path, strerror(errno)); + xbt_assert2(action_fp != NULL, "Cannot open %s: %s", path, + strerror(errno)); } res = MSG_main(); if (xbt_dict_size(action_queues)) { - WARN0("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); + WARN0 + ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); - xbt_dict_foreach(action_queues,cursor,name,todo) { - WARN2("Still %lu actions for %s",xbt_dynar_length(todo),name); + xbt_dict_foreach(action_queues, cursor, name, todo) { + WARN2("Still %lu actions for %s", xbt_dynar_length(todo), name); } } diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index ab3e89f70a..f88edeb91e 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -31,7 +31,7 @@ msg_mailbox_t MSG_mailbox_create(const char *alias) mailbox->cond = NULL; mailbox->alias = alias ? xbt_strdup(alias) : NULL; mailbox->rdv = SIMIX_rdv_create(alias); - + return mailbox; } @@ -51,7 +51,7 @@ void MSG_mailbox_free(void *mailbox) free(_mailbox->alias); SIMIX_rdv_destroy(_mailbox->rdv); - + free(_mailbox); } @@ -69,16 +69,18 @@ m_task_t MSG_mailbox_get_head(msg_mailbox_t mailbox) { smx_comm_t comm = SIMIX_rdv_get_head(mailbox->rdv); - if(!comm) - return NULL; - - return (m_task_t)SIMIX_communication_get_data(comm); + if (!comm) + return NULL; + + return (m_task_t) SIMIX_communication_get_data(comm); } int -MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, m_host_t host) +MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, + m_host_t host) { - return SIMIX_rdv_get_count_waiting_comm (mailbox->rdv, host->simdata->smx_host); + return SIMIX_rdv_get_count_waiting_comm(mailbox->rdv, + host->simdata->smx_host); } void MSG_mailbox_set_cond(msg_mailbox_t mailbox, smx_cond_t cond) @@ -102,7 +104,8 @@ msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias) return mailbox; } -msg_mailbox_t MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel) +msg_mailbox_t MSG_mailbox_get_by_channel(m_host_t host, + m_channel_t channel) { xbt_assert0((host != NULL), "Invalid host"); xbt_assert1((channel >= 0) @@ -113,8 +116,8 @@ msg_mailbox_t MSG_mailbox_get_by_channel(m_host_t host, m_channel_t channel) } MSG_error_t -MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t *task, m_host_t host, - double timeout) +MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task, + m_host_t host, double timeout) { xbt_ex_t e; MSG_error_t ret = MSG_OK; @@ -123,58 +126,59 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t *task, m_host_t host, double start_time = 0; #endif /* We no longer support getting a task from a specific host */ - if (host) THROW_UNIMPLEMENTED; + if (host) + THROW_UNIMPLEMENTED; CHECK_HOST(); #ifdef HAVE_TRACING - TRACE_msg_task_get_start (); + TRACE_msg_task_get_start(); start_time = MSG_get_clock(); #endif - memset(&comm,0,sizeof(comm)); + memset(&comm, 0, sizeof(comm)); /* Kept for compatibility with older implementation */ xbt_assert1(!MSG_mailbox_get_cond(mailbox), - "A process is already blocked on this channel %s", + "A process is already blocked on this channel %s", MSG_mailbox_get_alias(mailbox)); /* Sanity check */ xbt_assert0(task, "Null pointer for the task storage"); if (*task) - CRITICAL0("MSG_task_get() was asked to write in a non empty task struct."); + CRITICAL0 + ("MSG_task_get() was asked to write in a non empty task struct."); /* Try to receive it by calling SIMIX network layer */ - TRY{ + TRY { SIMIX_network_recv(mailbox->rdv, timeout, task, NULL, &comm); //INFO2("Got task %s from %s",(*task)->name,mailbox->alias); (*task)->simdata->refcount--; } - CATCH(e){ - switch(e.category){ - case host_error: - ret = MSG_HOST_FAILURE; - break; - case network_error: - ret = MSG_TRANSFER_FAILURE; - break; - case timeout_error: - ret = MSG_TIMEOUT; - break; - default: - xbt_die(bprintf("Unhandled SIMIX network exception: %s",e.msg)); + CATCH(e) { + switch (e.category) { + case host_error: + ret = MSG_HOST_FAILURE; + break; + case network_error: + ret = MSG_TRANSFER_FAILURE; + break; + case timeout_error: + ret = MSG_TIMEOUT; + break; + default: + xbt_die(bprintf("Unhandled SIMIX network exception: %s", e.msg)); } - xbt_ex_free(e); + xbt_ex_free(e); } if (ret != MSG_HOST_FAILURE && - ret != MSG_TRANSFER_FAILURE && - ret != MSG_TIMEOUT){ + ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) { #ifdef HAVE_TRACING - TRACE_msg_task_get_end (start_time, *task); + TRACE_msg_task_get_end(start_time, *task); #endif } - MSG_RETURN(ret); + MSG_RETURN(ret); } MSG_error_t @@ -191,7 +195,7 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, CHECK_HOST(); #ifdef HAVE_TRACING - call_end = TRACE_msg_task_put_start (task); //must be after CHECK_HOST() + call_end = TRACE_msg_task_put_start(task); //must be after CHECK_HOST() #endif @@ -207,30 +211,31 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, msg_global->sent_msg++; process->simdata->waiting_task = task; - + /* Try to send it by calling SIMIX network layer */ - TRY{ + TRY { /* Kept for semantical compatibility with older implementation */ - if(mailbox->cond) + if (mailbox->cond) SIMIX_cond_signal(mailbox->cond); - SIMIX_network_send(mailbox->rdv, t_simdata->message_size, t_simdata->rate, - timeout, task, sizeof(void*), &t_simdata->comm, task); + SIMIX_network_send(mailbox->rdv, t_simdata->message_size, + t_simdata->rate, timeout, task, sizeof(void *), + &t_simdata->comm, task); } - CATCH(e){ - switch(e.category){ - case host_error: - ret = MSG_HOST_FAILURE; - break; - case network_error: - ret = MSG_TRANSFER_FAILURE; - break; - case timeout_error: - ret = MSG_TIMEOUT; - break; - default: - xbt_die(bprintf("Unhandled SIMIX network exception: %s",e.msg)); + CATCH(e) { + switch (e.category) { + case host_error: + ret = MSG_HOST_FAILURE; + break; + case network_error: + ret = MSG_TRANSFER_FAILURE; + break; + case timeout_error: + ret = MSG_TIMEOUT; + break; + default: + xbt_die(bprintf("Unhandled SIMIX network exception: %s", e.msg)); } xbt_ex_free(e); @@ -240,7 +245,8 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, process->simdata->waiting_task = NULL; #ifdef HAVE_TRACING - if (call_end) TRACE_msg_task_put_end (); + if (call_end) + TRACE_msg_task_put_end(); #endif - MSG_RETURN(ret); + MSG_RETURN(ret); } diff --git a/src/msg/private.h b/src/msg/private.h index 37e18f5358..d0e1361ef5 100644 --- a/src/msg/private.h +++ b/src/msg/private.h @@ -21,75 +21,75 @@ SG_BEGIN_DECL() /**************** datatypes **********************************/ /* this structure represents a mailbox */ - typedef struct s_msg_mailbox { - char *alias; /* the key of the mailbox in the global dictionary */ - smx_cond_t cond; /* the condition on the mailbox */ - smx_rdv_t rdv; /* SIMIX rendez-vous point */ - } s_msg_mailbox_t; - - typedef struct simdata_host { - smx_host_t smx_host; /* SURF modeling */ - struct s_msg_mailbox **mailboxes; /* mailboxes to store msg tasks of of the host */ - smx_mutex_t mutex; /* mutex to access the host */ - } s_simdata_host_t; +typedef struct s_msg_mailbox { + char *alias; /* the key of the mailbox in the global dictionary */ + smx_cond_t cond; /* the condition on the mailbox */ + smx_rdv_t rdv; /* SIMIX rendez-vous point */ +} s_msg_mailbox_t; + +typedef struct simdata_host { + smx_host_t smx_host; /* SURF modeling */ + struct s_msg_mailbox **mailboxes; /* mailboxes to store msg tasks of of the host */ + smx_mutex_t mutex; /* mutex to access the host */ +} s_simdata_host_t; /********************************* Task **************************************/ - typedef struct simdata_task { - smx_action_t compute; /* SURF modeling of computation */ - smx_comm_t comm; /* SIMIX communication */ - double message_size; /* Data size */ - double computation_amount; /* Computation size */ - smx_cond_t cond; - smx_mutex_t mutex; /* Task mutex */ - m_process_t sender; - m_process_t receiver; - m_host_t source; - double priority; - double rate; - int refcount; - int host_nb; /* ==0 if sequential task; parallel task if not */ +typedef struct simdata_task { + smx_action_t compute; /* SURF modeling of computation */ + smx_comm_t comm; /* SIMIX communication */ + double message_size; /* Data size */ + double computation_amount; /* Computation size */ + smx_cond_t cond; + smx_mutex_t mutex; /* Task mutex */ + m_process_t sender; + m_process_t receiver; + m_host_t source; + double priority; + double rate; + int refcount; + int host_nb; /* ==0 if sequential task; parallel task if not */ /******* Parallel Tasks Only !!!! *******/ - smx_host_t *host_list; - double *comp_amount; - double *comm_amount; - } s_simdata_task_t; + smx_host_t *host_list; + double *comp_amount; + double *comm_amount; +} s_simdata_task_t; /******************************* Process *************************************/ - typedef struct simdata_process { - m_host_t m_host; /* the host on which the process is running */ - smx_process_t s_process; - int PID; /* used for debugging purposes */ - int PPID; /* The parent PID */ - m_host_t put_host; /* used for debugging purposes */ - 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 */ - MSG_error_t last_errno; /* the last value returned by a MSG_function */ - } s_simdata_process_t; - - typedef struct process_arg { - const char *name; - xbt_main_func_t code; - void *data; - m_host_t m_host; - int argc; - char **argv; - double kill_time; - } s_process_arg_t, *process_arg_t; +typedef struct simdata_process { + m_host_t m_host; /* the host on which the process is running */ + smx_process_t s_process; + int PID; /* used for debugging purposes */ + int PPID; /* The parent PID */ + m_host_t put_host; /* used for debugging purposes */ + 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 */ + MSG_error_t last_errno; /* the last value returned by a MSG_function */ +} s_simdata_process_t; + +typedef struct process_arg { + const char *name; + xbt_main_func_t code; + void *data; + m_host_t m_host; + int argc; + char **argv; + double kill_time; +} s_process_arg_t, *process_arg_t; /************************** Global variables ********************************/ - typedef struct MSG_Global { - xbt_fifo_t host; - xbt_fifo_t process_list; - int max_channel; - int PID; - int session; - unsigned long int sent_msg; /* Total amount of messages sent during the simulation */ - } s_MSG_Global_t, *MSG_Global_t; +typedef struct MSG_Global { + xbt_fifo_t host; + xbt_fifo_t process_list; + int max_channel; + int PID; + int session; + unsigned long int sent_msg; /* Total amount of messages sent during the simulation */ +} s_MSG_Global_t, *MSG_Global_t; /*extern MSG_Global_t msg_global;*/ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; @@ -105,21 +105,21 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; #define CHECK_HOST() xbt_assert1(SIMIX_host_get_state(SIMIX_host_self())==1,\ "Host failed, you cannot call this function. (state=%d)",SIMIX_host_get_state(SIMIX_host_self())) - m_host_t __MSG_host_create(smx_host_t workstation, void *data); +m_host_t __MSG_host_create(smx_host_t workstation, void *data); - void __MSG_host_destroy(m_host_t host); +void __MSG_host_destroy(m_host_t host); - void __MSG_display_process_status(void); +void __MSG_display_process_status(void); - void __MSG_process_cleanup(void *arg); - void *_MSG_process_create_from_SIMIX(const char *name, - xbt_main_func_t code, void *data, - char *hostname, int argc, - char **argv, xbt_dict_t properties); - void _MSG_process_kill_from_SIMIX(void *p); +void __MSG_process_cleanup(void *arg); +void *_MSG_process_create_from_SIMIX(const char *name, + xbt_main_func_t code, void *data, + char *hostname, int argc, + char **argv, xbt_dict_t properties); +void _MSG_process_kill_from_SIMIX(void *p); - void _MSG_action_init(void); - void _MSG_action_exit(void); +void _MSG_action_init(void); +void _MSG_action_exit(void); SG_END_DECL() #endif diff --git a/src/msg/task.c b/src/msg/task.c index aed326f71c..38a1b8fca4 100644 --- a/src/msg/task.c +++ b/src/msg/task.c @@ -23,7 +23,7 @@ * message size and some private data. */ -#ifdef HAVE_RUBY /* FIXME: KILLME */ +#ifdef HAVE_RUBY /* FIXME: KILLME */ XBT_LOG_EXTERNAL_CATEGORY(ruby); #endif @@ -80,7 +80,7 @@ m_task_t MSG_task_create(const char *name, double compute_duration, simdata->comp_amount = NULL; simdata->comm_amount = NULL; #ifdef HAVE_TRACING - TRACE_msg_task_create (task); + TRACE_msg_task_create(task); #endif return task; @@ -105,7 +105,7 @@ void *MSG_task_get_data(m_task_t task) * This function allows to associate a new pointer to the user data associated of \a task. */ -void MSG_task_set_data(m_task_t task,void *data) +void MSG_task_set_data(m_task_t task, void *data) { xbt_assert0((task != NULL), "Invalid parameter"); @@ -150,10 +150,10 @@ const char *MSG_task_get_name(m_task_t task) * * This functions allows to associate a name to a task */ -void MSG_task_set_name(m_task_t task,const char* name) +void MSG_task_set_name(m_task_t task, const char *name) { - xbt_assert0(task,"Invalid parameters"); - task->name = xbt_strdup(name); + xbt_assert0(task, "Invalid parameters"); + task->name = xbt_strdup(name); } @@ -178,7 +178,7 @@ MSG_error_t MSG_task_destroy(m_task_t task) if (task->simdata->refcount > 0) return MSG_OK; #ifdef HAVE_TRACING - TRACE_msg_task_destroy (task); + TRACE_msg_task_destroy(task); #endif if (task->name) @@ -190,7 +190,7 @@ MSG_error_t MSG_task_destroy(m_task_t task) action = task->simdata->compute; if (action) SIMIX_action_destroy(action); - + /* parallel tasks only */ if (task->simdata->host_list) xbt_free(task->simdata->host_list); @@ -240,12 +240,14 @@ double MSG_task_get_compute_duration(m_task_t task) * \brief set the computation amount needed to process a task #m_task_t. */ -void MSG_task_set_compute_duration(m_task_t task,double computation_amount) +void MSG_task_set_compute_duration(m_task_t task, + double computation_amount) { - xbt_assert0(task,"Invalid parameter"); - task->simdata->computation_amount = computation_amount; + xbt_assert0(task, "Invalid parameter"); + task->simdata->computation_amount = computation_amount; } + /** \ingroup m_task_management * \brief Returns the remaining computation amount of a task #m_task_t. * @@ -270,7 +272,8 @@ double MSG_task_get_remaining_communication(m_task_t task) { xbt_assert0((task != NULL) && (task->simdata != NULL), "Invalid parameter"); - DEBUG1("calling SIMIX_communication_get_remains(%p)", task->simdata->comm); + DEBUG1("calling SIMIX_communication_get_remains(%p)", + task->simdata->comm); return SIMIX_communication_get_remains(task->simdata->comm); } @@ -281,10 +284,11 @@ double MSG_task_get_remaining_communication(m_task_t task) */ int MSG_task_is_latency_bounded(m_task_t task) { - xbt_assert0((task != NULL) - && (task->simdata != NULL), "Invalid parameter"); - DEBUG1("calling SIMIX_communication_is_latency_bounded(%p)", task->simdata->comm); - return SIMIX_communication_is_latency_bounded(task->simdata->comm); + xbt_assert0((task != NULL) + && (task->simdata != NULL), "Invalid parameter"); + DEBUG1("calling SIMIX_communication_is_latency_bounded(%p)", + task->simdata->comm); + return SIMIX_communication_is_latency_bounded(task->simdata->comm); } #endif @@ -318,5 +322,3 @@ void MSG_task_set_priority(m_task_t task, double priority) SIMIX_action_set_priority(task->simdata->compute, task->simdata->priority); } - - diff --git a/src/portable.h b/src/portable.h index cb5bc991aa..f9dc951ba0 100644 --- a/src/portable.h +++ b/src/portable.h @@ -57,7 +57,7 @@ # else # define tcp_close( s ) close( s ) # endif -#endif /* windows or unix ? */ +#endif /* windows or unix ? */ /**** **** File handling @@ -110,24 +110,24 @@ XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list); /* use internal functions when OS provided ones are borken */ #if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF) - extern int portable_snprintf(char *str, size_t str_m, const char *fmt, - /*args */ ...); - extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, - va_list ap); +extern int portable_snprintf(char *str, size_t str_m, const char *fmt, + /*args */ ...); +extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, + va_list ap); #define snprintf portable_snprintf #define vsnprintf portable_vsnprintf #endif /* prototype of GNU functions */ #if (defined(__GNUC__) && !defined(__cplusplus)) - extern int asprintf(char **ptr, const char *fmt, /*args */ ...); - extern int vasprintf(char **ptr, const char *fmt, va_list ap); +extern int asprintf(char **ptr, const char *fmt, /*args */ ...); +extern int vasprintf(char **ptr, const char *fmt, va_list ap); #endif - extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */ - ...); - extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, - va_list ap); +extern int asnprintf(char **ptr, size_t str_m, const char *fmt, /*args */ + ...); +extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, + va_list ap); /* * That's needed to protect solaris's printf from ever seing NULL associated to a %s format @@ -150,7 +150,7 @@ XBT_PUBLIC(int) vsnprintf(char *, size_t, const char *, va_list); /**** **** Some debugging functions. Can't we find a better place for this?? ****/ - void hexa_print(const char *name, unsigned char *data, int size); - const char *hexa_str(unsigned char *data, int size, int downside); +void hexa_print(const char *name, unsigned char *data, int size); +const char *hexa_str(unsigned char *data, int size, int downside); -#endif /* GRAS_PORTABLE_H */ +#endif /* GRAS_PORTABLE_H */ diff --git a/src/set_unit.c b/src/set_unit.c index 038e1c4cb3..bf6afda305 100644 --- a/src/set_unit.c +++ b/src/set_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 316 "xbt/set.c" +#line 321 "xbt/set.c" #include "xbt.h" #include "xbt/ex.h" @@ -77,7 +77,8 @@ static void search_name(xbt_set_t head, const char *key) THROW2(mismatch_error, 0, "The key (%s) is not the one expected (%s)", key, elm->name); if (strcmp(elm->name, elm->data)) - THROW2(mismatch_error, 0, "The name (%s) != data (%s)", key, elm->name); + THROW2(mismatch_error, 0, "The name (%s) != data (%s)", key, + elm->name); fflush(stdout); } @@ -110,7 +111,8 @@ static void traverse(xbt_set_t set) xbt_test_assert0(elm, "Dude ! Got a null elm during traversal!"); xbt_test_log3("Id(%d): %s->%s\n", elm->ID, elm->name, elm->data); xbt_test_assert2(!strcmp(elm->name, elm->data), - "Key(%s) != value(%s). Abording", elm->name, elm->data); + "Key(%s) != value(%s). Abording", elm->name, + elm->data); } } @@ -121,8 +123,8 @@ static void search_not_found(xbt_set_t set, const char *data) xbt_test_add1("Search %s (expected not to be found)", data); TRY { xbt_set_get_by_name(set, data); - THROW1(unknown_error, 0, "Found something which shouldn't be there (%s)", - data); + THROW1(unknown_error, 0, + "Found something which shouldn't be there (%s)", data); } CATCH(e) { if (e.category != not_found_error) xbt_test_exception(e); diff --git a/src/simdag/dax_dtd.c b/src/simdag/dax_dtd.c index bfb91afa34..97abacbfdb 100644 --- a/src/simdag/dax_dtd.c +++ b/src/simdag/dax_dtd.c @@ -1255,8 +1255,8 @@ int dax__flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *dax_text; -/* Validating XML processor for /home/mquinson/Code/simgrid/src/simdag/dax.dtd. - * Generated 2010/10/01 22:34:14. +/* Validating XML processor for /home/alegrand/Work/SimGrid/simgrid-git/src/simdag/dax.dtd. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/simdag/dax_dtd.h b/src/simdag/dax_dtd.h index 24a63f3791..382abd7b0d 100644 --- a/src/simdag/dax_dtd.h +++ b/src/simdag/dax_dtd.h @@ -1,5 +1,5 @@ /* XML processor/application API for src/simdag/dax.dtd. - * Generated 2010/10/01 22:34:16. + * Generated 2010/10/11 11:35:08. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/simdag/dax_dtd.l b/src/simdag/dax_dtd.l index 6602574d3b..85235b4d38 100644 --- a/src/simdag/dax_dtd.l +++ b/src/simdag/dax_dtd.l @@ -1,5 +1,5 @@ -/* Validating XML processor for /home/mquinson/Code/simgrid/src/simdag/dax.dtd. - * Generated 2010/10/01 22:34:14. +/* Validating XML processor for /home/alegrand/Work/SimGrid/simgrid-git/src/simdag/dax.dtd. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/simdag/private.h b/src/simdag/private.h index 644c2ce977..aab3cd6044 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -80,7 +80,7 @@ typedef struct SD_task { double start_time; double finish_time; surf_action_t surf_action; - unsigned short watch_points; /* bit field xor()ed with masks */ + unsigned short watch_points; /* bit field xor()ed with masks */ int fifo_checked; /* used by SD_task_just_done to make sure we evaluate the task only once */ @@ -99,7 +99,7 @@ typedef struct SD_task { double rate; #ifdef HAVE_TRACING - char *category; /* sd task category for instrumentation */ + char *category; /* sd task category for instrumentation */ #endif } s_SD_task_t; @@ -117,7 +117,8 @@ typedef struct SD_dependency { SD_link_t __SD_link_create(void *surf_link, void *data); void __SD_link_destroy(void *link); -SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data); +SD_workstation_t __SD_workstation_create(void *surf_workstation, + void *data); void __SD_workstation_destroy(void *workstation); int __SD_workstation_is_busy(SD_workstation_t workstation); @@ -132,14 +133,14 @@ void __SD_task_just_done(SD_task_t task); static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task) { return task->state_set == sd_global->scheduled_task_set || - task->state_set == sd_global->runnable_task_set; + task->state_set == sd_global->runnable_task_set; } /* Returns whether the given task is scheduled or runnable. */ static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task) { return task->state_set == sd_global->schedulable_task_set || - task->state_set == sd_global->done_task_set; + task->state_set == sd_global->done_task_set; } /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */ @@ -176,7 +177,7 @@ static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task) static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task) { return task->state_set == sd_global->runnable_task_set || - task->state_set == sd_global->in_fifo_task_set; + task->state_set == sd_global->in_fifo_task_set; } /* Returns whether the state of the given task is SD_RUNNING. */ diff --git a/src/simdag/sd_daxloader.c b/src/simdag/sd_daxloader.c index 07b52946e2..d1f79c1fb5 100644 --- a/src/simdag/sd_daxloader.c +++ b/src/simdag/sd_daxloader.c @@ -9,7 +9,7 @@ #include "xbt/misc.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd,"Parsing DAX files"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd, "Parsing DAX files"); #undef CLEANUP #include "dax_dtd.h" @@ -17,11 +17,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd,"Parsing DAX files"); /* Parsing helpers */ -static void dax_parse_error(char *msg) { +static void dax_parse_error(char *msg) +{ fprintf(stderr, "Parse error on line %d: %s\n", dax_lineno, msg); abort(); } -static double dax_parse_double(const char *string) { + +static double dax_parse_double(const char *string) +{ int ret = 0; double value; @@ -30,7 +33,9 @@ static double dax_parse_double(const char *string) { dax_parse_error(bprintf("%s is not a double", string)); return value; } -static int dax_parse_int(const char *string) { + +static int dax_parse_int(const char *string) +{ int ret = 0; int value; @@ -43,27 +48,27 @@ static int dax_parse_int(const char *string) { /* Ensure that transfer tasks have unique names even though a file is used * several times */ -void uniq_transfer_task_name(SD_task_t task){ - SD_task_t child, parent; - xbt_dynar_t children, parents; - char *new_name; +void uniq_transfer_task_name(SD_task_t task) +{ + SD_task_t child, parent; + xbt_dynar_t children, parents; + char *new_name; - children = SD_task_get_children(task); - parents = SD_task_get_parents(task); + children = SD_task_get_children(task); + parents = SD_task_get_parents(task); - xbt_dynar_get_cpy(children,0,&child); - xbt_dynar_get_cpy(parents,0,&parent); + xbt_dynar_get_cpy(children, 0, &child); + xbt_dynar_get_cpy(parents, 0, &parent); - new_name = bprintf("%s_%s_%s", - SD_task_get_name(parent), - SD_task_get_name(task), - SD_task_get_name(child)); + new_name = bprintf("%s_%s_%s", + SD_task_get_name(parent), + SD_task_get_name(task), SD_task_get_name(child)); - SD_task_set_name (task, new_name); + SD_task_set_name(task, new_name); - xbt_dynar_free_container(&children); - xbt_dynar_free_container(&parents); - free(new_name); + xbt_dynar_free_container(&children); + xbt_dynar_free_container(&parents); + free(new_name); } @@ -73,19 +78,21 @@ static xbt_dynar_t result; static xbt_dict_t jobs; static xbt_dict_t files; static SD_task_t current_job; -static SD_task_t root_task,end_task; +static SD_task_t root_task, end_task; -static void dump_res() { +static void dump_res() +{ unsigned int cursor; SD_task_t task; - xbt_dynar_foreach(result,cursor,task) { - INFO1("Task %d",cursor); + xbt_dynar_foreach(result, cursor, task) { + INFO1("Task %d", cursor); SD_task_dump(task); } } -static void dax_task_free(void*task){ - SD_task_t t=task; +static void dax_task_free(void *task) +{ + SD_task_t t = task; SD_task_destroy(t); } @@ -94,27 +101,29 @@ static void dax_task_free(void*task){ * See https://confluence.pegasus.isi.edu/display/pegasus/WorkflowGenerator * for more details. */ -xbt_dynar_t SD_daxload(const char*filename) { +xbt_dynar_t SD_daxload(const char *filename) +{ xbt_dict_cursor_t cursor; SD_task_t file; char *name; - FILE* in_file = fopen(filename,"r"); + FILE *in_file = fopen(filename, "r"); xbt_assert1(in_file, "Unable to open \"%s\"\n", filename); input_buffer = dax__create_buffer(in_file, 10); dax__switch_to_buffer(input_buffer); dax_lineno = 1; - result = xbt_dynar_new(sizeof(SD_task_t),dax_task_free); - files=xbt_dict_new(); - jobs=xbt_dict_new(); - root_task = SD_task_create_comp_seq("root",NULL,0); + result = xbt_dynar_new(sizeof(SD_task_t), dax_task_free); + files = xbt_dict_new(); + jobs = xbt_dict_new(); + 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); - xbt_dynar_push(result,&root_task); - end_task = SD_task_create_comp_seq("end",NULL,0); + xbt_dynar_push(result, &root_task); + end_task = SD_task_create_comp_seq("end", NULL, 0); - xbt_assert2(!dax_lex(),"Parse error in %s: %s",filename,dax__parse_err_msg()); + xbt_assert2(!dax_lex(), "Parse error in %s: %s", filename, + dax__parse_err_msg()); dax__delete_buffer(input_buffer); fclose(in_file); xbt_dict_free(&jobs); @@ -125,122 +134,152 @@ xbt_dynar_t SD_daxload(const char*filename) { * Files not consumed in the system are said to be consumed by end task (bottom of DAG). */ - xbt_dict_foreach(files,cursor,name,file) { - unsigned int cpt1,cpt2; + xbt_dict_foreach(files, cursor, name, file) { + unsigned int cpt1, cpt2; SD_task_t newfile = NULL; - SD_dependency_t depbefore,depafter; + SD_dependency_t depbefore, depafter; if (xbt_dynar_length(file->tasks_before) == 0) { - xbt_dynar_foreach(file->tasks_after,cpt2,depafter) { - SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,root_task,newfile); - SD_task_dependency_add(NULL,NULL,newfile,depafter->dst); - xbt_dynar_push(result,&newfile); + xbt_dynar_foreach(file->tasks_after, cpt2, depafter) { + SD_task_t newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, root_task, newfile); + SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); + xbt_dynar_push(result, &newfile); } } else if (xbt_dynar_length(file->tasks_after) == 0) { - xbt_dynar_foreach(file->tasks_before,cpt2,depbefore) { - SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,depbefore->src,newfile); - SD_task_dependency_add(NULL,NULL,newfile,end_task); - xbt_dynar_push(result,&newfile); + xbt_dynar_foreach(file->tasks_before, cpt2, depbefore) { + SD_task_t newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); + SD_task_dependency_add(NULL, NULL, newfile, end_task); + xbt_dynar_push(result, &newfile); } } else { - xbt_dynar_foreach(file->tasks_before,cpt1,depbefore) { - xbt_dynar_foreach(file->tasks_after,cpt2,depafter) { + xbt_dynar_foreach(file->tasks_before, cpt1, depbefore) { + xbt_dynar_foreach(file->tasks_after, cpt2, depafter) { if (depbefore->src == depafter->dst) { - WARN2("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.", - file->name,depbefore->src->name); + WARN2 + ("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.", + file->name, depbefore->src->name); } - newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,depbefore->src,newfile); - SD_task_dependency_add(NULL,NULL,newfile,depafter->dst); - xbt_dynar_push(result,&newfile); + newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); + SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); + xbt_dynar_push(result, &newfile); } } } } /* Push end task last */ - xbt_dynar_push(result,&end_task); + xbt_dynar_push(result, &end_task); /* Free previous copy of the files */ xbt_dict_free(&files); unsigned int cpt; - xbt_dynar_foreach(result,cpt,file) { - if (SD_task_get_kind(file)==SD_TASK_COMM_E2E){ - uniq_transfer_task_name(file); - } + xbt_dynar_foreach(result, cpt, file) { + if (SD_task_get_kind(file) == SD_TASK_COMM_E2E) { + uniq_transfer_task_name(file); + } } return result; } -void STag_dax__adag(void) { +void STag_dax__adag(void) +{ double version = dax_parse_double(A_dax__adag_version); - xbt_assert1((version == 2.1), "Expected version 2.1 in tag, got %f. Fix the parser or your file",version); + xbt_assert1((version == 2.1), + "Expected version 2.1 in tag, got %f. Fix the parser or your file", + version); } -void STag_dax__job(void) { + +void STag_dax__job(void) +{ double runtime = dax_parse_double(A_dax__job_runtime); - char *name=bprintf("%s@%s",A_dax__job_id,A_dax__job_name); - runtime*=4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */ + char *name = bprintf("%s@%s", A_dax__job_id, A_dax__job_name); + runtime *= 4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */ // INFO3("See ",A_dax__job_id,A_dax__job_runtime,runtime); - current_job = SD_task_create_comp_seq(name,NULL,runtime); - xbt_dict_set(jobs,A_dax__job_id,current_job,NULL); + current_job = SD_task_create_comp_seq(name, NULL, runtime); + xbt_dict_set(jobs, A_dax__job_id, current_job, NULL); free(name); - xbt_dynar_push(result,¤t_job); + xbt_dynar_push(result, ¤t_job); } -void STag_dax__uses(void) { + +void STag_dax__uses(void) +{ SD_task_t file; double size = dax_parse_double(A_dax__uses_size); int is_input = (A_dax__uses_link == A_dax__uses_link_input); // INFO2("See ",A_dax__uses_file,(is_input?"in":"out")); - 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); + 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); } else { - if (SD_task_get_amount(file)!=size) { + if (SD_task_get_amount(file) != size) { WARN3("Ignoring file %s size redefinition from %.0f to %.0f", - A_dax__uses_file,SD_task_get_amount(file),size); + A_dax__uses_file, SD_task_get_amount(file), size); } } if (is_input) { - SD_task_dependency_add(NULL,NULL,file,current_job); + SD_task_dependency_add(NULL, NULL, file, current_job); } else { - SD_task_dependency_add(NULL,NULL,current_job,file); - if (xbt_dynar_length(file->tasks_before)>1) { - WARN1("File %s created at more than one location...",file->name); + SD_task_dependency_add(NULL, NULL, current_job, file); + if (xbt_dynar_length(file->tasks_before) > 1) { + WARN1("File %s created at more than one location...", file->name); } } } + static SD_task_t current_child; -void STag_dax__child(void) { - current_child = xbt_dict_get_or_null(jobs,A_dax__child_ref); - if (current_child==NULL) - dax_parse_error(bprintf("Asked to add dependencies to the non-existent %s task",A_dax__child_ref)); +void STag_dax__child(void) +{ + current_child = xbt_dict_get_or_null(jobs, A_dax__child_ref); + if (current_child == NULL) + dax_parse_error(bprintf + ("Asked to add dependencies to the non-existent %s task", + A_dax__child_ref)); } -void ETag_dax__child(void) { - current_child=NULL; + +void ETag_dax__child(void) +{ + current_child = NULL; } -void STag_dax__parent(void) { - SD_task_t parent = xbt_dict_get_or_null(jobs,A_dax__parent_ref); + +void STag_dax__parent(void) +{ + SD_task_t parent = xbt_dict_get_or_null(jobs, A_dax__parent_ref); if (parent == NULL) - dax_parse_error(bprintf("Asked to add a dependency from %s to %s, but %s does not exist", - current_child->name,A_dax__parent_ref,A_dax__parent_ref)); - SD_task_dependency_add(NULL,NULL,parent,current_child); - DEBUG2("Control-flow dependency from %s to %s", current_child->name,parent->name); + dax_parse_error(bprintf + ("Asked to add a dependency from %s to %s, but %s does not exist", + current_child->name, A_dax__parent_ref, + A_dax__parent_ref)); + SD_task_dependency_add(NULL, NULL, parent, current_child); + DEBUG2("Control-flow dependency from %s to %s", current_child->name, + parent->name); } -void ETag_dax__adag(void) { + +void ETag_dax__adag(void) +{ // INFO0("See "); } -void ETag_dax__job(void) { + +void ETag_dax__job(void) +{ current_job = NULL; // INFO0("See "); } -void ETag_dax__parent(void) { + +void ETag_dax__parent(void) +{ // INFO0("See "); } -void ETag_dax__uses(void) { + +void ETag_dax__uses(void) +{ // INFO0("See "); } diff --git a/src/simdag/sd_dotloader.c b/src/simdag/sd_dotloader.c index 1c96d2bbe5..31b9e8b946 100644 --- a/src/simdag/sd_dotloader.c +++ b/src/simdag/sd_dotloader.c @@ -9,56 +9,62 @@ #include "xbt/misc.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd,"Parsing DOT files"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files"); #undef CLEANUP #include -void dot_add_task(Agnode_t *dag_node) ; -void dot_add_input_dependencies(SD_task_t current_job, Agedge_t *edge) ; -void dot_add_output_dependencies(SD_task_t current_job, Agedge_t *edge) ; -xbt_dynar_t SD_dotload_FILE(FILE* in_file); +void dot_add_task(Agnode_t * dag_node); +void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge); +void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge); +xbt_dynar_t SD_dotload_FILE(FILE * in_file); -static double dot_parse_double(const char *string) { - if (string == NULL) return -1; - int ret = 0; - double value = -1; +static double dot_parse_double(const char *string) +{ + if (string == NULL) + return -1; + int ret = 0; + double value = -1; - ret = sscanf(string, "%lg", &value); - if (ret != 1) - WARN1("%s is not a double", string); - return value; + ret = sscanf(string, "%lg", &value); + if (ret != 1) + WARN1("%s is not a double", string); + return value; } -static int dot_parse_int(const char *string) { - if (string == NULL) return -10; - int ret = 0; - int value; +static int dot_parse_int(const char *string) +{ + if (string == NULL) + return -10; + int ret = 0; + int value; - ret = sscanf(string, "%d", &value); - if (ret != 1) - WARN1("%s is not an integer", string); - return value; + ret = sscanf(string, "%d", &value); + if (ret != 1) + WARN1("%s is not an integer", string); + return value; } static xbt_dynar_t result; static xbt_dict_t jobs; static xbt_dict_t files; -static SD_task_t root_task,end_task; -static Agraph_t * dag_dot; +static SD_task_t root_task, end_task; +static Agraph_t *dag_dot; -static void dump_res() { - unsigned int cursor; - SD_task_t task; - xbt_dynar_foreach(result,cursor,task) { - INFO1("Task %d",cursor); - SD_task_dump(task); - } +static void dump_res() +{ + unsigned int cursor; + SD_task_t task; + xbt_dynar_foreach(result, cursor, task) { + INFO1("Task %d", cursor); + SD_task_dump(task); + } } -static void dot_task_free(void*task){ - SD_task_t t=task; - SD_task_destroy(t); +static void dot_task_free(void *task) +{ + SD_task_t t = task; + SD_task_destroy(t); } /** @brief loads a DOT file describing a DAG @@ -70,189 +76,201 @@ static void dot_task_free(void*task){ * (the amount of data transfer in bit). * if they aren't here, there choose to be equal to zero. */ -xbt_dynar_t SD_dotload(const char*filename){ - FILE* in_file = fopen(filename,"r"); - xbt_assert1(in_file, "Unable to open \"%s\"\n", filename); - SD_dotload_FILE(in_file); - fclose(in_file); - return result; +xbt_dynar_t SD_dotload(const char *filename) +{ + FILE *in_file = fopen(filename, "r"); + xbt_assert1(in_file, "Unable to open \"%s\"\n", filename); + SD_dotload_FILE(in_file); + fclose(in_file); + return result; } -xbt_dynar_t SD_dotload_FILE(FILE* in_file){ - xbt_assert0(in_file, "Unable to use a null file descriptor\n"); - dag_dot = agread(in_file,NIL(Agdisc_t*)); +xbt_dynar_t SD_dotload_FILE(FILE * in_file) +{ + xbt_assert0(in_file, "Unable to use a null file descriptor\n"); + 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(); - 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); + result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free); + files = xbt_dict_new(); + jobs = xbt_dict_new(); + 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); - xbt_dict_set(jobs,"root",root_task,NULL); - xbt_dynar_push(result,&root_task); - end_task = SD_task_create_comp_seq("end",NULL,0); - xbt_dict_set(jobs,"end",end_task,NULL); + xbt_dict_set(jobs, "root", root_task, NULL); + xbt_dynar_push(result, &root_task); + end_task = SD_task_create_comp_seq("end", NULL, 0); + xbt_dict_set(jobs, "end", end_task, NULL); - Agnode_t *dag_node = NULL; - for (dag_node = agfstnode(dag_dot); dag_node; dag_node = agnxtnode(dag_dot,dag_node)){ - dot_add_task(dag_node); - } - agclose(dag_dot); - xbt_dict_free(&jobs); + Agnode_t *dag_node = NULL; + for (dag_node = agfstnode(dag_dot); dag_node; + dag_node = agnxtnode(dag_dot, dag_node)) { + dot_add_task(dag_node); + } + agclose(dag_dot); + xbt_dict_free(&jobs); - /* And now, post-process the files. - * We want a file task per pair of computation tasks exchanging the file. Duplicate on need - * Files not produced in the system are said to be produced by root task (top of DAG). - * Files not consumed in the system are said to be consumed by end task (bottom of DAG). - */ - xbt_dict_cursor_t cursor; - SD_task_t file; - char *name; - xbt_dict_foreach(files,cursor,name,file) { - unsigned int cpt1,cpt2; - SD_task_t newfile = NULL; - SD_dependency_t depbefore,depafter; - if (xbt_dynar_length(file->tasks_before) == 0) { - xbt_dynar_foreach(file->tasks_after,cpt2,depafter) { - SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,root_task,newfile); - SD_task_dependency_add(NULL,NULL,newfile,depafter->dst); - xbt_dynar_push(result,&newfile); - } - } else if (xbt_dynar_length(file->tasks_after) == 0) { - xbt_dynar_foreach(file->tasks_before,cpt2,depbefore) { - SD_task_t newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,depbefore->src,newfile); - SD_task_dependency_add(NULL,NULL,newfile,end_task); - xbt_dynar_push(result,&newfile); - } - } else { - xbt_dynar_foreach(file->tasks_before,cpt1,depbefore) { - xbt_dynar_foreach(file->tasks_after,cpt2,depafter) { - if (depbefore->src == depafter->dst) { - WARN2("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.", - file->name,depbefore->src->name); - } - newfile = SD_task_create_comm_e2e(file->name,NULL,file->amount); - SD_task_dependency_add(NULL,NULL,depbefore->src,newfile); - SD_task_dependency_add(NULL,NULL,newfile,depafter->dst); - xbt_dynar_push(result,&newfile); - } - } + /* And now, post-process the files. + * We want a file task per pair of computation tasks exchanging the file. Duplicate on need + * Files not produced in the system are said to be produced by root task (top of DAG). + * Files not consumed in the system are said to be consumed by end task (bottom of DAG). + */ + xbt_dict_cursor_t cursor; + SD_task_t file; + char *name; + xbt_dict_foreach(files, cursor, name, file) { + unsigned int cpt1, cpt2; + SD_task_t newfile = NULL; + SD_dependency_t depbefore, depafter; + if (xbt_dynar_length(file->tasks_before) == 0) { + xbt_dynar_foreach(file->tasks_after, cpt2, depafter) { + SD_task_t newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, root_task, newfile); + SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); + xbt_dynar_push(result, &newfile); + } + } else if (xbt_dynar_length(file->tasks_after) == 0) { + xbt_dynar_foreach(file->tasks_before, cpt2, depbefore) { + SD_task_t newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); + SD_task_dependency_add(NULL, NULL, newfile, end_task); + xbt_dynar_push(result, &newfile); + } + } else { + xbt_dynar_foreach(file->tasks_before, cpt1, depbefore) { + xbt_dynar_foreach(file->tasks_after, cpt2, depafter) { + if (depbefore->src == depafter->dst) { + WARN2 + ("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.", + file->name, depbefore->src->name); + } + newfile = + SD_task_create_comm_e2e(file->name, NULL, file->amount); + SD_task_dependency_add(NULL, NULL, depbefore->src, newfile); + SD_task_dependency_add(NULL, NULL, newfile, depafter->dst); + xbt_dynar_push(result, &newfile); } + } } + } - /* Push end task last */ - xbt_dynar_push(result,&end_task); + /* Push end task last */ + xbt_dynar_push(result, &end_task); - /* Free previous copy of the files */ - xbt_dict_free(&files); + /* Free previous copy of the files */ + xbt_dict_free(&files); - return result; + return result; } /* dot_add_task create a sd_task and all transfers required for this * task. The execution time of the task is given by the attribute size. * The unit of size is the Flop.*/ -void dot_add_task(Agnode_t *dag_node) { - char *name = agnameof(dag_node); - SD_task_t current_job; - double runtime = dot_parse_double(agget(dag_node,(char*)"size")); - long performer = (long)dot_parse_int((char *) agget(dag_node,(char*)"performer")); - INFO3("See ",name,agget(dag_node,(char*)"size"),runtime); - current_job = xbt_dict_get_or_null(jobs,name); - if (current_job == NULL) { - current_job = SD_task_create_comp_seq(name,(void*)performer,runtime); - xbt_dict_set(jobs,name,current_job,NULL); - xbt_dynar_push(result,¤t_job); - } - Agedge_t *e; - int count = 0; - for (e = agfstin(dag_dot,dag_node); e; e = agnxtin(dag_dot,e)) { - dot_add_input_dependencies(current_job,e); - count++; - } - if (count==0 && current_job != root_task){ - SD_task_dependency_add(NULL,NULL,root_task,current_job); - } - count = 0; - for (e = agfstout(dag_dot,dag_node); e; e = agnxtout(dag_dot,e)) { - dot_add_output_dependencies(current_job,e); - count++; - } - if (count==0 && current_job != end_task){ - SD_task_dependency_add(NULL,NULL,current_job,end_task); - } +void dot_add_task(Agnode_t * dag_node) +{ + char *name = agnameof(dag_node); + SD_task_t current_job; + double runtime = dot_parse_double(agget(dag_node, (char *) "size")); + long performer = + (long) dot_parse_int((char *) agget(dag_node, (char *) "performer")); + INFO3("See ", name, + agget(dag_node, (char *) "size"), runtime); + current_job = xbt_dict_get_or_null(jobs, name); + if (current_job == NULL) { + current_job = + SD_task_create_comp_seq(name, (void *) performer, runtime); + xbt_dict_set(jobs, name, current_job, NULL); + xbt_dynar_push(result, ¤t_job); + } + Agedge_t *e; + int count = 0; + for (e = agfstin(dag_dot, dag_node); e; e = agnxtin(dag_dot, e)) { + dot_add_input_dependencies(current_job, e); + count++; + } + if (count == 0 && current_job != root_task) { + SD_task_dependency_add(NULL, NULL, root_task, current_job); + } + count = 0; + for (e = agfstout(dag_dot, dag_node); e; e = agnxtout(dag_dot, e)) { + dot_add_output_dependencies(current_job, e); + count++; + } + if (count == 0 && current_job != end_task) { + SD_task_dependency_add(NULL, NULL, current_job, end_task); + } } /* dot_add_output_dependencies create the dependencies between a task * and a transfers. This is given by the edges in the dot file. * The amount of data transfers is given by the attribute size on the * edge. */ -void dot_add_input_dependencies(SD_task_t current_job, Agedge_t *edge) { - SD_task_t file; +void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge) +{ + SD_task_t file; - char name[80]; - sprintf(name ,"%s->%s",agnameof(agtail(edge)) ,agnameof(aghead(edge))); - double size = dot_parse_double(agget(edge,(char*)"size")); - INFO2("size : %e, get size : %s",size,agget(edge,(char*)"size")); - //int sender = dot_parse_int(agget(edge,(char*)"sender")); - //int reciever = dot_parse_int(agget(edge,(char*)"reciever")); - if(size >0){ - file = xbt_dict_get_or_null(files,name); - if (file==NULL) { - file = SD_task_create_comm_e2e(name,NULL,size); - xbt_dict_set(files,name,file,&dot_task_free); - } else { - if (SD_task_get_amount(file)!=size) { - WARN3("Ignoring file %s size redefinition from %.0f to %.0f", - name,SD_task_get_amount(file),size); - } - } - SD_task_dependency_add(NULL,NULL,file,current_job); - }else{ - file = xbt_dict_get_or_null(jobs,agnameof(agtail(edge))); - if (file != NULL){ - SD_task_dependency_add(NULL,NULL,file,current_job); + char name[80]; + sprintf(name, "%s->%s", agnameof(agtail(edge)), agnameof(aghead(edge))); + double size = dot_parse_double(agget(edge, (char *) "size")); + INFO2("size : %e, get size : %s", size, agget(edge, (char *) "size")); + //int sender = dot_parse_int(agget(edge,(char*)"sender")); + //int reciever = dot_parse_int(agget(edge,(char*)"reciever")); + if (size > 0) { + file = xbt_dict_get_or_null(files, name); + if (file == NULL) { + file = SD_task_create_comm_e2e(name, NULL, size); + xbt_dict_set(files, name, file, &dot_task_free); + } else { + if (SD_task_get_amount(file) != size) { + WARN3("Ignoring file %s size redefinition from %.0f to %.0f", + name, SD_task_get_amount(file), size); } } + SD_task_dependency_add(NULL, NULL, file, current_job); + } else { + file = xbt_dict_get_or_null(jobs, agnameof(agtail(edge))); + if (file != NULL) { + SD_task_dependency_add(NULL, NULL, file, current_job); + } + } } /* dot_add_output_dependencies create the dependencies between a * transfers and a task. This is given by the edges in the dot file. * The amount of data transfers is given by the attribute size on the * edge. */ -void dot_add_output_dependencies(SD_task_t current_job, Agedge_t *edge) { - SD_task_t file; - char name[80]; - sprintf(name ,"%s->%s",agnameof(agtail(edge)) ,agnameof(aghead(edge))); - double size = dot_parse_double(agget(edge,(char*)"size")); - INFO2("size : %e, get size : %s",size,agget(edge,(char*)"size")); - //int sender = dot_parse_int(agget(edge,(char*)"sender")); - //int reciever = dot_parse_int(agget(edge,(char*)"reciever")); +void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge) +{ + SD_task_t file; + char name[80]; + sprintf(name, "%s->%s", agnameof(agtail(edge)), agnameof(aghead(edge))); + double size = dot_parse_double(agget(edge, (char *) "size")); + INFO2("size : %e, get size : %s", size, agget(edge, (char *) "size")); + //int sender = dot_parse_int(agget(edge,(char*)"sender")); + //int reciever = dot_parse_int(agget(edge,(char*)"reciever")); - //INFO2("See ",A_dot__uses_file,(is_input?"in":"out")); - if(size >0){ - file = xbt_dict_get_or_null(files,name); - if (file==NULL) { - file = SD_task_create_comm_e2e(name,NULL,size); - xbt_dict_set(files,name,file,&dot_task_free); - } else { - if (SD_task_get_amount(file)!=size) { - WARN3("Ignoring file %s size redefinition from %.0f to %.0f", - name,SD_task_get_amount(file),size); - } - } - SD_task_dependency_add(NULL,NULL,current_job,file); - if (xbt_dynar_length(file->tasks_before)>1) { - WARN1("File %s created at more than one location...",file->name); - } - }else{ - file = xbt_dict_get_or_null(jobs,agnameof(aghead(edge))); - if (file != NULL){ - SD_task_dependency_add(NULL,NULL,current_job,file); + //INFO2("See ",A_dot__uses_file,(is_input?"in":"out")); + if (size > 0) { + file = xbt_dict_get_or_null(files, name); + if (file == NULL) { + file = SD_task_create_comm_e2e(name, NULL, size); + xbt_dict_set(files, name, file, &dot_task_free); + } else { + if (SD_task_get_amount(file) != size) { + WARN3("Ignoring file %s size redefinition from %.0f to %.0f", + name, SD_task_get_amount(file), size); } } + SD_task_dependency_add(NULL, NULL, current_job, file); + if (xbt_dynar_length(file->tasks_before) > 1) { + WARN1("File %s created at more than one location...", file->name); + } + } else { + file = xbt_dict_get_or_null(jobs, agnameof(aghead(edge))); + if (file != NULL) { + SD_task_dependency_add(NULL, NULL, current_job, file); + } + } } - diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 7662cdb795..17286094af 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -42,7 +42,7 @@ XBT_LOG_EXTERNAL_CATEGORY(sd_workstation); void SD_init(int *argc, char **argv) { #ifdef HAVE_TRACING - TRACE_global_init (argc, argv); + TRACE_global_init(argc, argv); #endif s_SD_task_t task; @@ -66,25 +66,26 @@ void SD_init(int *argc, char **argv) sd_global->watch_point_reached = 0; sd_global->not_scheduled_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->schedulable_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->runnable_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->in_fifo_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->running_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->done_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->failed_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->task_number = 0; surf_init(argc, argv); - xbt_cfg_setdefault_string(_surf_cfg_set, "workstation/model", "ptask_L07"); + xbt_cfg_setdefault_string(_surf_cfg_set, "workstation/model", + "ptask_L07"); } /** @@ -116,21 +117,21 @@ void SD_application_reinit(void) xbt_swag_free(sd_global->failed_task_set); sd_global->not_scheduled_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->schedulable_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->scheduled_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->runnable_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->in_fifo_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->running_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->done_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->failed_task_set = - xbt_swag_new(xbt_swag_offset(task, state_hookup)); + xbt_swag_new(xbt_swag_offset(task, state_hookup)); sd_global->task_number = 0; } else { WARN0("SD_application_reinit called before initialization of SimDag"); @@ -178,7 +179,8 @@ void SD_create_environment(const char *platform_file) __SD_workstation_create(surf_workstation, NULL); } - xbt_dict_foreach(surf_model_resource_set(surf_network_model), cursor, name, surf_link) { + xbt_dict_foreach(surf_model_resource_set(surf_network_model), cursor, + name, surf_link) { __SD_link_create(surf_link, NULL); } @@ -186,7 +188,7 @@ void SD_create_environment(const char *platform_file) SD_workstation_get_number(), SD_link_get_number()); #ifdef HAVE_TRACING - TRACE_surf_save_onelink (); + TRACE_surf_save_onelink(); #endif } @@ -231,7 +233,8 @@ xbt_dynar_t SD_simulate(double how_long) /* explore the runnable tasks */ xbt_swag_foreach_safe(task, task_safe, sd_global->runnable_task_set) { VERB1("Executing task '%s'", SD_task_get_name(task)); - if (__SD_task_try_to_run(task) && !xbt_dynar_member(changed_tasks, &task)) + if (__SD_task_try_to_run(task) + && !xbt_dynar_member(changed_tasks, &task)) xbt_dynar_push(changed_tasks, &task); } @@ -257,7 +260,9 @@ xbt_dynar_t SD_simulate(double how_long) xbt_dynar_foreach(model_list, iter, model) { while ((action = xbt_swag_extract(model->states.done_action_set))) { task = action->data; - task->start_time = surf_workstation_model->action_get_start_time(task->surf_action); + task->start_time = + surf_workstation_model-> + action_get_start_time(task->surf_action); task->finish_time = surf_get_clock(); VERB1("Task '%s' done", SD_task_get_name(task)); DEBUG0("Calling __SD_task_just_done"); @@ -270,37 +275,38 @@ xbt_dynar_t SD_simulate(double how_long) xbt_dynar_push(changed_tasks, &task); /* remove the dependencies after this task */ - xbt_dynar_foreach(task->tasks_after, depcnt, dependency){ - dst = dependency->dst; - if (dst->unsatisfied_dependencies>0) - dst->unsatisfied_dependencies--; - if (dst->is_not_ready>0) - dst->is_not_ready--; - - if (!(dst->unsatisfied_dependencies)){ - if (__SD_task_is_scheduled(dst)) - __SD_task_set_state(dst, SD_RUNNABLE); - else - __SD_task_set_state(dst, SD_SCHEDULABLE); + xbt_dynar_foreach(task->tasks_after, depcnt, dependency) { + dst = dependency->dst; + if (dst->unsatisfied_dependencies > 0) + dst->unsatisfied_dependencies--; + if (dst->is_not_ready > 0) + dst->is_not_ready--; + + if (!(dst->unsatisfied_dependencies)) { + if (__SD_task_is_scheduled(dst)) + __SD_task_set_state(dst, SD_RUNNABLE); + else + __SD_task_set_state(dst, SD_SCHEDULABLE); } - if (SD_task_get_kind(dst) == SD_TASK_COMM_E2E){ - SD_dependency_t comm_dep; - SD_task_t comm_dst; - xbt_dynar_get_cpy(dst->tasks_after, 0, &comm_dep); - comm_dst = comm_dep->dst; - if (__SD_task_is_not_scheduled(comm_dst) && - comm_dst->is_not_ready>0){ - comm_dst->is_not_ready--; - - if (!(comm_dst->is_not_ready)){ - __SD_task_set_state(comm_dst, SD_SCHEDULABLE); - } - } + if (SD_task_get_kind(dst) == SD_TASK_COMM_E2E) { + SD_dependency_t comm_dep; + SD_task_t comm_dst; + xbt_dynar_get_cpy(dst->tasks_after, 0, &comm_dep); + comm_dst = comm_dep->dst; + if (__SD_task_is_not_scheduled(comm_dst) && + comm_dst->is_not_ready > 0) { + comm_dst->is_not_ready--; + + if (!(comm_dst->is_not_ready)) { + __SD_task_set_state(comm_dst, SD_SCHEDULABLE); + } + } } /* is dst runnable now? */ - if (__SD_task_is_runnable(dst) && !sd_global->watch_point_reached) { + if (__SD_task_is_runnable(dst) + && !sd_global->watch_point_reached) { VERB1("Executing task '%s'", SD_task_get_name(dst)); if (__SD_task_try_to_run(dst) && !xbt_dynar_member(changed_tasks, &task)) @@ -312,7 +318,9 @@ xbt_dynar_t SD_simulate(double how_long) /* let's see which tasks have just failed */ while ((action = xbt_swag_extract(model->states.failed_action_set))) { task = action->data; - task->start_time = surf_workstation_model->action_get_start_time(task->surf_action); + task->start_time = + surf_workstation_model-> + action_get_start_time(task->surf_action); task->finish_time = surf_get_clock(); VERB1("Task '%s' failed", SD_task_get_name(task)); __SD_task_set_state(task, SD_FAILED); @@ -359,7 +367,7 @@ double SD_get_clock(void) void SD_exit(void) { #ifdef HAVE_TRACING - TRACE_surf_release (); + TRACE_surf_release(); #endif if (SD_INITIALISED()) { DEBUG0("Destroying workstation and link dictionaries..."); @@ -401,18 +409,19 @@ void SD_exit(void) * \bried load script file */ -void SD_load_environment_script(const char* script_file) +void SD_load_environment_script(const char *script_file) { #ifdef HAVE_LUA - lua_State *L = lua_open(); - luaL_openlibs(L); + lua_State *L = lua_open(); + luaL_openlibs(L); - if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { - printf("error: %s\n", lua_tostring(L, -1)); - return; - } + if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) { + printf("error: %s\n", lua_tostring(L, -1)); + return; + } #else - xbt_die("Lua is not available!! to call SD_load_environment_script, lua should be available..."); + xbt_die + ("Lua is not available!! to call SD_load_environment_script, lua should be available..."); #endif - return; + return; } diff --git a/src/simdag/sd_link.c b/src/simdag/sd_link.c index ed84a8bb57..9533ca4e3a 100644 --- a/src/simdag/sd_link.c +++ b/src/simdag/sd_link.c @@ -133,7 +133,7 @@ double SD_link_get_current_bandwidth(SD_link_t link) SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); return surf_workstation_model->extension.workstation. - get_link_bandwidth(link->surf_link); + get_link_bandwidth(link->surf_link); } /** @@ -147,7 +147,7 @@ double SD_link_get_current_latency(SD_link_t link) SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); return surf_workstation_model->extension.workstation. - get_link_latency(link->surf_link); + get_link_latency(link->surf_link); } /** diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index 261a59f205..47c41c3129 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -53,8 +53,8 @@ SD_task_t SD_task_create(const char *name, void *data, double amount) /* dependencies */ task->tasks_before = xbt_dynar_new(sizeof(SD_dependency_t), NULL); task->tasks_after = xbt_dynar_new(sizeof(SD_dependency_t), NULL); - task->unsatisfied_dependencies=0; - task->is_not_ready=0; + task->unsatisfied_dependencies = 0; + task->is_not_ready = 0; /* scheduling parameters */ task->workstation_nb = 0; @@ -66,7 +66,7 @@ SD_task_t SD_task_create(const char *name, void *data, double amount) sd_global->task_number++; #ifdef HAVE_TRACING - TRACE_sd_task_create (task); + TRACE_sd_task_create(task); #endif return task; @@ -142,12 +142,12 @@ void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state) case SD_RUNNING: task->state_set = sd_global->running_task_set; task->start_time = - surf_workstation_model->action_get_start_time(task->surf_action); + surf_workstation_model->action_get_start_time(task->surf_action); break; case SD_DONE: task->state_set = sd_global->done_task_set; task->finish_time = - surf_workstation_model->action_get_finish_time(task->surf_action); + surf_workstation_model->action_get_finish_time(task->surf_action); task->remains = 0; break; case SD_FAILED: @@ -180,7 +180,8 @@ const char *SD_task_get_name(SD_task_t task) } /** @brief Allows to change the name of a task */ -void SD_task_set_name(SD_task_t task, const char *name) { +void SD_task_set_name(SD_task_t task, const char *name) +{ xbt_free(task->name); task->name = xbt_strdup(name); } @@ -200,7 +201,7 @@ xbt_dynar_t SD_task_get_parents(SD_task_t task) xbt_assert0(task != NULL, "Invalid parameter"); parents = xbt_dynar_new(sizeof(SD_task_t), NULL); - xbt_dynar_foreach(task->tasks_before, i, dep){ + xbt_dynar_foreach(task->tasks_before, i, dep) { xbt_dynar_push(parents, &(dep->src)); } return parents; @@ -220,7 +221,7 @@ xbt_dynar_t SD_task_get_children(SD_task_t task) xbt_assert0(task != NULL, "Invalid parameter"); children = xbt_dynar_new(sizeof(SD_task_t), NULL); - xbt_dynar_foreach(task->tasks_after, i, dep){ + xbt_dynar_foreach(task->tasks_after, i, dep) { xbt_dynar_push(children, &(dep->dst)); } return children; @@ -237,7 +238,7 @@ int SD_task_get_workstation_count(SD_task_t task) SD_CHECK_INIT_DONE(); xbt_assert0(task != NULL, "Invalid parameter"); // xbt_assert1( task->state_set != sd_global->scheduled_task_set, - // "Unscheduled task %s", task->name); + // "Unscheduled task %s", task->name); return task->workstation_nb; } @@ -247,12 +248,12 @@ int SD_task_get_workstation_count(SD_task_t task) * Only call this on already scheduled tasks! * \param task a task */ -SD_workstation_t* SD_task_get_workstation_list(SD_task_t task) +SD_workstation_t *SD_task_get_workstation_list(SD_task_t task) { SD_CHECK_INIT_DONE(); xbt_assert0(task != NULL, "Invalid parameter"); //xbt_assert1( task->state_set != sd_global->scheduled_task_set, - // "Unscheduled task %s", task->name); + // "Unscheduled task %s", task->name); return task->workstation_list; } @@ -288,7 +289,8 @@ double SD_task_get_remaining_amount(SD_task_t task) return task->remains; } -int SD_task_get_kind(SD_task_t task) { +int SD_task_get_kind(SD_task_t task) +{ return task->kind; } @@ -299,21 +301,23 @@ void SD_task_dump(SD_task_t task) SD_dependency_t dependency; char *statename; - INFO1("Displaying task %s",SD_task_get_name(task)); - statename=bprintf("%s %s %s %s %s %s %s %s", - (task->state&SD_NOT_SCHEDULED?"not scheduled":""), - (task->state&SD_SCHEDULABLE?"schedulable":""), - (task->state&SD_SCHEDULED?"scheduled":""), - (task->state&SD_RUNNABLE?"runnable":"not runnable"), - (task->state&SD_IN_FIFO?"in fifo":""), - (task->state&SD_RUNNING?"running":""), - (task->state&SD_DONE?"done":""), - (task->state&SD_FAILED?"failed":"")); - INFO1(" - state: %s",statename); + INFO1("Displaying task %s", SD_task_get_name(task)); + statename = bprintf("%s %s %s %s %s %s %s %s", + (task->state & SD_NOT_SCHEDULED ? "not scheduled" : + ""), + (task->state & SD_SCHEDULABLE ? "schedulable" : ""), + (task->state & SD_SCHEDULED ? "scheduled" : ""), + (task->state & SD_RUNNABLE ? "runnable" : + "not runnable"), + (task->state & SD_IN_FIFO ? "in fifo" : ""), + (task->state & SD_RUNNING ? "running" : ""), + (task->state & SD_DONE ? "done" : ""), + (task->state & SD_FAILED ? "failed" : "")); + INFO1(" - state: %s", statename); free(statename); - if (task->kind!=0) { - switch(task->kind){ + if (task->kind != 0) { + switch (task->kind) { case SD_TASK_COMM_E2E: INFO0(" - kind: end-to-end communication"); break; @@ -321,42 +325,44 @@ void SD_task_dump(SD_task_t task) INFO0(" - kind: sequential computation"); break; default: - INFO1(" - (unknown kind %d)",task->kind); + INFO1(" - (unknown kind %d)", task->kind); } } - INFO1(" - amount: %.0f",SD_task_get_amount(task)); + INFO1(" - amount: %.0f", SD_task_get_amount(task)); INFO1(" - Dependencies to satisfy: %d", task->unsatisfied_dependencies); if (xbt_dynar_length(task->tasks_before)) { INFO0(" - pre-dependencies:"); - xbt_dynar_foreach(task->tasks_before,counter,dependency) { - INFO1(" %s",SD_task_get_name(dependency->src)); + xbt_dynar_foreach(task->tasks_before, counter, dependency) { + INFO1(" %s", SD_task_get_name(dependency->src)); } } if (xbt_dynar_length(task->tasks_after)) { INFO0(" - post-dependencies:"); - xbt_dynar_foreach(task->tasks_after,counter,dependency) { - INFO1(" %s",SD_task_get_name(dependency->dst)); + xbt_dynar_foreach(task->tasks_after, counter, dependency) { + INFO1(" %s", SD_task_get_name(dependency->dst)); } } } + /** @brief Dumps the task in dotty formalism into the FILE* passed as second argument */ -void SD_task_dotty(SD_task_t task,void* out) { +void SD_task_dotty(SD_task_t task, void *out) +{ unsigned int counter; SD_dependency_t dependency; - fprintf(out, " T%p [label=\"%.20s\"",task, task->name); - switch(task->kind){ - case SD_TASK_COMM_E2E: - fprintf(out,", shape=box"); - break; - case SD_TASK_COMP_SEQ: - fprintf(out,", shape=circle"); - break; - default: - xbt_die("Unknown task type!"); + fprintf(out, " T%p [label=\"%.20s\"", task, task->name); + switch (task->kind) { + case SD_TASK_COMM_E2E: + fprintf(out, ", shape=box"); + break; + case SD_TASK_COMP_SEQ: + fprintf(out, ", shape=circle"); + break; + default: + xbt_die("Unknown task type!"); } - fprintf(out,"];\n"); - xbt_dynar_foreach(task->tasks_before,counter,dependency) { - fprintf(out," T%p -> T%p;\n",dependency->src, dependency->dst); + fprintf(out, "];\n"); + xbt_dynar_foreach(task->tasks_before, counter, dependency) { + fprintf(out, " T%p -> T%p;\n", dependency->src, dependency->dst); } } @@ -413,8 +419,8 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED or SD_RUNNABLE", SD_task_get_name(dst)); - DEBUG2("SD_task_dependency_add: src = %s, dst = %s", SD_task_get_name(src), - SD_task_get_name(dst)); + DEBUG2("SD_task_dependency_add: src = %s, dst = %s", + SD_task_get_name(src), SD_task_get_name(dst)); for (i = 0; i < length && !found; i++) { xbt_dynar_get_cpy(dynar, i, &dependency); found = (dependency->dst == dst); @@ -429,7 +435,7 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src, dependency = xbt_new(s_SD_dependency_t, 1); - dependency->name = xbt_strdup(name); /* xbt_strdup is cleaver enough to deal with NULL args itself */ + dependency->name = xbt_strdup(name); /* xbt_strdup is cleaver enough to deal with NULL args itself */ dependency->data = data; dependency->src = src; dependency->dst = dst; @@ -444,8 +450,9 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src, /* if the task was runnable, then dst->tasks_before is not empty anymore, so we must go back to state SD_SCHEDULED */ if (__SD_task_is_runnable(dst)) { - DEBUG1("SD_task_dependency_add: %s was runnable and becomes scheduled!", - SD_task_get_name(dst)); + DEBUG1 + ("SD_task_dependency_add: %s was runnable and becomes scheduled!", + SD_task_get_name(dst)); __SD_task_set_state(dst, SD_SCHEDULED); } @@ -468,11 +475,13 @@ int SD_task_dependency_exists(SD_task_t src, SD_task_t dst) SD_dependency_t dependency; SD_CHECK_INIT_DONE(); - xbt_assert0(src != NULL || dst != NULL, "Invalid parameter: both src and dst are NULL"); + xbt_assert0(src != NULL + || dst != NULL, + "Invalid parameter: both src and dst are NULL"); if (src) { if (dst) { - xbt_dynar_foreach(src->tasks_after,counter,dependency) { + xbt_dynar_foreach(src->tasks_after, counter, dependency) { if (dependency->dst == dst) return 1; } @@ -544,15 +553,15 @@ void SD_task_dependency_remove(SD_task_t src, SD_task_t dst) /* if the task was scheduled and dst->tasks_before is empty now, we can make it runnable */ - if (dst->unsatisfied_dependencies == 0){ - if (__SD_task_is_scheduled(dst)) - __SD_task_set_state(dst, SD_RUNNABLE); - else - __SD_task_set_state(dst, SD_SCHEDULABLE); - } + if (dst->unsatisfied_dependencies == 0) { + if (__SD_task_is_scheduled(dst)) + __SD_task_set_state(dst, SD_RUNNABLE); + else + __SD_task_set_state(dst, SD_SCHEDULABLE); + } - if (dst->is_not_ready == 0) - __SD_task_set_state(dst, SD_SCHEDULABLE); + if (dst->is_not_ready == 0) + __SD_task_set_state(dst, SD_SCHEDULABLE); /* __SD_print_dependencies(src); __SD_print_dependencies(dst); */ @@ -596,9 +605,13 @@ void *SD_task_dependency_get_data(SD_task_t src, SD_task_t dst) static void __SD_print_watch_points(SD_task_t task) { static const int state_masks[] = - { SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNING, SD_RUNNABLE, SD_DONE, SD_FAILED }; + { SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNING, SD_RUNNABLE, SD_DONE, + SD_FAILED + }; static const char *state_names[] = - { "schedulable", "scheduled", "running", "runnable", "done", "failed" }; + { "schedulable", "scheduled", "running", "runnable", "done", + "failed" + }; int i; INFO2("Task '%s' watch points (%x): ", SD_task_get_name(task), @@ -669,15 +682,16 @@ void SD_task_unwatch(SD_task_t task, e_SD_task_state_t state) */ double SD_task_get_execution_time(SD_task_t task, int workstation_nb, - const SD_workstation_t * workstation_list, + const SD_workstation_t * + workstation_list, const double *computation_amount, const double *communication_amount) { double time, max_time = 0.0; int i, j; SD_CHECK_INIT_DONE(); - xbt_assert0(task != NULL && workstation_nb > 0 && workstation_list != NULL, - "Invalid parameter"); + xbt_assert0(task != NULL && workstation_nb > 0 + && workstation_list != NULL, "Invalid parameter"); /* the task execution time is the maximum execution time of the parallel tasks */ @@ -686,16 +700,16 @@ double SD_task_get_execution_time(SD_task_t task, if (computation_amount != NULL) time = SD_workstation_get_computation_time(workstation_list[i], - computation_amount[i]); + computation_amount[i]); if (communication_amount != NULL) for (j = 0; j < workstation_nb; j++) { time += SD_route_get_communication_time(workstation_list[i], - workstation_list[j], - communication_amount[i * - workstation_nb + - j]); + workstation_list[j], + communication_amount[i * + workstation_nb + + j]); } if (time > max_time) { @@ -704,14 +718,16 @@ double SD_task_get_execution_time(SD_task_t task, } return max_time; } -static XBT_INLINE void SD_task_do_schedule(SD_task_t task) { + +static XBT_INLINE void SD_task_do_schedule(SD_task_t task) +{ SD_CHECK_INIT_DONE(); - if (!__SD_task_is_not_scheduled(task) && !__SD_task_is_schedulable(task) ) - THROW1(arg_error, 0, "Task '%s' has already been scheduled", - SD_task_get_name(task)); + if (!__SD_task_is_not_scheduled(task) && !__SD_task_is_schedulable(task)) + THROW1(arg_error, 0, "Task '%s' has already been scheduled", + SD_task_get_name(task)); - /* update the task state */ + /* update the task state */ if (task->unsatisfied_dependencies == 0) __SD_task_set_state(task, SD_RUNNABLE); else @@ -749,7 +765,7 @@ void SD_task_schedule(SD_task_t task, int workstation_count, if (computation_amount) { task->computation_amount = xbt_new(double, workstation_count); memcpy(task->computation_amount, computation_amount, - sizeof(double) * workstation_count); + sizeof(double) * workstation_count); } else { task->computation_amount = NULL; } @@ -758,7 +774,7 @@ void SD_task_schedule(SD_task_t task, int workstation_count, if (communication_amount) { task->communication_amount = xbt_new(double, communication_nb); memcpy(task->communication_amount, communication_amount, - sizeof(double) * communication_nb); + sizeof(double) * communication_nb); } else { task->communication_amount = NULL; } @@ -769,6 +785,7 @@ void SD_task_schedule(SD_task_t task, int workstation_count, SD_task_do_schedule(task); } + /** * \brief Unschedules a task * @@ -792,17 +809,17 @@ void SD_task_unschedule(SD_task_t task) "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED", SD_task_get_name(task)); - if (__SD_task_is_scheduled_or_runnable(task) /* if the task is scheduled or runnable */ - && task->kind == SD_TASK_NOT_TYPED) /* Don't free scheduling data for typed tasks */ + if (__SD_task_is_scheduled_or_runnable(task) /* if the task is scheduled or runnable */ + &&task->kind == SD_TASK_NOT_TYPED) /* Don't free scheduling data for typed tasks */ __SD_task_destroy_scheduling_data(task); if (__SD_task_is_running(task)) /* the task should become SD_FAILED */ surf_workstation_model->action_cancel(task->surf_action); else { - if (task->unsatisfied_dependencies == 0) - __SD_task_set_state(task, SD_SCHEDULABLE); - else - __SD_task_set_state(task, SD_NOT_SCHEDULED); + if (task->unsatisfied_dependencies == 0) + __SD_task_set_state(task, SD_SCHEDULABLE); + else + __SD_task_set_state(task, SD_NOT_SCHEDULED); } task->remains = task->amount; task->start_time = -1.0; @@ -813,7 +830,8 @@ void SD_task_unschedule(SD_task_t task) static void __SD_task_destroy_scheduling_data(SD_task_t task) { SD_CHECK_INIT_DONE(); - if (!__SD_task_is_scheduled_or_runnable(task) && !__SD_task_is_in_fifo(task)) + if (!__SD_task_is_scheduled_or_runnable(task) + && !__SD_task_is_in_fifo(task)) THROW1(arg_error, 0, "Task '%s' must be SD_SCHEDULED, SD_RUNNABLE or SD_IN_FIFO", SD_task_get_name(task)); @@ -839,7 +857,8 @@ void __SD_task_really_run(SD_task_t task) "Task '%s' is not runnable or in a fifo! Task state: %d", SD_task_get_name(task), SD_task_get_state(task)); xbt_assert1(task->workstation_list != NULL, - "Task '%s': workstation_list is NULL!", SD_task_get_name(task)); + "Task '%s': workstation_list is NULL!", + SD_task_get_name(task)); @@ -870,34 +889,37 @@ void __SD_task_really_run(SD_task_t task) #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) task->surf_action = NULL; - if ((task->workstation_nb == 1) && (cost_or_zero(task->communication_amount,0) == 0.0)) { + if ((task->workstation_nb == 1) + && (cost_or_zero(task->communication_amount, 0) == 0.0)) { task->surf_action = - surf_workstation_model->extension. - workstation.execute(surf_workstations[0], cost_or_zero(task->computation_amount,0)); + surf_workstation_model->extension. + workstation.execute(surf_workstations[0], + cost_or_zero(task->computation_amount, 0)); } else if ((task->workstation_nb == 1) - && (cost_or_zero(task->computation_amount,0) == 0.0)) { + && (cost_or_zero(task->computation_amount, 0) == 0.0)) { task->surf_action = - surf_workstation_model->extension. - workstation.communicate(surf_workstations[0], surf_workstations[0], - cost_or_zero(task->communication_amount,0), task->rate); + surf_workstation_model->extension. + workstation.communicate(surf_workstations[0], surf_workstations[0], + cost_or_zero(task->communication_amount, + 0), task->rate); } else if ((task->workstation_nb == 2) - && (cost_or_zero(task->computation_amount,0) == 0.0) - && (cost_or_zero(task->computation_amount,1) == 0.0)) { + && (cost_or_zero(task->computation_amount, 0) == 0.0) + && (cost_or_zero(task->computation_amount, 1) == 0.0)) { int nb = 0; double value = 0.0; for (i = 0; i < task->workstation_nb * task->workstation_nb; i++) { - if (cost_or_zero(task->communication_amount,i) > 0.0) { + if (cost_or_zero(task->communication_amount, i) > 0.0) { nb++; - value = cost_or_zero(task->communication_amount,i); + value = cost_or_zero(task->communication_amount, i); } } if (nb == 1) { task->surf_action = - surf_workstation_model->extension. - workstation.communicate(surf_workstations[0], surf_workstations[1], - value, task->rate); + surf_workstation_model->extension. + workstation.communicate(surf_workstations[0], + surf_workstations[1], value, task->rate); } } #undef cost_or_zero @@ -913,11 +935,12 @@ void __SD_task_really_run(SD_task_t task) sizeof(double) * task->workstation_nb * task->workstation_nb); task->surf_action = - surf_workstation_model->extension. - workstation.execute_parallel_task(task->workstation_nb, - surf_workstations, computation_amount, - communication_amount, task->amount, - task->rate); + surf_workstation_model->extension. + workstation.execute_parallel_task(task->workstation_nb, + surf_workstations, + computation_amount, + communication_amount, + task->amount, task->rate); } else { xbt_free(surf_workstations); } @@ -927,7 +950,8 @@ void __SD_task_really_run(SD_task_t task) DEBUG1("surf_action = %p", task->surf_action); #ifdef HAVE_TRACING - if (task->category) TRACE_surf_action(task->surf_action, task->category); + if (task->category) + TRACE_surf_action(task->surf_action, task->category); #endif __SD_task_destroy_scheduling_data(task); /* now the scheduling data are not useful anymore */ @@ -958,8 +982,8 @@ int __SD_task_try_to_run(SD_task_t task) for (i = 0; i < task->workstation_nb; i++) { - can_start = can_start && - !__SD_workstation_is_busy(task->workstation_list[i]); + can_start = can_start && + !__SD_workstation_is_busy(task->workstation_list[i]); } DEBUG2("Task '%s' can start: %d", SD_task_get_name(task), can_start); @@ -969,7 +993,8 @@ int __SD_task_try_to_run(SD_task_t task) workstation = task->workstation_list[i]; if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { DEBUG2("Pushing task '%s' in the fifo of workstation '%s'", - SD_task_get_name(task), SD_workstation_get_name(workstation)); + SD_task_get_name(task), + SD_workstation_get_name(workstation)); xbt_fifo_push(workstation->task_fifo, task); } } @@ -1005,7 +1030,8 @@ void __SD_task_just_done(SD_task_t task) "The task must be running! Task state: %d", SD_task_get_state(task)); xbt_assert1(task->workstation_list != NULL, - "Task '%s': workstation_list is NULL!", SD_task_get_name(task)); + "Task '%s': workstation_list is NULL!", + SD_task_get_name(task)); candidates = xbt_new(SD_task_t, 8); @@ -1036,8 +1062,8 @@ void __SD_task_just_done(SD_task_t task) DEBUG0("Getting candidate in fifo"); candidate = - xbt_fifo_get_item_content(xbt_fifo_get_first_item - (workstation->task_fifo)); + xbt_fifo_get_item_content(xbt_fifo_get_first_item + (workstation->task_fifo)); if (candidate != NULL) { DEBUG1("Candidate: '%s'", SD_task_get_name(candidate)); @@ -1060,7 +1086,8 @@ void __SD_task_just_done(SD_task_t task) if (candidate_nb == candidate_capacity) { candidate_capacity *= 2; candidates = - xbt_realloc(candidates, sizeof(SD_task_t) * candidate_capacity); + xbt_realloc(candidates, + sizeof(SD_task_t) * candidate_capacity); } /* register the candidate */ @@ -1089,10 +1116,10 @@ void __SD_task_just_done(SD_task_t task) /* I can start on this workstation if the workstation is shared or if I am the first task in the fifo */ - can_start = workstation->access_mode == SD_WORKSTATION_SHARED_ACCESS || - candidate == - xbt_fifo_get_item_content(xbt_fifo_get_first_item - (workstation->task_fifo)); + can_start = workstation->access_mode == SD_WORKSTATION_SHARED_ACCESS + || candidate == + xbt_fifo_get_item_content(xbt_fifo_get_first_item + (workstation->task_fifo)); } DEBUG2("Candidate '%s' can start: %d", SD_task_get_name(candidate), @@ -1107,7 +1134,8 @@ void __SD_task_just_done(SD_task_t task) if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { candidate = xbt_fifo_shift(workstation->task_fifo); /* the return value is stored just for debugging */ DEBUG1("Head of the fifo: '%s'", - (candidate != NULL) ? SD_task_get_name(candidate) : "NULL"); + (candidate != + NULL) ? SD_task_get_name(candidate) : "NULL"); xbt_assert0(candidate == candidates[i], "Error in __SD_task_just_done: bad first task in the fifo"); } @@ -1119,11 +1147,12 @@ void __SD_task_just_done(SD_task_t task) __SD_task_really_run(candidate); DEBUG4 - ("Calling __SD_task_is_running: task '%s', state set: %p, running_task_set: %p, is running: %d", - SD_task_get_name(candidate), candidate->state_set, - sd_global->running_task_set, __SD_task_is_running(candidate)); + ("Calling __SD_task_is_running: task '%s', state set: %p, running_task_set: %p, is running: %d", + SD_task_get_name(candidate), candidate->state_set, + sd_global->running_task_set, __SD_task_is_running(candidate)); xbt_assert2(__SD_task_is_running(candidate), - "Bad state of task '%s': %d", SD_task_get_name(candidate), + "Bad state of task '%s': %d", + SD_task_get_name(candidate), SD_task_get_state(candidate)); DEBUG0("Okay, the task is running."); @@ -1165,7 +1194,8 @@ double SD_task_get_start_time(SD_task_t task) SD_CHECK_INIT_DONE(); xbt_assert0(task != NULL, "Invalid parameter"); if (task->surf_action) - return surf_workstation_model->action_get_start_time(task->surf_action); + return surf_workstation_model-> + action_get_start_time(task->surf_action); else return task->start_time; } @@ -1187,7 +1217,8 @@ double SD_task_get_finish_time(SD_task_t task) xbt_assert0(task != NULL, "Invalid parameter"); if (task->surf_action) /* should never happen as actions are destroyed right after their completion */ - return surf_workstation_model->action_get_finish_time(task->surf_action); + return surf_workstation_model-> + action_get_finish_time(task->surf_action); else return task->finish_time; } @@ -1211,7 +1242,7 @@ void SD_task_destroy(SD_task_t task) /* if the task was scheduled or runnable we have to free the scheduling parameters */ if (__SD_task_is_scheduled_or_runnable(task)) __SD_task_destroy_scheduling_data(task); - xbt_swag_remove(task,task->state_set); + xbt_swag_remove(task, task->state_set); if (task->name != NULL) xbt_free(task->name); @@ -1229,7 +1260,7 @@ void SD_task_destroy(SD_task_t task) xbt_free(task->computation_amount); #ifdef HAVE_TRACING - TRACE_sd_task_destroy (task); + TRACE_sd_task_destroy(task); #endif xbt_dynar_free(&task->tasks_before); @@ -1242,14 +1273,18 @@ void SD_task_destroy(SD_task_t task) } -static XBT_INLINE SD_task_t SD_task_create_sized(const char*name,void*data,double amount,int ws_count) { - SD_task_t task = SD_task_create(name,data,amount); - task->communication_amount = xbt_new0(double,ws_count*ws_count); - task->computation_amount = xbt_new0(double,ws_count); +static XBT_INLINE SD_task_t SD_task_create_sized(const char *name, + void *data, double amount, + int ws_count) +{ + SD_task_t task = SD_task_create(name, data, amount); + task->communication_amount = xbt_new0(double, ws_count * ws_count); + task->computation_amount = xbt_new0(double, ws_count); task->workstation_nb = ws_count; - task->workstation_list = xbt_new0(SD_workstation_t,ws_count); + task->workstation_list = xbt_new0(SD_workstation_t, ws_count); return task; } + /** @brief create a end-to-end communication task that can then be auto-scheduled * * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This @@ -1260,12 +1295,15 @@ static XBT_INLINE SD_task_t SD_task_create_sized(const char*name,void*data,doubl * A end-to-end communication must be scheduled on 2 hosts, and the amount * specified at creation is sent from hosts[0] to hosts[1]. */ -SD_task_t SD_task_create_comm_e2e(const char*name, void *data, double amount) { - SD_task_t res = SD_task_create_sized(name,data,amount,2); +SD_task_t SD_task_create_comm_e2e(const char *name, void *data, + double amount) +{ + SD_task_t res = SD_task_create_sized(name, data, amount, 2); res->communication_amount[2] = amount; - res->kind=SD_TASK_COMM_E2E; + res->kind = SD_TASK_COMM_E2E; return res; } + /** @brief create a sequential computation task that can then be auto-scheduled * * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This @@ -1276,10 +1314,12 @@ SD_task_t SD_task_create_comm_e2e(const char*name, void *data, double amount) { * A sequential computation must be scheduled on 1 host, and the amount * specified at creation to be run on hosts[0]. */ -SD_task_t SD_task_create_comp_seq(const char*name, void *data, double amount) { - SD_task_t res = SD_task_create_sized(name,data,amount,1); - res->computation_amount[0]=amount; - res->kind=SD_TASK_COMP_SEQ; +SD_task_t SD_task_create_comp_seq(const char *name, void *data, + double amount) +{ + SD_task_t res = SD_task_create_sized(name, data, amount, 1); + res->computation_amount[0] = amount; + res->kind = SD_TASK_COMP_SEQ; return res; } @@ -1302,84 +1342,98 @@ SD_task_t SD_task_create_comp_seq(const char*name, void *data, double amount) { * - parallel tasks with no internal communication (one kind per speedup model such as amdal) * - idem+ internal communication. Task type not enough since we cannot store comm cost alongside to comp one) */ -void SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list) { +void SD_task_schedulev(SD_task_t task, int count, + const SD_workstation_t * list) +{ int i; SD_dependency_t dep; unsigned int cpt; - xbt_assert1(task->kind != 0,"Task %s is not typed. Cannot automatically schedule it.",SD_task_get_name(task)); - switch(task->kind) { + xbt_assert1(task->kind != 0, + "Task %s is not typed. Cannot automatically schedule it.", + SD_task_get_name(task)); + switch (task->kind) { case SD_TASK_COMM_E2E: case SD_TASK_COMP_SEQ: - xbt_assert(task->workstation_nb==count); - for (i=0;iworkstation_list[i]=list[i]; + xbt_assert(task->workstation_nb == count); + for (i = 0; i < count; i++) + task->workstation_list[i] = list[i]; SD_task_do_schedule(task); break; default: xbt_die(bprintf("Kind of task %s not supported by SD_task_schedulev()", - SD_task_get_name(task))); + SD_task_get_name(task))); } if (task->kind == SD_TASK_COMM_E2E) { VERB4("Schedule comm task %s between %s -> %s. It costs %.f bytes", - SD_task_get_name(task), - SD_workstation_get_name(task->workstation_list[0]),SD_workstation_get_name(task->workstation_list[1]), - task->communication_amount[2]); + SD_task_get_name(task), + SD_workstation_get_name(task->workstation_list[0]), + SD_workstation_get_name(task->workstation_list[1]), + task->communication_amount[2]); } /* Iterate over all childs and parent being COMM_E2E to say where I am located (and start them if runnable) */ if (task->kind == SD_TASK_COMP_SEQ) { VERB3("Schedule computation task %s on %s. It costs %.f flops", - SD_task_get_name(task),SD_workstation_get_name(task->workstation_list[0]), - task->computation_amount[0]); + SD_task_get_name(task), + SD_workstation_get_name(task->workstation_list[0]), + task->computation_amount[0]); - xbt_dynar_foreach(task->tasks_before,cpt,dep) { + xbt_dynar_foreach(task->tasks_before, cpt, dep) { SD_task_t before = dep->src; if (before->kind == SD_TASK_COMM_E2E) { before->workstation_list[1] = task->workstation_list[0]; if (before->workstation_list[0] && - (__SD_task_is_schedulable(before) || __SD_task_is_not_scheduled(before))) { + (__SD_task_is_schedulable(before) + || __SD_task_is_not_scheduled(before))) { SD_task_do_schedule(before); - VERB4("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", - SD_task_get_name(before), - SD_workstation_get_name(before->workstation_list[0]),SD_workstation_get_name(before->workstation_list[1]), - before->communication_amount[2]); + VERB4 + ("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", + SD_task_get_name(before), + SD_workstation_get_name(before->workstation_list[0]), + SD_workstation_get_name(before->workstation_list[1]), + before->communication_amount[2]); } } } - xbt_dynar_foreach(task->tasks_after,cpt,dep) { + xbt_dynar_foreach(task->tasks_after, cpt, dep) { SD_task_t after = dep->dst; if (after->kind == SD_TASK_COMM_E2E) { after->workstation_list[0] = task->workstation_list[0]; //J-N : Why did you comment on these line (this comment add a bug I think)? - if (after->workstation_list[1] && (__SD_task_is_not_scheduled(after) || - __SD_task_is_schedulable(after))) { + if (after->workstation_list[1] + && (__SD_task_is_not_scheduled(after) + || __SD_task_is_schedulable(after))) { SD_task_do_schedule(after); - VERB4("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", - SD_task_get_name(after), - SD_workstation_get_name(after->workstation_list[0]),SD_workstation_get_name(after->workstation_list[1]), - after->communication_amount[2]); + VERB4 + ("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", + SD_task_get_name(after), + SD_workstation_get_name(after->workstation_list[0]), + SD_workstation_get_name(after->workstation_list[1]), + after->communication_amount[2]); } } } } } + /** @brief autoschedule a task on a list of workstations * * This function is very similar to SD_task_schedulev(), * but takes the list of workstations to schedule onto as separate parameters. * It builds a proper vector of workstations and then call SD_task_schedulev() */ -void SD_task_schedulel(SD_task_t task, int count, ...) { +void SD_task_schedulel(SD_task_t task, int count, ...) +{ va_list ap; - SD_workstation_t *list=xbt_new(SD_workstation_t,count); + SD_workstation_t *list = xbt_new(SD_workstation_t, count); int i; - va_start(ap,count); - for (i=0;iworkstation_list == NULL) { /* this is the first time the function is called */ sd_global->workstation_list = - xbt_new(SD_workstation_t, sd_global->workstation_count); + xbt_new(SD_workstation_t, sd_global->workstation_count); i = 0; xbt_dict_foreach(sd_global->workstations, cursor, key, data) { @@ -166,7 +167,8 @@ xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation) SD_CHECK_INIT_DONE(); xbt_assert0((workstation != NULL), "Invalid parameters"); - return surf_workstation_model->extension.workstation.get_properties(workstation->surf_workstation); + return surf_workstation_model->extension. + workstation.get_properties(workstation->surf_workstation); } @@ -181,7 +183,8 @@ xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation) * \return a new array of \ref SD_link_t representating the route between these two workstations * \see SD_route_get_size(), SD_link_t */ -const SD_link_t *SD_route_get_list(SD_workstation_t src, SD_workstation_t dst) +const SD_link_t *SD_route_get_list(SD_workstation_t src, + SD_workstation_t dst) { void *surf_src; void *surf_dst; @@ -199,12 +202,14 @@ const SD_link_t *SD_route_get_list(SD_workstation_t src, SD_workstation_t dst) surf_src = src->surf_workstation; surf_dst = dst->surf_workstation; - surf_route = surf_workstation_model->extension.workstation.get_route(surf_src,surf_dst); + surf_route = + surf_workstation_model->extension.workstation.get_route(surf_src, + surf_dst); xbt_dynar_foreach(surf_route, cpt, surf_link) { link_name = surf_resource_name(surf_link); sd_global->recyclable_route[cpt] = - xbt_dict_get(sd_global->links, link_name); + xbt_dict_get(sd_global->links, link_name); } return sd_global->recyclable_route; } @@ -220,8 +225,9 @@ const SD_link_t *SD_route_get_list(SD_workstation_t src, SD_workstation_t dst) int SD_route_get_size(SD_workstation_t src, SD_workstation_t dst) { SD_CHECK_INIT_DONE(); - return xbt_dynar_length(surf_workstation_model->extension.workstation.get_route( - src->surf_workstation,dst->surf_workstation)); + return xbt_dynar_length(surf_workstation_model->extension. + workstation.get_route(src->surf_workstation, + dst->surf_workstation)); } /** @@ -236,7 +242,7 @@ double SD_workstation_get_power(SD_workstation_t workstation) SD_CHECK_INIT_DONE(); xbt_assert0(workstation != NULL, "Invalid parameter"); return surf_workstation_model->extension.workstation. - get_speed(workstation->surf_workstation, 1.0); + get_speed(workstation->surf_workstation, 1.0); } /** @@ -251,7 +257,7 @@ double SD_workstation_get_available_power(SD_workstation_t workstation) SD_CHECK_INIT_DONE(); xbt_assert0(workstation != NULL, "Invalid parameter"); return surf_workstation_model->extension. - workstation.get_available_speed(workstation->surf_workstation); + workstation.get_available_speed(workstation->surf_workstation); } /** @@ -397,8 +403,8 @@ double SD_route_get_communication_time(SD_workstation_t src, * * \see SD_workstation_set_access_mode(), e_SD_workstation_access_mode_t */ -e_SD_workstation_access_mode_t SD_workstation_get_access_mode(SD_workstation_t - workstation) +e_SD_workstation_access_mode_t +SD_workstation_get_access_mode(SD_workstation_t workstation) { SD_CHECK_INIT_DONE(); xbt_assert0(workstation != NULL, "Invalid parameter"); @@ -442,15 +448,15 @@ void SD_workstation_set_access_mode(SD_workstation_t workstation, } /* Returns whether a task can start now on a workstation. - *//* - int __SD_workstation_can_start(SD_workstation_t workstation, SD_task_t task) { - SD_CHECK_INIT_DONE(); - xbt_assert0(workstation != NULL && task != NULL, "Invalid parameter"); + *//* + int __SD_workstation_can_start(SD_workstation_t workstation, SD_task_t task) { + SD_CHECK_INIT_DONE(); + xbt_assert0(workstation != NULL && task != NULL, "Invalid parameter"); - return !__SD_workstation_is_busy(workstation) && - (xbt_fifo_size(workstation->task_fifo) == 0) || xbt_fifo_get_first_item(workstation->task_fifo) == task); - } - */ + return !__SD_workstation_is_busy(workstation) && + (xbt_fifo_size(workstation->task_fifo) == 0) || xbt_fifo_get_first_item(workstation->task_fifo) == task); + } + */ /* Returns whether a workstation is busy. A workstation is busy is it is * in sequential mode and a task is running on it or the fifo is not empty. @@ -461,17 +467,19 @@ int __SD_workstation_is_busy(SD_workstation_t workstation) xbt_assert0(workstation != NULL, "Invalid parameter"); DEBUG4 - ("Workstation '%s' access mode: '%s', current task: %s, fifo size: %d", - SD_workstation_get_name(workstation), - (workstation->access_mode == - SD_WORKSTATION_SHARED_ACCESS) ? "SHARED" : "FIFO", - (workstation->current_task ? SD_task_get_name(workstation->current_task) - : "none"), - (workstation->task_fifo ? xbt_fifo_size(workstation->task_fifo) : 0)); + ("Workstation '%s' access mode: '%s', current task: %s, fifo size: %d", + SD_workstation_get_name(workstation), + (workstation->access_mode == + SD_WORKSTATION_SHARED_ACCESS) ? "SHARED" : "FIFO", + (workstation->current_task ? + SD_task_get_name(workstation->current_task) + : "none"), + (workstation->task_fifo ? xbt_fifo_size(workstation->task_fifo) : + 0)); return workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS && - (workstation->current_task != NULL - || xbt_fifo_size(workstation->task_fifo) > 0); + (workstation->current_task != NULL + || xbt_fifo_size(workstation->task_fifo) > 0); } /* Destroys a workstation. @@ -501,9 +509,9 @@ SD_task_t SD_workstation_get_current_task(SD_workstation_t workstation) { SD_CHECK_INIT_DONE(); xbt_assert0(workstation != NULL, "Invalid parameter"); - xbt_assert0(workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS, - "Access mode must be set to SD_WORKSTATION_SEQUENTIAL_ACCESS" - " to use this function"); - + xbt_assert0(workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS, + "Access mode must be set to SD_WORKSTATION_SEQUENTIAL_ACCESS" + " to use this function"); + return (workstation->current_task); } diff --git a/src/simgrid_units_main.c b/src/simgrid_units_main.c index 50cccda206..1c497acbe8 100644 --- a/src/simgrid_units_main.c +++ b/src/simgrid_units_main.c @@ -101,12 +101,12 @@ int main(int argc, char *argv[]) { xbt_test_suite_push(suite, "int", test_dynar_int, "Dynars of integers"); xbt_test_suite_push(suite, "double", test_dynar_double, "Dynars of doubles"); xbt_test_suite_push(suite, "string", test_dynar_string, "Dynars of strings"); - xbt_test_suite_push(suite, "synchronized int", test_dynar_sync_int, "Synchronized dynars of integers"); + xbt_test_suite_push(suite, "synchronized int", test_dynar_sync_int, "Synchronized dynars of integers"); /* SGU: END FILE */ /* SGU: BEGIN FILE xbt/dict.c */ suite = xbt_test_suite_by_name("dict","Dict data container"); - xbt_test_suite_push(suite, "basic", test_dict_basic, "Basic usage: change, retrieve, traverse"); + xbt_test_suite_push(suite, "basic", test_dict_basic, "Basic usage: change, retrieve, traverse"); xbt_test_suite_push(suite, "remove", test_dict_remove, "Removing some values"); xbt_test_suite_push(suite, "nulldata", test_dict_nulldata, "NULL data management"); xbt_test_suite_push(suite, "dicti", test_dict_scalar, "Scalar data and key management"); @@ -129,13 +129,13 @@ int main(int argc, char *argv[]) { /* SGU: BEGIN FILE xbt/xbt_str.c */ suite = xbt_test_suite_by_name("xbt_str","String Handling"); - xbt_test_suite_push(suite, "xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted"); - xbt_test_suite_push(suite, "xbt_str_split_str", test_split_str, "test the function xbt_str_split_str"); + xbt_test_suite_push(suite, "xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted"); + xbt_test_suite_push(suite, "xbt_str_split_str", test_split_str, "test the function xbt_str_split_str"); /* SGU: END FILE */ /* SGU: BEGIN FILE xbt/xbt_strbuff.c */ suite = xbt_test_suite_by_name("xbt_strbuff","String Buffers"); - xbt_test_suite_push(suite, "xbt_strbuff_substitute", test_strbuff_substitute, "test the function xbt_strbuff_substitute"); + xbt_test_suite_push(suite, "xbt_strbuff_substitute", test_strbuff_substitute, "test the function xbt_strbuff_substitute"); /* SGU: END FILE */ /* SGU: BEGIN FILE xbt/xbt_sha.c */ diff --git a/src/simix/private.h b/src/simix/private.h index 0a3e27ca68..568a9fc829 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -26,7 +26,7 @@ @ingroup m_datatypes_management_details */ typedef struct s_smx_host { char *name; /**< @brief host name if any */ - void *host; /* SURF modeling */ + void *host; /* SURF modeling */ xbt_swag_t process_list; void *data; /**< @brief user data */ } s_smx_host_t; @@ -55,27 +55,27 @@ extern SIMIX_Global_t simix_global; /** @brief Process datatype @ingroup m_datatypes_management_details @{ */ - typedef struct s_smx_process { - s_xbt_swag_hookup_t process_hookup; - s_xbt_swag_hookup_t synchro_hookup; /* process_to_run or mutex->sleeping and co */ - s_xbt_swag_hookup_t host_proc_hookup; - s_xbt_swag_hookup_t destroy_hookup; - - char *name; /**< @brief process name if any */ - smx_host_t smx_host; /* the host on which the process is running */ - smx_context_t context; /* the context that executes the scheduler function */ - ex_ctx_t *exception; - int blocked : 1; - int suspended : 1; - int iwannadie : 1; - smx_mutex_t mutex; /* mutex on which the process is blocked */ - smx_cond_t cond; /* cond on which the process is blocked */ - smx_sem_t sem; /* semaphore on which the process is blocked */ - smx_action_t waiting_action; - xbt_dict_t properties; - void *data; /* kept for compatibility, it should be replaced with moddata */ - - } s_smx_process_t; +typedef struct s_smx_process { + s_xbt_swag_hookup_t process_hookup; + s_xbt_swag_hookup_t synchro_hookup; /* process_to_run or mutex->sleeping and co */ + s_xbt_swag_hookup_t host_proc_hookup; + s_xbt_swag_hookup_t destroy_hookup; + + char *name; /**< @brief process name if any */ + smx_host_t smx_host; /* the host on which the process is running */ + smx_context_t context; /* the context that executes the scheduler function */ + ex_ctx_t *exception; + int blocked:1; + int suspended:1; + int iwannadie:1; + smx_mutex_t mutex; /* mutex on which the process is blocked */ + smx_cond_t cond; /* cond on which the process is blocked */ + smx_sem_t sem; /* semaphore on which the process is blocked */ + smx_action_t waiting_action; + xbt_dict_t properties; + void *data; /* kept for compatibility, it should be replaced with moddata */ + +} s_smx_process_t; /** @} */ typedef struct s_smx_process_arg { @@ -102,17 +102,17 @@ typedef struct s_smx_rvpoint { char *name; smx_mutex_t read; smx_mutex_t write; - xbt_fifo_t comm_fifo; + xbt_fifo_t comm_fifo; void *data; } s_smx_rvpoint_t; typedef struct s_smx_comm { - smx_comm_type_t type; /* Type of the communication (comm_send,comm_recv) */ - smx_rdv_t rdv; /* Rendez-vous where the comm is queued */ - smx_sem_t sem; /* Semaphore associated to the surf simulation */ - int refcount; /* Number of processes involved in the cond */ + smx_comm_type_t type; /* Type of the communication (comm_send,comm_recv) */ + smx_rdv_t rdv; /* Rendez-vous where the comm is queued */ + smx_sem_t sem; /* Semaphore associated to the surf simulation */ + int refcount; /* Number of processes involved in the cond */ /* Surf action data */ smx_process_t src_proc; @@ -129,34 +129,37 @@ typedef struct s_smx_comm { size_t src_buff_size; size_t *dst_buff_size; char copied; - - void *data; /* User data associated to communication */ + + void *data; /* User data associated to communication */ } s_smx_comm_t; void SIMIX_network_copy_data(smx_comm_t comm); smx_comm_t SIMIX_communication_new(smx_comm_type_t type); static XBT_INLINE void SIMIX_communication_use(smx_comm_t comm); -static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t comm, double timeout); +static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t + comm, + double + timeout); static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_comm_t comm); static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_comm_t comm); /********************************* Action *************************************/ -typedef enum {ready, ongoing, done, failed} smx_action_state_t; +typedef enum { ready, ongoing, done, failed } smx_action_state_t; /** @brief Action datatype @ingroup m_datatypes_management_details */ typedef struct s_smx_action { char *name; /**< @brief action name if any */ - xbt_fifo_t cond_list; /*< conditional variables that must be signaled when the action finish. */ - xbt_fifo_t sem_list; /*< semaphores that must be signaled when the action finish. */ + xbt_fifo_t cond_list; /*< conditional variables that must be signaled when the action finish. */ + xbt_fifo_t sem_list; /*< semaphores that must be signaled when the action finish. */ void *data; /**< @brief user data */ int refcount; /**< @brief reference counter */ surf_action_t surf_action; /* SURF modeling of computation */ smx_host_t source; #ifdef HAVE_TRACING - long long int counter; /* simix action unique identifier for instrumentation */ - char *category; /* simix action category for instrumentation */ + long long int counter; /* simix action unique identifier for instrumentation */ + char *category; /* simix action category for instrumentation */ #endif } s_smx_action_t; @@ -170,7 +173,8 @@ extern int _simix_init_status; /* 0: beginning of time; FIXME: KILLME ? get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\ "Host failed, you cannot call this function.") -smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data); +smx_host_t __SIMIX_host_create(const char *name, void *workstation, + void *data); void __SIMIX_host_destroy(void *host); void __SIMIX_cond_wait(smx_cond_t cond); void __SIMIX_cond_display_actions(smx_cond_t cond); @@ -181,9 +185,10 @@ void __SIMIX_action_display_conditions(smx_action_t action); /* The following function pointer types describe the interface that any context factory should implement */ -typedef smx_context_t (*smx_pfn_context_factory_create_context_t) - (xbt_main_func_t, int, char**, void_f_pvoid_t, void*); -typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*); +typedef smx_context_t(*smx_pfn_context_factory_create_context_t) + (xbt_main_func_t, int, char **, void_f_pvoid_t, void *); +typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t + *); typedef void (*smx_pfn_context_free_t) (smx_context_t); typedef void (*smx_pfn_context_start_t) (smx_context_t); typedef void (*smx_pfn_context_stop_t) (smx_context_t); @@ -214,7 +219,8 @@ int SIMIX_context_select_factory(const char *name); /* Initializes a context factory from the name specified by the parameter name. * If the factory cannot be found, an exception is raised. */ -void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, const char *name); +void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, + const char *name); /* All factories init */ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory); @@ -254,13 +260,15 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory); * \param cleanup_func the function to call when the context stops * \param cleanup_arg the argument of the cleanup_func function */ -static XBT_INLINE smx_context_t SIMIX_context_new(xbt_main_func_t code, int argc, - char** argv, - void_f_pvoid_t cleanup_func, - void* cleanup_arg) { +static XBT_INLINE smx_context_t SIMIX_context_new(xbt_main_func_t code, + int argc, char **argv, + void_f_pvoid_t + cleanup_func, + void *cleanup_arg) +{ return (*(simix_global->context_factory->create_context)) - (code, argc, argv, cleanup_func, cleanup_arg); + (code, argc, argv, cleanup_func, cleanup_arg); } /** @@ -268,7 +276,8 @@ static XBT_INLINE smx_context_t SIMIX_context_new(xbt_main_func_t code, int argc * \param context the context to destroy * Argument must be stopped first -- runs in maestro context */ -static XBT_INLINE void SIMIX_context_free(smx_context_t context) { +static XBT_INLINE void SIMIX_context_free(smx_context_t context) +{ (*(simix_global->context_factory->free)) (context); } @@ -276,7 +285,8 @@ static XBT_INLINE void SIMIX_context_free(smx_context_t context) { * \brief stops the execution of a context * \param context to stop */ -static XBT_INLINE void SIMIX_context_stop(smx_context_t context) { +static XBT_INLINE void SIMIX_context_stop(smx_context_t context) +{ (*(simix_global->context_factory->stop)) (context); } diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index 6aebc61550..59129137ae 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -23,20 +23,22 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix, * \return A new SIMIX action * */ smx_action_t SIMIX_action_communicate(smx_host_t sender, - smx_host_t receiver, const char *name, - double size, double rate) + smx_host_t receiver, + const char *name, double size, + double rate) { smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension.workstation.get_state(sender->host) != - SURF_RESOURCE_ON) { - THROW1(network_error, 0, "Host %s failed, you cannot call this function", - sender->name); + if (surf_workstation_model->extension. + workstation.get_state(sender->host) != SURF_RESOURCE_ON) { + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", sender->name); } if (surf_workstation_model->extension.workstation. get_state(receiver->host) != SURF_RESOURCE_ON) { - THROW1(network_error, 0, "Host %s failed, you cannot call this function", + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", receiver->name); } @@ -53,9 +55,8 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, #endif act->surf_action = - surf_workstation_model->extension.workstation.communicate(sender->host, - receiver->host, - size, rate); + surf_workstation_model->extension.workstation. + communicate(sender->host, receiver->host, size, rate); surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create communicate action %p", act); @@ -76,8 +77,8 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension.workstation.get_state(host->host) != - SURF_RESOURCE_ON) { + if (surf_workstation_model->extension. + workstation.get_state(host->host) != SURF_RESOURCE_ON) { THROW1(host_error, 0, "Host %s failed, you cannot call this function", host->name); } @@ -96,14 +97,15 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, /* set execute */ act->surf_action = - surf_workstation_model->extension.workstation.execute(host->host, amount); + surf_workstation_model->extension.workstation.execute(host->host, + amount); surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create execute action %p", act); #ifdef HAVE_TRACING - TRACE_smx_action_execute (act); - TRACE_surf_action (act->surf_action, act->category); + TRACE_smx_action_execute(act); + TRACE_surf_action(act->surf_action, act->category); #endif return act; } @@ -124,8 +126,8 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) smx_action_t act; /* check if the host is active */ - if (surf_workstation_model->extension.workstation.get_state(host->host) != - SURF_RESOURCE_ON) { + if (surf_workstation_model->extension. + workstation.get_state(host->host) != SURF_RESOURCE_ON) { THROW1(host_error, 0, "Host %s failed, you cannot call this function", host->name); } @@ -143,7 +145,8 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) #endif act->surf_action = - surf_workstation_model->extension.workstation.sleep(host->host, duration); + surf_workstation_model->extension.workstation.sleep(host->host, + duration); surf_workstation_model->action_data_set(act->surf_action, act); @@ -175,7 +178,8 @@ XBT_INLINE void SIMIX_action_cancel(smx_action_t action) * \param action The SIMIX action * \param priority The new priority */ -XBT_INLINE void SIMIX_action_set_priority(smx_action_t action, double priority) +XBT_INLINE void SIMIX_action_set_priority(smx_action_t action, + double priority) { xbt_assert0((action != NULL), "Invalid parameter"); @@ -246,7 +250,7 @@ int SIMIX_action_destroy(smx_action_t action) if (action->surf_action) action->surf_action->model_type->action_unref(action->surf_action); #ifdef HAVE_TRACING - TRACE_smx_action_destroy (action); + TRACE_smx_action_destroy(action); #endif xbt_free(action); return 1; @@ -288,27 +292,28 @@ XBT_INLINE void SIMIX_action_release(smx_action_t action) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) +void SIMIX_register_action_to_condition(smx_action_t action, + smx_cond_t cond) { xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); DEBUG2("Register action %p to cond %p", action, cond); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_cond_display_actions(cond); xbt_fifo_push(cond->actions, action); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_cond_display_actions(cond); DEBUG2("Register condition %p to action %p", cond, action); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_action_display_conditions(action); xbt_fifo_push(action->cond_list, cond); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_action_display_conditions(action); } @@ -324,40 +329,45 @@ void SIMIX_unregister_action_to_condition(smx_action_t action, { xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_cond_display_actions(cond); xbt_fifo_remove_all(cond->actions, action); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_cond_display_actions(cond); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_action_display_conditions(action); xbt_fifo_remove_all(action->cond_list, cond); - if(XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(simix_action, xbt_log_priority_debug)) __SIMIX_action_display_conditions(action); } + /** * \brief Link an action to a semaphore * * When the action terminates, the semaphore gets signaled automatically. */ -XBT_INLINE void SIMIX_register_action_to_semaphore(smx_action_t action, smx_sem_t sem) { +XBT_INLINE void SIMIX_register_action_to_semaphore(smx_action_t action, + smx_sem_t sem) +{ - DEBUG2("Register action %p to semaphore %p (and otherwise)", action, sem); + DEBUG2("Register action %p to semaphore %p (and otherwise)", action, + sem); xbt_fifo_push(sem->actions, action); xbt_fifo_push(action->sem_list, sem); } + /** * \brief Unset an action to a semaphore. * * Destroys the "links" from the semaphore to this action. */ XBT_INLINE void SIMIX_unregister_action_to_semaphore(smx_action_t action, - smx_sem_t sem) + smx_sem_t sem) { xbt_fifo_remove_all(sem->actions, action); xbt_fifo_remove_all(action->sem_list, sem); @@ -411,16 +421,17 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, workstation_list[i] = host_list[i]->host; act->surf_action = - surf_workstation_model->extension.workstation. - execute_parallel_task(host_nb, workstation_list, computation_amount, - communication_amount, amount, rate); + surf_workstation_model->extension.workstation. + execute_parallel_task(host_nb, workstation_list, computation_amount, + communication_amount, amount, rate); surf_workstation_model->action_data_set(act->surf_action, act); return act; } -XBT_INLINE e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) +XBT_INLINE e_surf_action_state_t SIMIX_action_get_state(smx_action_t + action) { xbt_assert0((action != NULL), "Invalid parameter"); return surf_workstation_model->action_state_get(action->surf_action); @@ -433,7 +444,7 @@ void __SIMIX_cond_display_actions(smx_cond_t cond) DEBUG1("Actions for condition %p", cond); xbt_fifo_foreach(cond->actions, item, action, smx_action_t) - DEBUG2("\t %p [%s]", action, action->name); + DEBUG2("\t %p [%s]", action, action->name); } void __SIMIX_action_display_conditions(smx_action_t action) @@ -443,7 +454,7 @@ void __SIMIX_action_display_conditions(smx_action_t action) DEBUG1("Conditions for action %p", action); xbt_fifo_foreach(action->cond_list, item, cond, smx_cond_t) - DEBUG1("\t %p", cond); + DEBUG1("\t %p", cond); } XBT_INLINE char *SIMIX_action_get_name(smx_action_t action) @@ -451,15 +462,17 @@ XBT_INLINE char *SIMIX_action_get_name(smx_action_t action) xbt_assert0((action != NULL), "Invalid parameter"); return action->name; } + /** @brief Change the name of the action. Warning, the string you provide is not strdup()ed */ -XBT_INLINE void SIMIX_action_set_name(smx_action_t action,char *name) +XBT_INLINE void SIMIX_action_set_name(smx_action_t action, char *name) { xbt_free(action->name); action->name = name; } /** @brief broadcast any condition and release any semaphore including this action */ -void SIMIX_action_signal_all(smx_action_t action){ +void SIMIX_action_signal_all(smx_action_t action) +{ smx_cond_t cond; smx_sem_t sem; diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 77efb14038..560a909668 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -16,10 +16,11 @@ #endif #ifdef HAVE_RUBY - void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory); -#endif +void SIMIX_ctx_ruby_factory_init(smx_context_factory_t * factory); +#endif -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix, "Context switching mecanism"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix, + "Context switching mecanism"); const char *xbt_ctx_factory_to_use = NULL; @@ -30,20 +31,20 @@ const char *xbt_ctx_factory_to_use = NULL; void SIMIX_context_mod_init(void) { if (!simix_global->context_factory) { - /* select context factory to use to create the context(depends of the macro definitions) */ + /* select context factory to use to create the context(depends of the macro definitions) */ if (xbt_ctx_factory_to_use) { SIMIX_context_select_factory(xbt_ctx_factory_to_use); } else { #ifdef CONTEXT_THREADS - /* context switch based os thread */ - SIMIX_ctx_thread_factory_init(&simix_global->context_factory); + /* context switch based os thread */ + SIMIX_ctx_thread_factory_init(&simix_global->context_factory); #elif defined(CONTEXT_UCONTEXT) - /* context switch based ucontext */ - SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); + /* context switch based ucontext */ + SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); #elif defined(_XBT_WIN32) - /* context switch based windows */ + /* context switch based windows */ #else - /* context switch is not allowed on Windows */ + /* context switch is not allowed on Windows */ #error ERROR [__FILE__, line __LINE__]: no context based implementation specified. #endif } @@ -57,7 +58,7 @@ void SIMIX_context_mod_exit(void) { if (simix_global->context_factory) { smx_pfn_context_factory_finalize_t finalize_factory; - + /* finalize the context factory */ finalize_factory = simix_global->context_factory->finalize; (*finalize_factory) (&simix_global->context_factory); @@ -74,33 +75,32 @@ int SIMIX_context_select_factory(const char *name) /* if a context factory is already instantiated and it is different from the newly selected one, then kill all the processes, exit the context module and initialize the new factory. - */ - + */ + if (simix_global->context_factory != NULL) { - if (strcmp(simix_global->context_factory->name, name)){ + if (strcmp(simix_global->context_factory->name, name)) { SIMIX_process_killall(); - + /* kill maestro process */ SIMIX_context_free(simix_global->maestro_process->context); - free(simix_global->maestro_process); + free(simix_global->maestro_process); simix_global->maestro_process = NULL; SIMIX_context_mod_exit(); - } - else + } else /* the same context factory is requested return directly */ return 0; } - + /* init the desired factory */ SIMIX_context_init_factory_by_name(&simix_global->context_factory, name); - SIMIX_create_maestro_process (); + SIMIX_create_maestro_process(); + - return 0; } @@ -110,40 +110,45 @@ int SIMIX_context_select_factory(const char *name) void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, const char *name) { - + if (!strcmp(name, "java")) -#ifdef HAVE_JAVA +#ifdef HAVE_JAVA SIMIX_ctx_java_factory_init(factory); #else - THROW0(not_found_error, 0, "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library"); -#endif /* HAVE_JAVA */ - + THROW0(not_found_error, 0, + "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library"); +#endif /* HAVE_JAVA */ + else if (!strcmp(name, "thread")) #ifdef CONTEXT_THREADS SIMIX_ctx_thread_factory_init(factory); #else - THROW0(not_found_error, 0, "Factory 'thread' does not exist: thread support was not compiled in the SimGrid library"); -#endif /* CONTEXT_THREADS */ - - else if (!strcmp(name, "sysv")) - #if !defined(_XBT_WIN32) && !defined(CONTEXT_THREADS) - SIMIX_ctx_sysv_factory_init(factory); - #else - THROW0(not_found_error, 0, "Factory 'sysv' does not exist: no System V thread support under Windows"); - #endif - else if (!strcmp(name, "lua")) + THROW0(not_found_error, 0, + "Factory 'thread' does not exist: thread support was not compiled in the SimGrid library"); +#endif /* CONTEXT_THREADS */ + + else if (!strcmp(name, "sysv")) +#if !defined(_XBT_WIN32) && !defined(CONTEXT_THREADS) + SIMIX_ctx_sysv_factory_init(factory); +#else + THROW0(not_found_error, 0, + "Factory 'sysv' does not exist: no System V thread support under Windows"); +#endif + else if (!strcmp(name, "lua")) #ifdef HAVE_LUA - SIMIX_ctx_lua_factory_init(factory); + SIMIX_ctx_lua_factory_init(factory); #else - THROW0(not_found_error, 0, "Factory 'lua' does not exist: Lua support was not compiled in the SimGrid library"); -#endif /* HAVE_LUA */ + THROW0(not_found_error, 0, + "Factory 'lua' does not exist: Lua support was not compiled in the SimGrid library"); +#endif /* HAVE_LUA */ - else if (!strcmp(name,"ruby")) + else if (!strcmp(name, "ruby")) #ifdef HAVE_RUBY SIMIX_ctx_ruby_factory_init(factory); #else - THROW0(not_found_error, 0, "Factory 'ruby' does not exist: Ruby support was not compiled in the SimGrid library"); + THROW0(not_found_error, 0, + "Factory 'ruby' does not exist: Ruby support was not compiled in the SimGrid library"); #endif else THROW1(not_found_error, 0, "Factory '%s' does not exist", name); diff --git a/src/simix/smx_context_base.c b/src/simix/smx_context_base.c index 88b7875783..fe09611520 100644 --- a/src/simix/smx_context_base.c +++ b/src/simix/smx_context_base.c @@ -12,7 +12,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(bindings); -void smx_ctx_base_factory_init(smx_context_factory_t * factory) { +void smx_ctx_base_factory_init(smx_context_factory_t * factory) +{ /* instantiate the context factory */ *factory = xbt_new0(s_smx_context_factory_t, 1); @@ -26,7 +27,8 @@ void smx_ctx_base_factory_init(smx_context_factory_t * factory) { (*factory)->name = "base context factory"; } -int smx_ctx_base_factory_finalize(smx_context_factory_t * factory) { +int smx_ctx_base_factory_finalize(smx_context_factory_t * factory) +{ free(*factory); *factory = NULL; return 0; @@ -34,25 +36,28 @@ int smx_ctx_base_factory_finalize(smx_context_factory_t * factory) { smx_context_t smx_ctx_base_factory_create_context_sized(size_t size, - xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) + xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg) { smx_context_t context = xbt_malloc0(size); /* If the user provided a function for the process then use it otherwise is the context for maestro */ - if(code){ + if (code) { context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; context->argc = argc; context->argv = argv; context->code = code; } - + return context; } -void smx_ctx_base_free(smx_context_t context) { +void smx_ctx_base_free(smx_context_t context) +{ int i; if (context) { @@ -69,9 +74,10 @@ void smx_ctx_base_free(smx_context_t context) { /* free structure */ free(context); } -} +} -void smx_ctx_base_stop(smx_context_t context) { +void smx_ctx_base_stop(smx_context_t context) +{ if (context->cleanup_func) (*(context->cleanup_func)) (context->cleanup_arg); diff --git a/src/simix/smx_context_java.c b/src/simix/smx_context_java.c index 87139b6bcc..6d002cfc3a 100644 --- a/src/simix/smx_context_java.c +++ b/src/simix/smx_context_java.c @@ -13,8 +13,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jmsg, bindings, "MSG for Java(TM)"); static smx_context_t -smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); +smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg); static void smx_ctx_java_free(smx_context_t context); static void smx_ctx_java_start(smx_context_t context); @@ -38,14 +40,16 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory) } static smx_context_t -smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) +smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg) { smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1); /* If the user provided a function for the process then use it otherwise is the context for maestro */ - if(code){ + if (code) { context->super.cleanup_func = cleanup_func; context->super.cleanup_arg = cleanup_arg; context->jprocess = (jobject) code; @@ -53,7 +57,7 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, jprocess_start(((smx_ctx_java_t) context)->jprocess, get_current_thread_env()); } - + return (smx_context_t) context; } @@ -74,7 +78,7 @@ static void smx_ctx_java_free(smx_context_t context) } smx_ctx_base_free(context); -} +} static void smx_ctx_java_stop(smx_context_t context) { @@ -87,7 +91,7 @@ static void smx_ctx_java_stop(smx_context_t context) ctx_java = (smx_ctx_java_t) context; - /*FIXME: is this really necessary?*/ + /*FIXME: is this really necessary? */ if (simix_global->current_process->iwannadie) { /* The maestro call xbt_context_stop() with an exit code set to one */ if (ctx_java->jprocess) { @@ -134,8 +138,7 @@ static void smx_ctx_java_suspend(smx_context_t context) } // FIXME: inline those functions -static void -smx_ctx_java_resume(smx_context_t new_context) +static void smx_ctx_java_resume(smx_context_t new_context) { jprocess_schedule(new_context); } diff --git a/src/simix/smx_context_java.h b/src/simix/smx_context_java.h index 5bcb8edae5..5062715e61 100644 --- a/src/simix/smx_context_java.h +++ b/src/simix/smx_context_java.h @@ -17,10 +17,10 @@ SG_BEGIN_DECL() typedef struct s_smx_ctx_java { - s_smx_ctx_base_t super; /* Fields of super implementation */ - jobject jprocess; /* the java process instance binded with the msg process structure */ - JNIEnv *jenv; /* jni interface pointer associated to this thread */ + s_smx_ctx_base_t super; /* Fields of super implementation */ + jobject jprocess; /* the java process instance binded with the msg process structure */ + JNIEnv *jenv; /* jni interface pointer associated to this thread */ } s_smx_ctx_java_t, *smx_ctx_java_t; SG_END_DECL() -#endif /* !_XBT_CONTEXT_JAVA_H */ +#endif /* !_XBT_CONTEXT_JAVA_H */ diff --git a/src/simix/smx_context_lua.c b/src/simix/smx_context_lua.c index 2d1b5c3ce6..33b3ecfb8d 100644 --- a/src/simix/smx_context_lua.c +++ b/src/simix/smx_context_lua.c @@ -16,7 +16,8 @@ */ lua_State *simgrid_lua_state; -void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) { +void SIMIX_ctx_lua_factory_init(smx_context_factory_t * factory) +{ } #ifdef KILLME @@ -26,11 +27,11 @@ void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) { XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(lua); -static smx_context_t -smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); +static smx_context_t +smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, void *cleanup_arg); -static int smx_ctx_lua_factory_finalize(smx_context_factory_t *factory); +static int smx_ctx_lua_factory_finalize(smx_context_factory_t * factory); static void smx_ctx_lua_free(smx_context_t context); static void smx_ctx_lua_stop(smx_context_t context); @@ -38,12 +39,13 @@ static void smx_ctx_lua_suspend(smx_context_t context); static void smx_ctx_lua_resume(smx_context_t new_context); -void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) { +void SIMIX_ctx_lua_factory_init(smx_context_factory_t * factory) +{ smx_ctx_base_factory_init(factory); (*factory)->create_context = smx_ctx_lua_create_context; - /* don't override (*factory)->finalize */; + /* don't override (*factory)->finalize */ ; (*factory)->free = smx_ctx_sysv_free; (*factory)->stop = smx_ctx_sysv_stop; (*factory)->suspend = smx_ctx_sysv_suspend; @@ -53,41 +55,48 @@ void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) { INFO0("Lua Factory created"); } -static smx_context_t -smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) { +static smx_context_t +smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, void *cleanup_arg) +{ return smx_ctx_sysv_create_context_sized(sizeof(s_smx_ctx_sysv_t), - code,argc,argv,cleanup_func,cleanup_arg); + code, argc, argv, cleanup_func, + cleanup_arg); } + #if KILLME -static void smx_ctx_lua_free(smx_context_t context) { +static void smx_ctx_lua_free(smx_context_t context) +{ - if (context){ - DEBUG1("smx_ctx_lua_free_context(%p)",context); + if (context) { + DEBUG1("smx_ctx_lua_free_context(%p)", context); } smx_ctx_sysv_free(context); } -static void smx_ctx_lua_stop(smx_context_t pcontext) { - DEBUG1("Stopping '%s' (nothing to do)",pcontext->argv[0]); +static void smx_ctx_lua_stop(smx_context_t pcontext) +{ + DEBUG1("Stopping '%s' (nothing to do)", pcontext->argv[0]); smx_ctx_sysv_stop(pcontext); } -static void smx_ctx_lua_suspend(smx_context_t pcontext) { - smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext; - DEBUG1("Suspending '%s' (using sysv facilities)",context->super.super.argv[0]); +static void smx_ctx_lua_suspend(smx_context_t pcontext) +{ + smx_ctx_lua_t context = (smx_ctx_lua_t) pcontext; + DEBUG1("Suspending '%s' (using sysv facilities)", + context->super.super.argv[0]); smx_ctx_sysv_suspend(pcontext); DEBUG0("Back from call yielding"); } -static void -smx_ctx_lua_resume(smx_context_t new_context) { - smx_ctx_lua_t context = (smx_ctx_lua_t)new_context; - DEBUG1("Resuming %s",context->super.super.argv[0]); +static void smx_ctx_lua_resume(smx_context_t new_context) +{ + smx_ctx_lua_t context = (smx_ctx_lua_t) new_context; + DEBUG1("Resuming %s", context->super.super.argv[0]); smx_ctx_sysv_resume(new_context); } #endif diff --git a/src/simix/smx_context_private.h b/src/simix/smx_context_private.h index 3769c9bb7d..e68769e77c 100644 --- a/src/simix/smx_context_private.h +++ b/src/simix/smx_context_private.h @@ -21,7 +21,6 @@ SG_BEGIN_DECL() concepts must implement */ /* the following function pointers types describe the interface that all context concepts must implement */ - /* each context type derive from this structure, so they must contain this structure * at their begining -- OOP in C :/ */ typedef struct s_smx_context { @@ -38,12 +37,12 @@ int smx_ctx_base_factory_finalize(smx_context_factory_t * factory); smx_context_t smx_ctx_base_factory_create_context_sized(size_t size, - xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); + xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg); void smx_ctx_base_free(smx_context_t context); void smx_ctx_base_stop(smx_context_t context); SG_END_DECL() -#endif /* !_XBT_CONTEXT_PRIVATE_H */ - - +#endif /* !_XBT_CONTEXT_PRIVATE_H */ diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index f3361d11c8..4f6358de26 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -17,16 +17,18 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby); static smx_context_t -smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, - void_f_pvoid_t cleanup_func,void *cleanup_arg); +smx_ctx_ruby_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg); static void smx_ctx_ruby_stop(smx_context_t context); static void smx_ctx_ruby_suspend(smx_context_t context); static void smx_ctx_ruby_resume(smx_context_t new_context); -static void smx_ctx_ruby_wrapper(void); +static void smx_ctx_ruby_wrapper(void); -void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { +void SIMIX_ctx_ruby_factory_init(smx_context_factory_t * factory) +{ smx_ctx_base_factory_init(factory); (*factory)->create_context = smx_ctx_ruby_create_context; @@ -40,39 +42,43 @@ void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { ruby_init_loadpath(); } -static smx_context_t -smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, - void_f_pvoid_t cleanup_func,void* cleanup_arg) { +static smx_context_t +smx_ctx_ruby_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, void *cleanup_arg) +{ - smx_ctx_ruby_t context = (smx_ctx_ruby_t)smx_ctx_base_factory_create_context_sized - (sizeof(s_smx_ctx_ruby_t), code,argc,argv,cleanup_func,cleanup_arg); + smx_ctx_ruby_t context = (smx_ctx_ruby_t) + smx_ctx_base_factory_create_context_sized(sizeof(s_smx_ctx_ruby_t), + code, argc, argv, + cleanup_func, cleanup_arg); /* if the user provided a function for the process , then use it Otherwise it's the context for maestro */ if (code) { - context->process = (VALUE)code; + context->process = (VALUE) code; - DEBUG1("smx_ctx_ruby_create_context(%s)...Done",argv[0]); + DEBUG1("smx_ctx_ruby_create_context(%s)...Done", argv[0]); } return (smx_context_t) context; } -static void smx_ctx_ruby_stop(smx_context_t context) { +static void smx_ctx_ruby_stop(smx_context_t context) +{ DEBUG0("smx_ctx_ruby_stop()"); VALUE process = Qnil; - smx_ctx_ruby_t ctx_ruby,current; + smx_ctx_ruby_t ctx_ruby, current; smx_ctx_base_stop(context); ctx_ruby = (smx_ctx_ruby_t) context; - - if ( simix_global->current_process->iwannadie ) { - if( ctx_ruby->process ) { - + + if (simix_global->current_process->iwannadie) { + if (ctx_ruby->process) { + //if the Ruby Process still Alive ,let's Schedule it - if ( rb_process_isAlive( ctx_ruby->process ) ) { + if (rb_process_isAlive(ctx_ruby->process)) { - current = (smx_ctx_ruby_t)simix_global->current_process->context; + current = (smx_ctx_ruby_t) simix_global->current_process->context; rb_process_schedule(current->process); process = ctx_ruby->process; // interupt/kill The Ruby Process @@ -81,23 +87,25 @@ static void smx_ctx_ruby_stop(smx_context_t context) { } } else { - if (ctx_ruby->process) - ctx_ruby->process = Qnil; + if (ctx_ruby->process) + ctx_ruby->process = Qnil; } } -static void smx_ctx_ruby_suspend(smx_context_t context) { +static void smx_ctx_ruby_suspend(smx_context_t context) +{ - DEBUG1("smx_ctx_ruby_suspend(%s)",context->argv[0]); - smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; - if (ctx_ruby->process) - rb_process_unschedule(ctx_ruby->process); + DEBUG1("smx_ctx_ruby_suspend(%s)", context->argv[0]); + smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; + if (ctx_ruby->process) + rb_process_unschedule(ctx_ruby->process); } -static void smx_ctx_ruby_resume(smx_context_t new_context) { +static void smx_ctx_ruby_resume(smx_context_t new_context) +{ DEBUG1("smx_ctx_ruby_resume(%s)", - (new_context->argc?new_context->argv[0]:"maestro")); + (new_context->argc ? new_context->argv[0] : "maestro")); smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context; rb_process_schedule(ctx_ruby->process); diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index 8def97a56d..a1dc635770 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -12,25 +12,27 @@ #ifdef HAVE_VALGRIND_VALGRIND_H # include -#endif /* HAVE_VALGRIND_VALGRIND_H */ +#endif /* HAVE_VALGRIND_VALGRIND_H */ #ifdef _XBT_WIN32 - #include "win32_ucontext.h" - #include "win32_ucontext.c" +#include "win32_ucontext.h" +#include "win32_ucontext.c" #else - #include "ucontext.h" +#include "ucontext.h" #endif XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); -static smx_context_t -smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); +static smx_context_t +smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg); static void smx_ctx_sysv_wrapper(void); -void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) { +void SIMIX_ctx_sysv_factory_init(smx_context_factory_t * factory) +{ smx_ctx_base_factory_init(factory); @@ -44,18 +46,27 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) { } smx_context_t -smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) { - - smx_ctx_sysv_t context = (smx_ctx_sysv_t)smx_ctx_base_factory_create_context_sized - (size, code,argc,argv,cleanup_func,cleanup_arg); +smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code, + int argc, char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg) +{ + + smx_ctx_sysv_t context = + (smx_ctx_sysv_t) smx_ctx_base_factory_create_context_sized(size, + code, + argc, + argv, + cleanup_func, + cleanup_arg); /* If the user provided a function for the process then use it otherwise is the context for maestro */ - if(code){ + if (code) { xbt_assert2(getcontext(&(context->uc)) == 0, - "Error in context saving: %d (%s)", errno, strerror(errno)); + "Error in context saving: %d (%s)", errno, + strerror(errno)); context->uc.uc_link = NULL; @@ -68,72 +79,83 @@ smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code, int argc, c #ifdef HAVE_VALGRIND_VALGRIND_H context->valgrind_stack_id = VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp, - ((char *) context->uc.uc_stack.ss_sp) + - context->uc.uc_stack.ss_size); -#endif /* HAVE_VALGRIND_VALGRIND_H */ + ((char *) context->uc.uc_stack.ss_sp) + + context->uc.uc_stack.ss_size); +#endif /* HAVE_VALGRIND_VALGRIND_H */ - makecontext(&((smx_ctx_sysv_t)context)->uc, smx_ctx_sysv_wrapper, 0); + makecontext(&((smx_ctx_sysv_t) context)->uc, smx_ctx_sysv_wrapper, 0); } - return (smx_context_t)context; + return (smx_context_t) context; } static smx_context_t -smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) { +smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv, + void_f_pvoid_t cleanup_func, void *cleanup_arg) +{ return smx_ctx_sysv_create_context_sized(sizeof(s_smx_ctx_sysv_t), - code,argc,argv,cleanup_func,cleanup_arg); + code, argc, argv, cleanup_func, + cleanup_arg); } -void smx_ctx_sysv_free(smx_context_t context) { +void smx_ctx_sysv_free(smx_context_t context) +{ - if (context){ + if (context) { #ifdef HAVE_VALGRIND_VALGRIND_H - VALGRIND_STACK_DEREGISTER(((smx_ctx_sysv_t) context)->valgrind_stack_id); -#endif /* HAVE_VALGRIND_VALGRIND_H */ + VALGRIND_STACK_DEREGISTER(((smx_ctx_sysv_t) + context)->valgrind_stack_id); +#endif /* HAVE_VALGRIND_VALGRIND_H */ } smx_ctx_base_free(context); } -void smx_ctx_sysv_stop(smx_context_t context) { +void smx_ctx_sysv_stop(smx_context_t context) +{ smx_ctx_base_stop(context); smx_ctx_sysv_suspend(context); } -void smx_ctx_sysv_wrapper() { +void smx_ctx_sysv_wrapper() +{ /*FIXME: I would like to avoid accessing simix_global to get the current - context by passing it as an argument of the wrapper function. The problem - is that this function is called from smx_ctx_sysv_start, and uses - makecontext for calling it, and the stupid posix specification states that - all the arguments of the function should be int(32 bits), making it useless - in 64-bit architectures where pointers are 64 bit long. + context by passing it as an argument of the wrapper function. The problem + is that this function is called from smx_ctx_sysv_start, and uses + makecontext for calling it, and the stupid posix specification states that + all the arguments of the function should be int(32 bits), making it useless + in 64-bit architectures where pointers are 64 bit long. */ - smx_ctx_sysv_t context = - (smx_ctx_sysv_t)simix_global->current_process->context; + smx_ctx_sysv_t context = + (smx_ctx_sysv_t) simix_global->current_process->context; (context->super.code) (context->super.argc, context->super.argv); - smx_ctx_sysv_stop((smx_context_t)context); + smx_ctx_sysv_stop((smx_context_t) context); } -void smx_ctx_sysv_suspend(smx_context_t context) { - ucontext_t maestro_ctx = ((smx_ctx_sysv_t)simix_global->maestro_process->context)->uc; +void smx_ctx_sysv_suspend(smx_context_t context) +{ + ucontext_t maestro_ctx = + ((smx_ctx_sysv_t) simix_global->maestro_process->context)->uc; int rv = swapcontext(&((smx_ctx_sysv_t) context)->uc, &maestro_ctx); xbt_assert0((rv == 0), "Context swapping failure"); } -void smx_ctx_sysv_resume(smx_context_t new_context) { - smx_ctx_sysv_t maestro = (smx_ctx_sysv_t)simix_global->maestro_process->context; +void smx_ctx_sysv_resume(smx_context_t new_context) +{ + smx_ctx_sysv_t maestro = + (smx_ctx_sysv_t) simix_global->maestro_process->context; - int rv = swapcontext(&(maestro->uc), &((smx_ctx_sysv_t)new_context)->uc); + int rv = + swapcontext(&(maestro->uc), &((smx_ctx_sysv_t) new_context)->uc); xbt_assert0((rv == 0), "Context swapping failure"); } diff --git a/src/simix/smx_context_sysv_private.h b/src/simix/smx_context_sysv_private.h index 5714534721..a3832957ae 100644 --- a/src/simix/smx_context_sysv_private.h +++ b/src/simix/smx_context_sysv_private.h @@ -18,13 +18,12 @@ SG_BEGIN_DECL() /* lower this if you want to reduce the memory consumption */ -#ifndef CONTEXT_STACK_SIZE /* allow lua to override this */ +#ifndef CONTEXT_STACK_SIZE /* allow lua to override this */ #define CONTEXT_STACK_SIZE 128*1024 -#endif /*CONTEXT_STACK_SIZE */ - +#endif /*CONTEXT_STACK_SIZE */ #include "context_sysv_config.h" /* loads context system definitions */ #ifdef _XBT_WIN32 -#include /* context relative declarations */ +#include /* context relative declarations */ #else #include /* context relative declarations */ #endif @@ -35,16 +34,16 @@ typedef struct s_smx_ctx_sysv { unsigned int valgrind_stack_id; /* the valgrind stack id */ #endif char stack[CONTEXT_STACK_SIZE]; /* the thread stack size */ -} s_smx_ctx_sysv_t, *smx_ctx_sysv_t;smx_context_t +} s_smx_ctx_sysv_t, *smx_ctx_sysv_t; +smx_context_t smx_ctx_sysv_create_context_sized(size_t structure_size, - xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); + xbt_main_func_t code, int argc, + char **argv, void_f_pvoid_t cleanup_func, + void *cleanup_arg); void smx_ctx_sysv_free(smx_context_t context); void smx_ctx_sysv_stop(smx_context_t context); void smx_ctx_sysv_suspend(smx_context_t context); void smx_ctx_sysv_resume(smx_context_t new_context); SG_END_DECL() -#endif /* !_XBT_CONTEXT_SYSV_PRIVATE_H */ - - +#endif /* !_XBT_CONTEXT_SYSV_PRIVATE_H */ diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index 51593917ca..95989a807d 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -25,8 +25,10 @@ typedef struct s_smx_ctx_thread { } s_smx_ctx_thread_t, *smx_ctx_thread_t; static smx_context_t -smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg); +smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg); static void smx_ctx_thread_free(smx_context_t context); static void smx_ctx_thread_stop(smx_context_t context); @@ -35,7 +37,8 @@ static void smx_ctx_thread_resume(smx_context_t new_context); static void *smx_ctx_thread_wrapper(void *param); -void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) { +void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) +{ smx_ctx_base_factory_init(factory); @@ -48,16 +51,20 @@ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) { (*factory)->name = "ctx_thread_factory"; } -static smx_context_t -smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** argv, - void_f_pvoid_t cleanup_func, void* cleanup_arg) +static smx_context_t +smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, + char **argv, + void_f_pvoid_t cleanup_func, + void *cleanup_arg) { - smx_ctx_thread_t context = (smx_ctx_thread_t)smx_ctx_base_factory_create_context_sized - (sizeof(s_smx_ctx_thread_t), code,argc,argv,cleanup_func,cleanup_arg); + smx_ctx_thread_t context = (smx_ctx_thread_t) + smx_ctx_base_factory_create_context_sized(sizeof(s_smx_ctx_thread_t), + code, argc, argv, + cleanup_func, cleanup_arg); /* If the user provided a function for the process then use it otherwise is the context for maestro */ - if(code){ + if (code) { context->begin = xbt_os_sem_init(0); context->end = xbt_os_sem_init(0); @@ -66,37 +73,37 @@ smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** arg /* NOTE: The first argument to xbt_os_thread_create used to be the process * * name, but now the name is stored at SIMIX level, so we pass a null */ context->thread = - xbt_os_thread_create(NULL, smx_ctx_thread_wrapper, context); + xbt_os_thread_create(NULL, smx_ctx_thread_wrapper, context); /* wait the starting of the newly created process */ xbt_os_sem_acquire(context->end); } - - return (smx_context_t)context; + + return (smx_context_t) context; } static void smx_ctx_thread_free(smx_context_t pcontext) { - smx_ctx_thread_t context = (smx_ctx_thread_t)pcontext; + smx_ctx_thread_t context = (smx_ctx_thread_t) pcontext; - /* check if this is the context of maestro (it doesn't has a real thread) */ + /* check if this is the context of maestro (it doesn't has a real thread) */ if (context->thread) { /* wait about the thread terminason */ xbt_os_thread_join(context->thread, NULL); - + /* destroy the synchronisation objects */ xbt_os_sem_destroy(context->begin); xbt_os_sem_destroy(context->end); } - + smx_ctx_base_free(pcontext); } static void smx_ctx_thread_stop(smx_context_t pcontext) { - smx_ctx_thread_t context = (smx_ctx_thread_t)pcontext; - + smx_ctx_thread_t context = (smx_ctx_thread_t) pcontext; + /* please no debug here: our procdata was already free'd */ smx_ctx_base_stop(pcontext); @@ -105,7 +112,7 @@ static void smx_ctx_thread_stop(smx_context_t pcontext) /* exit */ /* We should provide return value in case other wants it */ - xbt_os_thread_exit(NULL); + xbt_os_thread_exit(NULL); } static void *smx_ctx_thread_wrapper(void *param) @@ -118,16 +125,18 @@ static void *smx_ctx_thread_wrapper(void *param) (context->super.code) (context->super.argc, context->super.argv); - smx_ctx_thread_stop((smx_context_t)context); + smx_ctx_thread_stop((smx_context_t) context); return NULL; } -static void smx_ctx_thread_suspend(smx_context_t context) { +static void smx_ctx_thread_suspend(smx_context_t context) +{ xbt_os_sem_release(((smx_ctx_thread_t) context)->end); xbt_os_sem_acquire(((smx_ctx_thread_t) context)->begin); } -static void smx_ctx_thread_resume(smx_context_t new_context) { +static void smx_ctx_thread_resume(smx_context_t new_context) +{ xbt_os_sem_release(((smx_ctx_thread_t) new_context)->begin); xbt_os_sem_acquire(((smx_ctx_thread_t) new_context)->end); } diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index bff6a88cd1..e97d5740b4 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -71,16 +71,17 @@ static void parse_process_finalize(void) surf_timer_model->extension.timer.set(start_time, (void *) &SIMIX_process_create, arg); - } else { // start_time <= SIMIX_get_clock() + } else { // start_time <= SIMIX_get_clock() DEBUG2("Starting Process %s(%s) right now", parse_argv[0], parse_host); if (simix_global->create_process_function) process = - (*simix_global->create_process_function) (parse_argv[0], parse_code, - NULL, parse_host, - parse_argc, parse_argv, - /*the props */ - current_property_set); + (*simix_global->create_process_function) (parse_argv[0], + parse_code, NULL, + parse_host, parse_argc, + parse_argv, + /*the props */ + current_property_set); else process = SIMIX_process_create(parse_argv[0], parse_code, NULL, parse_host, parse_argc, parse_argv, /*the props */ current_property_set); @@ -90,12 +91,12 @@ static void parse_process_finalize(void) return; } if (kill_time > SIMIX_get_clock()) { - if (simix_global->kill_process_function) - surf_timer_model->extension.timer.set(start_time, (void *) + if (simix_global->kill_process_function) + surf_timer_model->extension.timer.set(start_time, (void *) simix_global->kill_process_function, process); - else - surf_timer_model->extension.timer.set(kill_time, (void *) + else + surf_timer_model->extension.timer.set(kill_time, (void *) &SIMIX_process_kill, (void *) process); } @@ -126,7 +127,8 @@ void SIMIX_launch_application(const char *file) surfxml_add_callback(STag_surfxml_process_cb_list, parse_process_init); surfxml_add_callback(ETag_surfxml_argument_cb_list, parse_argument); surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties); - surfxml_add_callback(ETag_surfxml_process_cb_list, parse_process_finalize); + surfxml_add_callback(ETag_surfxml_process_cb_list, + parse_process_finalize); surf_parse_open(file); parse_status = surf_parse(); @@ -142,7 +144,8 @@ void SIMIX_launch_application(const char *file) * \param name the reference name of the function. * \param code the function */ -XBT_INLINE void SIMIX_function_register(const char *name, xbt_main_func_t code) +XBT_INLINE void SIMIX_function_register(const char *name, + xbt_main_func_t code) { xbt_assert0(simix_global, "SIMIX_global_init has to be called before SIMIX_function_register."); @@ -188,7 +191,11 @@ xbt_main_func_t SIMIX_get_registered_function(const char *name) * \brief Bypass the parser, get arguments, and set function to each process */ -void SIMIX_process_set_function(const char* process_host,const char *process_function,xbt_dynar_t arguments,double process_start_time,double process_kill_time) +void SIMIX_process_set_function(const char *process_host, + const char *process_function, + xbt_dynar_t arguments, + double process_start_time, + double process_kill_time) { unsigned int i; char *arg; @@ -198,8 +205,7 @@ void SIMIX_process_set_function(const char* process_host,const char *process_fun xbt_assert1(SIMIX_host_get_by_name(parse_host), "Host '%s' unknown", parse_host); parse_code = SIMIX_get_registered_function(process_function); - xbt_assert1(parse_code, "Function '%s' unknown", - process_function); + xbt_assert1(parse_code, "Function '%s' unknown", process_function); parse_argc = 0; parse_argv = NULL; @@ -211,11 +217,10 @@ void SIMIX_process_set_function(const char* process_host,const char *process_fun current_property_set = xbt_dict_new(); /* add arguments */ - xbt_dynar_foreach(arguments,i,arg) - { - parse_argc++; - parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *)); - parse_argv[(parse_argc) - 1] = xbt_strdup(arg); + xbt_dynar_foreach(arguments, i, arg) { + parse_argc++; + parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *)); + parse_argv[(parse_argc) - 1] = xbt_strdup(arg); } /*finalize */ diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index 982188a9c6..0007cf925e 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -47,7 +47,7 @@ void SIMIX_create_environment(const char *file) DEBUG1("PARSE TIME: %lg", (end - start)); #ifdef HAVE_TRACING - TRACE_surf_save_onelink (); + TRACE_surf_save_onelink(); #endif xbt_dict_foreach(surf_model_resource_set(surf_workstation_model), cursor, diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 481afb22fe..a92036009a 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -60,11 +60,11 @@ void SIMIX_global_init(int *argc, char **argv) simix_global->host = xbt_dict_new(); simix_global->process_to_run = - xbt_swag_new(xbt_swag_offset(proc, synchro_hookup)); + xbt_swag_new(xbt_swag_offset(proc, synchro_hookup)); simix_global->process_list = - xbt_swag_new(xbt_swag_offset(proc, process_hookup)); + xbt_swag_new(xbt_swag_offset(proc, process_hookup)); simix_global->process_to_destroy = - xbt_swag_new(xbt_swag_offset(proc, destroy_hookup)); + xbt_swag_new(xbt_swag_offset(proc, destroy_hookup)); simix_global->current_process = NULL; simix_global->maestro_process = NULL; @@ -96,10 +96,11 @@ void SIMIX_display_process_status(void) smx_action_t act; int nbprocess = xbt_swag_size(simix_global->process_list); - INFO1("%d processes are still running, waiting for something.", nbprocess); + INFO1("%d processes are still running, waiting for something.", + nbprocess); /* List the process and their state */ INFO0 - ("Legend of the following listing: \" on : .\""); + ("Legend of the following listing: \" on : .\""); xbt_swag_foreach(process, simix_global->process_list) { char *who, *who2; @@ -111,50 +112,55 @@ void SIMIX_display_process_status(void) if (process->mutex) { who2 = - bprintf("%s Blocked on mutex %p", who, - (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) ? - process->mutex : (void *) 0xdead); + bprintf("%s Blocked on mutex %p", who, + (XBT_LOG_ISENABLED + (simix_kernel, + xbt_log_priority_verbose)) ? process->mutex : (void *) + 0xdead); free(who); who = who2; } else if (process->cond) { who2 = - bprintf - ("%s Blocked on condition %p; Waiting for the following actions:", - who, - (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) ? - process->cond : (void *) 0xdead); + bprintf + ("%s Blocked on condition %p; Waiting for the following actions:", + who, + (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) ? + process->cond : (void *) 0xdead); free(who); who = who2; xbt_fifo_foreach(process->cond->actions, item, act, smx_action_t) { who2 = - bprintf("%s '%s'(%p)", who, act->name, - (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) - ? act : (void *) 0xdead); + bprintf("%s '%s'(%p)", who, act->name, + (XBT_LOG_ISENABLED + (simix_kernel, xbt_log_priority_verbose)) + ? act : (void *) 0xdead); free(who); who = who2; } } else if (process->sem) { who2 = - bprintf - ("%s Blocked on semaphore %p; Waiting for the following actions:", - who, - (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) ? - process->sem : (void *) 0xdead); + bprintf + ("%s Blocked on semaphore %p; Waiting for the following actions:", + who, + (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) ? + process->sem : (void *) 0xdead); free(who); who = who2; xbt_fifo_foreach(process->sem->actions, item, act, smx_action_t) { who2 = - bprintf("%s '%s'(%p)", who, act->name, - (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_verbose)) - ? act : (void *) 0xdead); + bprintf("%s '%s'(%p)", who, act->name, + (XBT_LOG_ISENABLED + (simix_kernel, xbt_log_priority_verbose)) + ? act : (void *) 0xdead); free(who); who = who2; } } else { who2 = - bprintf - ("%s Blocked in an unknown status (please report this bug)", who); + bprintf + ("%s Blocked in an unknown status (please report this bug)", + who); free(who); who = who2; } @@ -316,7 +322,7 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) int actions_on_system = 0; SIMIX_process_empty_trash(); - if (XBT_LOG_ISENABLED(simix_kernel,xbt_log_priority_debug) && + if (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_debug) && xbt_swag_size(simix_global->process_to_run) && (elapsed_time > 0)) { DEBUG0("**************************************************"); } @@ -380,11 +386,13 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) smx_process_arg_t args = arg; DEBUG2("Launching %s on %s", args->name, args->hostname); process = - (*simix_global->create_process_function) (args->name, args->code, - args->data, - args->hostname, - args->argc, args->argv, - args->properties); + (*simix_global->create_process_function) (args->name, + args->code, + args->data, + args->hostname, + args->argc, + args->argv, + args->properties); /* verify if process has been created */ if (!process) { xbt_free(args); @@ -432,7 +440,7 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) while ((action = xbt_swag_extract(model->states.done_action_set))) { smx_action = action->data; if (smx_action) { - SIMIX_action_signal_all(smx_action); + SIMIX_action_signal_all(smx_action); } } } @@ -484,7 +492,8 @@ XBT_INLINE int SIMIX_timer_get(void **function, void **arg) * \param function Create process function * */ -XBT_INLINE void SIMIX_function_register_process_create(smx_creation_func_t function) +XBT_INLINE void SIMIX_function_register_process_create(smx_creation_func_t + function) { xbt_assert0((simix_global->create_process_function == NULL), "Data already set"); @@ -499,7 +508,8 @@ XBT_INLINE void SIMIX_function_register_process_create(smx_creation_func_t funct * \param function Kill process function * */ -XBT_INLINE void SIMIX_function_register_process_kill(void_f_pvoid_t function) +XBT_INLINE void SIMIX_function_register_process_kill(void_f_pvoid_t + function) { xbt_assert0((simix_global->kill_process_function == NULL), "Data already set"); @@ -514,7 +524,8 @@ XBT_INLINE void SIMIX_function_register_process_kill(void_f_pvoid_t function) * \param function cleanup process function * */ -XBT_INLINE void SIMIX_function_register_process_cleanup(void_f_pvoid_t function) +XBT_INLINE void SIMIX_function_register_process_cleanup(void_f_pvoid_t + function) { simix_global->cleanup_process_function = function; } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 9a19d0886d..fd71067cc6 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -23,10 +23,12 @@ smx_host_t __SIMIX_host_create(const char *name, smx_host->name = xbt_strdup(name); smx_host->data = data; smx_host->host = workstation; - smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); + smx_host->process_list = + xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); /* Update global variables */ - xbt_dict_set(simix_global->host, smx_host->name, smx_host, &__SIMIX_host_destroy); + xbt_dict_set(simix_global->host, smx_host->name, smx_host, + &__SIMIX_host_destroy); return smx_host; } @@ -103,7 +105,8 @@ void __SIMIX_host_destroy(void *h) /* Clean Simulator data */ if (xbt_swag_size(host->process_list) != 0) { - char *msg = bprintf("Shutting down host %s, but it's not empty:", host->name); + char *msg = + bprintf("Shutting down host %s, but it's not empty:", host->name); char *tmp; smx_process_t process = NULL; @@ -149,7 +152,7 @@ smx_host_t *SIMIX_host_get_table(void) int i = 0; xbt_dict_foreach(simix_global->host, c, name, h) - res[i++] = h; + res[i++] = h; return res; } @@ -203,7 +206,8 @@ XBT_INLINE double SIMIX_host_get_available_speed(smx_host_t host) XBT_INLINE smx_host_t SIMIX_host_get_by_name(const char *name) { xbt_assert0(((simix_global != NULL) - && (simix_global->host != NULL)), "Environment not set yet"); + && (simix_global->host != NULL)), + "Environment not set yet"); return xbt_dict_get_or_null(simix_global->host, name); } @@ -218,7 +222,8 @@ XBT_INLINE xbt_dict_t SIMIX_host_get_properties(smx_host_t host) { xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)"); - return surf_workstation_model->extension.workstation.get_properties(host->host); + return surf_workstation_model->extension. + workstation.get_properties(host->host); } diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 7af536e6ee..29e1bcf118 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, /******************************************************************************/ /* Rendez-Vous Points */ -/******************************************************************************/ +/******************************************************************************/ /** * \brief Creates a new rendez-vous point @@ -44,7 +44,7 @@ smx_rdv_t SIMIX_rdv_create(const char *name) */ void SIMIX_rdv_destroy(smx_rdv_t rdv) { - if(rdv->name) + if (rdv->name) xbt_free(rdv->name); SIMIX_mutex_destroy(rdv->read); SIMIX_mutex_destroy(rdv->write); @@ -73,17 +73,18 @@ static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_comm_t comm) xbt_fifo_remove(rdv->comm_fifo, comm); comm->rdv = NULL; } - + /** * \brief Checks if there is a communication request queued in a rendez-vous matching our needs * \param type The type of communication we are looking for (comm_send, comm_recv) * \return The communication request if found, NULL otherwise. */ -smx_comm_t SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type) { - smx_comm_t comm = (smx_comm_t)xbt_fifo_get_item_content( - xbt_fifo_get_first_item(rdv->comm_fifo)); +smx_comm_t SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type) +{ + smx_comm_t comm = (smx_comm_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo)); - if(comm && comm->type == type){ + if (comm && comm->type == type) { DEBUG0("Communication request found!"); xbt_fifo_shift(rdv->comm_fifo); SIMIX_communication_use(comm); @@ -102,8 +103,7 @@ smx_comm_t SIMIX_rdv_get_request(smx_rdv_t rdv, smx_comm_type_t type) { * \param host The host to be counted * \return The number of comm request pending in the rdv */ -int -SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, smx_host_t host) +int SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, smx_host_t host) { smx_comm_t comm = NULL; xbt_fifo_item_t item = NULL; @@ -124,27 +124,31 @@ SIMIX_rdv_get_count_waiting_comm(smx_rdv_t rdv, smx_host_t host) */ XBT_INLINE smx_comm_t SIMIX_rdv_get_head(smx_rdv_t rdv) { - return (smx_comm_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo)); + return (smx_comm_t) + xbt_fifo_get_item_content(xbt_fifo_get_first_item(rdv->comm_fifo)); } /** @brief adds some API-related data to the rendez-vous point */ -XBT_INLINE void SIMIX_rdv_set_data(smx_rdv_t rdv,void *data) { - rdv->data=data; +XBT_INLINE void SIMIX_rdv_set_data(smx_rdv_t rdv, void *data) +{ + rdv->data = data; } + /** @brief gets API-related data from the rendez-vous point */ -XBT_INLINE void *SIMIX_rdv_get_data(smx_rdv_t rdv) { +XBT_INLINE void *SIMIX_rdv_get_data(smx_rdv_t rdv) +{ return rdv->data; } /******************************************************************************/ /* Communication Requests */ -/******************************************************************************/ +/******************************************************************************/ /** * \brief Creates a new communication request * \param type The type of communication (comm_send, comm_recv) * \return The new communication request - */ + */ smx_comm_t SIMIX_communication_new(smx_comm_type_t type) { /* alloc structures */ @@ -152,7 +156,7 @@ smx_comm_t SIMIX_communication_new(smx_comm_type_t type) comm->type = type; comm->sem = SIMIX_sem_init(0); comm->refcount = 1; - + return comm; } @@ -162,42 +166,45 @@ smx_comm_t SIMIX_communication_new(smx_comm_type_t type) */ void SIMIX_communication_destroy(smx_comm_t comm) { - VERB2("Destroy communication %p; refcount initially %d",comm,comm->refcount); + VERB2("Destroy communication %p; refcount initially %d", comm, + comm->refcount); #ifdef HAVE_LATENCY_BOUND_TRACKING //save is latency limited flag to use afterwards if (latency_limited_dict == NULL) { - latency_limited_dict = xbt_dict_new(); + latency_limited_dict = xbt_dict_new(); } - if (comm->act){ - DEBUG2("adding key %p with latency limited value %d to the dict", comm, SIMIX_action_is_latency_bounded(comm->act)); - xbt_dicti_set(latency_limited_dict, (uintptr_t)comm, SIMIX_action_is_latency_bounded(comm->act)); + if (comm->act) { + DEBUG2("adding key %p with latency limited value %d to the dict", comm, + SIMIX_action_is_latency_bounded(comm->act)); + xbt_dicti_set(latency_limited_dict, (uintptr_t) comm, + SIMIX_action_is_latency_bounded(comm->act)); } #endif comm->refcount--; - if(comm->refcount > 0) + if (comm->refcount > 0) return; - if(comm->sem){ + if (comm->sem) { SIMIX_sem_destroy(comm->sem); comm->sem = NULL; } - - if(comm->act){ + + if (comm->act) { SIMIX_action_destroy(comm->act); comm->act = NULL; } - if(comm->src_timeout){ + if (comm->src_timeout) { SIMIX_action_destroy(comm->src_timeout); comm->src_timeout = NULL; } - if(comm->dst_timeout){ - SIMIX_action_destroy(comm->dst_timeout); - comm->dst_timeout = NULL; - } + if (comm->dst_timeout) { + SIMIX_action_destroy(comm->dst_timeout); + comm->dst_timeout = NULL; + } @@ -224,23 +231,23 @@ static XBT_INLINE void SIMIX_communication_use(smx_comm_t comm) static XBT_INLINE void SIMIX_communication_start(smx_comm_t comm) { /* If both the sender and the receiver are already there, start the communication */ - if(comm->src_proc && comm->dst_proc){ + if (comm->src_proc && comm->dst_proc) { DEBUG1("Starting communication %p", comm); - comm->act = SIMIX_action_communicate(comm->src_proc->smx_host, - comm->dst_proc->smx_host, NULL, + comm->act = SIMIX_action_communicate(comm->src_proc->smx_host, + comm->dst_proc->smx_host, NULL, comm->task_size, comm->rate); #ifdef HAVE_TRACING - TRACE_smx_action_communicate (comm->act, comm->src_proc); - TRACE_surf_action (comm->act->surf_action, comm->act->category); + TRACE_smx_action_communicate(comm->act, comm->src_proc); + TRACE_surf_action(comm->act->surf_action, comm->act->category); #endif /* If any of the process is suspend, create the action but stop its execution, it will be restarted when the sender process resume */ - if(SIMIX_process_is_suspended(comm->src_proc) || - SIMIX_process_is_suspended(comm->dst_proc)) { + if (SIMIX_process_is_suspended(comm->src_proc) || + SIMIX_process_is_suspended(comm->dst_proc)) { SIMIX_action_suspend(comm->act); } - + /* Add the communication as user data of the action */ comm->act->data = comm; @@ -261,18 +268,20 @@ static XBT_INLINE void SIMIX_communication_cleanup(smx_comm_t comm) /* Make sure that everyone sleeping on that semaphore is awake, and that nobody will ever block on it */ SIMIX_sem_release_forever(comm->sem); - + /* Check for errors other than timeouts */ - if (!SIMIX_host_get_state(SIMIX_host_self())){ - if(comm->rdv) + if (!SIMIX_host_get_state(SIMIX_host_self())) { + if (comm->rdv) SIMIX_rdv_remove(comm->rdv, comm); - SIMIX_communication_destroy(comm); + SIMIX_communication_destroy(comm); THROW0(host_error, 0, "Host failed"); - } else if (SIMIX_action_get_state(comm->act) == SURF_ACTION_FAILED){ + } else if (SIMIX_action_get_state(comm->act) == SURF_ACTION_FAILED) { SIMIX_communication_destroy(comm); THROW0(network_error, 0, "Link failure"); - } else if (!SIMIX_host_get_state(SIMIX_process_get_host(comm->dst_proc)) || - !SIMIX_host_get_state(SIMIX_process_get_host(comm->src_proc))) { + } else if (!SIMIX_host_get_state(SIMIX_process_get_host(comm->dst_proc)) + || + !SIMIX_host_get_state(SIMIX_process_get_host(comm->src_proc))) + { /* We test both src&dst because we dunno who we are today, and we already tested myself above. * So, at the end, we test the remote peer only * Moreover, we have to test it because if the remote peer fails, the action comm->act is not done nor failed. @@ -283,7 +292,7 @@ static XBT_INLINE void SIMIX_communication_cleanup(smx_comm_t comm) } /* Copy network data */ - SIMIX_network_copy_data(comm); + SIMIX_network_copy_data(comm); SIMIX_communication_destroy(comm); } @@ -298,21 +307,27 @@ static XBT_INLINE void SIMIX_communication_cleanup(smx_comm_t comm) * - timeout_error if communication reached the timeout specified (either because of local peer or remote peer) * - network_error if network failed or remote peer failed */ -static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t comm, double timeout) +static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t + comm, + double + timeout) { smx_action_t act_sleep = NULL; int src_timeout = 0; int dst_timeout = 0; DEBUG1("Waiting for the completion of communication %p", comm); - + if (timeout >= 0) { act_sleep = SIMIX_action_sleep(SIMIX_host_self(), timeout); - if(SIMIX_process_self()==comm->src_proc) - comm->src_timeout = act_sleep; - else - comm->dst_timeout = act_sleep; - SIMIX_action_set_name(act_sleep,bprintf("Timeout for comm %p and wait on semaphore %p (max_duration:%f)", comm, comm->sem,timeout)); + if (SIMIX_process_self() == comm->src_proc) + comm->src_timeout = act_sleep; + else + comm->dst_timeout = act_sleep; + SIMIX_action_set_name(act_sleep, + bprintf + ("Timeout for comm %p and wait on semaphore %p (max_duration:%f)", + comm, comm->sem, timeout)); SIMIX_register_action_to_semaphore(act_sleep, comm->sem); SIMIX_process_self()->waiting_action = act_sleep; SIMIX_sem_block_onto(comm->sem); @@ -323,13 +338,20 @@ static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t comm, } /* Check for timeouts */ - if ((src_timeout = ((comm->src_timeout) && (SIMIX_action_get_state(comm->src_timeout) == SURF_ACTION_DONE))) || - (dst_timeout = ((comm->dst_timeout) && (SIMIX_action_get_state(comm->dst_timeout) == SURF_ACTION_DONE))) ) { - /* Somebody did a timeout! */ - if (src_timeout) DEBUG1("Communication timeout from the src! %p", comm); - if (dst_timeout) DEBUG1("Communication timeout from the dst! %p", comm); - - if(comm->act && SIMIX_action_get_state(comm->act) == SURF_ACTION_RUNNING) + if ((src_timeout = ((comm->src_timeout) + && (SIMIX_action_get_state(comm->src_timeout) == + SURF_ACTION_DONE))) + || (dst_timeout = ((comm->dst_timeout) + && (SIMIX_action_get_state(comm->dst_timeout) == + SURF_ACTION_DONE)))) { + /* Somebody did a timeout! */ + if (src_timeout) + DEBUG1("Communication timeout from the src! %p", comm); + if (dst_timeout) + DEBUG1("Communication timeout from the dst! %p", comm); + + if (comm->act + && SIMIX_action_get_state(comm->act) == SURF_ACTION_RUNNING) SIMIX_communication_cancel(comm); else if (comm->rdv) SIMIX_rdv_remove(comm->rdv, comm); @@ -338,7 +360,8 @@ static XBT_INLINE void SIMIX_communication_wait_for_completion(smx_comm_t comm, SIMIX_sem_release_forever(comm->sem); SIMIX_communication_destroy(comm); - THROW1(timeout_error, 0, "Communication timeouted because of %s",src_timeout?"the source":"the destination"); + THROW1(timeout_error, 0, "Communication timeouted because of %s", + src_timeout ? "the source" : "the destination"); } DEBUG1("Communication %p complete!", comm); @@ -363,7 +386,7 @@ XBT_INLINE double SIMIX_communication_get_remains(smx_comm_t comm) { DEBUG1("calling SIMIX_action_get_remains(%p)", comm->act); return SIMIX_action_get_remains(comm->act); -} +} #ifdef HAVE_LATENCY_BOUND_TRACKING /** @@ -376,12 +399,13 @@ XBT_INLINE int SIMIX_communication_is_latency_bounded(smx_comm_t comm) uintptr_t key = 0; uintptr_t data = 0; xbt_dict_cursor_t cursor; - xbt_dict_foreach(latency_limited_dict,cursor,key,data) { - DEBUG2("comparing key=%p with comm=%p", (void*)key, (void*)comm); - if((void*)comm == (void*)key){ - DEBUG2("key %p found, return value latency limited value %d", (void*)key, (int)data); - return (int)data; - } + xbt_dict_foreach(latency_limited_dict, cursor, key, data) { + DEBUG2("comparing key=%p with comm=%p", (void *) key, (void *) comm); + if ((void *) comm == (void *) key) { + DEBUG2("key %p found, return value latency limited value %d", + (void *) key, (int) data); + return (int) data; + } } DEBUG1("calling SIMIX_action_is_latency_bounded(%p)", comm->act); @@ -392,18 +416,24 @@ XBT_INLINE int SIMIX_communication_is_latency_bounded(smx_comm_t comm) /******************************************************************************/ /* SIMIX_network_copy_data callbacks */ /******************************************************************************/ -static void (*SIMIX_network_copy_data_callback)(smx_comm_t, size_t) = &SIMIX_network_copy_pointer_callback; +static void (*SIMIX_network_copy_data_callback) (smx_comm_t, size_t) = + &SIMIX_network_copy_pointer_callback; -void SIMIX_network_set_copy_data_callback(void (*callback)(smx_comm_t, size_t)) { +void +SIMIX_network_set_copy_data_callback(void (*callback) (smx_comm_t, size_t)) +{ SIMIX_network_copy_data_callback = callback; } -void SIMIX_network_copy_pointer_callback(smx_comm_t comm, size_t buff_size) { - xbt_assert1((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)",buff_size); - *(void**)(comm->dst_buff) = comm->src_buff; +void SIMIX_network_copy_pointer_callback(smx_comm_t comm, size_t buff_size) +{ + xbt_assert1((buff_size == sizeof(void *)), + "Cannot copy %zu bytes: must be sizeof(void*)", buff_size); + *(void **) (comm->dst_buff) = comm->src_buff; } -void SIMIX_network_copy_buffer_callback(smx_comm_t comm, size_t buff_size) { +void SIMIX_network_copy_buffer_callback(smx_comm_t comm, size_t buff_size) +{ memcpy(comm->dst_buff, comm->src_buff, buff_size); } @@ -417,31 +447,30 @@ void SIMIX_network_copy_data(smx_comm_t comm) uintptr_t casted_size = 0; uintptr_t amount = 0; /* If there is no data to be copy then return */ - if(!comm->src_buff || !comm->dst_buff || comm->copied == 1) + if (!comm->src_buff || !comm->dst_buff || comm->copied == 1) return; DEBUG6("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", - comm, - comm->src_proc->smx_host->name, comm->src_buff, - comm->dst_proc->smx_host->name, comm->dst_buff, - buff_size); + comm, + comm->src_proc->smx_host->name, comm->src_buff, + comm->dst_proc->smx_host->name, comm->dst_buff, buff_size); /* Copy at most dst_buff_size bytes of the message to receiver's buffer */ if (comm->dst_buff_size) - buff_size = MIN(buff_size,*(comm->dst_buff_size)); - + buff_size = MIN(buff_size, *(comm->dst_buff_size)); + /* Update the receiver's buffer size to the copied amount */ if (comm->dst_buff_size) *comm->dst_buff_size = buff_size; - if(buff_size == 0) + if (buff_size == 0) return; - (*SIMIX_network_copy_data_callback)(comm, buff_size); + (*SIMIX_network_copy_data_callback) (comm, buff_size); /* Set the copied flag so we copy data only once */ - /* (this function might be called from both communication ends)*/ + /* (this function might be called from both communication ends) */ comm->copied = 1; - + /* pimple to display the message sizes */ { if (msg_sizes == NULL) @@ -450,21 +479,23 @@ void SIMIX_network_copy_data(smx_comm_t comm) amount = xbt_dicti_get(msg_sizes, casted_size); amount++; - xbt_dicti_set(msg_sizes,casted_size, amount); + xbt_dicti_set(msg_sizes, casted_size, amount); } } + #include "xbt.h" /* pimple to display the message sizes */ -void SIMIX_message_sizes_output(const char *filename) { +void SIMIX_message_sizes_output(const char *filename) +{ uintptr_t key = 0; uintptr_t data = 0; xbt_dict_cursor_t cursor; - FILE * out = NULL; - out = fopen(filename,"w"); - xbt_assert1(out,"Cannot open file %s",filename); + FILE *out = NULL; + out = fopen(filename, "w"); + xbt_assert1(out, "Cannot open file %s", filename); - xbt_dict_foreach(msg_sizes,cursor,key,data) { - fprintf(out,"%zu %zu\n",key,data); + xbt_dict_foreach(msg_sizes, cursor, key, data) { + fprintf(out, "%zu %zu\n", key, data); } fclose(out); } @@ -483,14 +514,17 @@ XBT_PUBLIC(void *) SIMIX_communication_get_src_buf(smx_comm_t comm) { return comm->src_buff; } + XBT_PUBLIC(void *) SIMIX_communication_get_dst_buf(smx_comm_t comm) { return comm->dst_buff; } + XBT_PUBLIC(size_t) SIMIX_communication_get_src_buf_size(smx_comm_t comm) { return comm->src_buff_size; } + XBT_PUBLIC(size_t) SIMIX_communication_get_dst_buf_size(smx_comm_t comm) { return *(comm->dst_buff_size); @@ -515,12 +549,15 @@ XBT_PUBLIC(size_t) SIMIX_communication_get_dst_buf_size(smx_comm_t comm) * - timeout_error if communication reached the timeout specified * - network_error if network failed or peer issued a timeout */ -XBT_INLINE void SIMIX_network_send(smx_rdv_t rdv, double task_size, double rate, - double timeout, void *src_buff, size_t src_buff_size, - smx_comm_t *comm_ref, void *data) +XBT_INLINE void SIMIX_network_send(smx_rdv_t rdv, double task_size, + double rate, double timeout, + void *src_buff, size_t src_buff_size, + smx_comm_t * comm_ref, void *data) { - *comm_ref = SIMIX_network_isend(rdv,task_size,rate,src_buff,src_buff_size,data); - SIMIX_network_wait(*comm_ref,timeout); + *comm_ref = + SIMIX_network_isend(rdv, task_size, rate, src_buff, src_buff_size, + data); + SIMIX_network_wait(*comm_ref, timeout); } /** @@ -536,31 +573,34 @@ XBT_INLINE void SIMIX_network_send(smx_rdv_t rdv, double task_size, double rate, * - timeout_error if communication reached the timeout specified * - network_error if network failed or peer issued a timeout */ -XBT_INLINE void SIMIX_network_recv(smx_rdv_t rdv, double timeout, void *dst_buff, - size_t *dst_buff_size, smx_comm_t *comm_ref) +XBT_INLINE void SIMIX_network_recv(smx_rdv_t rdv, double timeout, + void *dst_buff, size_t * dst_buff_size, + smx_comm_t * comm_ref) { - *comm_ref = (smx_comm_t) SIMIX_network_irecv(rdv,dst_buff,dst_buff_size); - SIMIX_network_wait(*comm_ref,timeout); + *comm_ref = + (smx_comm_t) SIMIX_network_irecv(rdv, dst_buff, dst_buff_size); + SIMIX_network_wait(*comm_ref, timeout); } /******************************************************************************/ /* Asynchronous Communication */ /******************************************************************************/ -smx_comm_t SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate, - void *src_buff, size_t src_buff_size, void *data) +smx_comm_t SIMIX_network_isend(smx_rdv_t rdv, double task_size, + double rate, void *src_buff, + size_t src_buff_size, void *data) { smx_comm_t comm; - /*If running in model-checking mode then intercept the communication action*/ - #ifdef HAVE_MC - if (_surf_do_model_check) - MC_trans_intercept_isend(rdv); - #endif + /*If running in model-checking mode then intercept the communication action */ +#ifdef HAVE_MC + if (_surf_do_model_check) + MC_trans_intercept_isend(rdv); +#endif /* Look for communication request matching our needs. If it is not found then create it and push it into the rendez-vous point */ comm = SIMIX_rdv_get_request(rdv, comm_recv); - if(!comm){ + if (!comm) { comm = SIMIX_communication_new(comm_send); SIMIX_rdv_push(rdv, comm); } @@ -572,16 +612,17 @@ smx_comm_t SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate, comm->src_buff = src_buff; comm->src_buff_size = src_buff_size; comm->data = data; - + SIMIX_communication_start(comm); return comm; } -smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size) +smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, + size_t * dst_buff_size) { smx_comm_t comm; - /*If running in model-checking mode then intercept the communication action*/ + /*If running in model-checking mode then intercept the communication action */ #ifdef HAVE_MC if (_surf_do_model_check) MC_trans_intercept_irecv(rdv); @@ -591,7 +632,7 @@ smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_s */ comm = SIMIX_rdv_get_request(rdv, comm_send); - if(!comm){ + if (!comm) { comm = SIMIX_communication_new(comm_recv); SIMIX_rdv_push(rdv, comm); } @@ -600,7 +641,7 @@ smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_s comm->dst_proc = SIMIX_process_self(); comm->dst_buff = dst_buff; comm->dst_buff_size = dst_buff_size; - + SIMIX_communication_start(comm); return comm; } @@ -608,7 +649,7 @@ smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_s /** @brief blocks until the communication terminates or the timeout occurs */ XBT_INLINE void SIMIX_network_wait(smx_comm_t comm, double timeout) { - /*If running in model-checking mode then intercept the communication action*/ + /*If running in model-checking mode then intercept the communication action */ #ifdef HAVE_MC if (_surf_do_model_check) MC_trans_intercept_wait(comm); @@ -620,14 +661,14 @@ XBT_INLINE void SIMIX_network_wait(smx_comm_t comm, double timeout) /** @Returns whether the (asynchronous) communication is done yet or not */ XBT_INLINE int SIMIX_network_test(smx_comm_t comm) { - /*If running in model-checking mode then intercept the communication action*/ + /*If running in model-checking mode then intercept the communication action */ #ifdef HAVE_MC if (_surf_do_model_check) MC_trans_intercept_test(comm); #endif /* Copy data if the communication is done */ - if(comm->sem && !SIMIX_sem_would_block(comm->sem)){ + if (comm->sem && !SIMIX_sem_would_block(comm->sem)) { /* Copy network data */ SIMIX_network_copy_data(comm); return TRUE; @@ -641,26 +682,28 @@ XBT_INLINE int SIMIX_network_test(smx_comm_t comm) */ unsigned int SIMIX_network_waitany(xbt_dynar_t comms) { - xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t),NULL); - unsigned int cursor, found_comm=-1; - smx_comm_t comm,comm_finished=NULL; + xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t), NULL); + unsigned int cursor, found_comm = -1; + smx_comm_t comm, comm_finished = NULL; - /*If running in model-checking mode then intercept the communication action*/ + /*If running in model-checking mode then intercept the communication action */ #ifdef HAVE_MC if (_surf_do_model_check) MC_trans_intercept_waitany(comms); #endif - xbt_dynar_foreach(comms,cursor,comm) - xbt_dynar_push(sems,&(comm->sem)); + xbt_dynar_foreach(comms, cursor, comm) + xbt_dynar_push(sems, &(comm->sem)); DEBUG1("Waiting for the completion of communication set %p", comms); found_comm = SIMIX_sem_acquire_any(sems); xbt_dynar_free_container(&sems); - xbt_assert0(found_comm!=-1,"Cannot find which communication finished"); - xbt_dynar_get_cpy(comms,found_comm,&comm_finished); + xbt_assert0(found_comm != -1, + "Cannot find which communication finished"); + xbt_dynar_get_cpy(comms, found_comm, &comm_finished); - DEBUG2("Communication %p of communication set %p finished", comm_finished, comms); + DEBUG2("Communication %p of communication set %p finished", + comm_finished, comms); /* let the regular code deal with the communication end (errors checking and cleanup). * A bit of useless work will be done, but that's good for source factorization */ diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 3d080f26bf..620f242622 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -98,7 +98,8 @@ smx_process_t SIMIX_process_create(const char *name, DEBUG2("Start process %s on host %s", name, hostname); if (!SIMIX_host_get_state(host)) { - WARN2("Cannot launch process '%s' on failed host '%s'", name, hostname); + WARN2("Cannot launch process '%s' on failed host '%s'", name, + hostname); return NULL; } process = xbt_new0(s_smx_process_t, 1); @@ -145,7 +146,8 @@ smx_process_t SIMIX_process_create(const char *name, */ void SIMIX_process_kill(smx_process_t process) { - DEBUG2("Killing process %s on %s", process->name, process->smx_host->name); + DEBUG2("Killing process %s on %s", process->name, + process->smx_host->name); process->iwannadie = 1; @@ -159,7 +161,8 @@ void SIMIX_process_kill(smx_process_t process) if (process->cond) xbt_swag_remove(process, process->cond->sleeping); if (process->waiting_action) { - SIMIX_unregister_action_to_condition(process->waiting_action, process->cond); + SIMIX_unregister_action_to_condition(process->waiting_action, + process->cond); SIMIX_action_destroy(process->waiting_action); } @@ -167,7 +170,8 @@ void SIMIX_process_kill(smx_process_t process) xbt_fifo_remove(process->sem->sleeping, process); if (process->waiting_action) { - SIMIX_unregister_action_to_semaphore(process->waiting_action, process->sem); + SIMIX_unregister_action_to_semaphore(process->waiting_action, + process->sem); SIMIX_action_destroy(process->waiting_action); } } @@ -176,8 +180,8 @@ void SIMIX_process_kill(smx_process_t process) } else { DEBUG4("%s(%p) here! killing %s(%p)", - simix_global->current_process->name,simix_global->current_process, - process->name,process); + simix_global->current_process->name, + simix_global->current_process, process->name, process); /* Cleanup if it were waiting for something */ if (process->mutex) { @@ -189,7 +193,8 @@ void SIMIX_process_kill(smx_process_t process) xbt_swag_remove(process, process->cond->sleeping); if (process->waiting_action) { - SIMIX_unregister_action_to_condition(process->waiting_action, process->cond); + SIMIX_unregister_action_to_condition(process->waiting_action, + process->cond); SIMIX_action_destroy(process->waiting_action); } process->cond = NULL; @@ -199,8 +204,9 @@ void SIMIX_process_kill(smx_process_t process) xbt_fifo_remove(process->sem->sleeping, process); if (process->waiting_action) { - SIMIX_unregister_action_to_semaphore(process->waiting_action, process->sem); - SIMIX_action_destroy(process->waiting_action); + SIMIX_unregister_action_to_semaphore(process->waiting_action, + process->sem); + SIMIX_action_destroy(process->waiting_action); } process->sem = NULL; } @@ -297,9 +303,9 @@ XBT_INLINE xbt_dict_t SIMIX_process_get_properties(smx_process_t process) */ XBT_INLINE smx_process_t SIMIX_process_self(void) { - if(simix_global) - return simix_global->current_process; - return NULL; + if (simix_global) + return simix_global->current_process; + return NULL; } /** @@ -483,8 +489,9 @@ void SIMIX_process_yield(void) void SIMIX_process_schedule(smx_process_t new_process) { - xbt_assert0(simix_global->current_process == simix_global->maestro_process, - "This function can only be called from maestro context"); + xbt_assert0(simix_global->current_process == + simix_global->maestro_process, + "This function can only be called from maestro context"); DEBUG1("Scheduling context: '%s'", new_process->name); /* update the current process */ diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index bf66a9d8db..1cd37ed82f 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -179,14 +179,14 @@ void SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex) DEBUG1("Wait condition %p", cond); /* If there is a mutex unlock it */ - if(mutex != NULL){ + if (mutex != NULL) { cond->mutex = mutex; SIMIX_mutex_unlock(mutex); } - + /* Always create an action null in case there is a host failure */ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); - SIMIX_action_set_name(act_sleep,bprintf("Wait condition %p", cond)); + SIMIX_action_set_name(act_sleep, bprintf("Wait condition %p", cond)); SIMIX_process_self()->waiting_action = act_sleep; SIMIX_register_action_to_condition(act_sleep, cond); __SIMIX_cond_wait(cond); @@ -195,7 +195,7 @@ void SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex) SIMIX_action_destroy(act_sleep); /* get the mutex again if necessary */ - if(mutex != NULL) + if (mutex != NULL) SIMIX_mutex_lock(cond->mutex); return; @@ -240,14 +240,17 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, DEBUG1("Timed wait condition %p", cond); /* If there is a mutex unlock it */ - if(mutex != NULL){ + if (mutex != NULL) { cond->mutex = mutex; SIMIX_mutex_unlock(mutex); } if (max_duration >= 0) { act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); - SIMIX_action_set_name(act_sleep,bprintf("Timed wait condition %p (max_duration:%f)", cond,max_duration)); + SIMIX_action_set_name(act_sleep, + bprintf + ("Timed wait condition %p (max_duration:%f)", + cond, max_duration)); SIMIX_register_action_to_condition(act_sleep, cond); SIMIX_process_self()->waiting_action = act_sleep; __SIMIX_cond_wait(cond); @@ -255,16 +258,16 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, SIMIX_unregister_action_to_condition(act_sleep, cond); if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { SIMIX_action_destroy(act_sleep); - THROW1(timeout_error, 0, "Condition timeout after %f",max_duration); + THROW1(timeout_error, 0, "Condition timeout after %f", max_duration); } else { SIMIX_action_destroy(act_sleep); } } else - SIMIX_cond_wait(cond,NULL); + SIMIX_cond_wait(cond, NULL); /* get the mutex again if necessary */ - if(mutex != NULL) + if (mutex != NULL) SIMIX_mutex_lock(cond->mutex); } @@ -338,7 +341,8 @@ void SIMIX_cond_display_info(smx_cond_t cond) /* ************************** Semaphores ************************************** */ #define SMX_SEM_NOLIMIT 99999 /** @brief Initialize a semaphore */ -smx_sem_t SIMIX_sem_init(int capacity) { +smx_sem_t SIMIX_sem_init(int capacity) +{ smx_sem_t sem = xbt_new0(s_smx_sem_t, 1); sem->sleeping = xbt_fifo_new(); @@ -346,19 +350,21 @@ smx_sem_t SIMIX_sem_init(int capacity) { sem->capacity = capacity; return sem; } + /** @brief Destroys a semaphore */ -void SIMIX_sem_destroy(smx_sem_t sem) { +void SIMIX_sem_destroy(smx_sem_t sem) +{ smx_action_t action = NULL; DEBUG1("Destroy semaphore %p", sem); if (sem == NULL) return; xbt_assert0(xbt_fifo_size(sem->sleeping) == 0, - "Cannot destroy semaphore since someone is still using it"); + "Cannot destroy semaphore since someone is still using it"); xbt_fifo_free(sem->sleeping); DEBUG1("%d actions registered", xbt_fifo_size(sem->actions)); - while((action=xbt_fifo_pop(sem->actions))) + while ((action = xbt_fifo_pop(sem->actions))) SIMIX_unregister_action_to_semaphore(action, sem); xbt_fifo_free(sem->actions); @@ -370,7 +376,8 @@ void SIMIX_sem_destroy(smx_sem_t sem) { * The first locked process on this semaphore is unlocked. * If no one was blocked, the semaphore capacity is increased by 1. * */ -void SIMIX_sem_release(smx_sem_t sem) { +void SIMIX_sem_release(smx_sem_t sem) +{ smx_process_t proc; if (sem->capacity != SMX_SEM_NOLIMIT) { @@ -381,6 +388,7 @@ void SIMIX_sem_release(smx_sem_t sem) { xbt_swag_insert(proc, simix_global->process_to_run); } } + /** @brief make sure the semaphore will never be blocking again * * This function is not really in the semaphore spirit. It makes @@ -393,7 +401,8 @@ void SIMIX_sem_release(smx_sem_t sem) { * * There is no way to reset the semaphore to a more regular state afterward. * */ -void SIMIX_sem_release_forever(smx_sem_t sem) { +void SIMIX_sem_release_forever(smx_sem_t sem) +{ smx_process_t proc; sem->capacity = SMX_SEM_NOLIMIT; @@ -413,12 +422,13 @@ void SIMIX_sem_release_forever(smx_sem_t sem) { * do not attach a dummy action beforehand. SIMIX_sem_acquire does all these * things for you so you it may be preferable to use. */ -void SIMIX_sem_block_onto(smx_sem_t sem) { +void SIMIX_sem_block_onto(smx_sem_t sem) +{ smx_process_t self = SIMIX_process_self(); /* process status */ self->sem = sem; - xbt_fifo_push (sem->sleeping, self); + xbt_fifo_push(sem->sleeping, self); SIMIX_process_yield(); self->sem = NULL; while (self->suspended) @@ -426,15 +436,17 @@ void SIMIX_sem_block_onto(smx_sem_t sem) { } /** @brief Returns true if acquiring this semaphore would block */ -XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem) { - return (sem->capacity<=0); +XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem) +{ + return (sem->capacity <= 0); } /** @brief Returns the current capacity of the semaphore * * If it's negative, that's the amount of processes locked on the semaphore */ -int SIMIX_sem_get_capacity(smx_sem_t sem){ +int SIMIX_sem_get_capacity(smx_sem_t sem) +{ return sem->capacity; } @@ -446,8 +458,9 @@ int SIMIX_sem_get_capacity(smx_sem_t sem){ * If capacity==0, locks the current process * until someone call SIMIX_sem_release() on this semaphore */ -void SIMIX_sem_acquire(smx_sem_t sem) { - SIMIX_sem_acquire_timeout (sem, -1); +void SIMIX_sem_acquire(smx_sem_t sem) +{ + SIMIX_sem_acquire_timeout(sem, -1); } /** @@ -455,18 +468,19 @@ void SIMIX_sem_acquire(smx_sem_t sem) { * * Same behavior of #SIMIX_sem_acquire, but waits a maximum time and throws an timeout_error if it happens. */ -void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { +void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) +{ smx_action_t act_sleep; DEBUG2("Wait semaphore %p (timeout:%f)", sem, max_duration); if (sem->capacity == SMX_SEM_NOLIMIT) { DEBUG1("semaphore %p wide open", sem); - return; /* don't even decrease it if wide open */ + return; /* don't even decrease it if wide open */ } /* If capacity sufficient, decrease it */ - if (sem->capacity>0) { + if (sem->capacity > 0) { DEBUG1("semaphore %p has enough capacity", sem); sem->capacity--; return; @@ -474,15 +488,19 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { /* Always create an action null in case there is a host failure */ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); - SIMIX_action_set_name(act_sleep,bprintf("Locked in semaphore %p (max_duration:%f)", sem, max_duration)); + SIMIX_action_set_name(act_sleep, + bprintf("Locked in semaphore %p (max_duration:%f)", + sem, max_duration)); SIMIX_process_self()->waiting_action = act_sleep; SIMIX_register_action_to_semaphore(act_sleep, sem); SIMIX_sem_block_onto(sem); SIMIX_process_self()->waiting_action = NULL; SIMIX_unregister_action_to_semaphore(act_sleep, sem); - if (max_duration >= 0 && SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { + if (max_duration >= 0 + && SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { SIMIX_action_destroy(act_sleep); - THROW1(timeout_error, 0, "Semaphore acquire timeouted after %f",max_duration); + THROW1(timeout_error, 0, "Semaphore acquire timeouted after %f", + max_duration); } else { if (sem->capacity != SMX_SEM_NOLIMIT) { /* Take the released token */ @@ -492,6 +510,7 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { } DEBUG1("End of Wait on semaphore %p", sem); } + /** * \brief Blocks on a set of semaphore * @@ -500,19 +519,21 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { * * \return the rank in the dynar of the semaphore which just got locked from the set */ -unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) { +unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) +{ smx_sem_t sem; - unsigned int counter,result=-1; + unsigned int counter, result = -1; smx_action_t act_sleep; smx_process_t self = SIMIX_process_self(); xbt_assert0(xbt_dynar_length(sems), - "I refuse to commit sucide by locking on an **empty** set of semaphores!!"); - DEBUG2("Wait on semaphore set %p (containing %ld semaphores)", sems,xbt_dynar_length(sems)); + "I refuse to commit sucide by locking on an **empty** set of semaphores!!"); + DEBUG2("Wait on semaphore set %p (containing %ld semaphores)", sems, + xbt_dynar_length(sems)); - xbt_dynar_foreach(sems,counter,sem) { + xbt_dynar_foreach(sems, counter, sem) { if (!SIMIX_sem_would_block(sem)) { - DEBUG1("Semaphore %p wouldn't block; get it without waiting",sem); + DEBUG1("Semaphore %p wouldn't block; get it without waiting", sem); SIMIX_sem_acquire(sem); return counter; } @@ -520,13 +541,14 @@ unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) { /* Always create an action null in case there is a host failure */ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); - SIMIX_action_set_name(act_sleep,bprintf("Locked in semaphore %p", sem)); + SIMIX_action_set_name(act_sleep, bprintf("Locked in semaphore %p", sem)); self->waiting_action = act_sleep; - SIMIX_register_action_to_semaphore(act_sleep, xbt_dynar_get_as(sems,0,smx_sem_t)); + SIMIX_register_action_to_semaphore(act_sleep, + xbt_dynar_get_as(sems, 0, smx_sem_t)); /* Get listed as member of all the provided semaphores */ - self->sem = (smx_sem_t)sems; /* FIXME: we pass a pointer to dynar where a pointer to sem is expected...*/ - xbt_dynar_foreach(sems,counter,sem) { + self->sem = (smx_sem_t) sems; /* FIXME: we pass a pointer to dynar where a pointer to sem is expected... */ + xbt_dynar_foreach(sems, counter, sem) { xbt_fifo_push(sem->sleeping, self); } SIMIX_process_yield(); @@ -535,7 +557,7 @@ unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) { SIMIX_process_yield(); /* at least one of the semaphore unsuspended us -- great, let's search the first one (and get out of the others) */ - xbt_dynar_foreach(sems,counter,sem) { + xbt_dynar_foreach(sems, counter, sem) { if (!xbt_fifo_remove(sem->sleeping, self) && result == -1) { if (sem->capacity != SMX_SEM_NOLIMIT) { /* Take the released token */ @@ -544,11 +566,13 @@ unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) { result = counter; } } - xbt_assert0(result!=-1,"Cannot find which semaphore unlocked me!"); + xbt_assert0(result != -1, "Cannot find which semaphore unlocked me!"); /* Destroy the waiting action */ self->waiting_action = NULL; - SIMIX_unregister_action_to_semaphore(act_sleep, xbt_dynar_get_as(sems,0,smx_sem_t)); + SIMIX_unregister_action_to_semaphore(act_sleep, + xbt_dynar_get_as(sems, 0, + smx_sem_t)); SIMIX_action_destroy(act_sleep); return result; } diff --git a/src/smpi/private.h b/src/smpi/private.h index 4816283321..bccb451346 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -14,7 +14,7 @@ #include "instr/private.h" struct s_smpi_process_data; -typedef struct s_smpi_process_data* smpi_process_data_t; +typedef struct s_smpi_process_data *smpi_process_data_t; #define PERSISTENT 0x0 #define NON_PERSISTENT 0x1 @@ -22,7 +22,7 @@ typedef struct s_smpi_process_data* smpi_process_data_t; #define RECV 0x2 typedef struct s_smpi_mpi_request { - void* buf; + void *buf; size_t size; int src; int dst; @@ -39,7 +39,7 @@ typedef struct s_smpi_mpi_request { #endif } s_smpi_mpi_request_t; -void smpi_process_init(int* argc, char*** argv); +void smpi_process_init(int *argc, char ***argv); void smpi_process_destroy(void); smpi_process_data_t smpi_process_data(void); @@ -49,7 +49,7 @@ int smpi_process_index(void); xbt_os_timer_t smpi_process_timer(void); void smpi_process_simulated_start(void); double smpi_process_simulated_elapsed(void); -void print_request(const char* message, MPI_Request request); +void print_request(const char *message, MPI_Request request); void smpi_process_post_send(MPI_Comm comm, MPI_Request request); void smpi_process_post_recv(MPI_Request request); @@ -59,12 +59,16 @@ void smpi_global_destroy(void); size_t smpi_datatype_size(MPI_Datatype datatype); MPI_Aint smpi_datatype_lb(MPI_Datatype datatype); MPI_Aint smpi_datatype_ub(MPI_Datatype datatype); -int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint * extent); -int smpi_datatype_copy(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype); +int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb, + MPI_Aint * extent); +int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, + MPI_Datatype recvtype); -MPI_Op smpi_op_new(MPI_User_function* function, int commute); +MPI_Op smpi_op_new(MPI_User_function * function, int commute); void smpi_op_destroy(MPI_Op op); -void smpi_op_apply(MPI_Op op, void* invec, void* inoutvec, int* len, MPI_Datatype* datatype); +void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, + MPI_Datatype * datatype); MPI_Group smpi_group_new(int size); void smpi_group_destroy(MPI_Group group); @@ -82,48 +86,97 @@ MPI_Group smpi_comm_group(MPI_Comm comm); int smpi_comm_size(MPI_Comm comm); int smpi_comm_rank(MPI_Comm comm); -MPI_Request smpi_mpi_send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); -MPI_Request smpi_mpi_recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); +MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm); +MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm); void smpi_mpi_start(MPI_Request request); -void smpi_mpi_startall(int count, MPI_Request* requests); -void smpi_mpi_request_free(MPI_Request* request); -MPI_Request smpi_isend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); -MPI_Request smpi_mpi_isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); -MPI_Request smpi_irecv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); -MPI_Request smpi_mpi_irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); -void smpi_mpi_recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status); -void smpi_mpi_send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); -void smpi_mpi_sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status); -int smpi_mpi_test(MPI_Request* request, MPI_Status* status); -int smpi_mpi_testany(int count, MPI_Request requests[], int* index, MPI_Status* status); -int smpi_mpi_get_count(MPI_Status* status, MPI_Datatype datatype); -void smpi_mpi_wait(MPI_Request* request, MPI_Status* status); -int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status* status); -void smpi_mpi_waitall(int count, MPI_Request requests[], MPI_Status status[]); -int smpi_mpi_waitsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]); -void smpi_mpi_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm); +void smpi_mpi_startall(int count, MPI_Request * requests); +void smpi_mpi_request_free(MPI_Request * request); +MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm); +MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm); +MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm); +MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm); +void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src, + int tag, MPI_Comm comm, MPI_Status * status); +void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst, + int tag, MPI_Comm comm); +void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + int dst, int sendtag, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int src, int recvtag, + MPI_Comm comm, MPI_Status * status); +int smpi_mpi_test(MPI_Request * request, MPI_Status * status); +int smpi_mpi_testany(int count, MPI_Request requests[], int *index, + MPI_Status * status); +int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype); +void smpi_mpi_wait(MPI_Request * request, MPI_Status * status); +int smpi_mpi_waitany(int count, MPI_Request requests[], + MPI_Status * status); +void smpi_mpi_waitall(int count, MPI_Request requests[], + MPI_Status status[]); +int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices, + MPI_Status status[]); +void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm); void smpi_mpi_barrier(MPI_Comm comm); -void smpi_mpi_gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -void smpi_mpi_gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm); -void smpi_mpi_allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -void smpi_mpi_allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm); -void smpi_mpi_scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -void smpi_mpi_scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); -void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); -void smpi_mpi_allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); - -void nary_tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, int arity); +void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm); +void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm); +void smpi_mpi_allgather(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm); +void smpi_mpi_allgatherv(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int *recvcounts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm); +void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm); +void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int root, MPI_Comm comm); +void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, + MPI_Comm comm); +void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); +void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); + +void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm, int arity); void nary_tree_barrier(MPI_Comm comm, int arity); -int smpi_coll_tuned_alltoall_bruck(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -int smpi_coll_tuned_alltoall_pairwise(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); -int smpi_coll_basic_alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm); +int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm); +int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, + MPI_Datatype sendtype, + void *recvbuf, int recvcount, + MPI_Datatype recvtype, + MPI_Comm comm); +int smpi_coll_tuned_alltoall_pairwise(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm); +int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts, + int *senddisps, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, + int *recvdisps, MPI_Datatype recvtype, + MPI_Comm comm); // utilities void smpi_bench_destroy(void); -void smpi_bench_begin(int rank, const char* mpi_call); -void smpi_bench_end(int rank, const char* mpi_call); +void smpi_bench_begin(int rank, const char *mpi_call); +void smpi_bench_end(int rank, const char *mpi_call); #endif diff --git a/src/smpi/sample/reduce.c b/src/smpi/sample/reduce.c index d939385bba..f7321d6028 100644 --- a/src/smpi/sample/reduce.c +++ b/src/smpi/sample/reduce.c @@ -7,11 +7,12 @@ #include #include -int main (int argc, char **argv) { +int main(int argc, char **argv) +{ int size, rank; - int root=0; + int root = 0; int value = 1; - int sum=-99; + int sum = -99; double start_timer; @@ -24,9 +25,9 @@ int main (int argc, char **argv) { printf("rank %d has value %d\n", rank, value); MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD); - if ( rank == root) { - printf("On root: sum=%d\n",sum); - printf("Elapsed time=%lf s\n", MPI_Wtime()-start_timer); + if (rank == root) { + printf("On root: sum=%d\n", sum); + printf("Elapsed time=%lf s\n", MPI_Wtime() - start_timer); } MPI_Finalize(); return 0; diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index e82e6d00c7..b032ec7d4c 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -19,7 +19,8 @@ XBT_LOG_EXTERNAL_CATEGORY(smpi_receiver); XBT_LOG_EXTERNAL_CATEGORY(smpi_sender); XBT_LOG_EXTERNAL_CATEGORY(smpi_util); -void smpi_process_init(int* argc, char*** argv) { +void smpi_process_init(int *argc, char ***argv) +{ int index; smpi_process_data_t data; smx_process_t proc; @@ -37,13 +38,17 @@ void smpi_process_init(int* argc, char*** argv) { DEBUG2("<%d> New process in the game: %p", index, proc); } -void smpi_process_destroy(void) { +void smpi_process_destroy(void) +{ int index = smpi_process_index(); DEBUG1("<%d> Process left the game", index); } -static MPI_Request build_request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) { +static MPI_Request build_request(void *buf, int count, + MPI_Datatype datatype, int src, int dst, + int tag, MPI_Comm comm, unsigned flags) +{ MPI_Request request; request = xbt_new(s_smpi_mpi_request_t, 1); @@ -66,117 +71,158 @@ static MPI_Request build_request(void* buf, int count, MPI_Datatype datatype, in } /* MPI Low level calls */ -MPI_Request smpi_mpi_send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - MPI_Request request = build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag, comm, PERSISTENT | SEND); +MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm) +{ + MPI_Request request = + build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag, + comm, PERSISTENT | SEND); return request; } -MPI_Request smpi_mpi_recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { - MPI_Request request = build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV); +MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm) +{ + MPI_Request request = + build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag, + comm, PERSISTENT | RECV); return request; } -void smpi_mpi_start(MPI_Request request) { - xbt_assert0(request->complete == 0, "Cannot start a non-finished communication"); - if((request->flags & RECV) == RECV) { +void smpi_mpi_start(MPI_Request request) +{ + xbt_assert0(request->complete == 0, + "Cannot start a non-finished communication"); + if ((request->flags & RECV) == RECV) { smpi_process_post_recv(request); print_request("New recv", request); - request->pair = SIMIX_network_irecv(request->rdv, request->buf, &request->size); + request->pair = + SIMIX_network_irecv(request->rdv, request->buf, &request->size); } else { - smpi_process_post_send(request->comm, request); // FIXME + smpi_process_post_send(request->comm, request); // FIXME print_request("New send", request); - request->pair = SIMIX_network_isend(request->rdv, request->size, -1.0, request->buf, request->size, NULL); + request->pair = + SIMIX_network_isend(request->rdv, request->size, -1.0, + request->buf, request->size, NULL); } } -void smpi_mpi_startall(int count, MPI_Request* requests) { +void smpi_mpi_startall(int count, MPI_Request * requests) +{ int i; - for(i = 0; i < count; i++) { + for (i = 0; i < count; i++) { smpi_mpi_start(requests[i]); } } -void smpi_mpi_request_free(MPI_Request* request) { +void smpi_mpi_request_free(MPI_Request * request) +{ xbt_free(*request); *request = MPI_REQUEST_NULL; } -MPI_Request smpi_isend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - MPI_Request request = build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag, comm, NON_PERSISTENT | SEND); +MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm) +{ + MPI_Request request = + build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag, + comm, NON_PERSISTENT | SEND); return request; } -MPI_Request smpi_mpi_isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - MPI_Request request = smpi_isend_init(buf, count, datatype, dst, tag, comm); +MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype, + int dst, int tag, MPI_Comm comm) +{ + MPI_Request request = + smpi_isend_init(buf, count, datatype, dst, tag, comm); smpi_mpi_start(request); return request; } -MPI_Request smpi_irecv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { - MPI_Request request = build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag, comm, NON_PERSISTENT | RECV); +MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm) +{ + MPI_Request request = + build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag, + comm, NON_PERSISTENT | RECV); return request; } -MPI_Request smpi_mpi_irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { - MPI_Request request = smpi_irecv_init(buf, count, datatype, src, tag, comm); +MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype, + int src, int tag, MPI_Comm comm) +{ + MPI_Request request = + smpi_irecv_init(buf, count, datatype, src, tag, comm); smpi_mpi_start(request); return request; } -void smpi_mpi_recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) { +void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src, + int tag, MPI_Comm comm, MPI_Status * status) +{ MPI_Request request; request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm); smpi_mpi_wait(&request, status); } -void smpi_mpi_send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { +void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst, + int tag, MPI_Comm comm) +{ MPI_Request request; request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm); smpi_mpi_wait(&request, MPI_STATUS_IGNORE); } -void smpi_mpi_sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) { +void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + int dst, int sendtag, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int src, int recvtag, + MPI_Comm comm, MPI_Status * status) +{ MPI_Request requests[2]; MPI_Status stats[2]; - requests[0] = smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm); - requests[1] = smpi_irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm); + requests[0] = + smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm); + requests[1] = + smpi_irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm); smpi_mpi_startall(2, requests); smpi_mpi_waitall(2, requests, stats); - if(status != MPI_STATUS_IGNORE) { + if (status != MPI_STATUS_IGNORE) { // Copy receive status memcpy(status, &stats[1], sizeof(MPI_Status)); } } -int smpi_mpi_get_count(MPI_Status* status, MPI_Datatype datatype) { - return status->count / smpi_datatype_size(datatype); +int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype) +{ + return status->count / smpi_datatype_size(datatype); } -static void finish_wait(MPI_Request* request, MPI_Status* status) { - if(status != MPI_STATUS_IGNORE) { +static void finish_wait(MPI_Request * request, MPI_Status * status) +{ + if (status != MPI_STATUS_IGNORE) { status->MPI_SOURCE = (*request)->src; status->MPI_TAG = (*request)->tag; status->MPI_ERROR = MPI_SUCCESS; status->count = SIMIX_communication_get_dst_buf_size((*request)->pair); } print_request("finishing wait", *request); - if((*request)->complete == 1) { + if ((*request)->complete == 1) { SIMIX_rdv_destroy((*request)->rdv); } else { (*request)->match->complete = 1; (*request)->match->match = MPI_REQUEST_NULL; } - if(((*request)->flags & NON_PERSISTENT) == NON_PERSISTENT) { + if (((*request)->flags & NON_PERSISTENT) == NON_PERSISTENT) { smpi_mpi_request_free(request); } else { (*request)->rdv = NULL; @@ -184,22 +230,25 @@ static void finish_wait(MPI_Request* request, MPI_Status* status) { } } -int smpi_mpi_test(MPI_Request* request, MPI_Status* status) { +int smpi_mpi_test(MPI_Request * request, MPI_Status * status) +{ int flag = (*request)->complete; - if(flag) { + if (flag) { smpi_mpi_wait(request, status); } return flag; } -int smpi_mpi_testany(int count, MPI_Request requests[], int* index, MPI_Status* status) { +int smpi_mpi_testany(int count, MPI_Request requests[], int *index, + MPI_Status * status) +{ int i, flag; *index = MPI_UNDEFINED; flag = 0; - for(i = 0; i < count; i++) { - if(requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { + for (i = 0; i < count; i++) { + if (requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { smpi_mpi_wait(&requests[i], status); *index = i; flag = 1; @@ -209,42 +258,45 @@ int smpi_mpi_testany(int count, MPI_Request requests[], int* index, MPI_Status* return flag; } -void smpi_mpi_wait(MPI_Request* request, MPI_Status* status) { +void smpi_mpi_wait(MPI_Request * request, MPI_Status * status) +{ print_request("wait", *request); SIMIX_network_wait((*request)->pair, -1.0); finish_wait(request, status); } -int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status* status) { +int smpi_mpi_waitany(int count, MPI_Request requests[], + MPI_Status * status) +{ xbt_dynar_t comms; int i, size, index; - int* map; + int *map; index = MPI_UNDEFINED; - if(count > 0) { + if (count > 0) { // First check for already completed requests - for(i = 0; i < count; i++) { - if(requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { + for (i = 0; i < count; i++) { + if (requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { index = i; smpi_mpi_wait(&requests[index], status); break; } } - if(index == MPI_UNDEFINED) { + if (index == MPI_UNDEFINED) { // Otherwise, wait for a request to complete comms = xbt_dynar_new(sizeof(smx_comm_t), NULL); map = xbt_new(int, count); size = 0; DEBUG0("Wait for one of"); - for(i = 0; i < count; i++) { - if(requests[i] != MPI_REQUEST_NULL && requests[i]->complete == 0) { + for (i = 0; i < count; i++) { + if (requests[i] != MPI_REQUEST_NULL && requests[i]->complete == 0) { print_request(" ", requests[i]); xbt_dynar_push(comms, &requests[i]->pair); map[size] = i; size++; } } - if(size > 0) { + if (size > 0) { index = SIMIX_network_waitany(comms); index = map[index]; finish_wait(&requests[index], status); @@ -256,16 +308,18 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status* status) { return index; } -void smpi_mpi_waitall(int count, MPI_Request requests[], MPI_Status status[]) { +void smpi_mpi_waitall(int count, MPI_Request requests[], + MPI_Status status[]) +{ int index; MPI_Status stat; - while(count > 0) { + while (count > 0) { index = smpi_mpi_waitany(count, requests, &stat); - if(index == MPI_UNDEFINED) { + if (index == MPI_UNDEFINED) { break; } - if(status != MPI_STATUS_IGNORE) { + if (status != MPI_STATUS_IGNORE) { memcpy(&status[index], &stat, sizeof(stat)); } // FIXME: check this -v @@ -276,13 +330,17 @@ void smpi_mpi_waitall(int count, MPI_Request requests[], MPI_Status status[]) { } } -int smpi_mpi_waitsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]) { +int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices, + MPI_Status status[]) +{ int i, count; count = 0; - for(i = 0; i < incount; i++) { - if(requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { - smpi_mpi_wait(&requests[i], status != MPI_STATUS_IGNORE ? &status[i] : MPI_STATUS_IGNORE); + for (i = 0; i < incount; i++) { + if (requests[i] != MPI_REQUEST_NULL && requests[i]->complete) { + smpi_mpi_wait(&requests[i], + status != + MPI_STATUS_IGNORE ? &status[i] : MPI_STATUS_IGNORE); indices[count] = i; count++; } @@ -290,37 +348,47 @@ int smpi_mpi_waitsome(int incount, MPI_Request requests[], int* indices, MPI_Sta return count; } -void smpi_mpi_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { +void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm) +{ // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI)) nary_tree_bcast(buf, count, datatype, root, comm, 4); } -void smpi_mpi_barrier(MPI_Comm comm) { +void smpi_mpi_barrier(MPI_Comm comm) +{ // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI)) nary_tree_barrier(comm, 4); } -void smpi_mpi_gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm) +{ int system_tag = 666; int rank, size, src, index, sendsize, recvsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); - if(rank != root) { + if (rank != root) { // Send buffer to root smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm); } else { sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); // Local copy from root - memcpy(&((char*)recvbuf)[root * recvcount * recvsize], sendbuf, sendcount * sendsize * sizeof(char)); + memcpy(&((char *) recvbuf)[root * recvcount * recvsize], sendbuf, + sendcount * sendsize * sizeof(char)); // Receive buffers from senders requests = xbt_new(MPI_Request, size - 1); index = 0; - for(src = 0; src < size; src++) { - if(src != root) { - requests[index] = smpi_irecv_init(&((char*)recvbuf)[src * recvcount * recvsize], recvcount, recvtype, src, system_tag, comm); + for (src = 0; src < size; src++) { + if (src != root) { + requests[index] = smpi_irecv_init(&((char *) recvbuf) + [src * recvcount * recvsize], + recvcount, recvtype, src, + system_tag, comm); index++; } } @@ -331,26 +399,33 @@ void smpi_mpi_gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* } } -void smpi_mpi_gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm) { +void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm) +{ int system_tag = 666; int rank, size, src, index, sendsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); - if(rank != root) { + if (rank != root) { // Send buffer to root smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm); } else { sendsize = smpi_datatype_size(sendtype); // Local copy from root - memcpy(&((char*)recvbuf)[displs[root]], sendbuf, sendcount * sendsize * sizeof(char)); + memcpy(&((char *) recvbuf)[displs[root]], sendbuf, + sendcount * sendsize * sizeof(char)); // Receive buffers from senders requests = xbt_new(MPI_Request, size - 1); index = 0; - for(src = 0; src < size; src++) { - if(src != root) { - requests[index] = smpi_irecv_init(&((char*)recvbuf)[displs[src]], recvcounts[src], recvtype, src, system_tag, comm); + for (src = 0; src < size; src++) { + if (src != root) { + requests[index] = + smpi_irecv_init(&((char *) recvbuf)[displs[src]], + recvcounts[src], recvtype, src, system_tag, + comm); index++; } } @@ -361,25 +436,35 @@ void smpi_mpi_gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* } } -void smpi_mpi_allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +void smpi_mpi_allgather(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) +{ int system_tag = 666; int rank, size, other, index, sendsize, recvsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); // Local copy from self - memcpy(&((char*)recvbuf)[rank * recvcount * recvsize], sendbuf, sendcount * sendsize * sizeof(char)); + memcpy(&((char *) recvbuf)[rank * recvcount * recvsize], sendbuf, + sendcount * sendsize * sizeof(char)); // Send/Recv buffers to/from others; requests = xbt_new(MPI_Request, 2 * (size - 1)); index = 0; - for(other = 0; other < size; other++) { - if(other != rank) { - requests[index] = smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag, comm); + for (other = 0; other < size; other++) { + if (other != rank) { + requests[index] = + smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag, + comm); index++; - requests[index] = smpi_irecv_init(&((char*)recvbuf)[other * recvcount * recvsize], recvcount, recvtype, other, system_tag, comm); + requests[index] = smpi_irecv_init(&((char *) recvbuf) + [other * recvcount * recvsize], + recvcount, recvtype, other, + system_tag, comm); index++; } } @@ -389,25 +474,35 @@ void smpi_mpi_allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, voi xbt_free(requests); } -void smpi_mpi_allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) { +void smpi_mpi_allgatherv(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int *recvcounts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm) +{ int system_tag = 666; int rank, size, other, index, sendsize, recvsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); // Local copy from self - memcpy(&((char*)recvbuf)[displs[rank]], sendbuf, sendcount * sendsize * sizeof(char)); + memcpy(&((char *) recvbuf)[displs[rank]], sendbuf, + sendcount * sendsize * sizeof(char)); // Send buffers to others; requests = xbt_new(MPI_Request, 2 * (size - 1)); index = 0; - for(other = 0; other < size; other++) { - if(other != rank) { - requests[index] = smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag, comm); + for (other = 0; other < size; other++) { + if (other != rank) { + requests[index] = + smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag, + comm); index++; - requests[index] = smpi_irecv_init(&((char*)recvbuf)[displs[other]], recvcounts[other], recvtype, other, system_tag, comm); + requests[index] = + smpi_irecv_init(&((char *) recvbuf)[displs[other]], + recvcounts[other], recvtype, other, system_tag, + comm); index++; } } @@ -417,27 +512,35 @@ void smpi_mpi_allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, vo xbt_free(requests); } -void smpi_mpi_scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm) +{ int system_tag = 666; int rank, size, dst, index, sendsize, recvsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); - if(rank != root) { + if (rank != root) { // Recv buffer from root - smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE); + smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, + MPI_STATUS_IGNORE); } else { sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); // Local copy from root - memcpy(recvbuf, &((char*)sendbuf)[root * sendcount * sendsize], recvcount * recvsize * sizeof(char)); + memcpy(recvbuf, &((char *) sendbuf)[root * sendcount * sendsize], + recvcount * recvsize * sizeof(char)); // Send buffers to receivers requests = xbt_new(MPI_Request, size - 1); index = 0; - for(dst = 0; dst < size; dst++) { - if(dst != root) { - requests[index] = smpi_isend_init(&((char*)sendbuf)[dst * sendcount * sendsize], sendcount, sendtype, dst, system_tag, comm); + for (dst = 0; dst < size; dst++) { + if (dst != root) { + requests[index] = smpi_isend_init(&((char *) sendbuf) + [dst * sendcount * sendsize], + sendcount, sendtype, dst, + system_tag, comm); index++; } } @@ -448,27 +551,35 @@ void smpi_mpi_scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* } } -void smpi_mpi_scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int root, MPI_Comm comm) +{ int system_tag = 666; int rank, size, dst, index, sendsize, recvsize; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); - if(rank != root) { + if (rank != root) { // Recv buffer from root - smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE); + smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, + MPI_STATUS_IGNORE); } else { sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); // Local copy from root - memcpy(recvbuf, &((char*)sendbuf)[displs[root]], recvcount * recvsize * sizeof(char)); + memcpy(recvbuf, &((char *) sendbuf)[displs[root]], + recvcount * recvsize * sizeof(char)); // Send buffers to receivers requests = xbt_new(MPI_Request, size - 1); index = 0; - for(dst = 0; dst < size; dst++) { - if(dst != root) { - requests[index] = smpi_isend_init(&((char*)sendbuf)[displs[dst]], sendcounts[dst], sendtype, dst, system_tag, comm); + for (dst = 0; dst < size; dst++) { + if (dst != root) { + requests[index] = + smpi_isend_init(&((char *) sendbuf)[displs[dst]], + sendcounts[dst], sendtype, dst, system_tag, + comm); index++; } } @@ -479,15 +590,18 @@ void smpi_mpi_scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype } } -void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { +void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, + MPI_Comm comm) +{ int system_tag = 666; int rank, size, src, index, datasize; - MPI_Request* requests; - void** tmpbufs; + MPI_Request *requests; + void **tmpbufs; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); - if(rank != root) { + if (rank != root) { // Send buffer to root smpi_mpi_send(sendbuf, count, datatype, root, system_tag, comm); } else { @@ -497,25 +611,27 @@ void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datat // Receive buffers from senders //TODO: make a MPI_barrier here ? requests = xbt_new(MPI_Request, size - 1); - tmpbufs = xbt_new(void*, size - 1); + tmpbufs = xbt_new(void *, size - 1); index = 0; - for(src = 0; src < size; src++) { - if(src != root) { + for (src = 0; src < size; src++) { + if (src != root) { tmpbufs[index] = xbt_malloc(count * datasize); - requests[index] = smpi_irecv_init(tmpbufs[index], count, datatype, src, system_tag, comm); + requests[index] = + smpi_irecv_init(tmpbufs[index], count, datatype, src, + system_tag, comm); index++; } } // Wait for completion of irecv's. smpi_mpi_startall(size - 1, requests); - for(src = 0; src < size - 1; src++) { + for (src = 0; src < size - 1; src++) { index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE); - if(index == MPI_UNDEFINED) { + if (index == MPI_UNDEFINED) { break; } smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); } - for(index = 0; index < size - 1; index++) { + for (index = 0; index < size - 1; index++) { xbt_free(tmpbufs[index]); } xbt_free(tmpbufs); @@ -523,7 +639,9 @@ void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datat } } -void smpi_mpi_allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { +void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm); smpi_mpi_bcast(recvbuf, count, datatype, 0, comm); @@ -572,12 +690,14 @@ FIXME: buggy implementation */ } -void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { +void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ int system_tag = 666; int rank, size, other, index, datasize; int total; - MPI_Request* requests; - void** tmpbufs; + MPI_Request *requests; + void **tmpbufs; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); @@ -587,30 +707,33 @@ void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatyp // Send/Recv buffers to/from others; total = rank + (size - (rank + 1)); requests = xbt_new(MPI_Request, total); - tmpbufs = xbt_new(void*, rank); + tmpbufs = xbt_new(void *, rank); index = 0; - for(other = 0; other < rank; other++) { + for (other = 0; other < rank; other++) { tmpbufs[index] = xbt_malloc(count * datasize); - requests[index] = smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag, comm); + requests[index] = + smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag, + comm); index++; } - for(other = rank + 1; other < size; other++) { - requests[index] = smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm); + for (other = rank + 1; other < size; other++) { + requests[index] = + smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm); index++; } // Wait for completion of all comms. smpi_mpi_startall(size - 1, requests); - for(other = 0; other < total; other++) { + for (other = 0; other < total; other++) { index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE); - if(index == MPI_UNDEFINED) { + if (index == MPI_UNDEFINED) { break; } - if(index < rank) { + if (index < rank) { // #Request is below rank: it's a irecv smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); } } - for(index = 0; index < size - 1; index++) { + for (index = 0; index < size - 1; index++) { xbt_free(tmpbufs[index]); } xbt_free(tmpbufs); diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index 387cac49b4..9a09864405 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -11,31 +11,33 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, "Logging specific to SMPI (benchmarking)"); -xbt_dict_t allocs = NULL; /* Allocated on first use */ -xbt_dict_t samples = NULL; /* Allocated on first use */ +xbt_dict_t allocs = NULL; /* Allocated on first use */ +xbt_dict_t samples = NULL; /* Allocated on first use */ typedef struct { - int count; - char data[]; + int count; + char data[]; } shared_data_t; typedef struct { - double time; - int count; - int max; - int started; + double time; + int count; + int max; + int started; } local_data_t; -void smpi_bench_destroy(void) { - if (allocs) { - xbt_dict_free(&allocs); - } - if (samples) { - xbt_dict_free(&samples); - } +void smpi_bench_destroy(void) +{ + if (allocs) { + xbt_dict_free(&allocs); + } + if (samples) { + xbt_dict_free(&samples); + } } -static void smpi_execute_flops(double flops) { +static void smpi_execute_flops(double flops) +{ smx_host_t host; smx_action_t action; smx_mutex_t mutex; @@ -49,9 +51,10 @@ static void smpi_execute_flops(double flops) { action = SIMIX_action_execute(host, "computation", flops); SIMIX_mutex_lock(mutex); SIMIX_register_action_to_condition(action, cond); - for(state = SIMIX_action_get_state(action); - state == SURF_ACTION_READY || - state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) { + for (state = SIMIX_action_get_state(action); + state == SURF_ACTION_READY || + state == SURF_ACTION_RUNNING; + state = SIMIX_action_get_state(action)) { SIMIX_cond_wait(cond, mutex); } SIMIX_unregister_action_to_condition(action, cond); @@ -61,151 +64,170 @@ static void smpi_execute_flops(double flops) { SIMIX_mutex_destroy(mutex); } -static void smpi_execute(double duration) { - if(duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) { +static void smpi_execute(double duration) +{ + if (duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) { DEBUG1("Sleep for %f to handle real computation time", duration); - smpi_execute_flops(duration * xbt_cfg_get_double(_surf_cfg_set, "smpi/running_power")); + smpi_execute_flops(duration * + xbt_cfg_get_double(_surf_cfg_set, + "smpi/running_power")); } } -void smpi_bench_begin(int rank, const char* mpi_call) { - if(mpi_call && rank >= 0 && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) { - INFO3("SMPE: ts=%f rank=%d type=end et=%s", SIMIX_get_clock(), rank, mpi_call); +void smpi_bench_begin(int rank, const char *mpi_call) +{ + if (mpi_call && rank >= 0 + && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) { + INFO3("SMPE: ts=%f rank=%d type=end et=%s", SIMIX_get_clock(), rank, + mpi_call); } xbt_os_timer_start(smpi_process_timer()); } -void smpi_bench_end(int rank, const char* mpi_call) { +void smpi_bench_end(int rank, const char *mpi_call) +{ xbt_os_timer_t timer = smpi_process_timer(); xbt_os_timer_stop(timer); smpi_execute(xbt_os_timer_elapsed(timer)); - if(mpi_call && rank >= 0 && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) { - INFO3("SMPE: ts=%f rank=%d type=begin et=%s", SIMIX_get_clock(), rank, mpi_call); + if (mpi_call && rank >= 0 + && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) { + INFO3("SMPE: ts=%f rank=%d type=begin et=%s", SIMIX_get_clock(), rank, + mpi_call); } } -unsigned int smpi_sleep(unsigned int secs) { - smpi_execute((double)secs); - return secs; +unsigned int smpi_sleep(unsigned int secs) +{ + smpi_execute((double) secs); + return secs; } -int smpi_gettimeofday(struct timeval* tv, struct timezone* tz) { - double now = SIMIX_get_clock(); +int smpi_gettimeofday(struct timeval *tv, struct timezone *tz) +{ + double now = SIMIX_get_clock(); - if(tv) { - tv->tv_sec = (time_t)now; - tv->tv_usec = (suseconds_t)(now * 1e6); - } - return 0; + if (tv) { + tv->tv_sec = (time_t) now; + tv->tv_usec = (suseconds_t) (now * 1e6); + } + return 0; } -static char* sample_location(int global, const char* file, int line) { - if(global) { - return bprintf("%s:%d", file, line); - } else { - return bprintf("%s:%d:%d", file, line, smpi_process_index()); - } +static char *sample_location(int global, const char *file, int line) +{ + if (global) { + return bprintf("%s:%d", file, line); + } else { + return bprintf("%s:%d:%d", file, line, smpi_process_index()); + } } -void smpi_sample_1(int global, const char* file, int line, int max) { - char* loc = sample_location(global, file, line); - local_data_t* data; - - smpi_bench_end(-1, NULL); /* Take time from previous MPI call into account */ - if (!samples) { - samples = xbt_dict_new(); - } - data = xbt_dict_get_or_null(samples, loc); - if (!data) { - data = (local_data_t*)xbt_new(local_data_t, 1); - data->time = 0.0; - data->count = 0; - data->max = max; - data->started = 0; - xbt_dict_set(samples, loc, data, &free); - } - free(loc); +void smpi_sample_1(int global, const char *file, int line, int max) +{ + char *loc = sample_location(global, file, line); + local_data_t *data; + + smpi_bench_end(-1, NULL); /* Take time from previous MPI call into account */ + if (!samples) { + samples = xbt_dict_new(); + } + data = xbt_dict_get_or_null(samples, loc); + if (!data) { + data = (local_data_t *) xbt_new(local_data_t, 1); + data->time = 0.0; + data->count = 0; + data->max = max; + data->started = 0; + xbt_dict_set(samples, loc, data, &free); + } + free(loc); } -int smpi_sample_2(int global, const char* file, int line) { - char* loc = sample_location(global, file, line); - local_data_t* data; - - xbt_assert0(samples, "You did something very inconsistent, didn't you?"); - data = xbt_dict_get_or_null(samples, loc); - if (!data) { - xbt_assert0(data, "Please, do thing in order"); - } - if (!data->started) { - if (data->count < data->max) { - data->started = 1; - data->count++; - } else { - DEBUG1("Perform some wait of %f", data->time / (double)data->count); - smpi_execute(data->time / (double)data->count); - } - } else { - data->started = 0; - } - free(loc); - smpi_bench_begin(-1, NULL); - smpi_process_simulated_start(); - return data->started; +int smpi_sample_2(int global, const char *file, int line) +{ + char *loc = sample_location(global, file, line); + local_data_t *data; + + xbt_assert0(samples, "You did something very inconsistent, didn't you?"); + data = xbt_dict_get_or_null(samples, loc); + if (!data) { + xbt_assert0(data, "Please, do thing in order"); + } + if (!data->started) { + if (data->count < data->max) { + data->started = 1; + data->count++; + } else { + DEBUG1("Perform some wait of %f", data->time / (double) data->count); + smpi_execute(data->time / (double) data->count); + } + } else { + data->started = 0; + } + free(loc); + smpi_bench_begin(-1, NULL); + smpi_process_simulated_start(); + return data->started; } -void smpi_sample_3(int global, const char* file, int line) { - char* loc = sample_location(global, file, line); - local_data_t* data; - - xbt_assert0(samples, "You did something very inconsistent, didn't you?"); - data = xbt_dict_get_or_null(samples, loc); - if (!data || !data->started || data->count >= data->max) { - xbt_assert0(data, "Please, do thing in order"); - } - smpi_bench_end(-1, NULL); - data->time += smpi_process_simulated_elapsed(); - DEBUG2("Average mean after %d steps is %f", data->count, data->time / (double)data->count); +void smpi_sample_3(int global, const char *file, int line) +{ + char *loc = sample_location(global, file, line); + local_data_t *data; + + xbt_assert0(samples, "You did something very inconsistent, didn't you?"); + data = xbt_dict_get_or_null(samples, loc); + if (!data || !data->started || data->count >= data->max) { + xbt_assert0(data, "Please, do thing in order"); + } + smpi_bench_end(-1, NULL); + data->time += smpi_process_simulated_elapsed(); + DEBUG2("Average mean after %d steps is %f", data->count, + data->time / (double) data->count); } -void smpi_sample_flops(double flops) { - smpi_execute_flops(flops); +void smpi_sample_flops(double flops) +{ + smpi_execute_flops(flops); } -void* smpi_shared_malloc(size_t size, const char* file, int line) { - char* loc = bprintf("%s:%d:%zu", file, line, size); - shared_data_t* data; - - if (!allocs) { - allocs = xbt_dict_new(); - } - 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); - } else { - data->count++; - } - free(loc); - return data->data; +void *smpi_shared_malloc(size_t size, const char *file, int line) +{ + char *loc = bprintf("%s:%d:%zu", file, line, size); + shared_data_t *data; + + if (!allocs) { + allocs = xbt_dict_new(); + } + 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); + } else { + data->count++; + } + free(loc); + return data->data; } -void smpi_shared_free(void* ptr) { - shared_data_t* data = (shared_data_t*)((int*)ptr - 1); - char* loc; - - if (!allocs) { - WARN0("Cannot free: nothing was allocated"); - return; - } - loc = xbt_dict_get_key(allocs, data); - if (!loc) { - WARN1("Cannot free: %p was not shared-allocated by SMPI", ptr); - return; - } - data->count--; - if (data->count <= 0) { - xbt_dict_remove(allocs, loc); - } +void smpi_shared_free(void *ptr) +{ + shared_data_t *data = (shared_data_t *) ((int *) ptr - 1); + char *loc; + + if (!allocs) { + WARN0("Cannot free: nothing was allocated"); + return; + } + loc = xbt_dict_get_key(allocs, data); + if (!loc) { + WARN1("Cannot free: %p was not shared-allocated by SMPI", ptr); + return; + } + data->count--; + if (data->count <= 0) { + xbt_dict_remove(allocs, loc); + } } diff --git a/src/smpi/smpi_coll.c b/src/smpi/smpi_coll.c index 19c3d5b156..b3c9b3ae27 100644 --- a/src/smpi/smpi_coll.c +++ b/src/smpi/smpi_coll.c @@ -19,18 +19,19 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, struct s_proc_tree { int PROCTREE_A; int numChildren; - int * child; + int *child; int parent; int me; int root; int isRoot; }; -typedef struct s_proc_tree * proc_tree_t; +typedef struct s_proc_tree *proc_tree_t; /** * alloc and init **/ -static proc_tree_t alloc_tree(int arity) { +static proc_tree_t alloc_tree(int arity) +{ proc_tree_t tree; int i; @@ -39,7 +40,7 @@ static proc_tree_t alloc_tree(int arity) { tree->isRoot = 0; tree->numChildren = 0; tree->child = xbt_new(int, arity); - for(i = 0; i < arity; i++) { + for (i = 0; i < arity; i++) { tree->child[i] = -1; } tree->root = -1; @@ -50,8 +51,9 @@ static proc_tree_t alloc_tree(int arity) { /** * free **/ -static void free_tree(proc_tree_t tree) { - xbt_free(tree->child ); +static void free_tree(proc_tree_t tree) +{ + xbt_free(tree->child); xbt_free(tree); } @@ -60,22 +62,23 @@ static void free_tree(proc_tree_t tree) { * @param index the rank of the calling process * @param extent the total number of processes **/ -static void build_tree(int index, int extent, proc_tree_t* tree) { +static void build_tree(int index, int extent, proc_tree_t * tree) +{ int places = (*tree)->PROCTREE_A * index; int i, ch, pr; (*tree)->me = index; - (*tree)->root = 0 ; - for(i = 1; i <= (*tree)->PROCTREE_A; i++) { + (*tree)->root = 0; + for (i = 1; i <= (*tree)->PROCTREE_A; i++) { ++places; ch = (*tree)->PROCTREE_A * index + i + (*tree)->root; ch %= extent; - if(places < extent) { + if (places < extent) { (*tree)->child[i - 1] = ch; (*tree)->numChildren++; } } - if(index == (*tree)->root) { + if (index == (*tree)->root) { (*tree)->isRoot = 1; } else { (*tree)->isRoot = 0; @@ -87,27 +90,34 @@ static void build_tree(int index, int extent, proc_tree_t* tree) { /** * bcast **/ -static void tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, proc_tree_t tree) { - int system_tag = 999; // used negative int but smpi_create_request() declares this illegal (to be checked) +static void tree_bcast(void *buf, int count, MPI_Datatype datatype, + int root, MPI_Comm comm, proc_tree_t tree) +{ + int system_tag = 999; // used negative int but smpi_create_request() declares this illegal (to be checked) int rank, i; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); /* wait for data from my parent in the tree */ - if(!tree->isRoot) { + if (!tree->isRoot) { DEBUG3("<%d> tree_bcast(): i am not root: recv from %d, tag=%d)", rank, tree->parent, system_tag + rank); - smpi_mpi_recv(buf, count, datatype, tree->parent, system_tag + rank, comm, MPI_STATUS_IGNORE); + smpi_mpi_recv(buf, count, datatype, tree->parent, system_tag + rank, + comm, MPI_STATUS_IGNORE); } requests = xbt_new(MPI_Request, tree->numChildren); - DEBUG2("<%d> creates %d requests (1 per child)", rank, tree->numChildren); + DEBUG2("<%d> creates %d requests (1 per child)", rank, + tree->numChildren); /* iniates sends to ranks lower in the tree */ - for(i = 0; i < tree->numChildren; i++) { - if(tree->child[i] == -1) { + for (i = 0; i < tree->numChildren; i++) { + if (tree->child[i] == -1) { requests[i] = MPI_REQUEST_NULL; } else { - DEBUG3("<%d> send to <%d>, tag=%d", rank, tree->child[i], system_tag + tree->child[i]); - requests[i] = smpi_isend_init(buf, count, datatype, tree->child[i], system_tag + tree->child[i], comm); + DEBUG3("<%d> send to <%d>, tag=%d", rank, tree->child[i], + system_tag + tree->child[i]); + requests[i] = + smpi_isend_init(buf, count, datatype, tree->child[i], + system_tag + tree->child[i], comm); } } smpi_mpi_startall(tree->numChildren, requests); @@ -118,27 +128,34 @@ static void tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MP /** * anti-bcast **/ -static void tree_antibcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, proc_tree_t tree) { - int system_tag = 999; // used negative int but smpi_create_request() declares this illegal (to be checked) +static void tree_antibcast(void *buf, int count, MPI_Datatype datatype, + int root, MPI_Comm comm, proc_tree_t tree) +{ + int system_tag = 999; // used negative int but smpi_create_request() declares this illegal (to be checked) int rank, i; - MPI_Request* requests; + MPI_Request *requests; rank = smpi_comm_rank(comm); // everyone sends to its parent, except root. - if(!tree->isRoot) { + if (!tree->isRoot) { DEBUG3("<%d> tree_antibcast(): i am not root: send to %d, tag=%d)", rank, tree->parent, system_tag + rank); - smpi_mpi_send(buf, count, datatype, tree->parent, system_tag + rank, comm); + smpi_mpi_send(buf, count, datatype, tree->parent, system_tag + rank, + comm); } //every one receives as many messages as it has children requests = xbt_new(MPI_Request, tree->numChildren); - DEBUG2("<%d> creates %d requests (1 per child)", rank, tree->numChildren); - for(i = 0; i < tree->numChildren; i++) { - if(tree->child[i] == -1) { + DEBUG2("<%d> creates %d requests (1 per child)", rank, + tree->numChildren); + for (i = 0; i < tree->numChildren; i++) { + if (tree->child[i] == -1) { requests[i] = MPI_REQUEST_NULL; } else { - DEBUG3("<%d> recv from <%d>, tag=%d", rank, tree->child[i], system_tag + tree->child[i]); - requests[i] = smpi_irecv_init(buf, count, datatype, tree->child[i], system_tag + tree->child[i], comm); + DEBUG3("<%d> recv from <%d>, tag=%d", rank, tree->child[i], + system_tag + tree->child[i]); + requests[i] = + smpi_irecv_init(buf, count, datatype, tree->child[i], + system_tag + tree->child[i], comm); } } smpi_mpi_startall(tree->numChildren, requests); @@ -149,7 +166,9 @@ static void tree_antibcast(void* buf, int count, MPI_Datatype datatype, int root /** * bcast with a binary, ternary, or whatever tree .. **/ -void nary_tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, int arity) { +void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm, int arity) +{ proc_tree_t tree = alloc_tree(arity); int rank, size; @@ -163,10 +182,11 @@ void nary_tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_ /** * barrier with a binary, ternary, or whatever tree .. **/ -void nary_tree_barrier(MPI_Comm comm, int arity) { - proc_tree_t tree = alloc_tree( arity ); +void nary_tree_barrier(MPI_Comm comm, int arity) +{ + proc_tree_t tree = alloc_tree(arity); int rank, size; - char dummy='$'; + char dummy = '$'; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); @@ -181,13 +201,17 @@ void nary_tree_barrier(MPI_Comm comm, int arity) { * * Openmpi calls this routine when the message size sent to each rank < 2000 bytes and size < 12 **/ -int smpi_coll_tuned_alltoall_bruck(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) +{ int system_tag = 777; int i, rank, size, err, count; MPI_Aint lb; MPI_Aint sendextent = 0; MPI_Aint recvextent = 0; - MPI_Request* requests; + MPI_Request *requests; // FIXME: check implementation rank = smpi_comm_rank(comm); @@ -196,30 +220,39 @@ int smpi_coll_tuned_alltoall_bruck(void* sendbuf, int sendcount, MPI_Datatype se err = smpi_datatype_extent(sendtype, &lb, &sendextent); err = smpi_datatype_extent(recvtype, &lb, &recvextent); /* Local copy from self */ - err = smpi_datatype_copy(&((char*)sendbuf)[rank * sendextent], sendcount, sendtype, &((char*)recvbuf)[rank * recvextent], recvcount, recvtype); - if(err == MPI_SUCCESS && size > 1) { + err = + smpi_datatype_copy(&((char *) sendbuf)[rank * sendextent], sendcount, + sendtype, &((char *) recvbuf)[rank * recvextent], + recvcount, recvtype); + if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ requests = xbt_new(MPI_Request, 2 * (size - 1)); count = 0; /* Create all receives that will be posted first */ - for(i = 0; i < size; ++i) { - if(i == rank) { - DEBUG3("<%d> skip request creation [src = %d, recvcount = %d]", rank, i, recvcount); + for (i = 0; i < size; ++i) { + if (i == rank) { + DEBUG3("<%d> skip request creation [src = %d, recvcount = %d]", + rank, i, recvcount); continue; } - requests[count] = smpi_irecv_init(&((char*)recvbuf)[i * recvextent], recvcount, recvtype, i, system_tag, comm); + requests[count] = + smpi_irecv_init(&((char *) recvbuf)[i * recvextent], recvcount, + recvtype, i, system_tag, comm); count++; } /* Now create all sends */ - for(i = 0; i < size; ++i) { - if(i == rank) { - DEBUG3("<%d> skip request creation [dst = %d, sendcount = %d]", rank, i, sendcount); + for (i = 0; i < size; ++i) { + if (i == rank) { + DEBUG3("<%d> skip request creation [dst = %d, sendcount = %d]", + rank, i, sendcount); continue; } - requests[count] = smpi_isend_init(&((char*)sendbuf)[i * sendextent], sendcount, sendtype, i, system_tag, comm); + requests[count] = + smpi_isend_init(&((char *) sendbuf)[i * sendextent], sendcount, + sendtype, i, system_tag, comm); count++; } - /* Wait for them all.*/ + /* Wait for them all. */ smpi_mpi_startall(count, requests); DEBUG2("<%d> wait for %d requests", rank, count); smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE); @@ -231,7 +264,12 @@ int smpi_coll_tuned_alltoall_bruck(void* sendbuf, int sendcount, MPI_Datatype se /** * Alltoall basic_linear **/ -int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, + MPI_Datatype sendtype, + void *recvbuf, int recvcount, + MPI_Datatype recvtype, + MPI_Comm comm) +{ int system_tag = 888; int i, rank, size, err, count; MPI_Aint lb; @@ -248,14 +286,19 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, MPI_Data sendinc *= sendcount; recvinc *= recvcount; /* simple optimization */ - err = smpi_datatype_copy(&((char*)sendbuf)[rank * sendinc], sendcount, sendtype, &((char*)recvbuf)[rank * recvinc], recvcount, recvtype); - if(err == MPI_SUCCESS && size > 1) { + err = + smpi_datatype_copy(&((char *) sendbuf)[rank * sendinc], sendcount, + sendtype, &((char *) recvbuf)[rank * recvinc], + recvcount, recvtype); + if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ requests = xbt_new(MPI_Request, 2 * (size - 1)); /* Post all receives first -- a simple optimization */ count = 0; - for(i = (rank + 1) % size; i != rank; i = (i + 1) % size) { - requests[count] = smpi_irecv_init(&((char*)recvbuf)[i * recvinc], recvcount, recvtype, i, system_tag, comm); + for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) { + requests[count] = + smpi_irecv_init(&((char *) recvbuf)[i * recvinc], recvcount, + recvtype, i, system_tag, comm); count++; } /* Now post all sends in reverse order @@ -263,11 +306,14 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, MPI_Data * when messages actually arrive in the order in which they were posted. * TODO: check the previous assertion */ - for(i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size ) { - requests[count] = smpi_isend_init(&((char*)sendbuf)[i * sendinc], sendcount, sendtype, i, system_tag, comm); + for (i = (rank + size - 1) % size; i != rank; + i = (i + size - 1) % size) { + requests[count] = + smpi_isend_init(&((char *) sendbuf)[i * sendinc], sendcount, + sendtype, i, system_tag, comm); count++; } - /* Wait for them all.*/ + /* Wait for them all. */ smpi_mpi_startall(count, requests); DEBUG2("<%d> wait for %d requests", rank, count); smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE); @@ -286,7 +332,11 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount, MPI_Data * .... * Openmpi calls this routine when the message size sent to each rank is greater than 3000 bytes **/ -int smpi_coll_tuned_alltoall_pairwise(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +int smpi_coll_tuned_alltoall_pairwise(void *sendbuf, int sendcount, + MPI_Datatype sendtype, void *recvbuf, + int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) +{ int system_tag = 999; int rank, size, step, sendto, recvfrom, sendsize, recvsize; @@ -296,23 +346,32 @@ int smpi_coll_tuned_alltoall_pairwise(void* sendbuf, int sendcount, MPI_Datatype sendsize = smpi_datatype_size(sendtype); recvsize = smpi_datatype_size(recvtype); /* Perform pairwise exchange - starting from 1 so the local copy is last */ - for(step = 1; step < size + 1; step++) { + for (step = 1; step < size + 1; step++) { /* who do we talk to in this step? */ - sendto = (rank+step)%size; - recvfrom = (rank+size-step)%size; + sendto = (rank + step) % size; + recvfrom = (rank + size - step) % size; /* send and receive */ - smpi_mpi_sendrecv(&((char*)sendbuf)[sendto * sendsize * sendcount], sendcount, sendtype, sendto, system_tag, &((char*)recvbuf)[recvfrom * recvsize * recvcount], recvcount, recvtype, recvfrom, system_tag, comm, MPI_STATUS_IGNORE); + smpi_mpi_sendrecv(&((char *) sendbuf)[sendto * sendsize * sendcount], + sendcount, sendtype, sendto, system_tag, + &((char *) recvbuf)[recvfrom * recvsize * recvcount], + recvcount, recvtype, recvfrom, system_tag, comm, + MPI_STATUS_IGNORE); } return MPI_SUCCESS; } -int smpi_coll_basic_alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm) { +int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts, + int *senddisps, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, + int *recvdisps, MPI_Datatype recvtype, + MPI_Comm comm) +{ int system_tag = 889; int i, rank, size, err, count; MPI_Aint lb; MPI_Aint sendextent = 0; MPI_Aint recvextent = 0; - MPI_Request* requests; + MPI_Request *requests; /* Initialize. */ rank = smpi_comm_rank(comm); @@ -321,30 +380,42 @@ int smpi_coll_basic_alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MP err = smpi_datatype_extent(sendtype, &lb, &sendextent); err = smpi_datatype_extent(recvtype, &lb, &recvextent); /* Local copy from self */ - err = smpi_datatype_copy(&((char*)sendbuf)[senddisps[rank] * sendextent], sendcounts[rank], sendtype, &((char*)recvbuf)[recvdisps[rank] * recvextent], recvcounts[rank], recvtype); - if(err == MPI_SUCCESS && size > 1) { + err = + smpi_datatype_copy(&((char *) sendbuf)[senddisps[rank] * sendextent], + sendcounts[rank], sendtype, + &((char *) recvbuf)[recvdisps[rank] * recvextent], + recvcounts[rank], recvtype); + if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ requests = xbt_new(MPI_Request, 2 * (size - 1)); count = 0; /* Create all receives that will be posted first */ - for(i = 0; i < size; ++i) { - if(i == rank || recvcounts[i] == 0) { - DEBUG3("<%d> skip request creation [src = %d, recvcounts[src] = %d]", rank, i, recvcounts[i]); + for (i = 0; i < size; ++i) { + if (i == rank || recvcounts[i] == 0) { + DEBUG3 + ("<%d> skip request creation [src = %d, recvcounts[src] = %d]", + rank, i, recvcounts[i]); continue; } - requests[count] = smpi_irecv_init(&((char*)recvbuf)[recvdisps[i] * recvextent], recvcounts[i], recvtype, i, system_tag, comm); + requests[count] = + smpi_irecv_init(&((char *) recvbuf)[recvdisps[i] * recvextent], + recvcounts[i], recvtype, i, system_tag, comm); count++; } /* Now create all sends */ - for(i = 0; i < size; ++i) { - if(i == rank || sendcounts[i] == 0) { - DEBUG3("<%d> skip request creation [dst = %d, sendcounts[dst] = %d]", rank, i, sendcounts[i]); + for (i = 0; i < size; ++i) { + if (i == rank || sendcounts[i] == 0) { + DEBUG3 + ("<%d> skip request creation [dst = %d, sendcounts[dst] = %d]", + rank, i, sendcounts[i]); continue; } - requests[count] = smpi_isend_init(&((char*)sendbuf)[senddisps[i] * sendextent], sendcounts[i], sendtype, i, system_tag, comm); + requests[count] = + smpi_isend_init(&((char *) sendbuf)[senddisps[i] * sendextent], + sendcounts[i], sendtype, i, system_tag, comm); count++; } - /* Wait for them all.*/ + /* Wait for them all. */ smpi_mpi_startall(count, requests); DEBUG2("<%d> wait for %d requests", rank, count); smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE); diff --git a/src/smpi/smpi_comm.c b/src/smpi/smpi_comm.c index 7b6b34c20a..9416dd0ba1 100644 --- a/src/smpi/smpi_comm.c +++ b/src/smpi/smpi_comm.c @@ -13,7 +13,8 @@ typedef struct s_smpi_mpi_communicator { MPI_Group group; } s_smpi_mpi_communicator_t; -MPI_Comm smpi_comm_new(MPI_Group group) { +MPI_Comm smpi_comm_new(MPI_Group group) +{ MPI_Comm comm; comm = xbt_new(s_smpi_mpi_communicator_t, 1); @@ -22,19 +23,23 @@ MPI_Comm smpi_comm_new(MPI_Group group) { return comm; } -void smpi_comm_destroy(MPI_Comm comm) { +void smpi_comm_destroy(MPI_Comm comm) +{ smpi_group_destroy(comm->group); xbt_free(comm); } -MPI_Group smpi_comm_group(MPI_Comm comm) { +MPI_Group smpi_comm_group(MPI_Comm comm) +{ return comm->group; } -int smpi_comm_size(MPI_Comm comm) { +int smpi_comm_size(MPI_Comm comm) +{ return smpi_group_size(smpi_comm_group(comm)); } -int smpi_comm_rank(MPI_Comm comm) { +int smpi_comm_rank(MPI_Comm comm) +{ return smpi_group_rank(smpi_comm_group(comm), smpi_process_index()); } diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 5628164b59..3e45341be1 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -24,63 +24,76 @@ typedef struct s_smpi_process_data { MPI_Comm comm_self; } s_smpi_process_data_t; -static smpi_process_data_t* process_data = NULL; +static smpi_process_data_t *process_data = NULL; static int process_count = 0; MPI_Comm MPI_COMM_WORLD = MPI_COMM_NULL; -smpi_process_data_t smpi_process_data(void) { +smpi_process_data_t smpi_process_data(void) +{ return SIMIX_process_get_data(SIMIX_process_self()); } -smpi_process_data_t smpi_process_remote_data(int index) { +smpi_process_data_t smpi_process_remote_data(int index) +{ return process_data[index]; } -int smpi_process_count(void) { +int smpi_process_count(void) +{ return process_count; } -int smpi_process_index(void) { +int smpi_process_index(void) +{ smpi_process_data_t data = smpi_process_data(); return data->index; } -xbt_os_timer_t smpi_process_timer(void) { +xbt_os_timer_t smpi_process_timer(void) +{ smpi_process_data_t data = smpi_process_data(); return data->timer; } -void smpi_process_simulated_start(void) { +void smpi_process_simulated_start(void) +{ smpi_process_data_t data = smpi_process_data(); - data->simulated = SIMIX_get_clock(); + data->simulated = SIMIX_get_clock(); } -double smpi_process_simulated_elapsed(void) { +double smpi_process_simulated_elapsed(void) +{ smpi_process_data_t data = smpi_process_data(); return SIMIX_get_clock() - data->simulated; } -MPI_Comm smpi_process_comm_self(void) { +MPI_Comm smpi_process_comm_self(void) +{ smpi_process_data_t data = smpi_process_data(); return data->comm_self; } -void print_request(const char* message, MPI_Request request) { - char* req = bprintf("[buf = %p, size = %zu, src = %d, dst = %d, tag= %d, complete = %d, flags = %u]", - request->buf, request->size, request->src, request->dst, request->tag, request->complete, request->flags); +void print_request(const char *message, MPI_Request request) +{ + char *req = + bprintf + ("[buf = %p, size = %zu, src = %d, dst = %d, tag= %d, complete = %d, flags = %u]", + request->buf, request->size, request->src, request->dst, + request->tag, request->complete, request->flags); DEBUG5("%s (request %p with rdv %p and match %p) %s", message, request, request->rdv, request->match, req); free(req); } -void smpi_process_post_send(MPI_Comm comm, MPI_Request request) { +void smpi_process_post_send(MPI_Comm comm, MPI_Request request) +{ int index = smpi_group_index(smpi_comm_group(comm), request->dst); smpi_process_data_t data = smpi_process_remote_data(index); xbt_fifo_item_t item; @@ -88,9 +101,9 @@ void smpi_process_post_send(MPI_Comm comm, MPI_Request request) { print_request("Isend", request); xbt_fifo_foreach(data->pending_recv, item, req, MPI_Request) { - if(req->comm == request->comm - && (req->src == MPI_ANY_SOURCE || req->src == request->src) - && (req->tag == MPI_ANY_TAG || req->tag == request->tag)){ + if (req->comm == request->comm + && (req->src == MPI_ANY_SOURCE || req->src == request->src) + && (req->tag == MPI_ANY_TAG || req->tag == request->tag)) { print_request("Match found", req); xbt_fifo_remove_item(data->pending_recv, item); /* Materialize the *_ANY_* fields from corresponding irecv request */ @@ -106,16 +119,17 @@ void smpi_process_post_send(MPI_Comm comm, MPI_Request request) { xbt_fifo_push(data->pending_sent, request); } -void smpi_process_post_recv(MPI_Request request) { +void smpi_process_post_recv(MPI_Request request) +{ smpi_process_data_t data = smpi_process_data(); xbt_fifo_item_t item; MPI_Request req; print_request("Irecv", request); xbt_fifo_foreach(data->pending_sent, item, req, MPI_Request) { - if(req->comm == request->comm - && (request->src == MPI_ANY_SOURCE || req->src == request->src) - && (request->tag == MPI_ANY_TAG || req->tag == request->tag)){ + if (req->comm == request->comm + && (request->src == MPI_ANY_SOURCE || req->src == request->src) + && (request->tag == MPI_ANY_TAG || req->tag == request->tag)) { print_request("Match found", req); xbt_fifo_remove_item(data->pending_sent, item); /* Materialize the *_ANY_* fields from the irecv request */ @@ -131,14 +145,16 @@ void smpi_process_post_recv(MPI_Request request) { xbt_fifo_push(data->pending_recv, request); } -void smpi_global_init(void) { +void smpi_global_init(void) +{ int i; MPI_Group group; - SIMIX_network_set_copy_data_callback(&SIMIX_network_copy_buffer_callback); + SIMIX_network_set_copy_data_callback + (&SIMIX_network_copy_buffer_callback); process_count = SIMIX_process_count(); process_data = xbt_new(smpi_process_data_t, process_count); - for(i = 0; i < process_count; i++) { + for (i = 0; i < process_count; i++) { process_data[i] = xbt_new(s_smpi_process_data_t, 1); process_data[i]->index = i; process_data[i]->pending_sent = xbt_fifo_new(); @@ -150,19 +166,20 @@ void smpi_global_init(void) { } group = smpi_group_new(process_count); MPI_COMM_WORLD = smpi_comm_new(group); - for(i = 0; i < process_count; i++) { + for (i = 0; i < process_count; i++) { smpi_group_set_mapping(group, i, i); } } -void smpi_global_destroy(void) { +void smpi_global_destroy(void) +{ int count = smpi_process_count(); int i; smpi_bench_destroy(); smpi_comm_destroy(MPI_COMM_WORLD); MPI_COMM_WORLD = MPI_COMM_NULL; - for(i = 0; i < count; i++) { + for (i = 0; i < count; i++) { smpi_comm_destroy(process_data[i]->comm_self); xbt_os_timer_free(process_data[i]->timer); xbt_fifo_free(process_data[i]->pending_recv); @@ -180,31 +197,35 @@ int main(int argc, char **argv) double default_reference_speed = 20000.0; xbt_cfg_register(&_surf_cfg_set, "smpi/running_power", "Power of the host running the simulation (in flop/s). Used to bench the operations.", - xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL, NULL); + xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL, + NULL); int default_display_timing = 0; xbt_cfg_register(&_surf_cfg_set, "smpi/display_timing", "Boolean indicating whether we should display the timing after simulation.", - xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, NULL); + xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, + NULL); int default_display_smpe = 0; xbt_cfg_register(&_surf_cfg_set, "smpi/log_events", "Boolean indicating whether we should display simulated time spent in MPI calls.", - xbt_cfgelm_int, &default_display_smpe, 1, 1, NULL, NULL); + xbt_cfgelm_int, &default_display_smpe, 1, 1, NULL, + NULL); double default_threshold = 1e-6; xbt_cfg_register(&_surf_cfg_set, "smpi/cpu_threshold", "Minimal computation time (in seconds) not discarded.", - xbt_cfgelm_double, &default_threshold, 1, 1, NULL, NULL); + xbt_cfgelm_double, &default_threshold, 1, 1, NULL, + NULL); #ifdef HAVE_TRACING - TRACE_global_init (&argc, argv); + TRACE_global_init(&argc, argv); #endif SIMIX_global_init(&argc, argv); #ifdef HAVE_TRACING - TRACE_smpi_start (); + TRACE_smpi_start(); #endif // parse the platform file: get the host list @@ -235,7 +256,7 @@ int main(int argc, char **argv) SIMIX_message_sizes_output("toto.txt"); #ifdef HAVE_TRACING - TRACE_smpi_release (); + TRACE_smpi_release(); #endif SIMIX_clean(); diff --git a/src/smpi/smpi_group.c b/src/smpi/smpi_group.c index a61e374e57..e84ed8e2dc 100644 --- a/src/smpi/smpi_group.c +++ b/src/smpi/smpi_group.c @@ -11,20 +11,22 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi, typedef struct s_smpi_mpi_group { int size; - int* rank_to_index_map; - int* index_to_rank_map; + int *rank_to_index_map; + int *index_to_rank_map; int refcount; } s_smpi_mpi_group_t; static s_smpi_mpi_group_t mpi_MPI_GROUP_EMPTY = { - 0, /* size */ - NULL, /* rank_to_index_map */ - NULL, /* index_to_rank_map */ - 1, /* refcount: start > 0 so that this group never gets freed */ + 0, /* size */ + NULL, /* rank_to_index_map */ + NULL, /* index_to_rank_map */ + 1, /* refcount: start > 0 so that this group never gets freed */ }; + MPI_Group MPI_GROUP_EMPTY = &mpi_MPI_GROUP_EMPTY; -MPI_Group smpi_group_new(int size) { +MPI_Group smpi_group_new(int size) +{ MPI_Group group; int i, count; @@ -34,79 +36,87 @@ MPI_Group smpi_group_new(int size) { group->rank_to_index_map = xbt_new(int, size); group->index_to_rank_map = xbt_new(int, count); group->refcount = 0; - for(i = 0; i < size; i++) { + for (i = 0; i < size; i++) { group->rank_to_index_map[i] = MPI_UNDEFINED; } - for(i = 0; i < count; i++) { + for (i = 0; i < count; i++) { group->index_to_rank_map[i] = MPI_UNDEFINED; } return group; } -void smpi_group_destroy(MPI_Group group) { - if(smpi_group_unuse(group) <= 0) { +void smpi_group_destroy(MPI_Group group) +{ + if (smpi_group_unuse(group) <= 0) { xbt_free(group->rank_to_index_map); xbt_free(group->index_to_rank_map); xbt_free(group); } } -void smpi_group_set_mapping(MPI_Group group, int index, int rank) { - if(rank < group->size && index < smpi_process_count()) { +void smpi_group_set_mapping(MPI_Group group, int index, int rank) +{ + if (rank < group->size && index < smpi_process_count()) { group->rank_to_index_map[rank] = index; group->index_to_rank_map[index] = rank; } } -int smpi_group_index(MPI_Group group, int rank) { +int smpi_group_index(MPI_Group group, int rank) +{ int index = MPI_UNDEFINED; - if(rank < group->size) { + if (rank < group->size) { index = group->rank_to_index_map[rank]; } return index; } -int smpi_group_rank(MPI_Group group, int index) { +int smpi_group_rank(MPI_Group group, int index) +{ int rank = MPI_UNDEFINED; - if(index < smpi_process_count()) { + if (index < smpi_process_count()) { rank = group->index_to_rank_map[index]; } return rank; } -int smpi_group_use(MPI_Group group) { +int smpi_group_use(MPI_Group group) +{ group->refcount++; return group->refcount; } -int smpi_group_unuse(MPI_Group group) { +int smpi_group_unuse(MPI_Group group) +{ group->refcount--; return group->refcount; } -int smpi_group_size(MPI_Group group) { +int smpi_group_size(MPI_Group group) +{ return group->size; } -int smpi_group_compare(MPI_Group group1, MPI_Group group2) { +int smpi_group_compare(MPI_Group group1, MPI_Group group2) +{ int result; int i, index, rank, size; result = MPI_IDENT; - if(smpi_group_size(group1) != smpi_group_size(group2)) { + if (smpi_group_size(group1) != smpi_group_size(group2)) { result = MPI_UNEQUAL; } else { size = smpi_group_size(group2); - for(i = 0; i < size; i++) { + for (i = 0; i < size; i++) { index = smpi_group_index(group1, i); rank = smpi_group_rank(group2, index); - if(rank == MPI_UNDEFINED) { + if (rank == MPI_UNDEFINED) { result = MPI_UNEQUAL; break; } - if(rank != i) { + if (rank != i) { result = MPI_SIMILAR; } } diff --git a/src/smpi/smpi_mpi.c b/src/smpi/smpi_mpi.c index 37518f91c1..0f08ff8b35 100644 --- a/src/smpi/smpi_mpi.c +++ b/src/smpi/smpi_mpi.c @@ -13,7 +13,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi, /* MPI User level calls */ -int MPI_Init(int* argc, char*** argv) { +int MPI_Init(int *argc, char ***argv) +{ smpi_process_init(argc, argv); #ifdef HAVE_TRACING TRACE_smpi_init(smpi_process_index()); @@ -22,7 +23,8 @@ int MPI_Init(int* argc, char*** argv) { return MPI_SUCCESS; } -int MPI_Finalize(void) { +int MPI_Finalize(void) +{ smpi_bench_end(-1, NULL); #ifdef HAVE_TRACING TRACE_smpi_finalize(smpi_process_index()); @@ -31,18 +33,20 @@ int MPI_Finalize(void) { return MPI_SUCCESS; } -int MPI_Init_thread(int* argc, char*** argv, int required, int* provided) { - if(provided != NULL) { +int MPI_Init_thread(int *argc, char ***argv, int required, int *provided) +{ + if (provided != NULL) { *provided = MPI_THREAD_MULTIPLE; } return MPI_Init(argc, argv); } -int MPI_Query_thread(int* provided) { +int MPI_Query_thread(int *provided) +{ int retval; smpi_bench_end(-1, NULL); - if(provided == NULL) { + if (provided == NULL) { retval = MPI_ERR_ARG; } else { *provided = MPI_THREAD_MULTIPLE; @@ -52,11 +56,12 @@ int MPI_Query_thread(int* provided) { return retval; } -int MPI_Is_thread_main(int* flag) { +int MPI_Is_thread_main(int *flag) +{ int retval; smpi_bench_end(-1, NULL); - if(flag == NULL) { + if (flag == NULL) { retval = MPI_ERR_ARG; } else { *flag = smpi_process_index() == 0; @@ -66,7 +71,8 @@ int MPI_Is_thread_main(int* flag) { return retval; } -int MPI_Abort(MPI_Comm comm, int errorcode) { +int MPI_Abort(MPI_Comm comm, int errorcode) +{ smpi_bench_end(-1, NULL); smpi_process_destroy(); // FIXME: should kill all processes in comm instead @@ -74,7 +80,8 @@ int MPI_Abort(MPI_Comm comm, int errorcode) { return MPI_SUCCESS; } -double MPI_Wtime(void) { +double MPI_Wtime(void) +{ double time; smpi_bench_end(-1, NULL); @@ -83,24 +90,26 @@ double MPI_Wtime(void) { return time; } -int MPI_Address(void *location, MPI_Aint *address) { +int MPI_Address(void *location, MPI_Aint * address) +{ int retval; smpi_bench_end(-1, NULL); - if(!address) { + if (!address) { retval = MPI_ERR_ARG; } else { - *address = (MPI_Aint)location; + *address = (MPI_Aint) location; } smpi_bench_begin(-1, NULL); return retval; } -int MPI_Type_free(MPI_Datatype* datatype) { +int MPI_Type_free(MPI_Datatype * datatype) +{ int retval; smpi_bench_end(-1, NULL); - if(!datatype) { + if (!datatype) { retval = MPI_ERR_ARG; } else { // FIXME: always fail for now @@ -110,29 +119,32 @@ int MPI_Type_free(MPI_Datatype* datatype) { return retval; } -int MPI_Type_size(MPI_Datatype datatype, int* size) { +int MPI_Type_size(MPI_Datatype datatype, int *size) +{ int retval; smpi_bench_end(-1, NULL); - if(datatype == MPI_DATATYPE_NULL) { + if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(size == NULL) { + } else if (size == NULL) { retval = MPI_ERR_ARG; } else { - *size = (int)smpi_datatype_size(datatype); + *size = (int) smpi_datatype_size(datatype); retval = MPI_SUCCESS; } smpi_bench_begin(-1, NULL); return retval; } -int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent) { +int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, + MPI_Aint * extent) +{ int retval; smpi_bench_end(-1, NULL); - if(datatype == MPI_DATATYPE_NULL) { + if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(lb == NULL || extent == NULL) { + } else if (lb == NULL || extent == NULL) { retval = MPI_ERR_ARG; } else { retval = smpi_datatype_extent(datatype, lb, extent); @@ -141,14 +153,15 @@ int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent) { return retval; } -int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent) { +int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent) +{ int retval; MPI_Aint dummy; smpi_bench_end(-1, NULL); - if(datatype == MPI_DATATYPE_NULL) { + if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(extent == NULL) { + } else if (extent == NULL) { retval = MPI_ERR_ARG; } else { retval = smpi_datatype_extent(datatype, &dummy, extent); @@ -157,13 +170,14 @@ int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent) { return retval; } -int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) { +int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp) +{ int retval; smpi_bench_end(-1, NULL); - if(datatype == MPI_DATATYPE_NULL) { + if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(disp == NULL) { + } else if (disp == NULL) { retval = MPI_ERR_ARG; } else { *disp = smpi_datatype_lb(datatype); @@ -173,13 +187,14 @@ int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) { return retval; } -int MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp) { +int MPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp) +{ int retval; smpi_bench_end(-1, NULL); - if(datatype == MPI_DATATYPE_NULL) { + if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(disp == NULL) { + } else if (disp == NULL) { retval = MPI_ERR_ARG; } else { *disp = smpi_datatype_ub(datatype); @@ -189,11 +204,12 @@ int MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp) { return retval; } -int MPI_Op_create(MPI_User_function* function, int commute, MPI_Op* op) { +int MPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op) +{ int retval; smpi_bench_end(-1, NULL); - if(function == NULL || op == NULL) { + if (function == NULL || op == NULL) { retval = MPI_ERR_ARG; } else { *op = smpi_op_new(function, commute); @@ -203,13 +219,14 @@ int MPI_Op_create(MPI_User_function* function, int commute, MPI_Op* op) { return retval; } -int MPI_Op_free(MPI_Op* op) { +int MPI_Op_free(MPI_Op * op) +{ int retval; smpi_bench_end(-1, NULL); - if(op == NULL) { + if (op == NULL) { retval = MPI_ERR_ARG; - } else if(*op == MPI_OP_NULL) { + } else if (*op == MPI_OP_NULL) { retval = MPI_ERR_OP; } else { smpi_op_destroy(*op); @@ -220,11 +237,12 @@ int MPI_Op_free(MPI_Op* op) { return retval; } -int MPI_Group_free(MPI_Group *group) { +int MPI_Group_free(MPI_Group * group) +{ int retval; smpi_bench_end(-1, NULL); - if(group == NULL) { + if (group == NULL) { retval = MPI_ERR_ARG; } else { smpi_group_destroy(*group); @@ -235,13 +253,14 @@ int MPI_Group_free(MPI_Group *group) { return retval; } -int MPI_Group_size(MPI_Group group, int* size) { +int MPI_Group_size(MPI_Group group, int *size) +{ int retval; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(size == NULL) { + } else if (size == NULL) { retval = MPI_ERR_ARG; } else { *size = smpi_group_size(group); @@ -251,13 +270,14 @@ int MPI_Group_size(MPI_Group group, int* size) { return retval; } -int MPI_Group_rank(MPI_Group group, int* rank) { +int MPI_Group_rank(MPI_Group group, int *rank) +{ int retval; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(rank == NULL) { + } else if (rank == NULL) { retval = MPI_ERR_ARG; } else { *rank = smpi_group_rank(group, smpi_process_index()); @@ -267,14 +287,16 @@ int MPI_Group_rank(MPI_Group group, int* rank) { return retval; } -int MPI_Group_translate_ranks (MPI_Group group1, int n, int* ranks1, MPI_Group group2, int* ranks2) { +int MPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, + MPI_Group group2, int *ranks2) +{ int retval, i, index; smpi_bench_end(-1, NULL); - if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { + if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; } else { - for(i = 0; i < n; i++) { + for (i = 0; i < n; i++) { index = smpi_group_index(group1, ranks1[i]); ranks2[i] = smpi_group_rank(group2, index); } @@ -284,13 +306,14 @@ int MPI_Group_translate_ranks (MPI_Group group1, int n, int* ranks1, MPI_Group g return retval; } -int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int* result) { +int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) +{ int retval; smpi_bench_end(-1, NULL); - if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { + if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(result == NULL) { + } else if (result == NULL) { retval = MPI_ERR_ARG; } else { *result = smpi_group_compare(group1, group2); @@ -300,34 +323,36 @@ int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int* result) { return retval; } -int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) { +int MPI_Group_union(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup) +{ int retval, i, proc1, proc2, size, size2; smpi_bench_end(-1, NULL); - if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { + if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { size = smpi_group_size(group1); size2 = smpi_group_size(group2); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc2 = smpi_group_index(group2, i); proc1 = smpi_group_rank(group1, proc2); - if(proc1 == MPI_UNDEFINED) { + if (proc1 == MPI_UNDEFINED) { size++; } } - if(size == 0) { + if (size == 0) { *newgroup = MPI_GROUP_EMPTY; } else { *newgroup = smpi_group_new(size); size2 = smpi_group_size(group1); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc1 = smpi_group_index(group1, i); smpi_group_set_mapping(*newgroup, proc1, i); } - for(i = size2; i < size; i++) { + for (i = size2; i < size; i++) { proc2 = smpi_group_index(group2, i - size2); smpi_group_set_mapping(*newgroup, proc2, i); } @@ -339,33 +364,35 @@ int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) { return retval; } -int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) { - int retval, i, proc1, proc2, size, size2; +int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup) +{ + int retval, i, proc1, proc2, size, size2; smpi_bench_end(-1, NULL); - if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { + if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { size = smpi_group_size(group1); size2 = smpi_group_size(group2); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc2 = smpi_group_index(group2, i); proc1 = smpi_group_rank(group1, proc2); - if(proc1 == MPI_UNDEFINED) { + if (proc1 == MPI_UNDEFINED) { size--; } } - if(size == 0) { + if (size == 0) { *newgroup = MPI_GROUP_EMPTY; } else { *newgroup = smpi_group_new(size); size2 = smpi_group_size(group1); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc1 = smpi_group_index(group1, i); proc2 = smpi_group_rank(group2, proc1); - if(proc2 != MPI_UNDEFINED) { + if (proc2 != MPI_UNDEFINED) { smpi_group_set_mapping(*newgroup, proc1, i); } } @@ -377,31 +404,33 @@ int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group* newgro return retval; } -int MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) { +int MPI_Group_difference(MPI_Group group1, MPI_Group group2, + MPI_Group * newgroup) +{ int retval, i, proc1, proc2, size, size2; smpi_bench_end(-1, NULL); - if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { + if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { size = size2 = smpi_group_size(group1); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc1 = smpi_group_index(group1, i); proc2 = smpi_group_rank(group2, proc1); - if(proc2 != MPI_UNDEFINED) { + if (proc2 != MPI_UNDEFINED) { size--; } } - if(size == 0) { + if (size == 0) { *newgroup = MPI_GROUP_EMPTY; } else { *newgroup = smpi_group_new(size); - for(i = 0; i < size2; i++) { + for (i = 0; i < size2; i++) { proc1 = smpi_group_index(group1, i); proc2 = smpi_group_rank(group2, proc1); - if(proc2 == MPI_UNDEFINED) { + if (proc2 == MPI_UNDEFINED) { smpi_group_set_mapping(*newgroup, proc1, i); } } @@ -413,22 +442,24 @@ int MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup return retval; } -int MPI_Group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) { +int MPI_Group_incl(MPI_Group group, int n, int *ranks, + MPI_Group * newgroup) +{ int retval, i, index; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { - if(n == 0) { + if (n == 0) { *newgroup = MPI_GROUP_EMPTY; - } else if(n == smpi_group_size(group)) { + } else if (n == smpi_group_size(group)) { *newgroup = group; } else { *newgroup = smpi_group_new(n); - for(i = 0; i < n; i++) { + for (i = 0; i < n; i++) { index = smpi_group_index(group, ranks[i]); smpi_group_set_mapping(*newgroup, index, i); } @@ -440,30 +471,32 @@ int MPI_Group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) { return retval; } -int MPI_Group_excl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) { +int MPI_Group_excl(MPI_Group group, int n, int *ranks, + MPI_Group * newgroup) +{ int retval, i, size, rank, index; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { - if(n == 0) { + if (n == 0) { *newgroup = group; - } else if(n == smpi_group_size(group)) { + } else if (n == smpi_group_size(group)) { *newgroup = MPI_GROUP_EMPTY; } else { size = smpi_group_size(group) - n; *newgroup = smpi_group_new(size); rank = 0; - while(rank < size) { - for(i = 0; i < n; i++) { - if(ranks[i] == rank) { + while (rank < size) { + for (i = 0; i < n; i++) { + if (ranks[i] == rank) { break; } } - if(i >= n) { + if (i >= n) { index = smpi_group_index(group, rank); smpi_group_set_mapping(*newgroup, index, rank); rank++; @@ -477,35 +510,37 @@ int MPI_Group_excl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) { return retval; } -int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup) { +int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], + MPI_Group * newgroup) +{ int retval, i, j, rank, size, index; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { - if(n == 0) { + if (n == 0) { *newgroup = MPI_GROUP_EMPTY; } else { size = 0; - for(i = 0; i < n; i++) { - for(rank = ranges[i][0]; /* First */ - rank >= 0 && rank <= ranges[i][1]; /* Last */ - rank += ranges[i][2] /* Stride */) { + for (i = 0; i < n; i++) { + for (rank = ranges[i][0]; /* First */ + rank >= 0 && rank <= ranges[i][1]; /* Last */ + rank += ranges[i][2] /* Stride */ ) { size++; } } - if(size == smpi_group_size(group)) { + if (size == smpi_group_size(group)) { *newgroup = group; } else { *newgroup = smpi_group_new(size); j = 0; - for(i = 0; i < n; i++) { - for(rank = ranges[i][0]; /* First */ - rank >= 0 && rank <= ranges[i][1]; /* Last */ - rank += ranges[i][2] /* Stride */) { + for (i = 0; i < n; i++) { + for (rank = ranges[i][0]; /* First */ + rank >= 0 && rank <= ranges[i][1]; /* Last */ + rank += ranges[i][2] /* Stride */ ) { index = smpi_group_index(group, rank); smpi_group_set_mapping(*newgroup, index, j); j++; @@ -520,43 +555,45 @@ int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group* new return retval; } -int MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup) { +int MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], + MPI_Group * newgroup) +{ int retval, i, newrank, rank, size, index, add; smpi_bench_end(-1, NULL); - if(group == MPI_GROUP_NULL) { + if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newgroup == NULL) { + } else if (newgroup == NULL) { retval = MPI_ERR_ARG; } else { - if(n == 0) { + if (n == 0) { *newgroup = group; } else { size = smpi_group_size(group); - for(i = 0; i < n; i++) { - for(rank = ranges[i][0]; /* First */ - rank >= 0 && rank <= ranges[i][1]; /* Last */ - rank += ranges[i][2] /* Stride */) { + for (i = 0; i < n; i++) { + for (rank = ranges[i][0]; /* First */ + rank >= 0 && rank <= ranges[i][1]; /* Last */ + rank += ranges[i][2] /* Stride */ ) { size--; } } - if(size == 0) { + if (size == 0) { *newgroup = MPI_GROUP_EMPTY; } else { *newgroup = smpi_group_new(size); newrank = 0; - while(newrank < size) { - for(i = 0; i < n; i++) { + while (newrank < size) { + for (i = 0; i < n; i++) { add = 1; - for(rank = ranges[i][0]; /* First */ - rank >= 0 && rank <= ranges[i][1]; /* Last */ - rank += ranges[i][2] /* Stride */) { - if(rank == newrank) { + for (rank = ranges[i][0]; /* First */ + rank >= 0 && rank <= ranges[i][1]; /* Last */ + rank += ranges[i][2] /* Stride */ ) { + if (rank == newrank) { add = 0; break; } } - if(add == 1) { + if (add == 1) { index = smpi_group_index(group, newrank); smpi_group_set_mapping(*newgroup, index, newrank); } @@ -571,11 +608,12 @@ int MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group* new return retval; } -int MPI_Comm_rank(MPI_Comm comm, int* rank) { +int MPI_Comm_rank(MPI_Comm comm, int *rank) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; } else { *rank = smpi_comm_rank(comm); @@ -585,13 +623,14 @@ int MPI_Comm_rank(MPI_Comm comm, int* rank) { return retval; } -int MPI_Comm_size(MPI_Comm comm, int* size) { +int MPI_Comm_size(MPI_Comm comm, int *size) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(size == NULL) { + } else if (size == NULL) { retval = MPI_ERR_ARG; } else { *size = smpi_comm_size(comm); @@ -601,13 +640,14 @@ int MPI_Comm_size(MPI_Comm comm, int* size) { return retval; } -int MPI_Comm_group(MPI_Comm comm, MPI_Group* group) { +int MPI_Comm_group(MPI_Comm comm, MPI_Group * group) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(group == NULL) { + } else if (group == NULL) { retval = MPI_ERR_ARG; } else { *group = smpi_comm_group(comm); @@ -617,20 +657,23 @@ int MPI_Comm_group(MPI_Comm comm, MPI_Group* group) { return retval; } -int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int* result) { +int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result) +{ int retval; smpi_bench_end(-1, NULL); - if(comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) { + if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(result == NULL) { + } else if (result == NULL) { retval = MPI_ERR_ARG; } else { - if(comm1 == comm2) { /* Same communicators means same groups */ + if (comm1 == comm2) { /* Same communicators means same groups */ *result = MPI_IDENT; } else { - *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2)); - if(*result == MPI_IDENT) { + *result = + smpi_group_compare(smpi_comm_group(comm1), + smpi_comm_group(comm2)); + if (*result == MPI_IDENT) { *result = MPI_CONGRUENT; } } @@ -640,13 +683,14 @@ int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int* result) { return retval; } -int MPI_Comm_dup(MPI_Comm comm, MPI_Comm* newcomm) { +int MPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(newcomm == NULL) { + } else if (newcomm == NULL) { retval = MPI_ERR_ARG; } else { *newcomm = smpi_comm_new(smpi_comm_group(comm)); @@ -656,15 +700,16 @@ int MPI_Comm_dup(MPI_Comm comm, MPI_Comm* newcomm) { return retval; } -int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm* newcomm) { +int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(group == MPI_GROUP_NULL) { + } else if (group == MPI_GROUP_NULL) { retval = MPI_ERR_GROUP; - } else if(newcomm == NULL) { + } else if (newcomm == NULL) { retval = MPI_ERR_ARG; } else { *newcomm = smpi_comm_new(group); @@ -674,13 +719,14 @@ int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm* newcomm) { return retval; } -int MPI_Comm_free(MPI_Comm* comm) { +int MPI_Comm_free(MPI_Comm * comm) +{ int retval; smpi_bench_end(-1, NULL); - if(comm == NULL) { + if (comm == NULL) { retval = MPI_ERR_ARG; - } else if(*comm == MPI_COMM_NULL) { + } else if (*comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; } else { smpi_comm_destroy(*comm); @@ -691,12 +737,14 @@ int MPI_Comm_free(MPI_Comm* comm) { return retval; } -int MPI_Send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) { +int MPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, + int tag, MPI_Comm comm, MPI_Request * request) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Send_init"); - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -708,12 +756,14 @@ int MPI_Send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, return retval; } -int MPI_Recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) { +int MPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, + int tag, MPI_Comm comm, MPI_Request * request) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Recv_init"); - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -725,13 +775,14 @@ int MPI_Recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, return retval; } -int MPI_Start(MPI_Request* request) { +int MPI_Start(MPI_Request * request) +{ int retval; MPI_Comm comm = (*request)->comm; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Start"); - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else { smpi_mpi_start(*request); @@ -741,13 +792,15 @@ int MPI_Start(MPI_Request* request) { return retval; } -int MPI_Startall(int count, MPI_Request* requests) { +int MPI_Startall(int count, MPI_Request * requests) +{ int retval; - MPI_Comm comm = count > 0 && requests ? requests[0]->comm : MPI_COMM_NULL; + MPI_Comm comm = count > 0 + && requests ? requests[0]->comm : MPI_COMM_NULL; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Startall"); - if(requests == NULL) { + if (requests == NULL) { retval = MPI_ERR_ARG; } else { smpi_mpi_startall(count, requests); @@ -757,13 +810,14 @@ int MPI_Startall(int count, MPI_Request* requests) { return retval; } -int MPI_Request_free(MPI_Request* request) { +int MPI_Request_free(MPI_Request * request) +{ int retval; MPI_Comm comm = (*request)->comm; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Request_free"); - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else { smpi_mpi_request_free(request); @@ -773,16 +827,18 @@ int MPI_Request_free(MPI_Request* request) { return retval; } -int MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) { +int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, + int tag, MPI_Comm comm, MPI_Request * request) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Irecv"); #ifdef HAVE_TRACING int src_traced = smpi_group_rank(smpi_comm_group(comm), src); - TRACE_smpi_ptp_in (rank, src_traced, rank, __FUNCTION__); + TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__); #endif - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -791,24 +847,26 @@ int MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, src_traced, rank, __FUNCTION__); + TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__); (*request)->recv = 1; #endif smpi_bench_begin(rank, "Irecv"); return retval; } -int MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) { +int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, + int tag, MPI_Comm comm, MPI_Request * request) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Isend"); #ifdef HAVE_TRACING int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst); - TRACE_smpi_ptp_in (rank, rank, dst_traced, __FUNCTION__); - TRACE_smpi_send (rank, rank, dst_traced); + TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__); + TRACE_smpi_send(rank, rank, dst_traced); #endif - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -817,21 +875,23 @@ int MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, rank, dst_traced, __FUNCTION__); + TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__); (*request)->send = 1; #endif smpi_bench_begin(rank, "Isend"); return retval; } -int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) { +int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, + MPI_Comm comm, MPI_Status * status) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Recv"); #ifdef HAVE_TRACING int src_traced = smpi_group_rank(smpi_comm_group(comm), src); - TRACE_smpi_ptp_in (rank, src_traced, rank, __FUNCTION__); + TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__); #endif if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -840,22 +900,24 @@ int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_ retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, src_traced, rank, __FUNCTION__); - TRACE_smpi_recv (rank, src_traced, rank); + TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__); + TRACE_smpi_recv(rank, src_traced, rank); #endif smpi_bench_begin(rank, "Recv"); return retval; } -int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { +int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, + MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Send"); #ifdef HAVE_TRACING int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst); - TRACE_smpi_ptp_in (rank, rank, dst_traced, __FUNCTION__); - TRACE_smpi_send (rank, rank, dst_traced); + TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__); + TRACE_smpi_send(rank, rank, dst_traced); #endif if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; @@ -864,13 +926,17 @@ int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_ retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, rank, dst_traced, __FUNCTION__); + TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Send"); return retval; } -int MPI_Sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) { +int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + int dst, int sendtag, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int src, int recvtag, + MPI_Comm comm, MPI_Status * status) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; @@ -878,50 +944,58 @@ int MPI_Sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, i #ifdef HAVE_TRACING int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst); int src_traced = smpi_group_rank(smpi_comm_group(comm), src); - TRACE_smpi_ptp_in (rank, src_traced, dst_traced, __FUNCTION__); - TRACE_smpi_send (rank, rank, dst_traced); - TRACE_smpi_send (rank, src_traced, rank); + TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__); + TRACE_smpi_send(rank, rank, dst_traced); + TRACE_smpi_send(rank, src_traced, rank); #endif if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; } else { - smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm, status); + smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, + recvcount, recvtype, src, recvtag, comm, status); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, src_traced, dst_traced, __FUNCTION__); - TRACE_smpi_recv (rank, rank, dst_traced); - TRACE_smpi_recv (rank, src_traced, rank); + TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__); + TRACE_smpi_recv(rank, rank, dst_traced); + TRACE_smpi_recv(rank, src_traced, rank); #endif smpi_bench_begin(rank, "Sendrecv"); return retval; } -int MPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag, MPI_Comm comm, MPI_Status* status) { +int MPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, + int dst, int sendtag, int src, int recvtag, + MPI_Comm comm, MPI_Status * status) +{ //TODO: suboptimal implementation - void* recvbuf; + void *recvbuf; int retval, size; size = smpi_datatype_size(datatype) * count; recvbuf = xbt_new(char, size); - retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status); + retval = + MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, + datatype, src, recvtag, comm, status); memcpy(buf, recvbuf, size * sizeof(char)); xbt_free(recvbuf); return retval; } -int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) { +int MPI_Test(MPI_Request * request, int *flag, MPI_Status * status) +{ int retval; int rank = request && (*request)->comm != MPI_COMM_NULL - ? smpi_comm_rank((*request)->comm) - : -1; + ? smpi_comm_rank((*request)->comm) + : -1; smpi_bench_end(rank, "Test"); - if(request == NULL || flag == NULL) { + if (request == NULL || flag == NULL) { retval = MPI_ERR_ARG; - } else if(*request == MPI_REQUEST_NULL) { + } else if (*request == MPI_REQUEST_NULL) { retval = MPI_ERR_REQUEST; } else { *flag = smpi_mpi_test(request, status); @@ -931,11 +1005,13 @@ int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) { return retval; } -int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status) { +int MPI_Testany(int count, MPI_Request requests[], int *index, int *flag, + MPI_Status * status) +{ int retval; - smpi_bench_end(-1, NULL); //FIXME - if(index == NULL || flag == NULL) { + smpi_bench_end(-1, NULL); //FIXME + if (index == NULL || flag == NULL) { retval = MPI_ERR_ARG; } else { *flag = smpi_mpi_testany(count, requests, index, status); @@ -945,65 +1021,68 @@ int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_St return retval; } -int MPI_Wait(MPI_Request* request, MPI_Status* status) { +int MPI_Wait(MPI_Request * request, MPI_Status * status) +{ int retval; int rank = request && (*request)->comm != MPI_COMM_NULL - ? smpi_comm_rank((*request)->comm) - : -1; + ? smpi_comm_rank((*request)->comm) + : -1; smpi_bench_end(rank, "Wait"); #ifdef HAVE_TRACING MPI_Group group = smpi_comm_group((*request)->comm); - int src_traced = smpi_group_rank (group , (*request)->src); - int dst_traced = smpi_group_rank (group , (*request)->dst); + int src_traced = smpi_group_rank(group, (*request)->src); + int dst_traced = smpi_group_rank(group, (*request)->dst); int is_wait_for_receive = (*request)->recv; - TRACE_smpi_ptp_in (rank, src_traced, dst_traced, __FUNCTION__); + TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__); #endif - if(request == NULL) { + if (request == NULL) { retval = MPI_ERR_ARG; - } else if(*request == MPI_REQUEST_NULL) { + } else if (*request == MPI_REQUEST_NULL) { retval = MPI_ERR_REQUEST; } else { smpi_mpi_wait(request, status); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_ptp_out (rank, src_traced, dst_traced, __FUNCTION__); - if (is_wait_for_receive){ - TRACE_smpi_recv (rank, src_traced, dst_traced); + TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__); + if (is_wait_for_receive) { + TRACE_smpi_recv(rank, src_traced, dst_traced); } #endif smpi_bench_begin(rank, "Wait"); return retval; } -int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* status) { +int MPI_Waitany(int count, MPI_Request requests[], int *index, + MPI_Status * status) +{ int retval; - smpi_bench_end(-1, NULL); //FIXME + smpi_bench_end(-1, NULL); //FIXME #ifdef HAVE_TRACING //save requests information for tracing int i; - xbt_dynar_t srcs = xbt_dynar_new (sizeof(int), xbt_free); - xbt_dynar_t dsts = xbt_dynar_new (sizeof(int), xbt_free); - xbt_dynar_t recvs = xbt_dynar_new (sizeof(int), xbt_free); - for (i = 0; i < count; i++){ - MPI_Request req = requests[i]; //already received requests are no longer valid - if (req){ + xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), xbt_free); + xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), xbt_free); + xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), xbt_free); + for (i = 0; i < count; i++) { + MPI_Request req = requests[i]; //already received requests are no longer valid + if (req) { int *asrc = xbt_new(int, 1); int *adst = xbt_new(int, 1); int *arecv = xbt_new(int, 1); *asrc = req->src; *adst = req->dst; *arecv = req->recv; - xbt_dynar_insert_at (srcs, i, asrc); - xbt_dynar_insert_at (dsts, i, adst); - xbt_dynar_insert_at (recvs, i, arecv); - }else{ + xbt_dynar_insert_at(srcs, i, asrc); + xbt_dynar_insert_at(dsts, i, adst); + xbt_dynar_insert_at(recvs, i, arecv); + } else { int *t = xbt_new(int, 1); - xbt_dynar_insert_at (srcs, i, t); - xbt_dynar_insert_at (dsts, i, t); - xbt_dynar_insert_at (recvs, i, t); + xbt_dynar_insert_at(srcs, i, t); + xbt_dynar_insert_at(dsts, i, t); + xbt_dynar_insert_at(recvs, i, t); } } @@ -1014,9 +1093,9 @@ int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* statu } MPI_Comm comm = (req)->comm; int rank_traced = smpi_comm_rank(comm); - TRACE_smpi_ptp_in (rank_traced, -1, -1, __FUNCTION__); + TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__); #endif - if(index == NULL) { + if (index == NULL) { retval = MPI_ERR_ARG; } else { *index = smpi_mpi_waitany(count, requests, status); @@ -1024,42 +1103,43 @@ int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* statu } #ifdef HAVE_TRACING int src_traced, dst_traced, is_wait_for_receive; - xbt_dynar_get_cpy (srcs, *index, &src_traced); - xbt_dynar_get_cpy (dsts, *index, &dst_traced); - xbt_dynar_get_cpy (recvs, *index, &is_wait_for_receive); - if (is_wait_for_receive){ - TRACE_smpi_recv (rank_traced, src_traced, dst_traced); + xbt_dynar_get_cpy(srcs, *index, &src_traced); + xbt_dynar_get_cpy(dsts, *index, &dst_traced); + xbt_dynar_get_cpy(recvs, *index, &is_wait_for_receive); + if (is_wait_for_receive) { + TRACE_smpi_recv(rank_traced, src_traced, dst_traced); } - TRACE_smpi_ptp_out (rank_traced, src_traced, dst_traced, __FUNCTION__); + TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__); //clean-up of dynars - xbt_free (srcs); - xbt_free (dsts); - xbt_free (recvs); + xbt_free(srcs); + xbt_free(dsts); + xbt_free(recvs); #endif smpi_bench_begin(-1, NULL); return retval; } -int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) { +int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) +{ - smpi_bench_end(-1, NULL); //FIXME + smpi_bench_end(-1, NULL); //FIXME #ifdef HAVE_TRACING //save information from requests int i; - xbt_dynar_t srcs = xbt_dynar_new (sizeof(int), xbt_free); - xbt_dynar_t dsts = xbt_dynar_new (sizeof(int), xbt_free); - xbt_dynar_t recvs = xbt_dynar_new (sizeof(int), xbt_free); - for (i = 0; i < count; i++){ - MPI_Request req = requests[i]; //all req should be valid in Waitall + xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), xbt_free); + xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), xbt_free); + xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), xbt_free); + for (i = 0; i < count; i++) { + MPI_Request req = requests[i]; //all req should be valid in Waitall int *asrc = xbt_new(int, 1); int *adst = xbt_new(int, 1); int *arecv = xbt_new(int, 1); *asrc = req->src; *adst = req->dst; *arecv = req->recv; - xbt_dynar_insert_at (srcs, i, asrc); - xbt_dynar_insert_at (dsts, i, adst); - xbt_dynar_insert_at (recvs, i, arecv); + xbt_dynar_insert_at(srcs, i, asrc); + xbt_dynar_insert_at(dsts, i, adst); + xbt_dynar_insert_at(recvs, i, arecv); } // find my rank inside one of MPI_Comm's of the requests @@ -1069,34 +1149,36 @@ int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) { } MPI_Comm comm = (req)->comm; int rank_traced = smpi_comm_rank(comm); - TRACE_smpi_ptp_in (rank_traced, -1, -1, __FUNCTION__); + TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__); #endif smpi_mpi_waitall(count, requests, status); #ifdef HAVE_TRACING - for (i = 0; i < count; i++){ + for (i = 0; i < count; i++) { int src_traced, dst_traced, is_wait_for_receive; - xbt_dynar_get_cpy (srcs, i, &src_traced); - xbt_dynar_get_cpy (dsts, i, &dst_traced); - xbt_dynar_get_cpy (recvs, i, &is_wait_for_receive); - if (is_wait_for_receive){ - TRACE_smpi_recv (rank_traced, src_traced, dst_traced); + xbt_dynar_get_cpy(srcs, i, &src_traced); + xbt_dynar_get_cpy(dsts, i, &dst_traced); + xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive); + if (is_wait_for_receive) { + TRACE_smpi_recv(rank_traced, src_traced, dst_traced); } } - TRACE_smpi_ptp_out (rank_traced, -1, -1, __FUNCTION__); + TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__); //clean-up of dynars - xbt_free (srcs); - xbt_free (dsts); - xbt_free (recvs); + xbt_free(srcs); + xbt_free(dsts); + xbt_free(recvs); #endif smpi_bench_begin(-1, NULL); return MPI_SUCCESS; } -int MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[]) { +int MPI_Waitsome(int incount, MPI_Request requests[], int *outcount, + int *indices, MPI_Status status[]) +{ int retval; - smpi_bench_end(-1, NULL); //FIXME - if(outcount == NULL || indices == NULL) { + smpi_bench_end(-1, NULL); //FIXME + if (outcount == NULL || indices == NULL) { retval = MPI_ERR_ARG; } else { *outcount = smpi_mpi_waitsome(incount, requests, indices, status); @@ -1106,287 +1188,328 @@ int MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indice return retval; } -int MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { +int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, + MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Bcast"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; } else { smpi_mpi_bcast(buf, count, datatype, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Bcast"); return retval; } -int MPI_Barrier(MPI_Comm comm) { +int MPI_Barrier(MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Barrier"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; } else { smpi_mpi_barrier(comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Barrier"); return retval; } -int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Gather"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; } else { - smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm); + smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, + recvtype, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Gather"); return retval; } -int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm) { +int MPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, int *displs, + MPI_Datatype recvtype, int root, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Gatherv"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(recvcounts == NULL || displs == NULL) { + } else if (recvcounts == NULL || displs == NULL) { retval = MPI_ERR_ARG; } else { - smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm); + smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, + displs, recvtype, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Gatherv"); return retval; } -int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +int MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Allgather"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; } else { - smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); + smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, + recvtype, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Allgather"); return retval; } -int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) { +int MPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int *recvcounts, int *displs, + MPI_Datatype recvtype, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Allgatherv"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(recvcounts == NULL || displs == NULL) { + } else if (recvcounts == NULL || displs == NULL) { retval = MPI_ERR_ARG; } else { - smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm); + smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, + displs, recvtype, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Allgatherv"); return retval; } -int MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +int MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + int root, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Scatter"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; } else { - smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm); + smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, + recvtype, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Scatter"); return retval; } -int MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { +int MPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, + MPI_Datatype sendtype, void *recvbuf, int recvcount, + MPI_Datatype recvtype, int root, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Scatterv"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(sendcounts == NULL || displs == NULL) { + } else if (sendcounts == NULL || displs == NULL) { retval = MPI_ERR_ARG; } else { - smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm); + smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, + recvcount, recvtype, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Scatterv"); return retval; } -int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { +int MPI_Reduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Reduce"); #ifdef HAVE_TRACING int root_traced = smpi_group_rank(smpi_comm_group(comm), root); - TRACE_smpi_collective_in (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) { + } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) { retval = MPI_ERR_ARG; } else { smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, root_traced, __FUNCTION__); + TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__); #endif smpi_bench_begin(rank, "Reduce"); return retval; } -int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { +int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Allreduce"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(datatype == MPI_DATATYPE_NULL) { + } else if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(op == MPI_OP_NULL) { + } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; } else { smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Allreduce"); return retval; } -int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { +int MPI_Scan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Scan"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(datatype == MPI_DATATYPE_NULL) { + } else if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(op == MPI_OP_NULL) { + } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; } else { smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Scan"); return retval; } -int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { +int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ int retval, i, size, count; - int* displs; + int *displs; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Reduce_scatter"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(datatype == MPI_DATATYPE_NULL) { + } else if (datatype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(op == MPI_OP_NULL) { + } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; - } else if(recvcounts == NULL) { + } else if (recvcounts == NULL) { retval = MPI_ERR_ARG; } else { /* arbitrarily choose root as rank 0 */ @@ -1394,89 +1517,116 @@ int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Dataty size = smpi_comm_size(comm); count = 0; displs = xbt_new(int, size); - for(i = 0; i < size; i++) { + for (i = 0; i < size; i++) { count += recvcounts[i]; displs[i] = 0; } smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm); - smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm); + smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf, + recvcounts[rank], datatype, 0, comm); xbt_free(displs); retval = MPI_SUCCESS; } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Reduce_scatter"); return retval; } -int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { +int MPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) +{ int retval, size, sendsize; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Alltoall"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; } else { size = smpi_comm_size(comm); sendsize = smpi_datatype_size(sendtype) * sendcount; - if(sendsize < 200 && size > 12) { - retval = smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); - } else if(sendsize < 3000) { - retval = smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); + if (sendsize < 200 && size > 12) { + retval = + smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype, + recvbuf, recvcount, recvtype, + comm); + } else if (sendsize < 3000) { + retval = + smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, + sendtype, recvbuf, + recvcount, recvtype, comm); } else { - retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); + retval = + smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype, + recvbuf, recvcount, recvtype, + comm); } } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Alltoall"); return retval; } -int MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm) { +int MPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps, + MPI_Datatype sendtype, void *recvbuf, int *recvcounts, + int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm) +{ int retval; int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; smpi_bench_end(rank, "Alltoallv"); #ifdef HAVE_TRACING - TRACE_smpi_collective_in (rank, -1, __FUNCTION__); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); #endif - if(comm == MPI_COMM_NULL) { + if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) { + } else if (sendtype == MPI_DATATYPE_NULL + || recvtype == MPI_DATATYPE_NULL) { retval = MPI_ERR_TYPE; - } else if(sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) { + } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL + || recvdisps == NULL) { retval = MPI_ERR_ARG; } else { - retval = smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm); + retval = + smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype, + recvbuf, recvcounts, recvdisps, recvtype, + comm); } #ifdef HAVE_TRACING - TRACE_smpi_collective_out (rank, -1, __FUNCTION__); + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); #endif smpi_bench_begin(rank, "Alltoallv"); return retval; } -int MPI_Get_processor_name(char* name, int* resultlen) { +int MPI_Get_processor_name(char *name, int *resultlen) +{ int retval = MPI_SUCCESS; smpi_bench_end(-1, NULL); - strncpy( name , SIMIX_host_get_name(SIMIX_host_self()), MPI_MAX_PROCESSOR_NAME-1); - *resultlen= strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name); + strncpy(name, SIMIX_host_get_name(SIMIX_host_self()), + MPI_MAX_PROCESSOR_NAME - 1); + *resultlen = + strlen(name) > + MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name); smpi_bench_begin(-1, NULL); return retval; } -int MPI_Get_count(MPI_Status* status, MPI_Datatype datatype, int* count) { +int MPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count) +{ int retval = MPI_SUCCESS; size_t size; @@ -1488,11 +1638,11 @@ int MPI_Get_count(MPI_Status* status, MPI_Datatype datatype, int* count) { } else { size = smpi_datatype_size(datatype); if (size == 0) { - *count = 0; + *count = 0; } else if (status->count % size != 0) { - retval = MPI_UNDEFINED; + retval = MPI_UNDEFINED; } else { - *count = smpi_mpi_get_count(status, datatype); + *count = smpi_mpi_get_count(status, datatype); } } smpi_bench_begin(-1, NULL); diff --git a/src/smpi/smpi_mpi_dt.c b/src/smpi/smpi_mpi_dt.c index de903ef5d0..9adfdb39e4 100644 --- a/src/smpi/smpi_mpi_dt.c +++ b/src/smpi/smpi_mpi_dt.c @@ -35,96 +35,121 @@ typedef struct s_smpi_mpi_datatype { //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC. -typedef struct { float value; int index;} float_int; -typedef struct { long value; int index;} long_int ; -typedef struct { double value; int index;} double_int; -typedef struct { short value; int index;} short_int; -typedef struct { int value; int index;} int_int; -typedef struct { long double value; int index;} long_double_int; +typedef struct { + float value; + int index; +} float_int; +typedef struct { + long value; + int index; +} long_int; +typedef struct { + double value; + int index; +} double_int; +typedef struct { + short value; + int index; +} short_int; +typedef struct { + int value; + int index; +} int_int; +typedef struct { + long double value; + int index; +} long_double_int; // Predefined data types -CREATE_MPI_DATATYPE(MPI_CHAR, char); -CREATE_MPI_DATATYPE(MPI_SHORT, short); -CREATE_MPI_DATATYPE(MPI_INT, int); -CREATE_MPI_DATATYPE(MPI_LONG, long); -CREATE_MPI_DATATYPE(MPI_LONG_LONG, long long); -CREATE_MPI_DATATYPE(MPI_SIGNED_CHAR, signed char); -CREATE_MPI_DATATYPE(MPI_UNSIGNED_CHAR, unsigned char); -CREATE_MPI_DATATYPE(MPI_UNSIGNED_SHORT, unsigned short); -CREATE_MPI_DATATYPE(MPI_UNSIGNED, unsigned int); -CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG, unsigned long); -CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG_LONG, unsigned long long); -CREATE_MPI_DATATYPE(MPI_FLOAT, float); -CREATE_MPI_DATATYPE(MPI_DOUBLE, double); -CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE, long double); -CREATE_MPI_DATATYPE(MPI_WCHAR, wchar_t); -CREATE_MPI_DATATYPE(MPI_C_BOOL, _Bool); -CREATE_MPI_DATATYPE(MPI_INT8_T, int8_t); -CREATE_MPI_DATATYPE(MPI_INT16_T, int16_t); -CREATE_MPI_DATATYPE(MPI_INT32_T, int32_t); -CREATE_MPI_DATATYPE(MPI_INT64_T, int64_t); -CREATE_MPI_DATATYPE(MPI_UINT8_T, uint8_t); -CREATE_MPI_DATATYPE(MPI_UINT16_T, uint16_t); -CREATE_MPI_DATATYPE(MPI_UINT32_T, uint32_t); -CREATE_MPI_DATATYPE(MPI_UINT64_T, uint64_t); -CREATE_MPI_DATATYPE(MPI_C_FLOAT_COMPLEX, float _Complex); -CREATE_MPI_DATATYPE(MPI_C_DOUBLE_COMPLEX, double _Complex); +CREATE_MPI_DATATYPE(MPI_CHAR, char); +CREATE_MPI_DATATYPE(MPI_SHORT, short); +CREATE_MPI_DATATYPE(MPI_INT, int); +CREATE_MPI_DATATYPE(MPI_LONG, long); +CREATE_MPI_DATATYPE(MPI_LONG_LONG, long long); +CREATE_MPI_DATATYPE(MPI_SIGNED_CHAR, signed char); +CREATE_MPI_DATATYPE(MPI_UNSIGNED_CHAR, unsigned char); +CREATE_MPI_DATATYPE(MPI_UNSIGNED_SHORT, unsigned short); +CREATE_MPI_DATATYPE(MPI_UNSIGNED, unsigned int); +CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG, unsigned long); +CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG_LONG, unsigned long long); +CREATE_MPI_DATATYPE(MPI_FLOAT, float); +CREATE_MPI_DATATYPE(MPI_DOUBLE, double); +CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE, long double); +CREATE_MPI_DATATYPE(MPI_WCHAR, wchar_t); +CREATE_MPI_DATATYPE(MPI_C_BOOL, _Bool); +CREATE_MPI_DATATYPE(MPI_INT8_T, int8_t); +CREATE_MPI_DATATYPE(MPI_INT16_T, int16_t); +CREATE_MPI_DATATYPE(MPI_INT32_T, int32_t); +CREATE_MPI_DATATYPE(MPI_INT64_T, int64_t); +CREATE_MPI_DATATYPE(MPI_UINT8_T, uint8_t); +CREATE_MPI_DATATYPE(MPI_UINT16_T, uint16_t); +CREATE_MPI_DATATYPE(MPI_UINT32_T, uint32_t); +CREATE_MPI_DATATYPE(MPI_UINT64_T, uint64_t); +CREATE_MPI_DATATYPE(MPI_C_FLOAT_COMPLEX, float _Complex); +CREATE_MPI_DATATYPE(MPI_C_DOUBLE_COMPLEX, double _Complex); CREATE_MPI_DATATYPE(MPI_C_LONG_DOUBLE_COMPLEX, long double _Complex); -CREATE_MPI_DATATYPE(MPI_AINT, MPI_Aint); -CREATE_MPI_DATATYPE(MPI_OFFSET, MPI_Offset); +CREATE_MPI_DATATYPE(MPI_AINT, MPI_Aint); +CREATE_MPI_DATATYPE(MPI_OFFSET, MPI_Offset); -CREATE_MPI_DATATYPE(MPI_FLOAT_INT, float_int); -CREATE_MPI_DATATYPE(MPI_LONG_INT, long_int); -CREATE_MPI_DATATYPE(MPI_DOUBLE_INT, double_int); -CREATE_MPI_DATATYPE(MPI_SHORT_INT, short_int); -CREATE_MPI_DATATYPE(MPI_2INT, int_int); -CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE_INT, long_double_int); +CREATE_MPI_DATATYPE(MPI_FLOAT_INT, float_int); +CREATE_MPI_DATATYPE(MPI_LONG_INT, long_int); +CREATE_MPI_DATATYPE(MPI_DOUBLE_INT, double_int); +CREATE_MPI_DATATYPE(MPI_SHORT_INT, short_int); +CREATE_MPI_DATATYPE(MPI_2INT, int_int); +CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE_INT, long_double_int); -size_t smpi_datatype_size(MPI_Datatype datatype) { +size_t smpi_datatype_size(MPI_Datatype datatype) +{ return datatype->size; } -MPI_Aint smpi_datatype_lb(MPI_Datatype datatype) { +MPI_Aint smpi_datatype_lb(MPI_Datatype datatype) +{ return datatype->lb; } -MPI_Aint smpi_datatype_ub(MPI_Datatype datatype) { +MPI_Aint smpi_datatype_ub(MPI_Datatype datatype) +{ return datatype->ub; } -int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint * extent) { +int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb, + MPI_Aint * extent) +{ int retval; - if((datatype->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) { + if ((datatype->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) { retval = MPI_ERR_TYPE; } else { - *lb = datatype->lb; - *extent = datatype->ub - datatype->lb; + *lb = datatype->lb; + *extent = datatype->ub - datatype->lb; retval = MPI_SUCCESS; } return MPI_SUCCESS; } -int smpi_datatype_copy(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype) { +int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, + void *recvbuf, int recvcount, MPI_Datatype recvtype) +{ int retval, count; /* First check if we really have something to do */ - if(recvcount == 0) { + if (recvcount == 0) { retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE; } else { - /* FIXME: treat packed cases */ - sendcount *= smpi_datatype_size(sendtype); - recvcount *= smpi_datatype_size(recvtype); - count = sendcount < recvcount ? sendcount : recvcount; - memcpy(recvbuf, sendbuf, count); - retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS; + /* FIXME: treat packed cases */ + sendcount *= smpi_datatype_size(sendtype); + recvcount *= smpi_datatype_size(recvtype); + count = sendcount < recvcount ? sendcount : recvcount; + memcpy(recvbuf, sendbuf, count); + retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS; } return retval; } typedef struct s_smpi_mpi_op { - MPI_User_function* func; + MPI_User_function *func; } s_smpi_mpi_op_t; #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a) @@ -151,262 +176,287 @@ typedef struct s_smpi_mpi_op { } \ } -static void max_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void max_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, MAX_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, MAX_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, MAX_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, MAX_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, MAX_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, MAX_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, MAX_OP); - } else if(*datatype == MPI_FLOAT) { + } else if (*datatype == MPI_FLOAT) { APPLY_FUNC(a, b, length, float, MAX_OP); - } else if(*datatype == MPI_DOUBLE) { + } else if (*datatype == MPI_DOUBLE) { APPLY_FUNC(a, b, length, double, MAX_OP); - } else if(*datatype == MPI_LONG_DOUBLE) { + } else if (*datatype == MPI_LONG_DOUBLE) { APPLY_FUNC(a, b, length, long double, MAX_OP); } } -static void min_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void min_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, MIN_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, MIN_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, MIN_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, MIN_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, MIN_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, MIN_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, MIN_OP); - } else if(*datatype == MPI_FLOAT) { + } else if (*datatype == MPI_FLOAT) { APPLY_FUNC(a, b, length, float, MIN_OP); - } else if(*datatype == MPI_DOUBLE) { + } else if (*datatype == MPI_DOUBLE) { APPLY_FUNC(a, b, length, double, MIN_OP); - } else if(*datatype == MPI_LONG_DOUBLE) { + } else if (*datatype == MPI_LONG_DOUBLE) { APPLY_FUNC(a, b, length, long double, MIN_OP); } } -static void sum_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void sum_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, SUM_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, SUM_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, SUM_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, SUM_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, SUM_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, SUM_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, SUM_OP); - } else if(*datatype == MPI_FLOAT) { + } else if (*datatype == MPI_FLOAT) { APPLY_FUNC(a, b, length, float, SUM_OP); - } else if(*datatype == MPI_DOUBLE) { + } else if (*datatype == MPI_DOUBLE) { APPLY_FUNC(a, b, length, double, SUM_OP); - } else if(*datatype == MPI_LONG_DOUBLE) { + } else if (*datatype == MPI_LONG_DOUBLE) { APPLY_FUNC(a, b, length, long double, SUM_OP); - } else if(*datatype == MPI_C_FLOAT_COMPLEX) { + } else if (*datatype == MPI_C_FLOAT_COMPLEX) { APPLY_FUNC(a, b, length, float _Complex, SUM_OP); - } else if(*datatype == MPI_C_DOUBLE_COMPLEX) { + } else if (*datatype == MPI_C_DOUBLE_COMPLEX) { APPLY_FUNC(a, b, length, double _Complex, SUM_OP); - } else if(*datatype == MPI_C_LONG_DOUBLE_COMPLEX) { + } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) { APPLY_FUNC(a, b, length, long double _Complex, SUM_OP); } } -static void prod_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void prod_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, PROD_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, PROD_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, PROD_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, PROD_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, PROD_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, PROD_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, PROD_OP); - } else if(*datatype == MPI_FLOAT) { + } else if (*datatype == MPI_FLOAT) { APPLY_FUNC(a, b, length, float, PROD_OP); - } else if(*datatype == MPI_DOUBLE) { + } else if (*datatype == MPI_DOUBLE) { APPLY_FUNC(a, b, length, double, PROD_OP); - } else if(*datatype == MPI_LONG_DOUBLE) { + } else if (*datatype == MPI_LONG_DOUBLE) { APPLY_FUNC(a, b, length, long double, PROD_OP); - } else if(*datatype == MPI_C_FLOAT_COMPLEX) { + } else if (*datatype == MPI_C_FLOAT_COMPLEX) { APPLY_FUNC(a, b, length, float _Complex, PROD_OP); - } else if(*datatype == MPI_C_DOUBLE_COMPLEX) { - APPLY_FUNC(a, b, length, double _Complex, PROD_OP); - } else if(*datatype == MPI_C_LONG_DOUBLE_COMPLEX) { + } else if (*datatype == MPI_C_DOUBLE_COMPLEX) { + APPLY_FUNC(a, b, length, double _Complex, PROD_OP); + } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) { APPLY_FUNC(a, b, length, long double _Complex, PROD_OP); } } -static void land_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void land_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, LAND_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, LAND_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, LAND_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, LAND_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, LAND_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, LAND_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, LAND_OP); - } else if(*datatype == MPI_C_BOOL) { + } else if (*datatype == MPI_C_BOOL) { APPLY_FUNC(a, b, length, _Bool, LAND_OP); } } -static void lor_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void lor_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, LOR_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, LOR_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, LOR_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, LOR_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, LOR_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, LOR_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, LOR_OP); - } else if(*datatype == MPI_C_BOOL) { + } else if (*datatype == MPI_C_BOOL) { APPLY_FUNC(a, b, length, _Bool, LOR_OP); } } -static void lxor_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void lxor_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, LXOR_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, LXOR_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, LXOR_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, LXOR_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, LXOR_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, LXOR_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, LXOR_OP); - } else if(*datatype == MPI_C_BOOL) { + } else if (*datatype == MPI_C_BOOL) { APPLY_FUNC(a, b, length, _Bool, LXOR_OP); } } -static void band_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void band_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, BAND_OP); - } if(*datatype == MPI_SHORT) { + } + if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, BAND_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, BAND_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, BAND_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, BAND_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, BAND_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, BAND_OP); - } else if(*datatype == MPI_BYTE) { + } else if (*datatype == MPI_BYTE) { APPLY_FUNC(a, b, length, uint8_t, BAND_OP); } } -static void bor_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void bor_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, BOR_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, BOR_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, BOR_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, BOR_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, BOR_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, BOR_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, BOR_OP); - } else if(*datatype == MPI_BYTE) { + } else if (*datatype == MPI_BYTE) { APPLY_FUNC(a, b, length, uint8_t, BOR_OP); } } -static void bxor_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_CHAR) { +static void bxor_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_CHAR) { APPLY_FUNC(a, b, length, char, BXOR_OP); - } else if(*datatype == MPI_SHORT) { + } else if (*datatype == MPI_SHORT) { APPLY_FUNC(a, b, length, short, BXOR_OP); - } else if(*datatype == MPI_INT) { + } else if (*datatype == MPI_INT) { APPLY_FUNC(a, b, length, int, BXOR_OP); - } else if(*datatype == MPI_LONG) { + } else if (*datatype == MPI_LONG) { APPLY_FUNC(a, b, length, long, BXOR_OP); - } else if(*datatype == MPI_UNSIGNED_SHORT) { + } else if (*datatype == MPI_UNSIGNED_SHORT) { APPLY_FUNC(a, b, length, unsigned short, BXOR_OP); - } else if(*datatype == MPI_UNSIGNED) { + } else if (*datatype == MPI_UNSIGNED) { APPLY_FUNC(a, b, length, unsigned int, BXOR_OP); - } else if(*datatype == MPI_UNSIGNED_LONG) { + } else if (*datatype == MPI_UNSIGNED_LONG) { APPLY_FUNC(a, b, length, unsigned long, BXOR_OP); - } else if(*datatype == MPI_BYTE) { + } else if (*datatype == MPI_BYTE) { APPLY_FUNC(a, b, length, uint8_t, BXOR_OP); } } -static void minloc_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_FLOAT_INT) { +static void minloc_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_FLOAT_INT) { APPLY_FUNC(a, b, length, float_int, MINLOC_OP); - } else if(*datatype == MPI_LONG_INT) { + } else if (*datatype == MPI_LONG_INT) { APPLY_FUNC(a, b, length, long_int, MINLOC_OP); - } else if(*datatype == MPI_DOUBLE_INT) { + } else if (*datatype == MPI_DOUBLE_INT) { APPLY_FUNC(a, b, length, double_int, MINLOC_OP); - } else if(*datatype == MPI_SHORT_INT) { + } else if (*datatype == MPI_SHORT_INT) { APPLY_FUNC(a, b, length, short_int, MINLOC_OP); - } else if(*datatype == MPI_2INT) { + } else if (*datatype == MPI_2INT) { APPLY_FUNC(a, b, length, int_int, MINLOC_OP); - } else if(*datatype == MPI_LONG_DOUBLE_INT) { + } else if (*datatype == MPI_LONG_DOUBLE_INT) { APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP); } } -static void maxloc_func(void* a, void* b, int* length, MPI_Datatype* datatype) { - if(*datatype == MPI_FLOAT_INT) { +static void maxloc_func(void *a, void *b, int *length, + MPI_Datatype * datatype) +{ + if (*datatype == MPI_FLOAT_INT) { APPLY_FUNC(a, b, length, float_int, MAXLOC_OP); - } else if(*datatype == MPI_LONG_INT) { + } else if (*datatype == MPI_LONG_INT) { APPLY_FUNC(a, b, length, long_int, MAXLOC_OP); - } else if(*datatype == MPI_DOUBLE_INT) { + } else if (*datatype == MPI_DOUBLE_INT) { APPLY_FUNC(a, b, length, double_int, MAXLOC_OP); - } else if(*datatype == MPI_SHORT_INT) { + } else if (*datatype == MPI_SHORT_INT) { APPLY_FUNC(a, b, length, short_int, MAXLOC_OP); - } else if(*datatype == MPI_2INT) { + } else if (*datatype == MPI_2INT) { APPLY_FUNC(a, b, length, int_int, MAXLOC_OP); - } else if(*datatype == MPI_LONG_DOUBLE_INT) { + } else if (*datatype == MPI_LONG_DOUBLE_INT) { APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP); } } @@ -416,20 +466,21 @@ static void maxloc_func(void* a, void* b, int* length, MPI_Datatype* datatype) { static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \ MPI_Op name = &mpi_##name; -CREATE_MPI_OP(MPI_MAX, max_func); -CREATE_MPI_OP(MPI_MIN, min_func); -CREATE_MPI_OP(MPI_SUM, sum_func); -CREATE_MPI_OP(MPI_PROD, prod_func); -CREATE_MPI_OP(MPI_LAND, land_func); -CREATE_MPI_OP(MPI_LOR, lor_func); -CREATE_MPI_OP(MPI_LXOR, lxor_func); -CREATE_MPI_OP(MPI_BAND, band_func); -CREATE_MPI_OP(MPI_BOR, bor_func); -CREATE_MPI_OP(MPI_BXOR, bxor_func); -CREATE_MPI_OP(MPI_MAXLOC, maxloc_func); -CREATE_MPI_OP(MPI_MINLOC, minloc_func); - -MPI_Op smpi_op_new(MPI_User_function* function, int commute) { +CREATE_MPI_OP(MPI_MAX, max_func); +CREATE_MPI_OP(MPI_MIN, min_func); +CREATE_MPI_OP(MPI_SUM, sum_func); +CREATE_MPI_OP(MPI_PROD, prod_func); +CREATE_MPI_OP(MPI_LAND, land_func); +CREATE_MPI_OP(MPI_LOR, lor_func); +CREATE_MPI_OP(MPI_LXOR, lxor_func); +CREATE_MPI_OP(MPI_BAND, band_func); +CREATE_MPI_OP(MPI_BOR, bor_func); +CREATE_MPI_OP(MPI_BXOR, bxor_func); +CREATE_MPI_OP(MPI_MAXLOC, maxloc_func); +CREATE_MPI_OP(MPI_MINLOC, minloc_func); + +MPI_Op smpi_op_new(MPI_User_function * function, int commute) +{ MPI_Op op; //FIXME: add commute param @@ -438,10 +489,13 @@ MPI_Op smpi_op_new(MPI_User_function* function, int commute) { return op; } -void smpi_op_destroy(MPI_Op op) { +void smpi_op_destroy(MPI_Op op) +{ xbt_free(op); } -void smpi_op_apply(MPI_Op op, void* invec, void* inoutvec, int* len, MPI_Datatype* datatype) { +void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, + MPI_Datatype * datatype) +{ op->func(invec, inoutvec, len, datatype); } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 4dcc8adf2a..7feee6f9cd 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -7,7 +7,7 @@ #include "surf_private.h" typedef s_surf_action_lmm_t s_surf_action_cpu_Cas01_t, - *surf_action_cpu_Cas01_t; + *surf_action_cpu_Cas01_t; typedef struct cpu_Cas01 { s_surf_resource_t generic_resource; @@ -28,7 +28,8 @@ surf_model_t surf_cpu_model = NULL; lmm_system_t cpu_maxmin_system = NULL; -static xbt_swag_t cpu_running_action_set_that_does_not_need_being_checked = NULL; +static xbt_swag_t cpu_running_action_set_that_does_not_need_being_checked = + NULL; static cpu_Cas01_t cpu_new(char *name, double power_peak, double power_scale, @@ -39,7 +40,8 @@ static cpu_Cas01_t cpu_new(char *name, double power_peak, { cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1); xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name), - "Host '%s' declared several times in the platform file", name); + "Host '%s' declared several times in the platform file", + name); cpu->generic_resource.model = surf_cpu_model; cpu->generic_resource.name = name; cpu->generic_resource.properties = cpu_properties; @@ -48,21 +50,21 @@ static cpu_Cas01_t cpu_new(char *name, double power_peak, cpu->power_scale = power_scale; if (power_trace) cpu->power_event = - tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); cpu->state_current = state_initial; if (state_trace) cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); cpu->constraint = - lmm_constraint_new(cpu_maxmin_system, cpu, - cpu->power_scale * cpu->power_peak); + lmm_constraint_new(cpu_maxmin_system, cpu, + cpu->power_scale * cpu->power_peak); xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, surf_resource_free); #ifdef HAVE_TRACING - TRACE_surf_host_declaration (name, cpu->power_scale * cpu->power_peak); + TRACE_surf_host_declaration(name, cpu->power_scale * cpu->power_peak); #endif return cpu; @@ -116,7 +118,8 @@ static void add_traces_cpu(void) xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->state_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { @@ -126,7 +129,8 @@ static void add_traces_cpu(void) xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->power_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } } @@ -152,7 +156,8 @@ static int cpu_action_unref(surf_action_t action) lmm_variable_free(cpu_maxmin_system, ((surf_action_cpu_Cas01_t) action)->variable); #ifdef HAVE_TRACING - if (action->category) xbt_free (action->category); + if (action->category) + xbt_free(action->category); #endif free(action); return 1; @@ -196,10 +201,16 @@ static void cpu_update_actions_state(double now, double delta) xbt_swag_foreach_safe(action, next_action, running_actions) { #ifdef HAVE_TRACING - cpu_Cas01_t x = lmm_constraint_id(lmm_get_cnst_from_var (cpu_maxmin_system, action->variable, 0)); - - TRACE_surf_host_set_utilization (x->generic_resource.name, - action->generic_action.data, (surf_action_t)action, lmm_variable_getvalue(action->variable), now-delta, delta); + cpu_Cas01_t x = + lmm_constraint_id(lmm_get_cnst_from_var + (cpu_maxmin_system, action->variable, 0)); + + TRACE_surf_host_set_utilization(x->generic_resource.name, + action->generic_action.data, + (surf_action_t) action, + lmm_variable_getvalue + (action->variable), now - delta, + delta); #endif double_update(&(action->generic_action.remains), lmm_variable_getvalue(action->variable) * delta); @@ -220,8 +231,8 @@ static void cpu_update_actions_state(double now, double delta) } static void cpu_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { cpu_Cas01_t cpu = id; @@ -230,7 +241,8 @@ static void cpu_update_resource_state(void *id, lmm_update_constraint_bound(cpu_maxmin_system, cpu->constraint, cpu->power_scale * cpu->power_peak); #ifdef HAVE_TRACING - TRACE_surf_host_set_power (date, cpu->generic_resource.name, cpu->power_scale * cpu->power_peak); + TRACE_surf_host_set_power(date, cpu->generic_resource.name, + cpu->power_scale * cpu->power_peak); #endif if (tmgr_trace_event_free(event_type)) cpu->power_event = NULL; @@ -249,7 +261,8 @@ static void cpu_update_resource_state(void *id, if (surf_action_state_get(action) == SURF_ACTION_RUNNING || surf_action_state_get(action) == SURF_ACTION_READY || - surf_action_state_get(action) == SURF_ACTION_NOT_IN_THE_SYSTEM) { + surf_action_state_get(action) == + SURF_ACTION_NOT_IN_THE_SYSTEM) { action->finish = date; cpu_action_state_set(action, SURF_ACTION_FAILED); } @@ -272,8 +285,9 @@ static surf_action_t cpu_execute(void *cpu, double size) XBT_IN2("(%s,%g)", surf_resource_name(CPU), size); action = - surf_action_new(sizeof(s_surf_action_cpu_Cas01_t), size, surf_cpu_model, - CPU->state_current != SURF_RESOURCE_ON); + surf_action_new(sizeof(s_surf_action_cpu_Cas01_t), size, + surf_cpu_model, + CPU->state_current != SURF_RESOURCE_ON); action->suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ @@ -302,7 +316,7 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration) is used to speed up update_resource_state */ xbt_swag_remove(action, ((surf_action_t) action)->state_set); ((surf_action_t) action)->state_set = - cpu_running_action_set_that_does_not_need_being_checked; + cpu_running_action_set_that_does_not_need_being_checked; xbt_swag_insert(action, ((surf_action_t) action)->state_set); } @@ -316,8 +330,8 @@ static void cpu_action_suspend(surf_action_t action) XBT_IN1("(%p)", action); if (((surf_action_cpu_Cas01_t) action)->suspended != 2) { lmm_update_variable_weight(cpu_maxmin_system, - ((surf_action_cpu_Cas01_t) action)->variable, - 0.0); + ((surf_action_cpu_Cas01_t) + action)->variable, 0.0); ((surf_action_cpu_Cas01_t) action)->suspended = 1; } XBT_OUT; @@ -328,8 +342,8 @@ static void cpu_action_resume(surf_action_t action) XBT_IN1("(%p)", action); if (((surf_action_cpu_Cas01_t) action)->suspended != 2) { lmm_update_variable_weight(cpu_maxmin_system, - ((surf_action_cpu_Cas01_t) action)->variable, - action->priority); + ((surf_action_cpu_Cas01_t) + action)->variable, action->priority); ((surf_action_cpu_Cas01_t) action)->suspended = 0; } XBT_OUT; @@ -340,7 +354,8 @@ static int cpu_action_is_suspended(surf_action_t action) return (((surf_action_cpu_Cas01_t) action)->suspended == 1); } -static void cpu_action_set_max_duration(surf_action_t action, double duration) +static void cpu_action_set_max_duration(surf_action_t action, + double duration) { XBT_IN2("(%p,%g)", action, duration); action->max_duration = duration; @@ -382,14 +397,14 @@ static double cpu_get_available_speed(void *cpu) } static void cpu_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - cpu_new(name,power_peak,power_scale,power_trace, - state_initial,state_trace,cpu_properties); + cpu_new(name, power_peak, power_scale, power_trace, + state_initial, state_trace, cpu_properties); } static void cpu_finalize(void) @@ -411,7 +426,7 @@ static void surf_cpu_model_init_internal(void) surf_cpu_model = surf_model_init(); cpu_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); surf_cpu_model->name = "CPU"; @@ -421,9 +436,10 @@ static void surf_cpu_model_init_internal(void) surf_cpu_model->model_private->resource_used = cpu_resource_used; surf_cpu_model->model_private->share_resources = cpu_share_resources; - surf_cpu_model->model_private->update_actions_state = cpu_update_actions_state; + surf_cpu_model->model_private->update_actions_state = + cpu_update_actions_state; surf_cpu_model->model_private->update_resource_state = - cpu_update_resource_state; + cpu_update_resource_state; surf_cpu_model->model_private->finalize = cpu_finalize; surf_cpu_model->suspend = cpu_action_suspend; @@ -438,7 +454,8 @@ static void surf_cpu_model_init_internal(void) surf_cpu_model->extension.cpu.get_state = cpu_get_state; surf_cpu_model->extension.cpu.get_speed = cpu_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = cpu_get_available_speed; + surf_cpu_model->extension.cpu.get_available_speed = + cpu_get_available_speed; surf_cpu_model->extension.cpu.create_resource = cpu_create_resource; surf_cpu_model->extension.cpu.add_traces = add_traces_cpu; diff --git a/src/surf/cpu_im.c b/src/surf/cpu_im.c index 4950f7793e..3d1190667d 100644 --- a/src/surf/cpu_im.c +++ b/src/surf/cpu_im.c @@ -43,25 +43,27 @@ static xbt_heap_t cpu_im_action_heap = NULL; extern int sg_maxmin_selective_update; -static xbt_swag_t cpu_im_running_action_set_that_does_not_need_being_checked = NULL; +static xbt_swag_t + cpu_im_running_action_set_that_does_not_need_being_checked = NULL; static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { cpu_Cas01_im_t cpu = NULL; s_surf_action_cpu_Cas01_im_t action; cpu = xbt_new0(s_cpu_Cas01_im_t, 1); - #ifdef HAVE_TRACING - TRACE_surf_host_declaration (name, power_scale * power_peak); - #endif +#ifdef HAVE_TRACING + TRACE_surf_host_declaration(name, power_scale * power_peak); +#endif xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name), - "Host '%s' declared several times in the platform file", name); + "Host '%s' declared several times in the platform file", + name); cpu->generic_resource.model = surf_cpu_model; cpu->generic_resource.name = name; cpu->generic_resource.properties = cpu_properties; @@ -70,16 +72,16 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, cpu->power_scale = power_scale; if (power_trace) cpu->power_event = - tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); cpu->state_current = state_initial; if (state_trace) cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); cpu->constraint = - lmm_constraint_new(cpu_im_maxmin_system, cpu, - cpu->power_scale * cpu->power_peak); + lmm_constraint_new(cpu_im_maxmin_system, cpu, + cpu->power_scale * cpu->power_peak); xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, surf_resource_free); @@ -112,7 +114,8 @@ static void parse_cpu_im_init(void) current_property_set = xbt_dict_new(); cpu_im_new(xbt_strdup(A_surfxml_host_id), power_peak, power_scale, - power_trace, state_initial, state_trace, current_property_set); + power_trace, state_initial, state_trace, + current_property_set); } @@ -133,7 +136,8 @@ static void cpu_im_add_traces_cpu(void) xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->state_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { @@ -143,7 +147,8 @@ static void cpu_im_add_traces_cpu(void) xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->power_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } } @@ -152,7 +157,8 @@ static void cpu_im_define_callbacks(const char *file) surf_parse_reset_parser(); surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_im_init); - surfxml_add_callback(ETag_surfxml_platform_cb_list, &cpu_im_add_traces_cpu); + surfxml_add_callback(ETag_surfxml_platform_cb_list, + &cpu_im_add_traces_cpu); } static int cpu_im_resource_used(void *resource_id) @@ -176,7 +182,8 @@ static int cpu_im_action_unref(surf_action_t action) ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set); xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu); #ifdef HAVE_TRACING - if (action->category) xbt_free (action->category); + if (action->category) + xbt_free(action->category); #endif free(action); return 1; @@ -195,7 +202,7 @@ static void cpu_im_action_cancel(surf_action_t action) } static void cpu_im_cpu_action_state_set(surf_action_t action, - e_surf_action_state_t state) + e_surf_action_state_t state) { /* if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */ /* if(((surf_action_lmm_t)action)->variable) { */ @@ -228,8 +235,15 @@ static void cpu_im_update_remains(cpu_Cas01_im_t cpu, double now) (action).variable) * (now - cpu->last_update)); #ifdef HAVE_TRACING - TRACE_surf_host_set_utilization (cpu->generic_resource.name, - action->generic_lmm_action.generic_action.data, (surf_action_t)action, lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable), cpu->last_update, now-cpu->last_update); + TRACE_surf_host_set_utilization(cpu->generic_resource.name, + action-> + generic_lmm_action.generic_action. + data, (surf_action_t) action, + lmm_variable_getvalue + (GENERIC_LMM_ACTION + (action).variable), + cpu->last_update, + now - cpu->last_update); #endif DEBUG2("Update action(%p) remains %lf", action, GENERIC_ACTION(action).remains); @@ -246,7 +260,7 @@ static double cpu_im_share_resources(double now) cpu_Cas01_im_t cpu, cpu_next; xbt_swag_foreach(cpu, cpu_im_modified_cpu) - cpu_im_update_remains(cpu, now); + cpu_im_update_remains(cpu, now); lmm_solve(cpu_im_maxmin_system); @@ -276,7 +290,8 @@ static double cpu_im_share_resources(double now) || GENERIC_ACTION(action).start + GENERIC_ACTION(action).max_duration < min)) min = - GENERIC_ACTION(action).start + GENERIC_ACTION(action).max_duration; + GENERIC_ACTION(action).start + + GENERIC_ACTION(action).max_duration; DEBUG4("Action(%p) Start %lf Finish %lf Max_duration %lf", action, GENERIC_ACTION(action).start, now + value, @@ -284,7 +299,7 @@ static double cpu_im_share_resources(double now) if (action->index_heap >= 0) { surf_action_cpu_Cas01_im_t heap_act = - xbt_heap_remove(cpu_im_action_heap, action->index_heap); + xbt_heap_remove(cpu_im_action_heap, action->index_heap); if (heap_act != action) DIE_IMPOSSIBLE; } @@ -296,7 +311,7 @@ static double cpu_im_share_resources(double now) xbt_swag_remove(cpu, cpu_im_modified_cpu); } return xbt_heap_size(cpu_im_action_heap) > - 0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1; + 0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1; } static void cpu_im_update_actions_state(double now, double delta) @@ -310,8 +325,18 @@ static void cpu_im_update_actions_state(double now, double delta) GENERIC_ACTION(action).finish = surf_get_clock(); /* set the remains to 0 due to precision problems when updating the remaining amount */ #ifdef HAVE_TRACING - TRACE_surf_host_set_utilization (((cpu_Cas01_im_t)(action->cpu))->generic_resource.name, - action->generic_lmm_action.generic_action.data, (surf_action_t)action, lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable), ((cpu_Cas01_im_t)(action->cpu))->last_update, now-((cpu_Cas01_im_t)(action->cpu))->last_update); + TRACE_surf_host_set_utilization(((cpu_Cas01_im_t) + (action->cpu))->generic_resource.name, + action-> + generic_lmm_action.generic_action.data, + (surf_action_t) action, + lmm_variable_getvalue + (GENERIC_LMM_ACTION(action).variable), + ((cpu_Cas01_im_t) + (action->cpu))->last_update, + now - + ((cpu_Cas01_im_t) + (action->cpu))->last_update); #endif GENERIC_ACTION(action).remains = 0; cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE); @@ -321,8 +346,8 @@ static void cpu_im_update_actions_state(double now, double delta) } static void cpu_im_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { cpu_Cas01_im_t cpu = id; if (event_type == cpu->power_event) { @@ -330,7 +355,8 @@ static void cpu_im_update_resource_state(void *id, lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint, cpu->power_scale * cpu->power_peak); #ifdef HAVE_TRACING - TRACE_surf_host_set_power (date, cpu->generic_resource.name, cpu->power_scale * cpu->power_peak); + TRACE_surf_host_set_power(date, cpu->generic_resource.name, + cpu->power_scale * cpu->power_peak); #endif xbt_swag_insert(cpu, cpu_im_modified_cpu); if (tmgr_trace_event_free(event_type)) @@ -345,12 +371,14 @@ static void cpu_im_update_resource_state(void *id, cpu->state_current = SURF_RESOURCE_OFF; - while ((var = lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) { + while ((var = + lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) { surf_action_t action = lmm_variable_id(var); if (surf_action_state_get(action) == SURF_ACTION_RUNNING || surf_action_state_get(action) == SURF_ACTION_READY || - surf_action_state_get(action) == SURF_ACTION_NOT_IN_THE_SYSTEM) { + surf_action_state_get(action) == + SURF_ACTION_NOT_IN_THE_SYSTEM) { action->finish = date; cpu_im_cpu_action_state_set(action, SURF_ACTION_FAILED); } @@ -373,15 +401,16 @@ static surf_action_t cpu_im_execute(void *cpu, double size) XBT_IN2("(%s,%g)", surf_resource_name(CPU), size); action = - surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size, - surf_cpu_model, CPU->state_current != SURF_RESOURCE_ON); + surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size, + surf_cpu_model, + CPU->state_current != SURF_RESOURCE_ON); GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ GENERIC_LMM_ACTION(action).variable = - lmm_variable_new(cpu_im_maxmin_system, action, - GENERIC_ACTION(action).priority, -1.0, 1); + lmm_variable_new(cpu_im_maxmin_system, action, + GENERIC_ACTION(action).priority, -1.0, 1); action->index_heap = -1; action->cpu = CPU; xbt_swag_insert(CPU, cpu_im_modified_cpu); @@ -408,7 +437,7 @@ static surf_action_t cpu_im_action_sleep(void *cpu, double duration) is used to speed up update_resource_state */ xbt_swag_remove(action, ((surf_action_t) action)->state_set); ((surf_action_t) action)->state_set = - cpu_im_running_action_set_that_does_not_need_being_checked; + cpu_im_running_action_set_that_does_not_need_being_checked; xbt_swag_insert(action, ((surf_action_t) action)->state_set); } @@ -424,7 +453,8 @@ static void cpu_im_action_suspend(surf_action_t action) XBT_IN1("(%p)", action); if (((surf_action_lmm_t) action)->suspended != 2) { lmm_update_variable_weight(cpu_im_maxmin_system, - ((surf_action_lmm_t) action)->variable, 0.0); + ((surf_action_lmm_t) action)->variable, + 0.0); ((surf_action_lmm_t) action)->suspended = 1; xbt_heap_remove(cpu_im_action_heap, ((surf_action_cpu_Cas01_im_t) action)->index_heap); @@ -452,7 +482,8 @@ static int cpu_im_action_is_suspended(surf_action_t action) return (((surf_action_lmm_t) action)->suspended == 1); } -static void cpu_im_action_set_max_duration(surf_action_t action, double duration) +static void cpu_im_action_set_max_duration(surf_action_t action, + double duration) { XBT_IN2("(%p,%g)", action, duration); @@ -462,7 +493,8 @@ static void cpu_im_action_set_max_duration(surf_action_t action, double duration XBT_OUT; } -static void cpu_im_action_set_priority(surf_action_t action, double priority) +static void cpu_im_action_set_priority(surf_action_t action, + double priority) { XBT_IN2("(%p,%g)", action, priority); action->priority = priority; @@ -503,15 +535,16 @@ static void cpu_im_action_update_index_heap(void *action, int i) { ((surf_action_cpu_Cas01_im_t) action)->index_heap = i; } + static void cpu_im_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - cpu_im_new(name,power_peak,power_scale,power_trace, - state_initial,state_trace,cpu_properties); + cpu_im_new(name, power_peak, power_scale, power_trace, + state_initial, state_trace, cpu_properties); } static void cpu_im_finalize(void) @@ -519,7 +552,8 @@ static void cpu_im_finalize(void) void *cpu; xbt_dict_cursor_t cursor; char *key; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, cpu) { + xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, + cpu) { cpu_Cas01_im_t CPU = cpu; xbt_swag_free(CPU->action_set); } @@ -530,7 +564,8 @@ static void cpu_im_finalize(void) surf_model_exit(surf_cpu_model); surf_cpu_model = NULL; - xbt_swag_free(cpu_im_running_action_set_that_does_not_need_being_checked); + xbt_swag_free + (cpu_im_running_action_set_that_does_not_need_being_checked); cpu_im_running_action_set_that_does_not_need_being_checked = NULL; xbt_heap_free(cpu_im_action_heap); xbt_swag_free(cpu_im_modified_cpu); @@ -544,7 +579,7 @@ static void surf_cpu_im_model_init_internal(void) surf_cpu_model = surf_model_init(); cpu_im_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); surf_cpu_model->name = "CPU_IM"; @@ -554,9 +589,10 @@ static void surf_cpu_im_model_init_internal(void) surf_cpu_model->model_private->resource_used = cpu_im_resource_used; surf_cpu_model->model_private->share_resources = cpu_im_share_resources; - surf_cpu_model->model_private->update_actions_state = cpu_im_update_actions_state; + surf_cpu_model->model_private->update_actions_state = + cpu_im_update_actions_state; surf_cpu_model->model_private->update_resource_state = - cpu_im_update_resource_state; + cpu_im_update_resource_state; surf_cpu_model->model_private->finalize = cpu_im_finalize; surf_cpu_model->suspend = cpu_im_action_suspend; @@ -571,7 +607,8 @@ static void surf_cpu_im_model_init_internal(void) surf_cpu_model->extension.cpu.get_state = cpu_im_get_state; surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = cpu_im_get_available_speed; + surf_cpu_model->extension.cpu.get_available_speed = + cpu_im_get_available_speed; surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource; surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu; @@ -580,8 +617,10 @@ static void surf_cpu_im_model_init_internal(void) cpu_im_maxmin_system = lmm_system_new(); } cpu_im_action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(cpu_im_action_heap, cpu_im_action_update_index_heap); - cpu_im_modified_cpu = xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup)); + xbt_heap_set_update_callback(cpu_im_action_heap, + cpu_im_action_update_index_heap); + cpu_im_modified_cpu = + xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup)); } /*********************************************************************/ diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index b266cc4d61..ef6de97cf7 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -20,29 +20,32 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf, "Logging specific to the SURF CPU TRACE INTEGRATION module"); -static xbt_swag_t cpu_ti_running_action_set_that_does_not_need_being_checked = NULL; +static xbt_swag_t + cpu_ti_running_action_set_that_does_not_need_being_checked = NULL; static xbt_swag_t cpu_ti_modified_cpu = NULL; static xbt_heap_t cpu_ti_action_heap; /* prototypes of new trace functions */ -static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, double a, - double b); +static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, + double a, double b); static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, - double amount); -static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t trace, - double a, double amount); + double amount); +static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t + trace, double a, + double amount); static void surf_cpu_ti_free_tmgr(surf_cpu_ti_tgmr_t trace); static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace, - double a, double b); -static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t trace, - double a); -static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, double a, - double amount); -static int surf_cpu_ti_binary_search(double *array, double a, int low, int high); + double a, double b); +static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t + trace, double a); +static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, + double a, double amount); +static int surf_cpu_ti_binary_search(double *array, double a, int low, + int high); /* end prototypes */ static void surf_cpu_ti_free_trace(surf_cpu_ti_trace_t trace) @@ -71,11 +74,11 @@ static surf_cpu_ti_trace_t surf_cpu_ti_trace_new(tmgr_trace_t power_trace) int i = 0; trace = xbt_new0(s_surf_cpu_ti_trace_t, 1); trace->time_points = - xbt_malloc0(sizeof(double) * - (xbt_dynar_length(power_trace->event_list) + 1)); + xbt_malloc0(sizeof(double) * + (xbt_dynar_length(power_trace->event_list) + 1)); trace->integral = - xbt_malloc0(sizeof(double) * - (xbt_dynar_length(power_trace->event_list) + 1)); + xbt_malloc0(sizeof(double) * + (xbt_dynar_length(power_trace->event_list) + 1)); trace->nb_points = xbt_dynar_length(power_trace->event_list); xbt_dynar_foreach(power_trace->event_list, cpt, val) { trace->time_points[i] = time; @@ -131,7 +134,8 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace, } trace->trace = surf_cpu_ti_trace_new(power_trace); trace->last_time = total_time; - trace->total = surf_cpu_ti_integrate_trace_simple(trace->trace, 0, total_time); + trace->total = + surf_cpu_ti_integrate_trace_simple(trace->trace, 0, total_time); DEBUG2("Total integral %lf, last_time %lf ", trace->total, trace->last_time); @@ -141,18 +145,21 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace, static cpu_ti_t cpu_ti_new(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { tmgr_trace_t empty_trace; s_tmgr_event_t val; cpu_ti_t cpu = xbt_new0(s_cpu_ti_t, 1); s_surf_action_cpu_ti_t ti_action; xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name), - "Host '%s' declared several times in the platform file", name); - cpu->action_set = xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup)); + "Host '%s' declared several times in the platform file", + name); + cpu->action_set = + xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup)); cpu->generic_resource.model = surf_cpu_model; cpu->generic_resource.name = name; cpu->generic_resource.properties = cpu_properties; @@ -164,7 +171,7 @@ static cpu_ti_t cpu_ti_new(char *name, double power_peak, cpu->state_current = state_initial; if (state_trace) cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); if (power_trace && xbt_dynar_length(power_trace->event_list) > 1) { /* add a fake trace event if periodicity == 0 */ xbt_dynar_get_cpy(power_trace->event_list, @@ -172,8 +179,8 @@ static cpu_ti_t cpu_ti_new(char *name, double power_peak, if (val.delta == 0) { empty_trace = tmgr_empty_trace_new(); cpu->power_event = - tmgr_history_add_trace(history, empty_trace, - cpu->avail_trace->last_time, 0, cpu); + tmgr_history_add_trace(history, empty_trace, + cpu->avail_trace->last_time, 0, cpu); } } xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, @@ -206,7 +213,8 @@ static void parse_cpu_ti_init(void) current_property_set = xbt_dict_new(); cpu_ti_new(xbt_strdup(A_surfxml_host_id), power_peak, power_scale, - power_trace, state_initial, state_trace, current_property_set); + power_trace, state_initial, state_trace, + current_property_set); } @@ -230,7 +238,8 @@ static void add_traces_cpu_ti(void) xbt_assert1(trace, "Trace %s undefined", trace_name); if (cpu->state_event) { - DEBUG1("Trace already configured for this CPU(%s), ignoring it", elm); + DEBUG1("Trace already configured for this CPU(%s), ignoring it", + elm); continue; } DEBUG2("Add state trace: %s to CPU(%s)", trace_name, elm); @@ -259,8 +268,8 @@ static void add_traces_cpu_ti(void) tmgr_trace_t empty_trace; empty_trace = tmgr_empty_trace_new(); cpu->power_event = - tmgr_history_add_trace(history, empty_trace, - cpu->avail_trace->last_time, 0, cpu); + tmgr_history_add_trace(history, empty_trace, + cpu->avail_trace->last_time, 0, cpu); } } } @@ -287,7 +296,8 @@ static int cpu_ti_action_unref(surf_action_t action) /* remove from action_set */ xbt_swag_remove(action, ACTION_GET_CPU(action)->action_set); /* remove from heap */ - xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); + xbt_heap_remove(cpu_ti_action_heap, + ((surf_action_cpu_ti_t) action)->index_heap); xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); free(action); return 1; @@ -298,13 +308,14 @@ static int cpu_ti_action_unref(surf_action_t action) static void cpu_ti_action_cancel(surf_action_t action) { surf_action_state_set(action, SURF_ACTION_FAILED); - xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); + xbt_heap_remove(cpu_ti_action_heap, + ((surf_action_cpu_ti_t) action)->index_heap); xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); return; } static void cpu_ti_action_state_set(surf_action_t action, - e_surf_action_state_t state) + e_surf_action_state_t state) { surf_action_state_set(action, state); xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); @@ -329,9 +340,10 @@ static void cpu_ti_update_remaining_amount(cpu_ti_t cpu, double now) /* calcule the surface */ area_total = - surf_cpu_ti_integrate_trace(cpu->avail_trace, cpu->last_update, - now) * cpu->power_peak; - DEBUG2("Flops total: %lf, Last update %lf", area_total, cpu->last_update); + surf_cpu_ti_integrate_trace(cpu->avail_trace, cpu->last_update, + now) * cpu->power_peak; + DEBUG2("Flops total: %lf, Last update %lf", area_total, + cpu->last_update); xbt_swag_foreach(action, cpu->action_set) { /* action not running, skip it */ @@ -411,34 +423,34 @@ static void cpu_ti_update_action_finish_date(cpu_ti_t cpu, double now) if (action->suspended == 0 && GENERIC_ACTION(action).priority > 0) { /* total area needed to finish the action. Used in trace integration */ total_area = - (GENERIC_ACTION(action).remains) * sum_priority * - GENERIC_ACTION(action).priority; + (GENERIC_ACTION(action).remains) * sum_priority * + GENERIC_ACTION(action).priority; total_area /= cpu->power_peak; GENERIC_ACTION(action).finish = - surf_cpu_ti_solve_trace(cpu->avail_trace, now, total_area); + surf_cpu_ti_solve_trace(cpu->avail_trace, now, total_area); /* verify which event will happen before (max_duration or finish time) */ if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) && (GENERIC_ACTION(action).start + GENERIC_ACTION(action).max_duration < GENERIC_ACTION(action).finish)) min_finish = GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration; + GENERIC_ACTION(action).max_duration; else min_finish = GENERIC_ACTION(action).finish; } else { /* put the max duration time on heap */ if (GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) min_finish = - (GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration); + (GENERIC_ACTION(action).start + + GENERIC_ACTION(action).max_duration); } /* add in action heap */ DEBUG2("action(%p) index %d", action, action->index_heap); if (action->index_heap >= 0) { surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, action->index_heap); + xbt_heap_remove(cpu_ti_action_heap, action->index_heap); if (heap_act != action) DIE_IMPOSSIBLE; } @@ -446,9 +458,10 @@ static void cpu_ti_update_action_finish_date(cpu_ti_t cpu, double now) xbt_heap_push(cpu_ti_action_heap, action, min_finish); DEBUG5 - ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf", - cpu->generic_resource.name, action, GENERIC_ACTION(action).start, - GENERIC_ACTION(action).finish, GENERIC_ACTION(action).max_duration); + ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf", + cpu->generic_resource.name, action, GENERIC_ACTION(action).start, + GENERIC_ACTION(action).finish, + GENERIC_ACTION(action).max_duration); } /* remove from modified cpu */ xbt_swag_remove(cpu, cpu_ti_modified_cpu); @@ -492,8 +505,8 @@ static void cpu_ti_update_actions_state(double now, double delta) } static void cpu_ti_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { cpu_ti_t cpu = id; surf_action_cpu_ti_t action; @@ -541,10 +554,11 @@ static void cpu_ti_update_resource_state(void *id, || surf_action_state_get((surf_action_t) action) == SURF_ACTION_NOT_IN_THE_SYSTEM) { action->generic_action.finish = date; - cpu_ti_action_state_set((surf_action_t) action, SURF_ACTION_FAILED); + cpu_ti_action_state_set((surf_action_t) action, + SURF_ACTION_FAILED); if (action->index_heap >= 0) { surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, action->index_heap); + xbt_heap_remove(cpu_ti_action_heap, action->index_heap); if (heap_act != action) DIE_IMPOSSIBLE; } @@ -568,8 +582,8 @@ static surf_action_t cpu_ti_execute(void *cpu, double size) XBT_IN2("(%s,%g)", surf_resource_name(CPU), size); action = - surf_action_new(sizeof(s_surf_action_cpu_ti_t), size, surf_cpu_model, - CPU->state_current != SURF_RESOURCE_ON); + surf_action_new(sizeof(s_surf_action_cpu_ti_t), size, surf_cpu_model, + CPU->state_current != SURF_RESOURCE_ON); action->cpu = cpu; action->index_heap = -1; @@ -605,7 +619,7 @@ static surf_action_t cpu_ti_action_sleep(void *cpu, double duration) is used to speed up update_resource_state */ xbt_swag_remove(action, ((surf_action_t) action)->state_set); ((surf_action_t) action)->state_set = - cpu_ti_running_action_set_that_does_not_need_being_checked; + cpu_ti_running_action_set_that_does_not_need_being_checked; xbt_swag_insert(action, ((surf_action_t) action)->state_set); } XBT_OUT; @@ -617,7 +631,8 @@ static void cpu_ti_action_suspend(surf_action_t action) XBT_IN1("(%p)", action); if (((surf_action_cpu_ti_t) action)->suspended != 2) { ((surf_action_cpu_ti_t) action)->suspended = 1; - xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); + xbt_heap_remove(cpu_ti_action_heap, + ((surf_action_cpu_ti_t) action)->index_heap); xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); } XBT_OUT; @@ -638,7 +653,8 @@ static int cpu_ti_action_is_suspended(surf_action_t action) return (((surf_action_cpu_ti_t) action)->suspended == 1); } -static void cpu_ti_action_set_max_duration(surf_action_t action, double duration) +static void cpu_ti_action_set_max_duration(surf_action_t action, + double duration) { surf_action_cpu_ti_t ACT = (surf_action_cpu_ti_t) action; double min_finish; @@ -649,16 +665,16 @@ static void cpu_ti_action_set_max_duration(surf_action_t action, double duration if (duration >= 0) min_finish = - (action->start + action->max_duration) < - action->finish ? (action->start + - action->max_duration) : action->finish; + (action->start + action->max_duration) < + action->finish ? (action->start + + action->max_duration) : action->finish; else min_finish = action->finish; /* add in action heap */ if (ACT->index_heap >= 0) { surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, ACT->index_heap); + xbt_heap_remove(cpu_ti_action_heap, ACT->index_heap); if (heap_act != ACT) DIE_IMPOSSIBLE; } @@ -667,7 +683,8 @@ static void cpu_ti_action_set_max_duration(surf_action_t action, double duration XBT_OUT; } -static void cpu_ti_action_set_priority(surf_action_t action, double priority) +static void cpu_ti_action_set_priority(surf_action_t action, + double priority) { XBT_IN2("(%p,%g)", action, priority); action->priority = priority; @@ -678,8 +695,9 @@ static void cpu_ti_action_set_priority(surf_action_t action, double priority) static double cpu_ti_action_get_remains(surf_action_t action) { XBT_IN1("(%p)", action); - cpu_ti_update_remaining_amount((cpu_ti_t) ((surf_action_cpu_ti_t) action)->cpu, - surf_get_clock()); + cpu_ti_update_remaining_amount((cpu_ti_t) + ((surf_action_cpu_ti_t) action)->cpu, + surf_get_clock()); return action->remains; XBT_OUT; } @@ -702,7 +720,8 @@ static double cpu_ti_get_speed(void *cpu, double load) * \param a Time * \return CPU power scale */ -static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace, double a) +static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace, + double a) { double reduced_a; int point; @@ -710,8 +729,8 @@ static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace, double a) reduced_a = a - floor(a / trace->last_time) * trace->last_time; point = - surf_cpu_ti_binary_search(trace->trace->time_points, reduced_a, 0, - trace->trace->nb_points - 1); + surf_cpu_ti_binary_search(trace->trace->time_points, reduced_a, 0, + trace->trace->nb_points - 1); xbt_dynar_get_cpy(trace->power_trace->event_list, 0, &val); return val.value; } @@ -720,20 +739,20 @@ static double cpu_ti_get_available_speed(void *cpu) { cpu_ti_t CPU = cpu; CPU->power_scale = - surf_cpu_ti_get_power_scale(CPU->avail_trace, surf_get_clock()); + surf_cpu_ti_get_power_scale(CPU->avail_trace, surf_get_clock()); /* number between 0 and 1 */ return CPU->power_scale; } static void cpu_ti_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - cpu_ti_new(name,power_peak,power_scale,power_trace, - state_initial,state_trace,cpu_properties); + cpu_ti_new(name, power_peak, power_scale, power_trace, + state_initial, state_trace, cpu_properties); } static void cpu_ti_finalize(void) @@ -741,7 +760,8 @@ static void cpu_ti_finalize(void) void *cpu; xbt_dict_cursor_t cursor; char *key; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, cpu) { + xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, + cpu) { cpu_ti_t CPU = cpu; xbt_swag_free(CPU->action_set); surf_cpu_ti_free_tmgr(CPU->avail_trace); @@ -750,7 +770,8 @@ static void cpu_ti_finalize(void) surf_model_exit(surf_cpu_model); surf_cpu_model = NULL; - xbt_swag_free(cpu_ti_running_action_set_that_does_not_need_being_checked); + xbt_swag_free + (cpu_ti_running_action_set_that_does_not_need_being_checked); xbt_swag_free(cpu_ti_modified_cpu); cpu_ti_running_action_set_that_does_not_need_being_checked = NULL; xbt_heap_free(cpu_ti_action_heap); @@ -764,9 +785,10 @@ static void surf_cpu_ti_model_init_internal(void) surf_cpu_model = surf_model_init(); cpu_ti_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); - cpu_ti_modified_cpu = xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup)); + cpu_ti_modified_cpu = + xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup)); surf_cpu_model->name = "CPU_TI"; @@ -776,9 +798,10 @@ static void surf_cpu_ti_model_init_internal(void) surf_cpu_model->model_private->resource_used = cpu_ti_resource_used; surf_cpu_model->model_private->share_resources = cpu_ti_share_resources; - surf_cpu_model->model_private->update_actions_state = cpu_ti_update_actions_state; + surf_cpu_model->model_private->update_actions_state = + cpu_ti_update_actions_state; surf_cpu_model->model_private->update_resource_state = - cpu_ti_update_resource_state; + cpu_ti_update_resource_state; surf_cpu_model->model_private->finalize = cpu_ti_finalize; surf_cpu_model->suspend = cpu_ti_action_suspend; @@ -793,12 +816,14 @@ static void surf_cpu_ti_model_init_internal(void) surf_cpu_model->extension.cpu.get_state = cpu_ti_get_state; surf_cpu_model->extension.cpu.get_speed = cpu_ti_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = cpu_ti_get_available_speed; + surf_cpu_model->extension.cpu.get_available_speed = + cpu_ti_get_available_speed; surf_cpu_model->extension.cpu.create_resource = cpu_ti_create_resource; surf_cpu_model->extension.cpu.add_traces = add_traces_cpu_ti; cpu_ti_action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(cpu_ti_action_heap, cpu_ti_action_update_index_heap); + xbt_heap_set_update_callback(cpu_ti_action_heap, + cpu_ti_action_update_index_heap); } @@ -823,8 +848,8 @@ void surf_cpu_model_init_ti(const char *filename) * \param b End of interval * \return the integrate value. -1 if an error occurs. */ -static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, double a, - double b) +static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, + double a, double b) { double first_chunk; double middle_chunk; @@ -833,8 +858,8 @@ static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, double a, if ((a < 0.0) || (a > b)) { CRITICAL2 - ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.", - a, b); + ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.", + a, b); xbt_abort(); } if (a == b) @@ -853,20 +878,24 @@ static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, double a, if (a_index > b_index) { /* Same chunk */ return surf_cpu_ti_integrate_trace_simple(trace->trace, - a - (a_index - - 1) * trace->last_time, - b - (b_index) * trace->last_time); + a - (a_index - + 1) * trace->last_time, + b - + (b_index) * + trace->last_time); } first_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace, - a - (a_index - - 1) * trace->last_time, - trace->last_time); + a - (a_index - + 1) * + trace->last_time, + trace->last_time); middle_chunk = (b_index - a_index) * trace->total; last_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace, - 0.0, - b - - (b_index) * trace->last_time); + 0.0, + b - + (b_index) * + trace->last_time); DEBUG3("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n", first_chunk, middle_chunk, last_chunk); @@ -884,11 +913,11 @@ static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, double a, * \return Integral */ static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace, - double a, double b) + double a, double b) { return surf_cpu_ti_integrate_trace_simple_point(trace, - b) - - surf_cpu_ti_integrate_trace_simple_point(trace, a); + b) - + surf_cpu_ti_integrate_trace_simple_point(trace, a); } /** @@ -897,27 +926,29 @@ static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace, * \param a point * \return Integral */ -static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t trace, - double a) +static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t + trace, double a) { double integral = 0; int ind; double a_aux = a; ind = - surf_cpu_ti_binary_search(trace->time_points, a, 0, trace->nb_points - 1); + surf_cpu_ti_binary_search(trace->time_points, a, 0, + trace->nb_points - 1); integral += trace->integral[ind]; - DEBUG7("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf", - a, ind, integral, trace->integral[ind + 1], trace->integral[ind], - trace->time_points[ind + 1], trace->time_points[ind]); + DEBUG7 + ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf", + a, ind, integral, trace->integral[ind + 1], trace->integral[ind], + trace->time_points[ind + 1], trace->time_points[ind]); double_update(&a_aux, trace->time_points[ind]); if (a_aux > 0) integral += - ((trace->integral[ind + 1] - - trace->integral[ind]) / (trace->time_points[ind + 1] - - trace->time_points[ind])) * (a - - trace-> - time_points - [ind]); + ((trace->integral[ind + 1] - + trace->integral[ind]) / (trace->time_points[ind + 1] - + trace->time_points[ind])) * (a - + trace-> + time_points + [ind]); DEBUG2("Integral a %lf = %lf", a, integral); return integral; @@ -934,7 +965,7 @@ static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t trace * \return End time */ static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, - double amount) + double amount) { int quotient; double reduced_b; @@ -953,8 +984,8 @@ static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, /* Sanity checks */ if ((a < 0.0) || (amount < 0.0)) { CRITICAL2 - ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.", - a, amount); + ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.", + a, amount); xbt_abort(); } @@ -984,11 +1015,12 @@ static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount); */ reduced_b = - surf_cpu_ti_solve_trace_somewhat_simple(trace, reduced_a, reduced_amount); + surf_cpu_ti_solve_trace_somewhat_simple(trace, reduced_a, + reduced_amount); /* Re-map to the original b and amount */ b = (trace->last_time) * (int) (floor(a / trace->last_time)) + - (quotient * trace->last_time) + reduced_b; + (quotient * trace->last_time) + reduced_b; return b; } @@ -999,14 +1031,16 @@ static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, * and a <=trace->last_time * */ -static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t trace, - double a, double amount) +static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t + trace, double a, + double amount) { double amount_till_end; double b; DEBUG2("Solve integral: [%.2f, amount=%.2f]", a, amount); - amount_till_end = surf_cpu_ti_integrate_trace(trace, a, trace->last_time); + amount_till_end = + surf_cpu_ti_integrate_trace(trace, a, trace->last_time); /* fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end); */ @@ -1015,8 +1049,8 @@ static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t trace, b = surf_cpu_ti_solve_trace_simple(trace->trace, a, amount); } else { b = trace->last_time + - surf_cpu_ti_solve_trace_simple(trace->trace, 0.0, - amount - amount_till_end); + surf_cpu_ti_solve_trace_simple(trace->trace, 0.0, + amount - amount_till_end); } return b; } @@ -1029,23 +1063,23 @@ static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t trace, * \param amount Amount of flops * \return The date when amount is available. */ -static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, double a, - double amount) +static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, + double a, double amount) { double integral_a; int ind; double time; integral_a = surf_cpu_ti_integrate_trace_simple_point(trace, a); ind = - surf_cpu_ti_binary_search(trace->integral, integral_a + amount, 0, - trace->nb_points - 1); + surf_cpu_ti_binary_search(trace->integral, integral_a + amount, 0, + trace->nb_points - 1); time = trace->time_points[ind]; time += - (integral_a + amount - - trace->integral[ind]) / ((trace->integral[ind + 1] - - trace->integral[ind]) / - (trace->time_points[ind + 1] - - trace->time_points[ind])); + (integral_a + amount - + trace->integral[ind]) / ((trace->integral[ind + 1] - + trace->integral[ind]) / + (trace->time_points[ind + 1] - + trace->time_points[ind])); return time; } @@ -1059,7 +1093,8 @@ static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, double a * \param high Upper bound to search in array * \return Index of point */ -static int surf_cpu_ti_binary_search(double *array, double a, int low, int high) +static int surf_cpu_ti_binary_search(double *array, double a, int low, + int high) { int mid = low + (high - low) / 2; DEBUG5("a %lf low %d high %d mid %d value %lf", a, low, high, mid, diff --git a/src/surf/cpu_ti_private.h b/src/surf/cpu_ti_private.h index a99988ba9c..b4c50c1ebc 100644 --- a/src/surf/cpu_ti_private.h +++ b/src/surf/cpu_ti_private.h @@ -62,4 +62,4 @@ typedef struct surf_action_ti { #define ACTION_GET_CPU(action) ((cpu_ti_t)((surf_action_cpu_ti_t)action)->cpu) -#endif /* _SURF_CPU_TI_PRIVATE_H */ +#endif /* _SURF_CPU_TI_PRIVATE_H */ diff --git a/src/surf/fair_bottleneck.c b/src/surf/fair_bottleneck.c index d707587f18..c7ebba87db 100644 --- a/src/surf/fair_bottleneck.c +++ b/src/surf/fair_bottleneck.c @@ -96,7 +96,8 @@ void bottleneck_solve(lmm_system_t sys) xbt_swag_foreach(elem, elem_list) { if (elem->variable->weight <= 0) break; - if ((elem->value > 0) && xbt_swag_belongs(elem->variable, var_list)) + if ((elem->value > 0) + && xbt_swag_belongs(elem->variable, var_list)) nb++; } DEBUG1("\tThere are %d variables", nb); @@ -114,7 +115,8 @@ void bottleneck_solve(lmm_system_t sys) } xbt_swag_foreach_safe(var, var_next, var_list) { - double min_inc = var->cnsts[0].constraint->usage / var->cnsts[0].value; + double min_inc = + var->cnsts[0].constraint->usage / var->cnsts[0].value; for (i = 1; i < var->cnsts_number; i++) { lmm_element_t elm = &var->cnsts[i]; min_inc = MIN(min_inc, elm->constraint->usage / elm->value); @@ -137,12 +139,14 @@ void bottleneck_solve(lmm_system_t sys) break; if (cnst->shared) { DEBUG4("\tUpdate constraint %p (%g) with variable %p by %g", - cnst, cnst->remaining, elem->variable, elem->variable->mu); - double_update(&(cnst->remaining), elem->value * elem->variable->mu); + cnst, cnst->remaining, elem->variable, + elem->variable->mu); + double_update(&(cnst->remaining), + elem->value * elem->variable->mu); } else { DEBUG4 - ("\tNon-Shared variable. Update constraint usage of %p (%g) with variable %p by %g", - cnst, cnst->usage, elem->variable, elem->variable->mu); + ("\tNon-Shared variable. Update constraint usage of %p (%g) with variable %p by %g", + cnst, cnst->usage, elem->variable, elem->variable->mu); cnst->usage = MIN(cnst->usage, elem->value * elem->variable->mu); } } diff --git a/src/surf/gtnets/gtnets_interface.h b/src/surf/gtnets/gtnets_interface.h index 9b5bbd8cd0..0e637c5095 100644 --- a/src/surf/gtnets/gtnets_interface.h +++ b/src/surf/gtnets/gtnets_interface.h @@ -20,7 +20,7 @@ extern "C" { int gtnets_create_flow(int src, int dst, long datasize, void *metadata); double gtnets_get_time_to_next_flow_completion(); double gtnets_run_until_next_flow_completion(void ***metadata, - int *number_of_flows); + int *number_of_flows); double gtnets_get_flow_rx(void *metadata); void gtnets_print_topology(void); diff --git a/src/surf/gtnets/gtnets_simulator.h b/src/surf/gtnets/gtnets_simulator.h index 8f814531b2..1be24e3b88 100644 --- a/src/surf/gtnets/gtnets_simulator.h +++ b/src/surf/gtnets/gtnets_simulator.h @@ -44,7 +44,8 @@ public: int add_router(int id); int create_flow(int src, int dst, long datasize, void *metadata); double get_time_to_next_flow_completion(); - int run_until_next_flow_completion(void ***metadata, int *number_of_flows); + int run_until_next_flow_completion(void ***metadata, + int *number_of_flows); int run(double deltat); // returns the total received by the TCPServer peer of the given action double gtnets_get_flow_rx(void *metadata); @@ -67,17 +68,17 @@ private: int nflow_; double jitter_; int jitter_seed_; - map< int, Uniform * > uniform_jitter_generator_; + map < int, Uniform * >uniform_jitter_generator_; - map < int, TCPServer * >gtnets_servers_; - map < int, TCPSend * >gtnets_clients_; - map < int, Linkp2p * >gtnets_links_; - map < int, Node * >gtnets_nodes_; - map < void *, int >gtnets_action_to_flow_; + map < int, TCPServer * >gtnets_servers_; + map < int, TCPSend * >gtnets_clients_; + map < int, Linkp2p * >gtnets_links_; + map < int, Node * >gtnets_nodes_; + map < void *, int >gtnets_action_to_flow_; - map < int, void *>gtnets_metadata_; + map < int, void *>gtnets_metadata_; }; -#endif /* __cplusplus */ +#endif /* __cplusplus */ #endif diff --git a/src/surf/gtnets/gtnets_topology.h b/src/surf/gtnets/gtnets_topology.h index d73d6b1fcc..0f2a2a2169 100644 --- a/src/surf/gtnets/gtnets_topology.h +++ b/src/surf/gtnets/gtnets_topology.h @@ -23,8 +23,8 @@ class GTNETS_Node { public: GTNETS_Node(int); - GTNETS_Node(const GTNETS_Node & node); - ~GTNETS_Node(); + GTNETS_Node(const GTNETS_Node & node); + ~GTNETS_Node(); int add_host(int); int add_router(int); @@ -46,8 +46,8 @@ class GTNETS_Link { public: GTNETS_Link(); GTNETS_Link(int id); - GTNETS_Link(const GTNETS_Link &); - ~GTNETS_Link(); + GTNETS_Link(const GTNETS_Link &); + ~GTNETS_Link(); GTNETS_Node *src_node(); GTNETS_Node *dst_node(); @@ -92,12 +92,12 @@ public: private: int nodeID_; - map < int, GTNETS_Link * >links_; - vector < GTNETS_Node * >nodes_; + map < int, GTNETS_Link * >links_; + vector < GTNETS_Node * >nodes_; - map < int, int >hosts_; //hostid->nodeid + map < int, int >hosts_; //hostid->nodeid - set < int >routers_; + set < int >routers_; }; #endif diff --git a/src/surf/lagrange.c b/src/surf/lagrange.c index f46883e957..dab45e3896 100644 --- a/src/surf/lagrange.c +++ b/src/surf/lagrange.c @@ -65,13 +65,13 @@ static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, if (double_positive(tmp - cnst->bound)) { if (warn) WARN3 - ("The link (%p) is over-used. Expected less than %f and got %f", - cnst, cnst->bound, tmp); + ("The link (%p) is over-used. Expected less than %f and got %f", + cnst, cnst->bound, tmp); return 0; } DEBUG3 - ("Checking feasability for constraint (%p): sat = %f, lambda = %f ", - cnst, tmp - cnst->bound, cnst->lambda); + ("Checking feasability for constraint (%p): sat = %f, lambda = %f ", + cnst, tmp - cnst->bound, cnst->lambda); } xbt_swag_foreach(var, var_list) { @@ -85,8 +85,8 @@ static int __check_feasible(xbt_swag_t cnst_list, xbt_swag_t var_list, if (double_positive(var->value - var->bound)) { if (warn) WARN3 - ("The variable (%p) is too large. Expected less than %f and got %f", - var, var->bound, var->value); + ("The variable (%p) is too large. Expected less than %f and got %f", + var, var->bound, var->value); return 0; } } @@ -147,14 +147,14 @@ static double dual_objective(xbt_swag_t var_list, xbt_swag_t cnst_list) DEBUG2("var %p : sigma_i = %1.20f", var, sigma_i); obj += var->func_f(var, var->func_fpi(var, sigma_i)) - - sigma_i * var->func_fpi(var, sigma_i); + sigma_i * var->func_fpi(var, sigma_i); if (var->bound > 0) obj += var->mu * var->bound; } xbt_swag_foreach(cnst, cnst_list) - obj += cnst->lambda * cnst->bound; + obj += cnst->lambda * cnst->bound; return obj; } @@ -189,7 +189,8 @@ void lagrange_solve(lmm_system_t sys) DEBUG0("Iterative method configuration snapshot =====>"); DEBUG1("#### Maximum number of iterations : %d", max_iterations); - DEBUG1("#### Minimum error tolerated : %e", epsilon_min_error); + DEBUG1("#### Minimum error tolerated : %e", + epsilon_min_error); DEBUG1("#### Minimum error tolerated (dichotomy) : %e", dichotomy_min_error); @@ -290,8 +291,8 @@ void lagrange_solve(lmm_system_t sys) xbt_swag_foreach(cnst, cnst_list) { DEBUG1("Working on cnst (%p)", cnst); cnst->new_lambda = - dichotomy(cnst->lambda, partial_diff_lambda, cnst, - dichotomy_min_error); + dichotomy(cnst->lambda, partial_diff_lambda, cnst, + dichotomy_min_error); /* dual_updated += (fabs(cnst->new_lambda-cnst->lambda)>dichotomy_min_error); */ /* DEBUG2("dual_updated (%d) : %1.20f",dual_updated,fabs(cnst->new_lambda-cnst->lambda)); */ DEBUG3("Updating lambda : cnst->lambda (%p) : %1.20f -> %1.20f", @@ -319,7 +320,7 @@ void lagrange_solve(lmm_system_t sys) tmp = new_value(var); overall_modification = - MAX(overall_modification, fabs(var->value - tmp)); + MAX(overall_modification, fabs(var->value - tmp)); var->value = tmp; DEBUG3("New value of var (%p) = %e, overall_modification = %e", @@ -345,8 +346,8 @@ void lagrange_solve(lmm_system_t sys) } if (iteration >= max_iterations) { DEBUG1 - ("Method reach %d iterations, which is the maximum number of iterations allowed.", - iteration); + ("Method reach %d iterations, which is the maximum number of iterations allowed.", + iteration); } /* INFO1("Method converged after %d iterations", iteration); */ @@ -422,7 +423,8 @@ static double dichotomy(double init, double diff(double, void *), } } else if (min_diff < 0 && max_diff > 0) { middle = (max + min) / 2.0; - CDEBUG1(surf_lagrange_dichotomy, "Trying (max+min)/2 : %1.20f", middle); + CDEBUG1(surf_lagrange_dichotomy, "Trying (max+min)/2 : %1.20f", + middle); if ((min == middle) || (max == middle)) { CWARN4(surf_lagrange_dichotomy, @@ -495,7 +497,8 @@ static double partial_diff_lambda(double lambda, void *param_cnst) if (var->weight <= 0) continue; - CDEBUG1(surf_lagrange_dichotomy, "Computing sigma_i for var (%p)", var); + CDEBUG1(surf_lagrange_dichotomy, "Computing sigma_i for var (%p)", + var); // Initialize the summation variable sigma_i = 0.0; @@ -537,12 +540,12 @@ void lmm_set_default_protocol_function(double (*func_f) - - (lmm_variable_t var, double x), - double (*func_fp) (lmm_variable_t var, - double x), - double (*func_fpi) (lmm_variable_t var, - double x)) + + (lmm_variable_t var, double x), + double (*func_fp) (lmm_variable_t + var, double x), + double (*func_fpi) (lmm_variable_t + var, double x)) { func_f_def = func_f; func_fp_def = func_fp; @@ -591,13 +594,14 @@ double func_reno_f(lmm_variable_t var, double x) { xbt_assert0(var->weight > 0.0, "Don't call me with stupid values!"); - return RENO_SCALING * sqrt(3.0 / 2.0) / var->weight * atan(sqrt(3.0 / 2.0) * - var->weight * x); + return RENO_SCALING * sqrt(3.0 / 2.0) / var->weight * + atan(sqrt(3.0 / 2.0) * var->weight * x); } double func_reno_fp(lmm_variable_t var, double x) { - return RENO_SCALING * 3.0 / (3.0 * var->weight * var->weight * x * x + 2.0); + return RENO_SCALING * 3.0 / (3.0 * var->weight * var->weight * x * x + + 2.0); } double func_reno_fpi(lmm_variable_t var, double x) @@ -608,8 +612,8 @@ double func_reno_fpi(lmm_variable_t var, double x) xbt_assert0(x > 0.0, "Don't call me with stupid values!"); res_fpi = - 1.0 / (var->weight * var->weight * (x / RENO_SCALING)) - - 2.0 / (3.0 * var->weight * var->weight); + 1.0 / (var->weight * var->weight * (x / RENO_SCALING)) - + 2.0 / (3.0 * var->weight * var->weight); if (res_fpi <= 0.0) return 0.0; /* xbt_assert0(res_fpi>0.0,"Don't call me with stupid values!"); */ diff --git a/src/surf/maxmin.c b/src/surf/maxmin.c index accceb5c93..bd092b453c 100644 --- a/src/surf/maxmin.c +++ b/src/surf/maxmin.c @@ -18,7 +18,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, 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); -static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst); +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); int sg_maxmin_selective_update = 1; static int Global_debug_id = 1; @@ -66,8 +67,9 @@ void lmm_system_free(lmm_system_t sys) lmm_constraint_t cnst = NULL; while ((var = extract_variable(sys))) { - WARN2("Variable %p (%d) still in LMM system when freing it: this may be a bug", - var,var->id_int); + WARN2 + ("Variable %p (%d) still in LMM system when freing it: this may be a bug", + var, var->id_int); lmm_var_free(sys, var); } @@ -107,7 +109,8 @@ static void lmm_var_free(lmm_system_t sys, lmm_variable_t var) xbt_mallocator_release(sys->variable_mallocator, var); } -static XBT_INLINE void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst) +static XBT_INLINE void lmm_cnst_free(lmm_system_t sys, + lmm_constraint_t cnst) { /* xbt_assert0(xbt_swag_size(&(cnst->element_set)), */ /* "This list should be empty!"); */ @@ -147,7 +150,8 @@ XBT_INLINE int lmm_constraint_is_shared(lmm_constraint_t cnst) return (cnst->shared); } -XBT_INLINE void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst) +XBT_INLINE void lmm_constraint_free(lmm_system_t sys, + lmm_constraint_t cnst) { remove_constraint(sys, cnst); lmm_cnst_free(sys, cnst); @@ -292,7 +296,8 @@ void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst, } XBT_INLINE lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, - lmm_variable_t var, int num) + lmm_variable_t var, + int num) { if (num < var->cnsts_number) return (var->cnsts[num].constraint); @@ -300,7 +305,8 @@ XBT_INLINE lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, return NULL; } -XBT_INLINE int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var) +XBT_INLINE int lmm_get_number_of_cnst_from_var(lmm_system_t sys, + lmm_variable_t var) { return (var->cnsts_number); } @@ -330,8 +336,9 @@ XBT_INLINE void *lmm_variable_id(lmm_variable_t var) } static XBT_INLINE void saturated_constraint_set_update(lmm_system_t sys, - lmm_constraint_t cnst, - double *min_usage) + lmm_constraint_t + cnst, + double *min_usage) { lmm_constraint_t useless_cnst = NULL; @@ -396,17 +403,17 @@ void lmm_print(lmm_system_t sys) var_list = &(sys->variable_set); sprintf(print_buf, "MAX-MIN ( "); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); xbt_swag_foreach(var, var_list) { sprintf(print_buf, "'%d'(%f) ", var->id_int, var->weight); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); } sprintf(print_buf, ")"); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); fprintf(stderr, "%s", trace_buf); //DEBUG1("%20s", trace_buf); FIXME @@ -420,25 +427,27 @@ void lmm_print(lmm_system_t sys) elem_list = &(cnst->element_set); sprintf(print_buf, "\t"); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); xbt_swag_foreach(elem, elem_list) { sprintf(print_buf, "%f.'%d'(%f) + ", elem->value, elem->variable->id_int, elem->variable->value); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, + strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); sum += elem->value * elem->variable->value; } sprintf(print_buf, "0 <= %f ('%d')", cnst->bound, cnst->id_int); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); if (!cnst->shared) { sprintf(print_buf, " [MAX-Constraint]"); trace_buf = - xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1); + xbt_realloc(trace_buf, + strlen(trace_buf) + strlen(print_buf) + 1); strcat(trace_buf, print_buf); } // DEBUG1("%s", trace_buf); @@ -483,8 +492,10 @@ void lmm_solve(lmm_system_t sys) /* * Compute Usage and store the variables that reach the maximum. */ - cnst_list = sys->selective_update_active ? &(sys->modified_constraint_set) : - &(sys->active_constraint_set); + cnst_list = + sys-> + selective_update_active ? &(sys->modified_constraint_set) : + &(sys->active_constraint_set); DEBUG1("Active constraints : %d", xbt_swag_size(cnst_list)); /* Init: Only modified code portions */ @@ -538,9 +549,9 @@ void lmm_solve(lmm_system_t sys) /* First check if some of these variables have reach their upper bound and update min_usage accordingly. */ DEBUG5 - ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f", - var->id_int, var->bound, var->weight, min_usage, - var->bound * var->weight); + ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f", + var->id_int, var->bound, var->weight, min_usage, + var->bound * var->weight); if ((var->bound > 0) && (var->bound * var->weight < min_usage)) { if (min_bound < 0) min_bound = var->bound; @@ -587,8 +598,10 @@ void lmm_solve(lmm_system_t sys) if (elem->variable->value > 0) break; if ((elem->value > 0)) { - cnst->usage=MAX(cnst->usage,elem->value / elem->variable->weight); - DEBUG2("Constraint Usage %d : %f", cnst->id_int, cnst->usage); + cnst->usage = + MAX(cnst->usage, elem->value / elem->variable->weight); + DEBUG2("Constraint Usage %d : %f", cnst->id_int, + cnst->usage); make_elem_active(elem); } } @@ -599,8 +612,8 @@ void lmm_solve(lmm_system_t sys) /* Find out which variables reach the maximum */ cnst_list = - sys->selective_update_active ? &(sys->modified_constraint_set) : - &(sys->active_constraint_set); + sys->selective_update_active ? &(sys->modified_constraint_set) : + &(sys->active_constraint_set); min_usage = -1; min_bound = -1; xbt_swag_foreach(cnst, cnst_list) { @@ -699,8 +712,9 @@ XBT_INLINE double lmm_get_variable_weight(lmm_variable_t var) return var->weight; } -XBT_INLINE void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, - double bound) +XBT_INLINE void lmm_update_constraint_bound(lmm_system_t sys, + lmm_constraint_t cnst, + double bound) { sys->modified = 1; lmm_update_modified_set(sys, cnst); @@ -712,13 +726,16 @@ XBT_INLINE int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst) return xbt_swag_belongs(cnst, &(sys->active_constraint_set)); } -XBT_INLINE lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys) +XBT_INLINE lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t + sys) { return xbt_swag_getFirst(&(sys->active_constraint_set)); } -XBT_INLINE lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, - lmm_constraint_t cnst) +XBT_INLINE lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t + sys, + lmm_constraint_t + cnst) { return xbt_swag_getNext(cnst, (sys->active_constraint_set).offset); } @@ -741,7 +758,8 @@ XBT_INLINE int lmm_is_variable_limited_by_latency(lmm_variable_t var) * constraints that have changed. Each constraint change is propagated * to the list of constraints for each variable. */ -static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst) +static void lmm_update_modified_set(lmm_system_t sys, + lmm_constraint_t cnst) { lmm_element_t elem = NULL; lmm_variable_t var = NULL; diff --git a/src/surf/maxmin_private.h b/src/surf/maxmin_private.h index 6195bbe7f6..7b82d55a17 100644 --- a/src/surf/maxmin_private.h +++ b/src/surf/maxmin_private.h @@ -92,7 +92,8 @@ typedef struct lmm_system { #define make_constraint_inactive(sys,cnst) remove_active_constraint(sys,cnst) static void lmm_var_free(lmm_system_t sys, lmm_variable_t var); -static XBT_INLINE void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst); +static XBT_INLINE void lmm_cnst_free(lmm_system_t sys, + lmm_constraint_t cnst); void lmm_print(lmm_system_t sys); @@ -100,4 +101,4 @@ extern double (*func_f_def) (lmm_variable_t, double); extern double (*func_fp_def) (lmm_variable_t, double); extern double (*func_fpi_def) (lmm_variable_t, double); -#endif /* _SURF_MAXMIN_PRIVATE_H */ +#endif /* _SURF_MAXMIN_PRIVATE_H */ diff --git a/src/surf/network.c b/src/surf/network.c index c933aaef6a..5879b62f69 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -15,9 +15,9 @@ surf_model_t surf_network_model = NULL; static lmm_system_t network_maxmin_system = NULL; static void (*network_solve) (lmm_system_t) = NULL; -double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */ -double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */ -double sg_weight_S_parameter = 0.0;/* default value; can be set by model or from command line */ +double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */ +double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */ +double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */ double sg_tcp_gamma = 0.0; int sg_network_fullduplex = 0; @@ -25,7 +25,7 @@ int sg_network_fullduplex = 0; /******************************************************************************/ /* Factors callbacks */ -/******************************************************************************/ +/******************************************************************************/ static double constant_latency_factor(double size) { return sg_latency_factor; @@ -36,7 +36,8 @@ static double constant_bandwidth_factor(double size) return sg_bandwidth_factor; } -static double constant_bandwidth_constraint(double rate, double bound, double size) +static double constant_bandwidth_constraint(double rate, double bound, + double size) { return rate; } @@ -76,44 +77,50 @@ static double smpi_bandwidth_factor(double size) return 0.9359; } -static double smpi_bandwidth_constraint(double rate, double bound, double size) +static double smpi_bandwidth_constraint(double rate, double bound, + double size) { return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size)); } -static double (*latency_factor_callback)(double) = &constant_latency_factor; -static double (*bandwidth_factor_callback)(double) = &constant_bandwidth_factor; -static double (*bandwidth_constraint_callback)(double, double, double) = &constant_bandwidth_constraint; +static double (*latency_factor_callback) (double) = + &constant_latency_factor; +static double (*bandwidth_factor_callback) (double) = + &constant_bandwidth_factor; +static double (*bandwidth_constraint_callback) (double, double, double) = + &constant_bandwidth_constraint; static link_CM02_t net_link_new(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties) { link_CM02_t nw_link = (link_CM02_t) - surf_resource_lmm_new(sizeof(s_link_CM02_t), - surf_network_model, name, properties, - network_maxmin_system, - sg_bandwidth_factor * bw_initial, - history, - state_initial, state_trace, - bw_initial, bw_trace); - - xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_set, name), - "Link '%s' declared several times in the platform file.", name); + surf_resource_lmm_new(sizeof(s_link_CM02_t), + surf_network_model, name, properties, + network_maxmin_system, + sg_bandwidth_factor * bw_initial, + history, + state_initial, state_trace, + bw_initial, bw_trace); + + xbt_assert1(!xbt_dict_get_or_null + (surf_network_model->resource_set, name), + "Link '%s' declared several times in the platform file.", + name); nw_link->lat_current = lat_initial; if (lat_trace) nw_link->lat_event = - tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link); + tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link); if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(nw_link->lmm_resource.constraint); @@ -121,7 +128,7 @@ static link_CM02_t net_link_new(char *name, xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free); #ifdef HAVE_TRACING - TRACE_surf_link_declaration (nw_link, name, bw_initial, lat_initial); + TRACE_surf_link_declaration(nw_link, name, bw_initial, lat_initial); #endif return nw_link; @@ -152,7 +159,8 @@ static void net_parse_link_init(void) else if (A_surfxml_link_state == A_surfxml_link_state_OFF) state_initial_link = SURF_RESOURCE_OFF; - if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED) + if (A_surfxml_link_sharing_policy == + A_surfxml_link_sharing_policy_SHARED) policy_initial_link = SURF_LINK_SHARED; else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE) @@ -161,26 +169,27 @@ static void net_parse_link_init(void) state_trace = tmgr_trace_new(A_surfxml_link_state_file); net_link_new(name_link, bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, state_trace, - policy_initial_link, xbt_dict_new()); + lat_initial, lat_trace, state_initial_link, state_trace, + policy_initial_link, xbt_dict_new()); } static void net_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t policy, - xbt_dict_t properties) -{ - net_link_new(name, bw_initial, bw_trace, - lat_initial, lat_trace, state_initial, state_trace, - policy, xbt_dict_new()); + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t policy, + xbt_dict_t properties) +{ + net_link_new(name, bw_initial, bw_trace, + lat_initial, lat_trace, state_initial, state_trace, + policy, xbt_dict_new()); } + static void net_add_traces(void) { xbt_dict_cursor_t cursor = NULL; @@ -195,39 +204,42 @@ static void net_add_traces(void) xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined", + xbt_assert2(trace, + "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); link->lmm_resource.state_event = - tmgr_history_add_trace(history, trace, 0.0, 0, link); + tmgr_history_add_trace(history, trace, 0.0, 0, link); } xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined", + xbt_assert2(trace, + "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); link->lmm_resource.power.event = - tmgr_history_add_trace(history, trace, 0.0, 0, link); + tmgr_history_add_trace(history, trace, 0.0, 0, link); } xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_CM02_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined", trace_name, elm); - xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined", + xbt_assert2(trace, + "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); @@ -244,7 +256,8 @@ static void net_define_callbacks(const char *file) static int net_resource_used(void *resource_id) { return lmm_constraint_used(network_maxmin_system, - ((surf_resource_lmm_t) resource_id)->constraint); + ((surf_resource_lmm_t) + resource_id)->constraint); } static int net_action_unref(surf_action_t action) @@ -256,9 +269,10 @@ static int net_action_unref(surf_action_t action) lmm_variable_free(network_maxmin_system, ((surf_action_network_CM02_t) action)->variable); #ifdef HAVE_TRACING - xbt_free (((surf_action_network_CM02_t)action)->src_name); - xbt_free (((surf_action_network_CM02_t)action)->dst_name); - if (action->category) xbt_free (action->category); + xbt_free(((surf_action_network_CM02_t) action)->src_name); + xbt_free(((surf_action_network_CM02_t) action)->dst_name); + if (action->category) + xbt_free(action->category); #endif free(action); return 1; @@ -292,21 +306,23 @@ static double net_share_resources(double now) { s_surf_action_network_CM02_t s_action; surf_action_network_CM02_t action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; double min; min = generic_maxmin_share_resources(running_actions, xbt_swag_offset(s_action, variable), - network_maxmin_system, network_solve); + network_maxmin_system, + network_solve); #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable) ))) xbt_swag_foreach(action, running_actions) { #ifdef HAVE_LATENCY_BOUND_TRACKING - if( lmm_is_variable_limited_by_latency(action->variable) ){ + if (lmm_is_variable_limited_by_latency(action->variable)) { (action->generic_action).latency_limited = 1; - }else{ + } else { (action->generic_action).latency_limited = 0; } #endif @@ -326,7 +342,8 @@ static void net_update_actions_state(double now, double delta) double deltap = 0.0; surf_action_network_CM02_t action = NULL; surf_action_network_CM02_t next_action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; /* xbt_swag_t failed_actions = surf_network_model->states.failed_action_set; @@ -347,12 +364,17 @@ static void net_update_actions_state(double now, double delta) action->weight); } #ifdef HAVE_TRACING - xbt_dynar_t route = global_routing->get_route(action->src_name, action->dst_name); + xbt_dynar_t route = + global_routing->get_route(action->src_name, action->dst_name); link_CM02_t link; unsigned int i; xbt_dynar_foreach(route, i, link) { - TRACE_surf_link_set_utilization (link, - action->generic_action.data, (surf_action_t)action, lmm_variable_getvalue(action->variable), now-delta, delta); + TRACE_surf_link_set_utilization(link, + action->generic_action.data, + (surf_action_t) action, + lmm_variable_getvalue + (action->variable), now - delta, + delta); } #endif double_update(&(action->generic_action.remains), @@ -377,8 +399,8 @@ static void net_update_actions_state(double now, double delta) } static void net_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { link_CM02_t nw_link = id; /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */ @@ -387,8 +409,9 @@ static void net_update_resource_state(void *id, if (event_type == nw_link->lmm_resource.power.event) { double delta = - sg_weight_S_parameter / value - sg_weight_S_parameter / - (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale); + sg_weight_S_parameter / value - sg_weight_S_parameter / + (nw_link->lmm_resource.power.peak * + nw_link->lmm_resource.power.scale); lmm_variable_t var = NULL; lmm_element_t elem = NULL; surf_action_network_CM02_t action = NULL; @@ -400,7 +423,10 @@ static void net_update_resource_state(void *id, (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale)); #ifdef HAVE_TRACING - TRACE_surf_link_set_bandwidth (date, nw_link, sg_bandwidth_factor * (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale)); + TRACE_surf_link_set_bandwidth(date, nw_link, + sg_bandwidth_factor * + (nw_link->lmm_resource.power.peak * + nw_link->lmm_resource.power.scale)); #endif if (sg_weight_S_parameter > 0) { while ((var = lmm_get_var_from_cnst @@ -409,8 +435,8 @@ static void net_update_resource_state(void *id, action = lmm_variable_id(var); action->weight += delta; if (!(action->suspended)) - lmm_update_variable_weight(network_maxmin_system, action->variable, - action->weight); + lmm_update_variable_weight(network_maxmin_system, + action->variable, action->weight); } } if (tmgr_trace_event_free(event_type)) @@ -430,17 +456,19 @@ static void net_update_resource_state(void *id, action->weight += delta; if (action->rate < 0) lmm_update_variable_bound(network_maxmin_system, action->variable, - sg_tcp_gamma / (2.0 * action->lat_current)); - else{ + sg_tcp_gamma / (2.0 * + action->lat_current)); + else { lmm_update_variable_bound(network_maxmin_system, action->variable, min(action->rate, sg_tcp_gamma / (2.0 * action->lat_current))); - if(action->rate < sg_tcp_gamma / (2.0 * action->lat_current) ){ - INFO0("Flow is limited BYBANDWIDTH"); - }else{ - INFO1("Flow is limited BYLATENCY, latency of flow is %f",action->lat_current); + if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) { + INFO0("Flow is limited BYBANDWIDTH"); + } else { + INFO1("Flow is limited BYLATENCY, latency of flow is %f", + action->lat_current); } } if (!(action->suspended)) @@ -481,8 +509,9 @@ static void net_update_resource_state(void *id, } -static surf_action_t net_communicate(const char *src_name, const char *dst_name, - double size, double rate) +static surf_action_t net_communicate(const char *src_name, + const char *dst_name, double size, + double rate) { unsigned int i; link_CM02_t link; @@ -497,10 +526,10 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, xbt_dynar_t back_route = NULL; int constraints_per_variable = 0; - if( sg_network_fullduplex == 1){ - back_route = global_routing->get_route(src_name, dst_name); + if (sg_network_fullduplex == 1) { + back_route = global_routing->get_route(src_name, dst_name); } - + /* LARGE PLATFORMS HACK: total_route_size = route_size + src->link_nb + dst->nb */ @@ -518,8 +547,8 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, } } action = - surf_action_new(sizeof(s_surf_action_network_CM02_t), size, - surf_network_model, failed); + surf_action_new(sizeof(s_surf_action_network_CM02_t), size, + surf_network_model, failed); #ifdef HAVE_LATENCY_BOUND_TRACKING (action->generic_action).latency_limited = 0; #endif @@ -533,39 +562,51 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, xbt_dynar_foreach(route, i, link) { action->latency += link->lat_current; action->weight += - link->lat_current + - sg_weight_S_parameter / - (link->lmm_resource.power.peak * link->lmm_resource.power.scale); - if(bandwidth_bound < 0.0) - bandwidth_bound = (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale); + link->lat_current + + sg_weight_S_parameter / + (link->lmm_resource.power.peak * link->lmm_resource.power.scale); + if (bandwidth_bound < 0.0) + bandwidth_bound = + (*bandwidth_factor_callback) (size) * + (link->lmm_resource.power.peak * link->lmm_resource.power.scale); else - bandwidth_bound = min(bandwidth_bound, (*bandwidth_factor_callback)(size) * (link->lmm_resource.power.peak * link->lmm_resource.power.scale)); + bandwidth_bound = + min(bandwidth_bound, + (*bandwidth_factor_callback) (size) * + (link->lmm_resource.power.peak * + link->lmm_resource.power.scale)); } /* LARGE PLATFORMS HACK: Add src->link and dst->link latencies */ action->lat_current = action->latency; - action->latency *= (*latency_factor_callback)(size); - action->rate = (*bandwidth_constraint_callback)(action->rate, bandwidth_bound, size); + action->latency *= (*latency_factor_callback) (size); + action->rate = + (*bandwidth_constraint_callback) (action->rate, bandwidth_bound, + size); /* LARGE PLATFORMS HACK: lmm_variable_new(..., total_route_size) */ - if(back_route != NULL){ - constraints_per_variable = xbt_dynar_length(route)+xbt_dynar_length(back_route); - }else{ - constraints_per_variable = xbt_dynar_length(route); + if (back_route != NULL) { + constraints_per_variable = + xbt_dynar_length(route) + xbt_dynar_length(back_route); + } else { + constraints_per_variable = xbt_dynar_length(route); } if (action->latency > 0) action->variable = - lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,constraints_per_variable); + lmm_variable_new(network_maxmin_system, action, 0.0, -1.0, + constraints_per_variable); else action->variable = - lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,constraints_per_variable); + lmm_variable_new(network_maxmin_system, action, 1.0, -1.0, + constraints_per_variable); if (action->rate < 0) { if (action->lat_current > 0) lmm_update_variable_bound(network_maxmin_system, action->variable, - sg_tcp_gamma / (2.0 * action->lat_current)); + sg_tcp_gamma / (2.0 * + action->lat_current)); else lmm_update_variable_bound(network_maxmin_system, action->variable, -1.0); @@ -585,21 +626,21 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, action->variable, 1.0); } - if( sg_network_fullduplex == 1){ - DEBUG1("Fullduplex active adding backward flow using 5%c", '%'); - xbt_dynar_foreach(back_route, i, link) { - lmm_expand(network_maxmin_system, link->lmm_resource.constraint, - action->variable, .05); - } - } /* LARGE PLATFORMS HACK: + if (sg_network_fullduplex == 1) { + DEBUG1("Fullduplex active adding backward flow using 5%c", '%'); + xbt_dynar_foreach(back_route, i, link) { + lmm_expand(network_maxmin_system, link->lmm_resource.constraint, + action->variable, .05); + } + } + /* LARGE PLATFORMS HACK: expand also with src->link and dst->link */ - #ifdef HAVE_TRACING - action->src_name = xbt_new (char, strlen(src_name)+1); - strncpy (action->src_name, src_name, strlen(src_name)+1); + action->src_name = xbt_new(char, strlen(src_name) + 1); + strncpy(action->src_name, src_name, strlen(src_name) + 1); - action->dst_name = xbt_new (char, strlen(dst_name)+1); - strncpy (action->dst_name, dst_name, strlen(dst_name)+1); + action->dst_name = xbt_new(char, strlen(dst_name) + 1); + strncpy(action->dst_name, dst_name, strlen(dst_name) + 1); #endif XBT_OUT; @@ -609,7 +650,7 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name, static xbt_dynar_t net_get_route(const char *src, const char *dst) { - return global_routing->get_route( src, dst); + return global_routing->get_route(src, dst); } static double net_get_link_bandwidth(const void *link) @@ -620,20 +661,21 @@ static double net_get_link_bandwidth(const void *link) static double net_get_link_latency(const void *link) { - return ((link_CM02_t) link)->lat_current; + return ((link_CM02_t) link)->lat_current; } static int net_link_shared(const void *link) { - return lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint); + return + lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint); } static void net_action_suspend(surf_action_t action) { ((surf_action_network_CM02_t) action)->suspended = 1; lmm_update_variable_weight(network_maxmin_system, - ((surf_action_network_CM02_t) action)->variable, - 0.0); + ((surf_action_network_CM02_t) + action)->variable, 0.0); } static void net_action_resume(surf_action_t action) @@ -642,7 +684,8 @@ static void net_action_resume(surf_action_t action) lmm_update_variable_weight(network_maxmin_system, ((surf_action_network_CM02_t) action)->variable, - ((surf_action_network_CM02_t) action)->weight); + ((surf_action_network_CM02_t) + action)->weight); ((surf_action_network_CM02_t) action)->suspended = 0; } } @@ -661,9 +704,9 @@ static void net_finalize(void) { surf_model_exit(surf_network_model); surf_network_model = NULL; - + global_routing->finalize(); - + lmm_system_free(network_maxmin_system); network_maxmin_system = NULL; } @@ -684,9 +727,9 @@ static void surf_network_model_init_internal(void) surf_network_model->model_private->resource_used = net_resource_used; surf_network_model->model_private->share_resources = net_share_resources; surf_network_model->model_private->update_actions_state = - net_update_actions_state; + net_update_actions_state; surf_network_model->model_private->update_resource_state = - net_update_resource_state; + net_update_resource_state; surf_network_model->model_private->finalize = net_finalize; surf_network_model->suspend = net_action_suspend; @@ -697,21 +740,22 @@ static void surf_network_model_init_internal(void) surf_network_model->extension.network.communicate = net_communicate; surf_network_model->extension.network.get_route = net_get_route; surf_network_model->extension.network.get_link_bandwidth = - net_get_link_bandwidth; + net_get_link_bandwidth; surf_network_model->extension.network.get_link_latency = - net_get_link_latency; + net_get_link_latency; surf_network_model->extension.network.link_shared = net_link_shared; surf_network_model->extension.network.add_traces = net_add_traces; - surf_network_model->extension.network.create_resource = net_create_resource; + surf_network_model->extension.network.create_resource = + net_create_resource; if (!network_maxmin_system) network_maxmin_system = lmm_system_new(); routing_model_create(sizeof(link_CM02_t), net_link_new(xbt_strdup("__loopback__"), - 498000000, NULL, 0.000015, NULL, - SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE, - NULL)); + 498000000, NULL, 0.000015, NULL, + SURF_RESOURCE_ON, NULL, + SURF_LINK_FATPIPE, NULL)); } @@ -732,7 +776,7 @@ void surf_network_model_init_SMPI(const char *filename) xbt_dynar_push(model_list, &surf_network_model); network_solve = lmm_solve; - xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); update_model_description(surf_network_model_description, "SMPI", surf_network_model); @@ -751,9 +795,10 @@ void surf_network_model_init_LegrandVelho(const char *filename) xbt_dynar_push(model_list, &surf_network_model); network_solve = lmm_solve; - xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor",10.4); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", + 0.92); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); update_model_description(surf_network_model_description, "LV08", surf_network_model); @@ -792,12 +837,14 @@ void surf_network_model_init_Reno(const char *filename) net_define_callbacks(filename); xbt_dynar_push(model_list, &surf_network_model); - lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); + lmm_set_default_protocol_function(func_reno_f, func_reno_fp, + func_reno_fpi); network_solve = lagrange_solve; - xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", + 0.92); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); update_model_description(surf_network_model_description, "Reno", surf_network_model); @@ -816,9 +863,11 @@ void surf_network_model_init_Reno2(const char *filename) func_reno2_fpi); network_solve = lagrange_solve; - xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S_parameter", 8775); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", + 0.92); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S_parameter", + 8775); update_model_description(surf_network_model_description, "Reno2", surf_network_model); @@ -836,12 +885,11 @@ void surf_network_model_init_Vegas(const char *filename) func_vegas_fpi); network_solve = lagrange_solve; - xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92); - xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", + 0.92); + xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); update_model_description(surf_network_model_description, "Vegas", surf_network_model); } - - diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index d12b9efc06..866ac41b5b 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -55,7 +55,8 @@ static void netcste_action_cancel(surf_action_t action) static double netcste_share_resources(double now) { surf_action_network_Constant_t action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; double min = -1.0; xbt_swag_foreach(action, running_actions) { @@ -74,7 +75,8 @@ static void netcste_update_actions_state(double now, double delta) { surf_action_network_Constant_t action = NULL; surf_action_network_Constant_t next_action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; xbt_swag_foreach_safe(action, next_action, running_actions) { if (action->latency > 0) { @@ -103,22 +105,23 @@ static void netcste_update_actions_state(double now, double delta) } static void netcste_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double time) + tmgr_trace_event_t event_type, + double value, double time) { DIE_IMPOSSIBLE; } -static surf_action_t netcste_communicate(const char *src_name, const char *dst_name, - double size, double rate) +static surf_action_t netcste_communicate(const char *src_name, + const char *dst_name, double size, + double rate) { surf_action_network_Constant_t action = NULL; XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); action = - surf_action_new(sizeof(s_surf_action_network_Constant_t), size, - surf_network_model, 0); + surf_action_new(sizeof(s_surf_action_network_Constant_t), size, + surf_network_model, 0); action->suspended = 0; @@ -127,7 +130,7 @@ static surf_action_t netcste_communicate(const char *src_name, const char *dst_n if (action->latency <= 0.0) { action->generic_action.state_set = - surf_network_model->states.done_action_set; + surf_network_model->states.done_action_set; xbt_swag_insert(action, action->generic_action.state_set); } @@ -199,11 +202,12 @@ void surf_network_model_init_Constant(const char *filename) #endif surf_network_model->model_private->resource_used = netcste_resource_used; - surf_network_model->model_private->share_resources = netcste_share_resources; + surf_network_model->model_private->share_resources = + netcste_share_resources; surf_network_model->model_private->update_actions_state = - netcste_update_actions_state; + netcste_update_actions_state; surf_network_model->model_private->update_resource_state = - netcste_update_resource_state; + netcste_update_resource_state; surf_network_model->model_private->finalize = netcste_finalize; surf_network_model->suspend = netcste_action_suspend; @@ -213,8 +217,9 @@ void surf_network_model_init_Constant(const char *filename) surf_network_model->extension.network.communicate = netcste_communicate; surf_network_model->extension.network.get_link_bandwidth = - netcste_get_link_bandwidth; - surf_network_model->extension.network.get_link_latency = netcste_get_link_latency; + netcste_get_link_bandwidth; + surf_network_model->extension.network.get_link_latency = + netcste_get_link_latency; surf_network_model->extension.network.link_shared = link_shared; if (!random_latency) diff --git a/src/surf/network_gtnets.c b/src/surf/network_gtnets.c index ea448bd73e..b33e07de9b 100644 --- a/src/surf/network_gtnets.c +++ b/src/surf/network_gtnets.c @@ -15,33 +15,34 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf, extern routing_global_t global_routing; -double sg_gtnets_jitter=0.0; -int sg_gtnets_jitter_seed=10; +double sg_gtnets_jitter = 0.0; +int sg_gtnets_jitter_seed = 10; static void link_new(char *name, double bw, double lat, xbt_dict_t props) { static int link_count = -1; network_link_GTNETS_t gtnets_link; network_link_GTNETS_t gtnets_link_friend; - int tmp_idsrc=-1; - int tmp_iddst=-1; + int tmp_idsrc = -1; + int tmp_iddst = -1; char *name_friend; if (xbt_dict_get_or_null(surf_network_model->resource_set, name)) { return; } - #ifdef HAVE_TRACING - TRACE_surf_link_declaration (name, bw, lat); + TRACE_surf_link_declaration(name, bw, lat); #endif DEBUG1("Scanning link name %s", name); sscanf(name, "%d_%d", &tmp_idsrc, &tmp_iddst); DEBUG2("Link name split into %d and %d", tmp_idsrc, tmp_iddst); - xbt_assert0( (tmp_idsrc!=-1)&&(tmp_idsrc!=-1), "You need to respect fullduplex convention x_y for xml link id."); + xbt_assert0((tmp_idsrc != -1) + && (tmp_idsrc != -1), + "You need to respect fullduplex convention x_y for xml link id."); - name_friend = (char *)calloc(strlen(name), sizeof(char)); + name_friend = (char *) calloc(strlen(name), sizeof(char)); sprintf(name_friend, "%d_%d", tmp_iddst, tmp_idsrc); gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1); @@ -50,26 +51,30 @@ static void link_new(char *name, double bw, double lat, xbt_dict_t props) gtnets_link->bw_current = bw; gtnets_link->lat_current = lat; - if((gtnets_link_friend=xbt_dict_get_or_null(surf_network_model->resource_set, name_friend))) { + if ((gtnets_link_friend = + xbt_dict_get_or_null(surf_network_model->resource_set, + name_friend))) { gtnets_link->id = gtnets_link_friend->id; } else { link_count++; - DEBUG4("Adding new link, linkid %d, name %s, latency %g, bandwidth %g", link_count, name, lat, bw); + DEBUG4("Adding new link, linkid %d, name %s, latency %g, bandwidth %g", + link_count, name, lat, bw); if (gtnets_add_link(link_count, bw, lat)) { xbt_assert0(0, "Cannot create GTNetS link"); } gtnets_link->id = link_count; } xbt_dict_set(surf_network_model->resource_set, name, gtnets_link, - surf_resource_free); + surf_resource_free); } -static void route_new(int src_id, int dst_id, xbt_dynar_t links,int nb_link) +static void route_new(int src_id, int dst_id, xbt_dynar_t links, + int nb_link) { network_link_GTNETS_t link; unsigned int cursor; - int i=0; + int i = 0; int *gtnets_links; XBT_IN4("(src_id=%d, dst_id=%d, links=%p, nb_link=%d)", @@ -118,7 +123,8 @@ static void parse_link_init(void) state_trace = tmgr_trace_new(A_surfxml_link_state_file); if (bw_trace) - INFO0("The GTNetS network model doesn't support bandwidth state traces"); + INFO0 + ("The GTNetS network model doesn't support bandwidth state traces"); if (lat_trace) INFO0("The GTNetS network model doesn't support latency state traces"); if (state_trace) @@ -142,22 +148,22 @@ static void create_gtnets_topology() // Ensuite, on peut utiliser les id pour refaire les appels GTNets qui suivent. // xbt_dict_foreach(onelink_routes, cursor, key, data){ -// s_onelink_t link = (s_onelink_t) data; +// s_onelink_t link = (s_onelink_t) data; // -// DEBUG3("Link (#%d), src (#%s), dst (#%s)", ((network_link_GTNETS_t)(link->link_ptr))->id , link->src, link->dst); +// DEBUG3("Link (#%d), src (#%s), dst (#%s)", ((network_link_GTNETS_t)(link->link_ptr))->id , link->src, link->dst); // DEBUG0("Calling one link route"); // if(global_routing->is_router(link->src)){ -// gtnets_add_router(link->src_id); +// gtnets_add_router(link->src_id); // } // if(global_routing->is_router(link->dst)){ -// gtnets_add_router(link->dst_id); +// gtnets_add_router(link->dst_id); // } // route_onehop_new(link->src_id, link->dst_id, (network_link_GTNETS_t)(link->link_ptr)); // } // // xbt_dict_free(&route_table); // if (XBT_LOG_ISENABLED(surf_network_gtnets, xbt_log_priority_debug)) { -// gtnets_print_topology(); +// gtnets_print_topology(); // } } @@ -166,12 +172,14 @@ static void define_callbacks(const char *file) { /* Figuring out the network links */ surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init); - surfxml_add_callback(ETag_surfxml_platform_cb_list, &create_gtnets_topology); + surfxml_add_callback(ETag_surfxml_platform_cb_list, + &create_gtnets_topology); } static int resource_used(void *resource_id) { - xbt_assert0(0, "The resource_used feature is not implemented in GTNets model"); + xbt_assert0(0, + "The resource_used feature is not implemented in GTNets model"); } static int action_unref(surf_action_t action) @@ -180,7 +188,8 @@ static int action_unref(surf_action_t action) if (!action->refcount) { xbt_swag_remove(action, action->state_set); #ifdef HAVE_TRACING - if (action->category) xbt_free (action->category); + if (action->category) + xbt_free(action->category); #endif free(action); return 1; @@ -190,13 +199,13 @@ static int action_unref(surf_action_t action) static void action_cancel(surf_action_t action) { - xbt_assert0(0,"Cannot cancel GTNetS flow"); + xbt_assert0(0, "Cannot cancel GTNetS flow"); return; } static void action_recycle(surf_action_t action) { - xbt_assert0(0,"Cannot recycle GTNetS flow"); + xbt_assert0(0, "Cannot recycle GTNetS flow"); return; } @@ -213,7 +222,8 @@ static void action_state_set(surf_action_t action, static double share_resources(double now) { - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; //get the first relevant value from the running_actions list if (!xbt_swag_size(running_actions)) @@ -224,7 +234,8 @@ static double share_resources(double now) DEBUG0("Calling gtnets_get_time_to_next_flow_completion"); time_to_next_flow_completion = gtnets_get_time_to_next_flow_completion(); - DEBUG1("gtnets_get_time_to_next_flow_completion received %lg", time_to_next_flow_completion); + DEBUG1("gtnets_get_time_to_next_flow_completion received %lg", + time_to_next_flow_completion); return time_to_next_flow_completion; } @@ -232,7 +243,8 @@ static double share_resources(double now) static void update_actions_state(double now, double delta) { surf_action_network_GTNETS_t action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; /* If there are no renning flows, just return */ if (time_to_next_flow_completion < 0.0) { @@ -262,7 +274,7 @@ static void update_actions_state(double now, double delta) #ifdef HAVE_TRACING double trace_sent = sent; - if (trace_sent == 0){ + if (trace_sent == 0) { //if sent is equals to 0, means that gtnets sent all the bytes trace_sent = action->generic_action.cost; } @@ -275,7 +287,7 @@ static void update_actions_state(double now, double delta) // network_link_GTNETS_t link; // unsigned int i; // xbt_dynar_foreach(route, i, link) { -// TRACE_surf_link_set_utilization (link->generic_resource.name, +// TRACE_surf_link_set_utilization (link->generic_resource.name, // action->generic_action.data, trace_sent/delta, now-delta, delta); // } // } @@ -286,7 +298,8 @@ static void update_actions_state(double now, double delta) if (sent == 0) { action->generic_action.remains = 0; } else { - action->generic_action.remains = action->generic_action.cost - sent; + action->generic_action.remains = + action->generic_action.cost - sent; } DEBUG2("Action (%p) remains new value: %f", action, action->generic_action.remains); @@ -297,7 +310,7 @@ static void update_actions_state(double now, double delta) action->generic_action.finish = now + time_to_next_flow_completion; #ifdef HAVE_TRACING - TRACE_surf_gtnets_destroy (action); + TRACE_surf_gtnets_destroy(action); #endif action_state_set((surf_action_t) action, SURF_ACTION_DONE); DEBUG1("----> Action (%p) just terminated", action); @@ -321,23 +334,28 @@ static void update_resource_state(void *id, } /* Max durations are not supported */ -static surf_action_t communicate(const char *src_name, const char *dst_name, - double size, double rate) +static surf_action_t communicate(const char *src_name, + const char *dst_name, double size, + double rate) { - int src,dst; + int src, dst; // Utiliser le dictionnaire définit dans create_gtnets_topology pour initialiser correctement src et dst - src=dst=-1; + src = dst = -1; surf_action_network_GTNETS_t action = NULL; - xbt_assert0((src >= 0 && dst >= 0), "Either src or dst have invalid id (id<0)"); + xbt_assert0((src >= 0 + && dst >= 0), "Either src or dst have invalid id (id<0)"); - DEBUG4("Setting flow src %d \"%s\", dst %d \"%s\"", src, src_name, dst, dst_name); + DEBUG4("Setting flow src %d \"%s\", dst %d \"%s\"", src, src_name, dst, + dst_name); xbt_dynar_t links = global_routing->get_route(src_name, dst_name); route_new(src, dst, links, xbt_dynar_length(links)); - action = surf_action_new(sizeof(s_surf_action_network_GTNETS_t), size, surf_network_model, 0); + action = + surf_action_new(sizeof(s_surf_action_network_GTNETS_t), size, + surf_network_model, 0); /* Add a flow to the GTNets Simulation, associated to this action */ if (gtnets_create_flow(src, dst, size, (void *) action) < 0) { @@ -345,7 +363,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name, dst_name); } #ifdef HAVE_TRACING - TRACE_surf_gtnets_communicate (action, src, dst); + TRACE_surf_gtnets_communicate(action, src, dst); #endif return (surf_action_t) action; @@ -388,9 +406,9 @@ static void surf_network_model_init_internal(void) surf_network_model->model_private->resource_used = resource_used; surf_network_model->model_private->share_resources = share_resources; surf_network_model->model_private->update_actions_state = - update_actions_state; + update_actions_state; surf_network_model->model_private->update_resource_state = - update_resource_state; + update_resource_state; surf_network_model->model_private->finalize = finalize; surf_network_model->suspend = action_suspend; @@ -408,8 +426,9 @@ static void surf_network_model_init_internal(void) } #ifdef HAVE_LATENCY_BOUND_TRACKING -static int get_latency_limited(surf_action_t action){ - return 0; +static int get_latency_limited(surf_action_t action) +{ + return 0; } #endif @@ -426,9 +445,9 @@ void surf_network_model_init_GTNETS(const char *filename) surf_network_model->get_latency_limited = get_latency_limited; #endif - if(sg_gtnets_jitter > 0.0){ - gtnets_set_jitter(sg_gtnets_jitter); - gtnets_set_jitter_seed(sg_gtnets_jitter_seed); + if (sg_gtnets_jitter > 0.0) { + gtnets_set_jitter(sg_gtnets_jitter); + gtnets_set_jitter_seed(sg_gtnets_jitter_seed); } update_model_description(surf_network_model_description, diff --git a/src/surf/network_gtnets_private.h b/src/surf/network_gtnets_private.h index 145c10f26c..b6acca57e7 100644 --- a/src/surf/network_gtnets_private.h +++ b/src/surf/network_gtnets_private.h @@ -11,7 +11,7 @@ #include "xbt/dict.h" typedef struct network_link_GTNETS { - s_surf_resource_t generic_resource; /* Must remain first to allow casting */ + s_surf_resource_t generic_resource; /* Must remain first to allow casting */ /* Using this object with the public part of model does not make sense */ double bw_current; @@ -32,4 +32,4 @@ xbt_dict_t network_card_ids; -#endif /* _SURF_NETWORK_PRIVATE_H */ +#endif /* _SURF_NETWORK_PRIVATE_H */ diff --git a/src/surf/network_private.h b/src/surf/network_private.h index 8ce2e6b353..b03750e1d8 100644 --- a/src/surf/network_private.h +++ b/src/surf/network_private.h @@ -11,7 +11,7 @@ #include "xbt/dict.h" typedef struct network_link_CM02 { - s_surf_resource_lmm_t lmm_resource; /* must remain first to be added to a trace */ + s_surf_resource_lmm_t lmm_resource; /* must remain first to be added to a trace */ /* Using this object with the public part of model does not make sense */ @@ -33,10 +33,10 @@ typedef struct surf_action_network_CM02 { int suspended; #ifdef HAVE_TRACING - char* src_name; - char* dst_name; + char *src_name; + char *dst_name; #endif - + } s_surf_action_network_CM02_t, *surf_action_network_CM02_t; -#endif /* _SURF_NETWORK_PRIVATE_H */ +#endif /* _SURF_NETWORK_PRIVATE_H */ diff --git a/src/surf/network_vivaldi.c b/src/surf/network_vivaldi.c index 5698b44501..bf264c87a6 100644 --- a/src/surf/network_vivaldi.c +++ b/src/surf/network_vivaldi.c @@ -18,9 +18,9 @@ typedef struct surf_action_network_Vivaldi { } s_surf_action_network_Vivaldi_t, *surf_action_network_Vivaldi_t; typedef struct s_netviva_coords { - double x,y,h; + double x, y, h; } s_netviva_coords_t, *netviva_coords_t; -xbt_dict_t coords; /* Host name -> coordinates */ +xbt_dict_t coords; /* Host name -> coordinates */ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); static random_data_t random_latency_viva = NULL; @@ -36,7 +36,8 @@ static void netviva_define_callbacks(const char *file) surfxml_add_callback(STag_surfxml_host_cb_list, &netviva_count_hosts); } -static int netviva_resource_used(void *resource_id) { +static int netviva_resource_used(void *resource_id) +{ /* nothing to do here */ return 0; } @@ -47,7 +48,8 @@ static int netviva_action_unref(surf_action_t action) if (!action->refcount) { xbt_swag_remove(action, action->state_set); #ifdef HAVE_TRACING - if (action->category) xbt_free (action->category); + if (action->category) + xbt_free(action->category); #endif free(action); return 1; @@ -74,7 +76,8 @@ static double netviva_action_get_remains(surf_action_t action) static double netviva_share_resources(double now) { surf_action_network_Vivaldi_t action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; double min = -1.0; xbt_swag_foreach(action, running_actions) { @@ -89,11 +92,13 @@ static double netviva_share_resources(double now) return min; } -static void netviva_update_actions_state(double now, double delta) { +static void netviva_update_actions_state(double now, double delta) +{ /* Advance the actions by delta seconds */ surf_action_network_Vivaldi_t action = NULL; surf_action_network_Vivaldi_t next_action = NULL; - xbt_swag_t running_actions = surf_network_model->states.running_action_set; + xbt_swag_t running_actions = + surf_network_model->states.running_action_set; xbt_swag_foreach_safe(action, next_action, running_actions) { if (action->latency > 0) { @@ -108,7 +113,7 @@ static void netviva_update_actions_state(double now, double delta) { if (action->generic_action.max_duration != NO_MAX_DURATION) double_update(&(action->generic_action.max_duration), delta); - if (action->generic_action.remains <= 0) { /* This action is done, inform SURF about it */ + if (action->generic_action.remains <= 0) { /* This action is done, inform SURF about it */ action->generic_action.finish = surf_get_clock(); surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE); @@ -122,30 +127,33 @@ static void netviva_update_actions_state(double now, double delta) { } static void netviva_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double time) -{ /* Called as soon as there is a trace modification */ + tmgr_trace_event_t event_type, + double value, double time) +{ /* Called as soon as there is a trace modification */ DIE_IMPOSSIBLE; } -static surf_action_t netviva_communicate(const char *src_name, const char *dst_name, - double size, double rate) +static surf_action_t netviva_communicate(const char *src_name, + const char *dst_name, double size, + double rate) { surf_action_network_Vivaldi_t action = NULL; - netviva_coords_t c1,c2; - c1 = xbt_dict_get(coords,src_name); - c2 = xbt_dict_get(coords,dst_name); + netviva_coords_t c1, c2; + c1 = xbt_dict_get(coords, src_name); + c2 = xbt_dict_get(coords, dst_name); - action = surf_action_new(sizeof(s_surf_action_network_Vivaldi_t), size,surf_network_model, 0); + action = + surf_action_new(sizeof(s_surf_action_network_Vivaldi_t), size, + surf_network_model, 0); action->suspended = 0; - action->latency = sqrt((c1->x-c2->x)*(c1->x-c2->x) + (c1->y-c2->y)*(c1->y-c2->y)) + fabs(c1->h)+ fabs(c2->h) ; //random_generate(random_latency_viva); + action->latency = sqrt((c1->x - c2->x) * (c1->x - c2->x) + (c1->y - c2->y) * (c1->y - c2->y)) + fabs(c1->h) + fabs(c2->h); //random_generate(random_latency_viva); action->lat_init = action->latency; if (action->latency <= 0.0) { action->generic_action.state_set = - surf_network_model->states.done_action_set; + surf_network_model->states.done_action_set; xbt_swag_insert(action, action->generic_action.state_set); } @@ -189,7 +197,8 @@ static int netviva_action_is_suspended(surf_action_t action) return ((surf_action_network_Vivaldi_t) action)->suspended; } -static void netviva_action_set_max_duration(surf_action_t action, double duration) +static void netviva_action_set_max_duration(surf_action_t action, + double duration) { action->max_duration = duration; } @@ -200,25 +209,28 @@ static void netviva_finalize(void) surf_network_model = NULL; } -static void netviva_parse_host(void) { - netviva_coords_t coord = xbt_new(s_netviva_coords_t,1); +static void netviva_parse_host(void) +{ + netviva_coords_t coord = xbt_new(s_netviva_coords_t, 1); - xbt_dynar_t ctn =xbt_str_split_str(A_surfxml_host_vivaldi," "); + xbt_dynar_t ctn = xbt_str_split_str(A_surfxml_host_vivaldi, " "); - coord->x = atof(xbt_dynar_get_as(ctn, 0, char*)); - coord->y = atof(xbt_dynar_get_as(ctn, 1, char*)); - coord->h = atof(xbt_dynar_get_as(ctn, 2, char*)); + coord->x = atof(xbt_dynar_get_as(ctn, 0, char *)); + coord->y = atof(xbt_dynar_get_as(ctn, 1, char *)); + coord->h = atof(xbt_dynar_get_as(ctn, 2, char *)); #ifdef HAVE_TRACING - TRACE_surf_host_vivaldi_parse (A_surfxml_host_id, coord->x, coord->y, coord->h); + TRACE_surf_host_vivaldi_parse(A_surfxml_host_id, coord->x, coord->y, + coord->h); #endif xbt_dynar_free(&ctn); - xbt_dict_set(coords, A_surfxml_host_id,coord,NULL); + xbt_dict_set(coords, A_surfxml_host_id, coord, NULL); } #ifdef HAVE_LATENCY_BOUND_TRACKING -static int netviva_get_latency_limited(surf_action_t action){ +static int netviva_get_latency_limited(surf_action_t action) +{ return 0; } #endif @@ -242,11 +254,12 @@ void surf_network_model_init_Vivaldi(const char *filename) #endif surf_network_model->model_private->resource_used = netviva_resource_used; - surf_network_model->model_private->share_resources = netviva_share_resources; + surf_network_model->model_private->share_resources = + netviva_share_resources; surf_network_model->model_private->update_actions_state = - netviva_update_actions_state; + netviva_update_actions_state; surf_network_model->model_private->update_resource_state = - netviva_update_resource_state; + netviva_update_resource_state; surf_network_model->model_private->finalize = netviva_finalize; surf_network_model->suspend = netviva_action_suspend; @@ -256,8 +269,9 @@ void surf_network_model_init_Vivaldi(const char *filename) surf_network_model->extension.network.communicate = netviva_communicate; surf_network_model->extension.network.get_link_bandwidth = - netviva_get_link_bandwidth; - surf_network_model->extension.network.get_link_latency = netviva_get_link_latency; + netviva_get_link_bandwidth; + surf_network_model->extension.network.get_link_latency = + netviva_get_link_latency; surf_network_model->extension.network.link_shared = netviva_link_shared; if (!random_latency_viva) @@ -272,12 +286,11 @@ void surf_network_model_init_Vivaldi(const char *filename) "Vivaldi", surf_network_model); #ifdef HAVE_TRACING - TRACE_user_host_variable(0,"vivaldi_x",0,"declare"); - TRACE_user_host_variable(0,"vivaldi_y",0,"declare"); - TRACE_user_host_variable(0,"vivaldi_h",0,"declare"); + TRACE_user_host_variable(0, "vivaldi_x", 0, "declare"); + TRACE_user_host_variable(0, "vivaldi_y", 0, "declare"); + TRACE_user_host_variable(0, "vivaldi_h", 0, "declare"); #endif xbt_cfg_set_string(_surf_cfg_set, "routing", "none"); routing_model_create(sizeof(double), NULL); } - diff --git a/src/surf/random_mgr.c b/src/surf/random_mgr.c index 48769c429c..cec30f9702 100644 --- a/src/surf/random_mgr.c +++ b/src/surf/random_mgr.c @@ -88,7 +88,8 @@ _erand48_r(unsigned short int xsubi[3], struct drand48_data *buffer, return 0; } -int _drand48_iterate(unsigned short int xsubi[3], struct drand48_data *buffer) +int _drand48_iterate(unsigned short int xsubi[3], + struct drand48_data *buffer) { uint64_t X; uint64_t result; @@ -122,7 +123,8 @@ double _drand48(void) { double result; - (void) _erand48_r(__libc_drand48_data.__x, &__libc_drand48_data, &result); + (void) _erand48_r(__libc_drand48_data.__x, &__libc_drand48_data, + &result); return result; } @@ -213,14 +215,12 @@ double random_generate(random_data_t random) if (random->std == 0) return random->mean * (random->max - random->min) + random->min; - a = - random->mean * (random->mean * (1 - random->mean) / - (random->std * random->std) - 1); - b = - (1 - - random->mean) * (random->mean * (1 - - random->mean) / (random->std * - random->std) - 1); + a = random->mean * (random->mean * (1 - random->mean) / + (random->std * random->std) - 1); + b = (1 - + random->mean) * (random->mean * (1 - + random->mean) / (random->std * + random->std) - 1); alpha = a + b; if (a <= 1. || b <= 1.) @@ -261,9 +261,11 @@ random_data_t random_new(Generator generator, long int seed, if (max < min) THROW2(arg_error, 0, "random->max < random->min (%f < %f)", max, min); if (mean < min) - THROW2(arg_error, 0, "random->mean < random->min (%f < %f)", mean, min); + THROW2(arg_error, 0, "random->mean < random->min (%f < %f)", mean, + min); if (mean > max) - THROW2(arg_error, 0, "random->mean > random->max (%f > %f)", mean, max); + THROW2(arg_error, 0, "random->mean > random->max (%f > %f)", mean, + max); /* normalize the mean and standard deviation before storing */ random->mean = (mean - min) / (max - min); diff --git a/src/surf/simgrid_dtd.c b/src/surf/simgrid_dtd.c index a21b7fabe9..a8d92f6c55 100644 --- a/src/surf/simgrid_dtd.c +++ b/src/surf/simgrid_dtd.c @@ -2617,7 +2617,7 @@ int surf_parse__flex_debug = 0; #define YY_RESTORE_YY_MORE_OFFSET char *surf_parse_text; /* Validating XML processor for src/surf/simgrid.dtd. - * Generated 2010/10/06 17:47:05. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/surf/simgrid_dtd.l b/src/surf/simgrid_dtd.l index 6a81690547..8eaf6d22b1 100644 --- a/src/surf/simgrid_dtd.l +++ b/src/surf/simgrid_dtd.l @@ -1,5 +1,5 @@ /* Validating XML processor for src/surf/simgrid.dtd. - * Generated 2010/10/01 22:34:13. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. @@ -90,34 +90,48 @@ AT_surfxml_random_generator AX_surfxml_random_generator; #define A_surfxml_random_generator AX_surfxml_random_generator AT_surfxml_ASroute_gw_dst AX_surfxml_ASroute_gw_dst; #define A_surfxml_ASroute_gw_dst (surfxml_bufferstack + AX_surfxml_ASroute_gw_dst) +AT_surfxml_link_id AX_surfxml_link_id; +#define A_surfxml_link_id (surfxml_bufferstack + AX_surfxml_link_id) AT_surfxml_trace_connect_element AX_surfxml_trace_connect_element; #define A_surfxml_trace_connect_element (surfxml_bufferstack + AX_surfxml_trace_connect_element) AT_surfxml_prop_id AX_surfxml_prop_id; #define A_surfxml_prop_id (surfxml_bufferstack + AX_surfxml_prop_id) -AT_surfxml_host_interference_recv AX_surfxml_host_interference_recv; -#define A_surfxml_host_interference_recv (surfxml_bufferstack + AX_surfxml_host_interference_recv) AT_surfxml_host_id AX_surfxml_host_id; #define A_surfxml_host_id (surfxml_bufferstack + AX_surfxml_host_id) AT_surfxml_link_latency_file AX_surfxml_link_latency_file; #define A_surfxml_link_latency_file (surfxml_bufferstack + AX_surfxml_link_latency_file) +AT_surfxml_process_host AX_surfxml_process_host; +#define A_surfxml_process_host (surfxml_bufferstack + AX_surfxml_process_host) +AT_surfxml_cluster_lat AX_surfxml_cluster_lat; +#define A_surfxml_cluster_lat (surfxml_bufferstack + AX_surfxml_cluster_lat) AT_surfxml_host_state AX_surfxml_host_state; #define A_surfxml_host_state AX_surfxml_host_state -AT_surfxml_host_interference_send_recv AX_surfxml_host_interference_send_recv; -#define A_surfxml_host_interference_send_recv (surfxml_bufferstack + AX_surfxml_host_interference_send_recv) -AT_surfxml_host_interference_send AX_surfxml_host_interference_send; -#define A_surfxml_host_interference_send (surfxml_bufferstack + AX_surfxml_host_interference_send) +AT_surfxml_host_availability_file AX_surfxml_host_availability_file; +#define A_surfxml_host_availability_file (surfxml_bufferstack + AX_surfxml_host_availability_file) +AT_surfxml_trace_periodicity AX_surfxml_trace_periodicity; +#define A_surfxml_trace_periodicity (surfxml_bufferstack + AX_surfxml_trace_periodicity) +AT_surfxml_prop_value AX_surfxml_prop_value; +#define A_surfxml_prop_value (surfxml_bufferstack + AX_surfxml_prop_value) AT_surfxml_AS_id AX_surfxml_AS_id; #define A_surfxml_AS_id (surfxml_bufferstack + AX_surfxml_AS_id) +AT_surfxml_ASroute_dst AX_surfxml_ASroute_dst; +#define A_surfxml_ASroute_dst (surfxml_bufferstack + AX_surfxml_ASroute_dst) AT_surfxml_host_power AX_surfxml_host_power; #define A_surfxml_host_power (surfxml_bufferstack + AX_surfxml_host_power) +AT_surfxml_link_state_file AX_surfxml_link_state_file; +#define A_surfxml_link_state_file (surfxml_bufferstack + AX_surfxml_link_state_file) AT_surfxml_router_id AX_surfxml_router_id; #define A_surfxml_router_id (surfxml_bufferstack + AX_surfxml_router_id) +AT_surfxml_trace_connect_trace AX_surfxml_trace_connect_trace; +#define A_surfxml_trace_connect_trace (surfxml_bufferstack + AX_surfxml_trace_connect_trace) AT_surfxml_process_start_time AX_surfxml_process_start_time; #define A_surfxml_process_start_time (surfxml_bufferstack + AX_surfxml_process_start_time) AT_surfxml_cluster_suffix AX_surfxml_cluster_suffix; #define A_surfxml_cluster_suffix (surfxml_bufferstack + AX_surfxml_cluster_suffix) -AT_surfxml_platform_xmlns_c_route AX_surfxml_platform_xmlns_c_route; -#define A_surfxml_platform_xmlns_c_route (surfxml_bufferstack + AX_surfxml_platform_xmlns_c_route) +AT_surfxml_cluster_power AX_surfxml_cluster_power; +#define A_surfxml_cluster_power (surfxml_bufferstack + AX_surfxml_cluster_power) +AT_surfxml_process_function AX_surfxml_process_function; +#define A_surfxml_process_function (surfxml_bufferstack + AX_surfxml_process_function) AT_surfxml_ASroute_src AX_surfxml_ASroute_src; #define A_surfxml_ASroute_src (surfxml_bufferstack + AX_surfxml_ASroute_src) AT_surfxml_cluster_prefix AX_surfxml_cluster_prefix; @@ -128,90 +142,66 @@ AT_surfxml_link_sharing_policy AX_surfxml_link_sharing_policy; #define A_surfxml_link_sharing_policy AX_surfxml_link_sharing_policy AT_surfxml_random_min AX_surfxml_random_min; #define A_surfxml_random_min (surfxml_bufferstack + AX_surfxml_random_min) +AT_surfxml_bypassRoute_dst AX_surfxml_bypassRoute_dst; +#define A_surfxml_bypassRoute_dst (surfxml_bufferstack + AX_surfxml_bypassRoute_dst) AT_surfxml_link_ctn_id AX_surfxml_link_ctn_id; #define A_surfxml_link_ctn_id (surfxml_bufferstack + AX_surfxml_link_ctn_id) AT_surfxml_process_kill_time AX_surfxml_process_kill_time; #define A_surfxml_process_kill_time (surfxml_bufferstack + AX_surfxml_process_kill_time) +AT_surfxml_host_availability AX_surfxml_host_availability; +#define A_surfxml_host_availability (surfxml_bufferstack + AX_surfxml_host_availability) AT_surfxml_cluster_bb_bw AX_surfxml_cluster_bb_bw; #define A_surfxml_cluster_bb_bw (surfxml_bufferstack + AX_surfxml_cluster_bb_bw) AT_surfxml_argument_value AX_surfxml_argument_value; #define A_surfxml_argument_value (surfxml_bufferstack + AX_surfxml_argument_value) +AT_surfxml_bypassRoute_src AX_surfxml_bypassRoute_src; +#define A_surfxml_bypassRoute_src (surfxml_bufferstack + AX_surfxml_bypassRoute_src) AT_surfxml_link_state AX_surfxml_link_state; #define A_surfxml_link_state AX_surfxml_link_state AT_surfxml_ASroute_gw_src AX_surfxml_ASroute_gw_src; #define A_surfxml_ASroute_gw_src (surfxml_bufferstack + AX_surfxml_ASroute_gw_src) +AT_surfxml_route_src AX_surfxml_route_src; +#define A_surfxml_route_src (surfxml_bufferstack + AX_surfxml_route_src) AT_surfxml_AS_routing AX_surfxml_AS_routing; #define A_surfxml_AS_routing (surfxml_bufferstack + AX_surfxml_AS_routing) AT_surfxml_link_bandwidth AX_surfxml_link_bandwidth; #define A_surfxml_link_bandwidth (surfxml_bufferstack + AX_surfxml_link_bandwidth) +AT_surfxml_bypassRoute_gw_dst AX_surfxml_bypassRoute_gw_dst; +#define A_surfxml_bypassRoute_gw_dst (surfxml_bufferstack + AX_surfxml_bypassRoute_gw_dst) AT_surfxml_cluster_id AX_surfxml_cluster_id; #define A_surfxml_cluster_id (surfxml_bufferstack + AX_surfxml_cluster_id) AT_surfxml_random_mean AX_surfxml_random_mean; #define A_surfxml_random_mean (surfxml_bufferstack + AX_surfxml_random_mean) +AT_surfxml_trace_id AX_surfxml_trace_id; +#define A_surfxml_trace_id (surfxml_bufferstack + AX_surfxml_trace_id) AT_surfxml_cluster_bb_lat AX_surfxml_cluster_bb_lat; #define A_surfxml_cluster_bb_lat (surfxml_bufferstack + AX_surfxml_cluster_bb_lat) AT_surfxml_link_latency AX_surfxml_link_latency; #define A_surfxml_link_latency (surfxml_bufferstack + AX_surfxml_link_latency) +AT_surfxml_cluster_radical AX_surfxml_cluster_radical; +#define A_surfxml_cluster_radical (surfxml_bufferstack + AX_surfxml_cluster_radical) +AT_surfxml_config_id AX_surfxml_config_id; +#define A_surfxml_config_id (surfxml_bufferstack + AX_surfxml_config_id) AT_surfxml_trace_connect_kind AX_surfxml_trace_connect_kind; #define A_surfxml_trace_connect_kind AX_surfxml_trace_connect_kind -AT_surfxml_platform_xmlns_c_link AX_surfxml_platform_xmlns_c_link; -#define A_surfxml_platform_xmlns_c_link (surfxml_bufferstack + AX_surfxml_platform_xmlns_c_link) +AT_surfxml_bypassRoute_gw_src AX_surfxml_bypassRoute_gw_src; +#define A_surfxml_bypassRoute_gw_src (surfxml_bufferstack + AX_surfxml_bypassRoute_gw_src) +AT_surfxml_random_std_deviation AX_surfxml_random_std_deviation; +#define A_surfxml_random_std_deviation (surfxml_bufferstack + AX_surfxml_random_std_deviation) AT_surfxml_link_bandwidth_file AX_surfxml_link_bandwidth_file; #define A_surfxml_link_bandwidth_file (surfxml_bufferstack + AX_surfxml_link_bandwidth_file) AT_surfxml_host_vivaldi AX_surfxml_host_vivaldi; #define A_surfxml_host_vivaldi (surfxml_bufferstack + AX_surfxml_host_vivaldi) -AT_surfxml_random_id AX_surfxml_random_id; -#define A_surfxml_random_id (surfxml_bufferstack + AX_surfxml_random_id) -AT_surfxml_random_max AX_surfxml_random_max; -#define A_surfxml_random_max (surfxml_bufferstack + AX_surfxml_random_max) -AT_surfxml_link_id AX_surfxml_link_id; -#define A_surfxml_link_id (surfxml_bufferstack + AX_surfxml_link_id) -AT_surfxml_process_host AX_surfxml_process_host; -#define A_surfxml_process_host (surfxml_bufferstack + AX_surfxml_process_host) -AT_surfxml_host_availability_file AX_surfxml_host_availability_file; -#define A_surfxml_host_availability_file (surfxml_bufferstack + AX_surfxml_host_availability_file) -AT_surfxml_cluster_lat AX_surfxml_cluster_lat; -#define A_surfxml_cluster_lat (surfxml_bufferstack + AX_surfxml_cluster_lat) -AT_surfxml_trace_periodicity AX_surfxml_trace_periodicity; -#define A_surfxml_trace_periodicity (surfxml_bufferstack + AX_surfxml_trace_periodicity) -AT_surfxml_prop_value AX_surfxml_prop_value; -#define A_surfxml_prop_value (surfxml_bufferstack + AX_surfxml_prop_value) -AT_surfxml_ASroute_dst AX_surfxml_ASroute_dst; -#define A_surfxml_ASroute_dst (surfxml_bufferstack + AX_surfxml_ASroute_dst) -AT_surfxml_link_state_file AX_surfxml_link_state_file; -#define A_surfxml_link_state_file (surfxml_bufferstack + AX_surfxml_link_state_file) -AT_surfxml_trace_connect_trace AX_surfxml_trace_connect_trace; -#define A_surfxml_trace_connect_trace (surfxml_bufferstack + AX_surfxml_trace_connect_trace) -AT_surfxml_cluster_power AX_surfxml_cluster_power; -#define A_surfxml_cluster_power (surfxml_bufferstack + AX_surfxml_cluster_power) -AT_surfxml_process_function AX_surfxml_process_function; -#define A_surfxml_process_function (surfxml_bufferstack + AX_surfxml_process_function) -AT_surfxml_host_max_outgoing_rate AX_surfxml_host_max_outgoing_rate; -#define A_surfxml_host_max_outgoing_rate (surfxml_bufferstack + AX_surfxml_host_max_outgoing_rate) -AT_surfxml_bypassRoute_dst AX_surfxml_bypassRoute_dst; -#define A_surfxml_bypassRoute_dst (surfxml_bufferstack + AX_surfxml_bypassRoute_dst) -AT_surfxml_host_availability AX_surfxml_host_availability; -#define A_surfxml_host_availability (surfxml_bufferstack + AX_surfxml_host_availability) -AT_surfxml_bypassRoute_src AX_surfxml_bypassRoute_src; -#define A_surfxml_bypassRoute_src (surfxml_bufferstack + AX_surfxml_bypassRoute_src) -AT_surfxml_route_src AX_surfxml_route_src; -#define A_surfxml_route_src (surfxml_bufferstack + AX_surfxml_route_src) -AT_surfxml_bypassRoute_gw_dst AX_surfxml_bypassRoute_gw_dst; -#define A_surfxml_bypassRoute_gw_dst (surfxml_bufferstack + AX_surfxml_bypassRoute_gw_dst) -AT_surfxml_trace_id AX_surfxml_trace_id; -#define A_surfxml_trace_id (surfxml_bufferstack + AX_surfxml_trace_id) -AT_surfxml_cluster_radical AX_surfxml_cluster_radical; -#define A_surfxml_cluster_radical (surfxml_bufferstack + AX_surfxml_cluster_radical) -AT_surfxml_random_std_deviation AX_surfxml_random_std_deviation; -#define A_surfxml_random_std_deviation (surfxml_bufferstack + AX_surfxml_random_std_deviation) -AT_surfxml_bypassRoute_gw_src AX_surfxml_bypassRoute_gw_src; -#define A_surfxml_bypassRoute_gw_src (surfxml_bufferstack + AX_surfxml_bypassRoute_gw_src) AT_surfxml_host_state_file AX_surfxml_host_state_file; #define A_surfxml_host_state_file (surfxml_bufferstack + AX_surfxml_host_state_file) +AT_surfxml_random_id AX_surfxml_random_id; +#define A_surfxml_random_id (surfxml_bufferstack + AX_surfxml_random_id) AT_surfxml_route_dst AX_surfxml_route_dst; #define A_surfxml_route_dst (surfxml_bufferstack + AX_surfxml_route_dst) AT_surfxml_cluster_bw AX_surfxml_cluster_bw; #define A_surfxml_cluster_bw (surfxml_bufferstack + AX_surfxml_cluster_bw) +AT_surfxml_random_max AX_surfxml_random_max; +#define A_surfxml_random_max (surfxml_bufferstack + AX_surfxml_random_max) AT_surfxml_platform_version AX_surfxml_platform_version; #define A_surfxml_platform_version (surfxml_bufferstack + AX_surfxml_platform_version) @@ -375,7 +365,7 @@ Literal \'[^'']*\'|\"[^""]*\" * IMPOSSIBLE dummy to permit disabling rules; must be last */ %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA -%x ROOT_surfxml_platform AL_surfxml_platform S_surfxml_platform S_surfxml_platform_1 S_surfxml_platform_2 S_surfxml_platform_3 S_surfxml_platform_4 S_surfxml_platform_5 S_surfxml_platform_6 S_surfxml_platform_7 S_surfxml_platform_8 E_surfxml_platform +%x ROOT_surfxml_platform AL_surfxml_platform S_surfxml_platform S_surfxml_platform_1 S_surfxml_platform_2 S_surfxml_platform_3 S_surfxml_platform_4 S_surfxml_platform_5 S_surfxml_platform_6 E_surfxml_platform %x AL_surfxml_trace IN_trace %x AL_surfxml_random S_surfxml_random S_surfxml_random_1 S_surfxml_random_2 E_surfxml_random %x AL_surfxml_trace_connect E_surfxml_trace_connect @@ -390,6 +380,7 @@ Literal \'[^'']*\'|\"[^""]*\" %x AL_surfxml_bypassRoute S_surfxml_bypassRoute S_surfxml_bypassRoute_1 S_surfxml_bypassRoute_2 E_surfxml_bypassRoute %x AL_surfxml_process S_surfxml_process S_surfxml_process_1 S_surfxml_process_2 E_surfxml_process %x AL_surfxml_argument E_surfxml_argument +%x AL_surfxml_config S_surfxml_config S_surfxml_config_1 S_surfxml_config_2 E_surfxml_config %x AL_surfxml_prop E_surfxml_prop %x IMPOSSIBLE @@ -421,13 +412,7 @@ const char* *surfxml_statenames=NULL; /* FleXML_init */ bnext = inext = 1; surfxml_bufferliteral('\0', &bnext, "0.0"); - surfxml_bufferliteral('\0', &bnext, "http://simgrid.gforge.inria.fr/"); - surfxml_bufferliteral('\0', &bnext, "http://simgrid.gforge.inria.fr/"); - surfxml_bufferliteral('\0', &bnext, "1.0"); - surfxml_bufferliteral('\0', &bnext, "1.0"); - surfxml_bufferliteral('\0', &bnext, "1.0"); surfxml_bufferliteral('\0', &bnext, "1.0"); - surfxml_bufferliteral('\0', &bnext, "-1.0"); surfxml_bufferliteral('\0', &bnext, "0 0 0"); surfxml_bufferliteral('\0', &bnext, "0.0"); surfxml_bufferliteral('\0', &bnext, "-1.0"); @@ -450,8 +435,6 @@ const char* *surfxml_statenames=NULL; surfxml_statenames[S_surfxml_platform_4] = "platform"; surfxml_statenames[S_surfxml_platform_5] = "platform"; surfxml_statenames[S_surfxml_platform_6] = "platform"; - surfxml_statenames[S_surfxml_platform_7] = "platform"; - surfxml_statenames[S_surfxml_platform_8] = "platform"; surfxml_statenames[E_surfxml_platform] = "platform"; surfxml_statenames[AL_surfxml_trace] = NULL; surfxml_statenames[IN_trace] = "trace"; @@ -516,13 +499,18 @@ const char* *surfxml_statenames=NULL; surfxml_statenames[E_surfxml_process] = "process"; surfxml_statenames[AL_surfxml_argument] = NULL; surfxml_statenames[E_surfxml_argument] = "argument"; + surfxml_statenames[AL_surfxml_config] = NULL; + surfxml_statenames[S_surfxml_config] = "config"; + surfxml_statenames[S_surfxml_config_1] = "config"; + surfxml_statenames[S_surfxml_config_2] = "config"; + surfxml_statenames[E_surfxml_config] = "config"; surfxml_statenames[AL_surfxml_prop] = NULL; surfxml_statenames[E_surfxml_prop] = "prop"; } /* COMMENTS and PIs: handled uniformly for efficiency. */ -{ +{ " */ -" is not allowed here."); +" is not allowed here."); "" { LEAVE; STag_surfxml_platform();surfxml_pcdata_ix = 0; ENTER(S_surfxml_platform); } @@ -595,7 +575,7 @@ const char* *surfxml_statenames=NULL; <> FAIL("EOF in attribute list of `platform' element."); } -{ +{ "" { LEAVE; ETag_surfxml_platform(); @@ -609,9 +589,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -736,9 +722,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -799,9 +791,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -850,20 +840,16 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -937,9 +909,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1030,9 +1000,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1073,13 +1041,13 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1152,9 +1118,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1260,9 +1224,9 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1364,13 +1328,13 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); -""" FAIL("Unexpected end-tag `%s': `' expected.",yytext); @@ -1419,7 +1383,7 @@ const char* *surfxml_statenames=NULL; <> FAIL("Premature EOF: `' expected."); } -" is not allowed here."); +" is not allowed here."); "> FAIL("Premature EOF: `' expected."); } +" is not allowed here."); + +"{ + "id"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_surfxml_config_id); + "id"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_surfxml_config_id); + + ">" { + LEAVE; STag_surfxml_config();surfxml_pcdata_ix = 0; ENTER(S_surfxml_config); + } + "/>" { + LEAVE; STag_surfxml_config(); surfxml_pcdata_ix = 0; ETag_surfxml_config(); popbuffer(); /* attribute */ + switch (YY_START) { + case S_surfxml_platform: SET(S_surfxml_platform_1); break; + } + } + . FAIL("Unexpected character `%c' in attribute list of config element.", yytext[0]); + {Name} FAIL("Bad attribute `%s' in `config' element start tag.",yytext); + <> FAIL("EOF in attribute list of `config' element."); +} + +{ + "" { + LEAVE; + ETag_surfxml_config(); + popbuffer(); /* attribute */ + switch (YY_START) { + case S_surfxml_platform: SET(S_surfxml_platform_1); break; + } + } + "" FAIL("Unexpected end-tag `%s': `' expected.",yytext); + . FAIL("Unexpected character `%c': `' expected.",yytext[0]); + <> FAIL("Premature EOF: `' expected."); +} + /* * */ -" is not allowed here."); +" is not allowed here."); -""= 64 KiB)", NULL, surf_network_model_init_SMPI}, + {"Constant", + "Simplistic network model where all communication take a constant time (one second)", + NULL, surf_network_model_init_Constant}, + {"Vivaldi", "Scalable network model using the Vivaldi coordinate ideas", + NULL, surf_network_model_init_Vivaldi}, + {"CM02", + "Realistic network model with lmm_solve and no correction factors", + NULL, surf_network_model_init_CM02}, + {"LV08", + "Realistic network model with lmm_solve and these correction factors: latency*=10.4, bandwidth*=.92, S=8775", + NULL, surf_network_model_init_LegrandVelho}, + {"SMPI", + "Realistic network model with lmm_solve and correction factors on three intervals (< 1KiB, < 64 KiB, >= 64 KiB)", + NULL, surf_network_model_init_SMPI}, #ifdef HAVE_GTNETS - {"GTNets", "Network Pseudo-model using the GTNets simulator instead of an analytic model", NULL, surf_network_model_init_GTNETS}, + {"GTNets", + "Network Pseudo-model using the GTNets simulator instead of an analytic model", + NULL, surf_network_model_init_GTNETS}, #endif - {"Reno", "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, surf_network_model_init_Reno}, - {"Reno2", "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, surf_network_model_init_Reno2}, - {"Vegas", "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, surf_network_model_init_Vegas}, - {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ + {"Reno", + "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, + surf_network_model_init_Reno}, + {"Reno2", + "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, + surf_network_model_init_Reno2}, + {"Vegas", + "Model using lagrange_solve instead of lmm_solve (experts only)", NULL, + surf_network_model_init_Vegas}, + {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ }; s_surf_model_description_t surf_cpu_model_description[] = { - {"Cas01_fullupdate", "CPU classical model time=size/power", NULL, surf_cpu_model_init_Cas01}, - {"Cas01", "Variation of Cas01_fullupdate with partial invalidation optimization of lmm system. Should produce the same values, only faster", NULL, surf_cpu_model_init_Cas01_im}, - {"CpuTI", "Variation of Cas01 with also trace integration. Should produce the same values, only faster if you use availability traces", NULL, surf_cpu_model_init_ti}, - {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ + {"Cas01_fullupdate", "CPU classical model time=size/power", NULL, + surf_cpu_model_init_Cas01}, + {"Cas01", + "Variation of Cas01_fullupdate with partial invalidation optimization of lmm system. Should produce the same values, only faster", + NULL, surf_cpu_model_init_Cas01_im}, + {"CpuTI", + "Variation of Cas01 with also trace integration. Should produce the same values, only faster if you use availability traces", + NULL, surf_cpu_model_init_ti}, + {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ }; s_surf_model_description_t surf_workstation_model_description[] = { - {"CLM03", "Default workstation model, using LV08 and CM02 as network and CPU", NULL, surf_workstation_model_init_CLM03, create_workstations}, - {"compound", "Workstation model allowing you to use other network and CPU models", NULL, surf_workstation_model_init_compound, create_workstations}, - {"ptask_L07", "Workstation model with better parallel task modeling", NULL, surf_workstation_model_init_ptask_L07, NULL}, - {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ + {"CLM03", + "Default workstation model, using LV08 and CM02 as network and CPU", + NULL, surf_workstation_model_init_CLM03, create_workstations}, + {"compound", + "Workstation model allowing you to use other network and CPU models", + NULL, surf_workstation_model_init_compound, create_workstations}, + {"ptask_L07", "Workstation model with better parallel task modeling", + NULL, surf_workstation_model_init_ptask_L07, NULL}, + {NULL, NULL, NULL, NULL} /* this array must be NULL terminated */ }; void update_model_description(s_surf_model_description_t * table, @@ -148,9 +175,11 @@ void update_model_description(s_surf_model_description_t * table, } /** Displays the long description of all registered models, and quit */ -void model_help(const char* category, s_surf_model_description_t * table) { +void model_help(const char *category, s_surf_model_description_t * table) +{ int i; - printf("Long description of the %s models accepted by this simulator:\n",category); + printf("Long description of the %s models accepted by this simulator:\n", + category); for (i = 0; table[i].name; i++) printf(" %s: %s\n", table[i].name, table[i].description); } @@ -168,7 +197,8 @@ int find_model_description(s_surf_model_description_t * table, name_list = strdup(table[0].name); for (i = 1; table[i].name; i++) { name_list = - xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 2); + xbt_realloc(name_list, + strlen(name_list) + strlen(table[i].name) + 2); strcat(name_list, ", "); strcat(name_list, table[i].name); } @@ -210,7 +240,8 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions, for (action = xbt_swag_getNext(action, running_actions->offset); - action; action = xbt_swag_getNext(action, running_actions->offset)) { + action; + action = xbt_swag_getNext(action, running_actions->offset)) { value = lmm_variable_getvalue(VARIABLE(action)); if (value > 0) { if (action->remains > 0) @@ -251,7 +282,7 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_network_gtnets); #endif void surf_init(int *argc, char **argv) -{ +{ /* Connect our log channels: that must be done manually under windows */ XBT_LOG_CONNECT(surf_cpu, surf); XBT_LOG_CONNECT(surf_kernel, surf); @@ -321,7 +352,7 @@ void surf_exit(void) surf_config_finalize(); xbt_dynar_foreach(model_list, iter, model) - model->model_private->finalize(); + model->model_private->finalize(); xbt_dynar_free(&model_list); if (maxmin_system) { @@ -352,20 +383,21 @@ void surf_presolve(void) unsigned int iter; DEBUG0 - ("First Run! Let's \"purge\" events and put models in the right state"); + ("First Run! Let's \"purge\" events and put models in the right state"); while ((next_event_date = tmgr_history_next_date(history)) != -1.0) { if (next_event_date > NOW) break; while ((event = tmgr_history_get_next_event_leq(history, next_event_date, - &value, (void **) &resource))) { + &value, + (void **) &resource))) { resource->model->model_private->update_resource_state(resource, event, value, NOW); } } xbt_dynar_foreach(model_list, iter, model) - model->model_private->update_actions_state(NOW, 0.0); + model->model_private->update_actions_state(NOW, 0.0); } double surf_solve(void) @@ -401,18 +433,21 @@ double surf_solve(void) DEBUG0("Updating models"); while ((event = tmgr_history_get_next_event_leq(history, next_event_date, - &value, (void **) &resource))) { + &value, + (void **) &resource))) { if (resource->model->model_private->resource_used(resource)) { min = next_event_date - NOW; DEBUG1 - ("This event will modify model state. Next event set to %f", min); + ("This event will modify model state. Next event set to %f", + min); } /* update state of model_obj according to new value. Does not touch lmm. It will be modified if needed when updating actions */ DEBUG2("Calling update_resource_state for resource %s with min %lf", resource->model->name, min); - resource->model->model_private->update_resource_state(resource, event, - value, NOW + min); + resource->model->model_private->update_resource_state(resource, + event, value, + NOW + min); } } @@ -427,7 +462,7 @@ double surf_solve(void) NOW = NOW + min; xbt_dynar_foreach(model_list, iter, model) - model->model_private->update_actions_state(NOW, min); + model->model_private->update_actions_state(NOW, min); return min; } diff --git a/src/surf/surf_action.c b/src/surf/surf_action.c index f3768b310e..2c34a4e77e 100644 --- a/src/surf/surf_action.c +++ b/src/surf/surf_action.c @@ -80,7 +80,8 @@ XBT_INLINE void surf_action_free(surf_action_t * action) *action = NULL; } -void surf_action_state_set(surf_action_t action, e_surf_action_state_t state) +void surf_action_state_set(surf_action_t action, + e_surf_action_state_t state) { surf_action_state_t action_state = &(action->model_type->states); XBT_IN2("(%p,%s)", action, surf_action_state_names[state]); diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index dab8332b20..68869a6332 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -33,14 +33,18 @@ static void surf_config_cmd_line(int *argc, char **argv) remove_it = 1; } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) || !strncmp(argv[i], "--help", strlen("--help") + 1)) { - printf("Description of the configuration accepted by this simulator:\n"); + printf + ("Description of the configuration accepted by this simulator:\n"); xbt_cfg_help(_surf_cfg_set); - printf("\nYou can also use --help-models to see the details of all models known by this simulator.\n"); + printf + ("\nYou can also use --help-models to see the details of all models known by this simulator.\n"); exit(0); - } else if (!strncmp(argv[i], "--help-models", strlen("--help-models")+1)) { - model_help("workstation",surf_workstation_model_description); - model_help("CPU",surf_cpu_model_description); - model_help("network",surf_network_model_description); + } else + if (!strncmp + (argv[i], "--help-models", strlen("--help-models") + 1)) { + model_help("workstation", surf_workstation_model_description); + model_help("CPU", surf_cpu_model_description); + model_help("network", surf_network_model_description); exit(0); } if (remove_it) { /*remove this from argv */ @@ -70,8 +74,8 @@ static void _surf_cfg_cb__workstation_model(const char *name, int pos) val = xbt_cfg_get_string(_surf_cfg_set, name); - if (!strcmp(val,"help")) { - model_help("workstation",surf_workstation_model_description); + if (!strcmp(val, "help")) { + model_help("workstation", surf_workstation_model_description); exit(0); } @@ -89,8 +93,8 @@ static void _surf_cfg_cb__cpu_model(const char *name, int pos) val = xbt_cfg_get_string(_surf_cfg_set, name); - if (!strcmp(val,"help")) { - model_help("CPU",surf_cpu_model_description); + if (!strcmp(val, "help")) { + model_help("CPU", surf_cpu_model_description); exit(0); } @@ -108,8 +112,8 @@ static void _surf_cfg_cb__network_model(const char *name, int pos) val = xbt_cfg_get_string(_surf_cfg_set, name); - if (!strcmp(val,"help")) { - model_help("network",surf_network_model_description); + if (!strcmp(val, "help")) { + model_help("network", surf_network_model_description); exit(0); } @@ -119,74 +123,91 @@ static void _surf_cfg_cb__network_model(const char *name, int pos) /* callbacks of the network models values */ -static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) { +static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) +{ sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name); } -static void _surf_cfg_cb__latency_factor(const char *name, int pos) { + +static void _surf_cfg_cb__latency_factor(const char *name, int pos) +{ sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name); } -static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) { + +static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) +{ sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name); } -static void _surf_cfg_cb__weight_S(const char *name, int pos) { + +static void _surf_cfg_cb__weight_S(const char *name, int pos) +{ sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name); } -static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos) { - sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name); + +static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, + int pos) +{ + sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name); } /* callback of the inclusion path */ -static void _surf_cfg_cb__surf_path(const char *name, int pos) { +static void _surf_cfg_cb__surf_path(const char *name, int pos) +{ char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos); xbt_dynar_push(surf_path, &path); } /* callback to decide if we want to use the model-checking */ #include "xbt_modinter.h" -int _surf_do_model_check = 0; /* this variable is used accros the lib */ +int _surf_do_model_check = 0; /* this variable is used accros the lib */ -static void _surf_cfg_cb_model_check(const char *name, int pos) { +static void _surf_cfg_cb_model_check(const char *name, int pos) +{ _surf_do_model_check = 1; /* Tell modules using mallocators that they shouldn't. MC don't like them */ xbt_fifo_preinit(); xbt_dict_preinit(); } -static void _surf_cfg_cb__surf_network_fullduplex(const char *name, int pos) +static void _surf_cfg_cb__surf_network_fullduplex(const char *name, + int pos) { - sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name); + sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name); } #ifdef HAVE_GTNETS -static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){ - sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name); +static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos) +{ + sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name); } -static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){ - sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name); + +static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos) +{ + sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name); } #endif /* create the config set, register what should be and parse the command line*/ void surf_config_init(int *argc, char **argv) { - char *description = xbt_malloc(1024), *p = description; - char *default_value; - double double_default_value; - int default_value_int; - int i; + char *description = xbt_malloc(1024), *p = description; + char *default_value; + double double_default_value; + int default_value_int; + int i; /* Create the configuration support */ if (_surf_init_status == 0) { /* Only create stuff if not already inited */ _surf_init_status = 1; - sprintf(description, "The model to use for the CPU. Possible values: "); + sprintf(description, + "The model to use for the CPU. Possible values: "); p = description; while (*(++p) != '\0'); for (i = 0; surf_cpu_model_description[i].name; i++) - p += - sprintf(p, "%s%s", (i == 0 ? "" : ", "), - surf_cpu_model_description[i].name); - sprintf(p,".\n (use 'help' as a value to see the long description of each model)"); + p += sprintf(p, "%s%s", (i == 0 ? "" : ", "), + surf_cpu_model_description[i].name); + sprintf(p, + ".\n (use 'help' as a value to see the long description of each model)"); default_value = xbt_strdup("Cas01"); xbt_cfg_register(&_surf_cfg_set, "cpu/model", description, xbt_cfgelm_string, @@ -197,10 +218,10 @@ void surf_config_init(int *argc, char **argv) p = description; while (*(++p) != '\0'); for (i = 0; surf_network_model_description[i].name; i++) - p += - sprintf(p, "%s%s", (i == 0 ? "" : ", "), - surf_network_model_description[i].name); - sprintf(p,".\n (use 'help' as a value to see the long description of each model)"); + p += sprintf(p, "%s%s", (i == 0 ? "" : ", "), + surf_network_model_description[i].name); + sprintf(p, + ".\n (use 'help' as a value to see the long description of each model)"); default_value = xbt_strdup("LV08"); xbt_cfg_register(&_surf_cfg_set, "network/model", description, xbt_cfgelm_string, @@ -212,15 +233,15 @@ void surf_config_init(int *argc, char **argv) p = description; while (*(++p) != '\0'); for (i = 0; surf_workstation_model_description[i].name; i++) - p += - sprintf(p, "%s%s", (i == 0 ? "" : ", "), - surf_workstation_model_description[i].name); - sprintf(p,".\n (use 'help' as a value to see the long description of each model)"); + p += sprintf(p, "%s%s", (i == 0 ? "" : ", "), + surf_workstation_model_description[i].name); + sprintf(p, + ".\n (use 'help' as a value to see the long description of each model)"); default_value = xbt_strdup("CLM03"); xbt_cfg_register(&_surf_cfg_set, "workstation/model", description, xbt_cfgelm_string, - &default_value, 1, 1, &_surf_cfg_cb__workstation_model, - NULL); + &default_value, 1, 1, + &_surf_cfg_cb__workstation_model, NULL); xbt_free(description); @@ -231,61 +252,70 @@ void surf_config_init(int *argc, char **argv) xbt_cfg_register(&_surf_cfg_set, "TCP_gamma", "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)", - xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL); + xbt_cfgelm_double, NULL, 1, 1, + _surf_cfg_cb__tcp_gamma, NULL); xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0); /* The parameters of network models */ double_default_value = 1.0; xbt_cfg_register(&_surf_cfg_set, "network/latency_factor", "Correction factor to apply to the provided latency (default value set by network model)", - xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__latency_factor, NULL); + xbt_cfgelm_double, &double_default_value, 1, 1, + _surf_cfg_cb__latency_factor, NULL); double_default_value = 1.0; xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor", "Correction factor to apply to the provided bandwidth (default value set by network model)", - xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__bandwidth_factor, NULL); + xbt_cfgelm_double, &double_default_value, 1, 1, + _surf_cfg_cb__bandwidth_factor, NULL); double_default_value = 0.0; xbt_cfg_register(&_surf_cfg_set, "network/weight_S", "Correction factor to apply to the weight of competing streams(default value set by network model)", - xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__weight_S, NULL); + xbt_cfgelm_double, &double_default_value, 1, 1, + _surf_cfg_cb__weight_S, NULL); /* Inclusion path */ xbt_cfg_register(&_surf_cfg_set, "path", "Lookup path for inclusions in platform and deployment XML files", - xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path, - NULL); + xbt_cfgelm_string, NULL, 0, 0, + _surf_cfg_cb__surf_path, NULL); - default_value_int = 0; + default_value_int = 0; xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update", "Update the constraint set propagating recursively to others constraints", - xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL); + xbt_cfgelm_int, &default_value_int, 0, 1, + _surf_cfg_cb__surf_maxmin_selective_update, NULL); /* do model-check */ default_value_int = 0; xbt_cfg_register(&_surf_cfg_set, "model-check", "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)", - xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb_model_check, NULL); + xbt_cfgelm_int, &default_value_int, 0, 1, + _surf_cfg_cb_model_check, NULL); /* - FIXME: this function is not setting model-check to it's default value because - internally it calls to variable->cb_set that in this case is the function - _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0) - xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */ + FIXME: this function is not setting model-check to it's default value because + internally it calls to variable->cb_set that in this case is the function + _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0) + xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */ default_value_int = 0; xbt_cfg_register(&_surf_cfg_set, "fullduplex", - "Update the constraint set propagating recursively to others constraints", - xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_network_fullduplex, NULL); + "Update the constraint set propagating recursively to others constraints", + xbt_cfgelm_int, &default_value_int, 0, 1, + _surf_cfg_cb__surf_network_fullduplex, NULL); xbt_cfg_set_int(_surf_cfg_set, "fullduplex", default_value_int); #ifdef HAVE_GTNETS xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter", - "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double, - NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL); + "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", + xbt_cfgelm_double, NULL, 1, 1, + _surf_cfg_cb__gtnets_jitter, NULL); xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0); default_value_int = 10; xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed", "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10", - xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL); + xbt_cfgelm_int, &default_value_int, 0, 1, + _surf_cfg_cb__gtnets_jitter_seed, NULL); #endif if (!surf_path) { @@ -323,7 +353,7 @@ void surf_config_models_setup(const char *platform_file) surf_timer_model_init(platform_file); workstation_model_name = - xbt_cfg_get_string(_surf_cfg_set, "workstation/model"); + xbt_cfg_get_string(_surf_cfg_set, "workstation/model"); network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model"); cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model"); @@ -331,52 +361,55 @@ void surf_config_models_setup(const char *platform_file) * we should switch to the "compound" workstation model to correctly dispatch stuff to * the right net/cpu models. */ - if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01")) - && !strcmp(workstation_model_name, "CLM03")){ + if ((strcmp(network_model_name, "LV08") + || strcmp(cpu_model_name, "Cas01")) + && !strcmp(workstation_model_name, "CLM03")) { const char *val = "compound"; - INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)"); - xbt_cfg_set_string(_surf_cfg_set,"workstation/model",val); - workstation_model_name = (char*)"compound"; + INFO0 + ("Switching workstation model to compound since you changed the network and/or cpu model(s)"); + xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val); + workstation_model_name = (char *) "compound"; } DEBUG1("Workstation model: %s", workstation_model_name); workstation_id = - find_model_description(surf_workstation_model_description, - workstation_model_name); + find_model_description(surf_workstation_model_description, + workstation_model_name); if (!strcmp(workstation_model_name, "compound")) { int network_id = -1; int cpu_id = -1; xbt_assert0(cpu_model_name, - "Set a cpu model to use with the 'compound' workstation model"); + "Set a cpu model to use with the 'compound' workstation model"); xbt_assert0(network_model_name, - "Set a network model to use with the 'compound' workstation model"); + "Set a network model to use with the 'compound' workstation model"); network_id = - find_model_description(surf_network_model_description, - network_model_name); + find_model_description(surf_network_model_description, + network_model_name); cpu_id = - find_model_description(surf_cpu_model_description, cpu_model_name); + find_model_description(surf_cpu_model_description, cpu_model_name); surf_cpu_model_description[cpu_id].model_init_preparse(platform_file); - surf_network_model_description[network_id]. - model_init_preparse(platform_file); + surf_network_model_description[network_id].model_init_preparse + (platform_file); } DEBUG0("Call workstation_model_init"); surf_workstation_model_description[workstation_id].model_init_preparse - (platform_file); + (platform_file); } void surf_config_models_create_elms(void) { char *workstation_model_name = - xbt_cfg_get_string(_surf_cfg_set, "workstation/model"); + xbt_cfg_get_string(_surf_cfg_set, "workstation/model"); int workstation_id = - find_model_description(surf_workstation_model_description, - workstation_model_name); - if (surf_workstation_model_description[workstation_id]. - model_init_postparse != NULL) - surf_workstation_model_description[workstation_id].model_init_postparse(); + find_model_description(surf_workstation_model_description, + workstation_model_name); + if (surf_workstation_model_description + [workstation_id].model_init_postparse != NULL) + surf_workstation_model_description[workstation_id].model_init_postparse + (); } diff --git a/src/surf/surf_model.c b/src/surf/surf_model.c index 77134100b1..cfe7d57ace 100644 --- a/src/surf/surf_model.c +++ b/src/surf/surf_model.c @@ -27,13 +27,13 @@ surf_model_t surf_model_init(void) model->model_private = xbt_new0(s_surf_model_private_t, 1); model->states.ready_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.running_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.failed_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.done_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); + xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->resource_set = xbt_dict_new(); model->action_unref = int_die_impossible_paction; @@ -49,6 +49,7 @@ surf_model_t surf_model_init(void) return model; } + /** @brief finalize common datastructures to all models */ void surf_model_exit(surf_model_t model) { @@ -65,5 +66,3 @@ void *surf_model_resource_by_name(surf_model_t model, const char *name) { return xbt_dict_get_or_null(model->resource_set, name); } - - diff --git a/src/surf/surf_model_timer.c b/src/surf/surf_model_timer.c index 5a448d1037..14ee6b2594 100644 --- a/src/surf/surf_model_timer.c +++ b/src/surf/surf_model_timer.c @@ -39,7 +39,8 @@ static command_t command_new(void *fun, void *args) command->args = args; xbt_swag_insert(command, command_pending); command->action = - surf_action_new(sizeof(s_surf_action_timer_t), 0, surf_timer_model, 0); + surf_action_new(sizeof(s_surf_action_timer_t), 0, surf_timer_model, + 0); return command; } @@ -179,9 +180,9 @@ static void surf_timer_model_init_internal(void) surf_timer_model->model_private->resource_used = resource_used; surf_timer_model->model_private->share_resources = share_resources; surf_timer_model->model_private->update_actions_state = - update_actions_state; + update_actions_state; surf_timer_model->model_private->update_resource_state = - update_resource_state; + update_resource_state; surf_timer_model->model_private->finalize = finalize; surf_timer_model->suspend = action_suspend; @@ -193,8 +194,10 @@ static void surf_timer_model_init_internal(void) { s_command_t var; - command_pending = xbt_swag_new(xbt_swag_offset(var, command_set_hookup)); - command_to_run = xbt_swag_new(xbt_swag_offset(var, command_set_hookup)); + command_pending = + xbt_swag_new(xbt_swag_offset(var, command_set_hookup)); + command_to_run = + xbt_swag_new(xbt_swag_offset(var, command_set_hookup)); } empty_trace = tmgr_empty_trace_new(); diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 8f42b3a43a..f3ecc2b894 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -24,8 +24,8 @@ extern double sg_weight_S_parameter; extern int sg_maxmin_selective_update; extern int sg_network_fullduplex; #ifdef HAVE_GTNETS - extern double sg_gtnets_jitter; - extern int sg_gtnets_jitter_seed; +extern double sg_gtnets_jitter; +extern int sg_gtnets_jitter_seed; #endif @@ -49,12 +49,13 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions, void (*solve) (lmm_system_t)); /* Generic functions common to all models */ -e_surf_action_state_t surf_action_state_get(surf_action_t action); /* cannot declare inline since we use a pointer to it */ -double surf_action_get_start_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */ -double surf_action_get_finish_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */ +e_surf_action_state_t surf_action_state_get(surf_action_t action); /* cannot declare inline since we use a pointer to it */ +double surf_action_get_start_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */ +double surf_action_get_finish_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */ void surf_action_free(surf_action_t * action); -void surf_action_state_set(surf_action_t action, e_surf_action_state_t state); -void surf_action_data_set(surf_action_t action, void *data); /* cannot declare inline since we use a pointer to it */ +void surf_action_state_set(surf_action_t action, + e_surf_action_state_t state); +void surf_action_data_set(surf_action_t action, void *data); /* cannot declare inline since we use a pointer to it */ FILE *surf_fopen(const char *name, const char *mode); extern tmgr_history_t history; @@ -88,9 +89,9 @@ int __surf_is_absolute_file_path(const char *file_path); * One link routing list */ typedef struct s_onelink { - char *src; - char *dst; - void *link_ptr; + char *src; + char *dst; + void *link_ptr; } s_onelink_t, *onelink_t; /** @@ -98,82 +99,89 @@ typedef struct s_onelink { */ typedef struct s_model_type { - const char *name; - const char *desc; - void* (*create)(); - void (*load)(); - void (*unload)(); - void (*end)(); + const char *name; + const char *desc; + void *(*create) (); + void (*load) (); + void (*unload) (); + void (*end) (); } s_model_type_t, *model_type_t; -typedef struct s_route { +typedef struct s_route { xbt_dynar_t link_list; } s_route_t, *route_t; typedef struct s_route_limits { - char* src_gateway; - char* dst_gateway; + char *src_gateway; + char *dst_gateway; } s_route_limits_t, *route_limits_t; typedef struct s_route_extended { - s_route_t generic_route; - char* src_gateway; - char* dst_gateway; + s_route_t generic_route; + char *src_gateway; + char *dst_gateway; } s_route_extended_t, *route_extended_t; /* This enum used in the routing structure helps knowing in which situation we are. */ typedef enum { - SURF_ROUTING_NULL = 0, /**< Indefined type */ + SURF_ROUTING_NULL = 0, /**< Indefined type */ SURF_ROUTING_BASE, /**< Base case: use simple link lists for routing */ SURF_ROUTING_RECURSIVE /**< Recursive case: also return gateway informations */ } e_surf_routing_hierarchy_t; typedef enum { - SURF_NETWORK_ELEMENT_NULL = 0, /* NULL */ - SURF_NETWORK_ELEMENT_HOST, /* host type */ - SURF_NETWORK_ELEMENT_ROUTER, /* router type */ - SURF_NETWORK_ELEMENT_AS, /* AS type */ + SURF_NETWORK_ELEMENT_NULL = 0, /* NULL */ + SURF_NETWORK_ELEMENT_HOST, /* host type */ + SURF_NETWORK_ELEMENT_ROUTER, /* router type */ + SURF_NETWORK_ELEMENT_AS, /* AS type */ } e_surf_network_element_type_t; typedef struct s_routing_component *routing_component_t; typedef struct s_routing_component { - model_type_t routing; - e_surf_routing_hierarchy_t hierarchy; - char *name; - struct s_routing_component* routing_father; - xbt_dict_t routing_sons; - route_extended_t (*get_route)(routing_component_t rc, const char* src, const char* dst); - xbt_dynar_t (*get_onelink_routes)(routing_component_t rc); - e_surf_network_element_type_t (*get_network_element_type) (const char *name); - route_extended_t (*get_bypass_route)(routing_component_t rc, const char* src, const char* dst); - void (*finalize)(routing_component_t rc); - void (*set_processing_unit)(routing_component_t rc, const char* name); - void (*set_autonomous_system)(routing_component_t rc, const char* name); - void (*set_route)(routing_component_t rc, const char* src, const char* dst, route_t route); - void (*set_ASroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t route); - void (*set_bypassroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route); + model_type_t routing; + e_surf_routing_hierarchy_t hierarchy; + char *name; + struct s_routing_component *routing_father; + xbt_dict_t routing_sons; + route_extended_t(*get_route) (routing_component_t rc, const char *src, + const char *dst); + xbt_dynar_t(*get_onelink_routes) (routing_component_t rc); + e_surf_network_element_type_t(*get_network_element_type) (const char + *name); + route_extended_t(*get_bypass_route) (routing_component_t rc, + const char *src, const char *dst); + void (*finalize) (routing_component_t rc); + void (*set_processing_unit) (routing_component_t rc, const char *name); + void (*set_autonomous_system) (routing_component_t rc, const char *name); + void (*set_route) (routing_component_t rc, const char *src, + const char *dst, route_t route); + void (*set_ASroute) (routing_component_t rc, const char *src, + const char *dst, route_extended_t route); + void (*set_bypassroute) (routing_component_t rc, const char *src, + const char *dst, route_extended_t e_route); } s_routing_component_t; typedef struct s_network_element_info { - routing_component_t rc_component; - e_surf_network_element_type_t rc_type; + routing_component_t rc_component; + e_surf_network_element_type_t rc_type; } s_network_element_info_t, *network_element_info_t; typedef int *network_element_t; struct s_routing_global { routing_component_t root; - xbt_dict_t where_network_elements; /* char* -> network_element_info_t */ + xbt_dict_t where_network_elements; /* char* -> network_element_info_t */ void *loopback; size_t size_of_link; - xbt_dynar_t (*get_route)(const char* src, const char* dst); - xbt_dynar_t (*get_onelink_routes)(void); - e_surf_network_element_type_t (*get_network_element_type)(const char *name); - void (*finalize)(void); + xbt_dynar_t(*get_route) (const char *src, const char *dst); + xbt_dynar_t(*get_onelink_routes) (void); + e_surf_network_element_type_t(*get_network_element_type) (const char + *name); + void (*finalize) (void); xbt_dynar_t last_route; }; -XBT_PUBLIC(void) routing_model_create(size_t size_of_link,void *loopback); +XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback); /** * Resource protected methods @@ -185,4 +193,4 @@ XBT_PUBLIC(void) surfxml_bufferstack_pop(int new); XBT_PUBLIC_DATA(int) surfxml_bufferstack_size; -#endif /* _SURF_SURF_PRIVATE_H */ +#endif /* _SURF_SURF_PRIVATE_H */ diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index dbfaad90ba..bf91cae7c9 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -10,7 +10,7 @@ #include "gras_config.h" #ifdef HAVE_PCRE_LIB - #include /* regular expresion library */ +#include /* regular expresion library */ #endif #include "surf_private.h" #include "xbt/dynar.h" @@ -19,7 +19,7 @@ #include "xbt/graph.h" #include "xbt/set.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); /* Global vars */ routing_global_t global_routing = NULL; @@ -27,117 +27,147 @@ routing_component_t current_routing = NULL; model_type_t current_routing_model = NULL; /* Prototypes of each model */ -static void* model_full_create(void); /* create structures for full routing model */ -static void model_full_load(void); /* load parse functions for full routing model */ -static void model_full_unload(void); /* unload parse functions for full routing model */ -static void model_full_end(void); /* finalize the creation of full routing model */ +static void *model_full_create(void); /* create structures for full routing model */ +static void model_full_load(void); /* load parse functions for full routing model */ +static void model_full_unload(void); /* unload parse functions for full routing model */ +static void model_full_end(void); /* finalize the creation of full routing model */ -static void* model_floyd_create(void); /* create structures for floyd routing model */ -static void model_floyd_load(void); /* load parse functions for floyd routing model */ -static void model_floyd_unload(void); /* unload parse functions for floyd routing model */ -static void model_floyd_end(void); /* finalize the creation of floyd routing model */ +static void *model_floyd_create(void); /* create structures for floyd routing model */ +static void model_floyd_load(void); /* load parse functions for floyd routing model */ +static void model_floyd_unload(void); /* unload parse functions for floyd routing model */ +static void model_floyd_end(void); /* finalize the creation of floyd routing model */ -static void* model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */ -static void* model_dijkstra_create(void); /* create structures for dijkstra routing model */ -static void* model_dijkstracache_create(void); /* create structures for dijkstracache routing model */ -static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */ -static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */ -static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */ +static void *model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */ +static void *model_dijkstra_create(void); /* create structures for dijkstra routing model */ +static void *model_dijkstracache_create(void); /* create structures for dijkstracache routing model */ +static void model_dijkstra_both_load(void); /* load parse functions for dijkstra routing model */ +static void model_dijkstra_both_unload(void); /* unload parse functions for dijkstra routing model */ +static void model_dijkstra_both_end(void); /* finalize the creation of dijkstra routing model */ -static void* model_rulebased_create(void); /* create structures for rulebased routing model */ -static void model_rulebased_load(void); /* load parse functions for rulebased routing model */ -static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */ -static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */ +static void *model_rulebased_create(void); /* create structures for rulebased routing model */ +static void model_rulebased_load(void); /* load parse functions for rulebased routing model */ +static void model_rulebased_unload(void); /* unload parse functions for rulebased routing model */ +static void model_rulebased_end(void); /* finalize the creation of rulebased routing model */ -static void* model_none_create(void); /* none routing model */ -static void model_none_load(void); /* none routing model */ -static void model_none_unload(void); /* none routing model */ -static void model_none_end(void); /* none routing model */ +static void *model_none_create(void); /* none routing model */ +static void model_none_load(void); /* none routing model */ +static void model_none_unload(void); /* none routing model */ +static void model_none_end(void); /* none routing model */ -static void routing_full_parse_Scluster(void);/*cluster bypass*/ +static void routing_full_parse_Scluster(void); /*cluster bypass */ -static void parse_Sconfig(void);/*config Tag*/ +static void parse_Sconfig(void); /*config Tag */ /* this lines are only for replace use like index in the model table */ typedef enum { - SURF_MODEL_FULL=0, - SURF_MODEL_FLOYD, - SURF_MODEL_DIJKSTRA, - SURF_MODEL_DIJKSTRACACHE, - SURF_MODEL_NONE, + SURF_MODEL_FULL = 0, + SURF_MODEL_FLOYD, + SURF_MODEL_DIJKSTRA, + SURF_MODEL_DIJKSTRACACHE, + SURF_MODEL_NONE, #ifdef HAVE_PCRE_LIB - SURF_MODEL_RULEBASED + SURF_MODEL_RULEBASED #endif } e_routing_types; /* must be finish with null and carefull if change de order */ -struct s_model_type routing_models[] = -{ {"Full", "Full routing data (fast, large memory requirements, fully expressive)", - model_full_create, model_full_load, model_full_unload, model_full_end }, - {"Floyd", "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)", - model_floyd_create, model_floyd_load, model_floyd_unload, model_floyd_end }, - {"Dijkstra", "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)", - model_dijkstra_create ,model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end }, - {"DijkstraCache", "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)", - model_dijkstracache_create, model_dijkstra_both_load, model_dijkstra_both_unload, model_dijkstra_both_end }, - {"none", "No routing (usable with Constant network only)", - model_none_create, model_none_load, model_none_unload, model_none_end }, +struct s_model_type routing_models[] = { {"Full", + "Full routing data (fast, large memory requirements, fully expressive)", + model_full_create, + model_full_load, + model_full_unload, + model_full_end}, +{"Floyd", + "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)", + model_floyd_create, model_floyd_load, model_floyd_unload, + model_floyd_end}, +{"Dijkstra", + "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)", + model_dijkstra_create, model_dijkstra_both_load, + model_dijkstra_both_unload, model_dijkstra_both_end}, +{"DijkstraCache", + "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)", + model_dijkstracache_create, model_dijkstra_both_load, + model_dijkstra_both_unload, model_dijkstra_both_end}, +{"none", "No routing (usable with Constant network only)", + model_none_create, model_none_load, model_none_unload, model_none_end}, #ifdef HAVE_PCRE_LIB - {"RuleBased", "Rule-Based routing data (...)", model_rulebased_create, model_rulebased_load, model_rulebased_unload, model_rulebased_end }, +{"RuleBased", "Rule-Based routing data (...)", model_rulebased_create, + model_rulebased_load, model_rulebased_unload, model_rulebased_end}, #endif - {NULL,NULL,NULL,NULL,NULL,NULL}}; +{NULL, NULL, NULL, NULL, NULL, NULL} +}; /* ************************************************************************** */ /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */ -static void generic_set_processing_unit(routing_component_t rc, const char* name); -static void generic_set_autonomous_system(routing_component_t rc, const char* name); -static void generic_set_route(routing_component_t rc, const char* src, const char* dst, route_t route); -static void generic_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route); -static void generic_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route); +static void generic_set_processing_unit(routing_component_t rc, + const char *name); +static void generic_set_autonomous_system(routing_component_t rc, + const char *name); +static void generic_set_route(routing_component_t rc, const char *src, + const char *dst, route_t route); +static void generic_set_ASroute(routing_component_t rc, const char *src, + const char *dst, route_extended_t e_route); +static void generic_set_bypassroute(routing_component_t rc, + const char *src, const char *dst, + route_extended_t e_route); /* ************************************************************************** */ /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */ -static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc); -static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst); +static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc); +static route_extended_t generic_get_bypassroute(routing_component_t rc, + const char *src, + const char *dst); /* ************************************************************************** */ /* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */ -static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order); +static route_extended_t +generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, + void *data, int order); static void generic_free_route(route_t route); static void generic_free_extended_route(route_extended_t e_route); -static routing_component_t generic_autonomous_system_exist(routing_component_t rc, char* element); -static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element); -static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst); +static routing_component_t +generic_autonomous_system_exist(routing_component_t rc, char *element); +static routing_component_t +generic_processing_units_exist(routing_component_t rc, char *element); +static void generic_src_dst_check(routing_component_t rc, const char *src, + const char *dst); /* ************************************************************************** */ /* **************************** GLOBAL FUNCTIONS **************************** */ - + /* global parse functions */ -static char* src = NULL; /* temporary store the source name of a route */ -static char* dst = NULL; /* temporary store the destination name of a route */ -static char* gw_src = NULL; /* temporary store the gateway source name of a route */ -static char* gw_dst = NULL; /* temporary store the gateway destination name of a route */ -static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */ +static char *src = NULL; /* temporary store the source name of a route */ +static char *dst = NULL; /* temporary store the destination name of a route */ +static char *gw_src = NULL; /* temporary store the gateway source name of a route */ +static char *gw_dst = NULL; /* temporary store the gateway destination name of a route */ +static xbt_dynar_t link_list = NULL; /* temporary store of current list link of a route */ /** * \brief Add a "host" to the network element list */ -static void parse_S_host(char* host_id) { - network_element_info_t info = NULL; - if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,host_id), - "Reading a host, processing unit \"%s\" already exist",host_id); +static void parse_S_host(char *host_id) +{ + network_element_info_t info = NULL; + if (current_routing->hierarchy == SURF_ROUTING_NULL) + current_routing->hierarchy = SURF_ROUTING_BASE; + xbt_assert1(!xbt_dict_get_or_null + (global_routing->where_network_elements, host_id), + "Reading a host, processing unit \"%s\" already exist", + host_id); xbt_assert1(current_routing->set_processing_unit, - "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name); - (*(current_routing->set_processing_unit))(current_routing,host_id); - info = xbt_new0(s_network_element_info_t,1); - info->rc_component=current_routing; - info->rc_type=SURF_NETWORK_ELEMENT_HOST; - xbt_dict_set(global_routing->where_network_elements,host_id,(void*)info,NULL); + "no defined method \"set_processing_unit\" in \"%s\"", + current_routing->name); + (*(current_routing->set_processing_unit)) (current_routing, host_id); + info = xbt_new0(s_network_element_info_t, 1); + info->rc_component = current_routing; + info->rc_type = SURF_NETWORK_ELEMENT_HOST; + xbt_dict_set(global_routing->where_network_elements, host_id, + (void *) info, NULL); } /* @@ -145,7 +175,7 @@ static void parse_S_host(char* host_id) { */ static void parse_S_host_XML(void) { - parse_S_host(A_surfxml_host_id); + parse_S_host(A_surfxml_host_id); } /* @@ -153,8 +183,9 @@ static void parse_S_host_XML(void) */ static void parse_S_host_lua(char *host_id) { - parse_S_host(host_id); + parse_S_host(host_id); } + /* * */ @@ -162,35 +193,46 @@ static void parse_S_host_lua(char *host_id) /** * \brief Add a "router" to the network element list */ -static void parse_S_router(void) { +static void parse_S_router(void) +{ network_element_info_t info = NULL; - if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_router_id), - "Reading a router, processing unit \"%s\" already exist",A_surfxml_router_id); + if (current_routing->hierarchy == SURF_ROUTING_NULL) + current_routing->hierarchy = SURF_ROUTING_BASE; + xbt_assert1(!xbt_dict_get_or_null + (global_routing->where_network_elements, + A_surfxml_router_id), + "Reading a router, processing unit \"%s\" already exist", + A_surfxml_router_id); xbt_assert1(current_routing->set_processing_unit, - "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name); - (*(current_routing->set_processing_unit))(current_routing,A_surfxml_router_id); - info = xbt_new0(s_network_element_info_t,1); - info->rc_component=current_routing; - info->rc_type=SURF_NETWORK_ELEMENT_ROUTER; - xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)info,NULL); - #ifdef HAVE_TRACING - TRACE_surf_host_declaration (A_surfxml_router_id, 0); - #endif + "no defined method \"set_processing_unit\" in \"%s\"", + current_routing->name); + (*(current_routing->set_processing_unit)) (current_routing, + A_surfxml_router_id); + info = xbt_new0(s_network_element_info_t, 1); + info->rc_component = current_routing; + info->rc_type = SURF_NETWORK_ELEMENT_ROUTER; + xbt_dict_set(global_routing->where_network_elements, A_surfxml_router_id, + (void *) info, NULL); +#ifdef HAVE_TRACING + TRACE_surf_host_declaration(A_surfxml_router_id, 0); +#endif } /** * \brief Set the endponints for a route */ -static void parse_S_route_new_and_endpoints(char *src_id,char *dst_id) { - if( src != NULL && dst != NULL && link_list != NULL ) - THROW2(arg_error,0,"Route between %s to %s can not be defined",src_id,dst_id); +static void parse_S_route_new_and_endpoints(char *src_id, char *dst_id) +{ + if (src != NULL && dst != NULL && link_list != NULL) + THROW2(arg_error, 0, "Route between %s to %s can not be defined", + src_id, dst_id); src = src_id; dst = dst_id; - xbt_assert2(strlen(src)>0||strlen(dst)>0, - "Some limits are null in the route between \"%s\" and \"%s\"",src,dst); - link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref); + xbt_assert2(strlen(src) > 0 || strlen(dst) > 0, + "Some limits are null in the route between \"%s\" and \"%s\"", + src, dst); + link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } /** @@ -198,51 +240,62 @@ static void parse_S_route_new_and_endpoints(char *src_id,char *dst_id) { */ static void parse_S_route_new_and_endpoints_XML(void) { - parse_S_route_new_and_endpoints(A_surfxml_route_src,A_surfxml_route_dst); + parse_S_route_new_and_endpoints(A_surfxml_route_src, + A_surfxml_route_dst); } /** * \breif Set the endpoints for a route from lua */ -static void parse_S_route_new_and_endpoints_lua(char *id_src,char *id_dst) +static void parse_S_route_new_and_endpoints_lua(char *id_src, char *id_dst) { - parse_S_route_new_and_endpoints(id_src,id_dst); + parse_S_route_new_and_endpoints(id_src, id_dst); } /** * \brief Set the endponints and gateways for a ASroute */ -static void parse_S_ASroute_new_and_endpoints(void) { - if( src != NULL && dst != NULL && link_list != NULL ) - THROW2(arg_error,0,"Route between %s to %s can not be defined",A_surfxml_ASroute_src,A_surfxml_ASroute_dst); +static void parse_S_ASroute_new_and_endpoints(void) +{ + if (src != NULL && dst != NULL && link_list != NULL) + THROW2(arg_error, 0, "Route between %s to %s can not be defined", + A_surfxml_ASroute_src, A_surfxml_ASroute_dst); src = A_surfxml_ASroute_src; dst = A_surfxml_ASroute_dst; gw_src = A_surfxml_ASroute_gw_src; gw_dst = A_surfxml_ASroute_gw_dst; - xbt_assert2(strlen(src)>0||strlen(dst)>0||strlen(gw_src)>0||strlen(gw_dst)>0, - "Some limits are null in the route between \"%s\" and \"%s\"",src,dst); - link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref); + xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 + || strlen(gw_dst) > 0, + "Some limits are null in the route between \"%s\" and \"%s\"", + src, dst); + link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } /** * \brief Set the endponints for a bypassRoute */ -static void parse_S_bypassRoute_new_and_endpoints(void) { - if( src != NULL && dst != NULL && link_list != NULL ) - THROW2(arg_error,0,"Bypass Route between %s to %s can not be defined",A_surfxml_bypassRoute_src,A_surfxml_bypassRoute_dst); +static void parse_S_bypassRoute_new_and_endpoints(void) +{ + if (src != NULL && dst != NULL && link_list != NULL) + THROW2(arg_error, 0, + "Bypass Route between %s to %s can not be defined", + A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst); src = A_surfxml_bypassRoute_src; dst = A_surfxml_bypassRoute_dst; gw_src = A_surfxml_bypassRoute_gw_src; gw_dst = A_surfxml_bypassRoute_gw_dst; - xbt_assert2(strlen(src)>0||strlen(dst)>0||strlen(gw_src)>0||strlen(gw_dst)>0, - "Some limits are null in the route between \"%s\" and \"%s\"",src,dst); - link_list = xbt_dynar_new(sizeof(char*), &xbt_free_ref); + xbt_assert2(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 + || strlen(gw_dst) > 0, + "Some limits are null in the route between \"%s\" and \"%s\"", + src, dst); + link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); } /** * \brief Set a new link on the actual list of link for a route or ASroute */ -static void parse_E_link_ctn_new_elem(char *link_id) { +static void parse_E_link_ctn_new_elem(char *link_id) +{ char *val; val = xbt_strdup(link_id); xbt_dynar_push(link_list, &val); @@ -254,27 +307,31 @@ static void parse_E_link_ctn_new_elem(char *link_id) { static void parse_E_link_ctn_new_elem_XML(void) { - parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id); + parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id); } /** * \brief Set a new link on the actual list of link for a route or ASroute from lua */ -static void parse_E_link_c_ctn_new_elem_lua(char *link_id) { +static void parse_E_link_c_ctn_new_elem_lua(char *link_id) +{ - parse_E_link_ctn_new_elem(link_id); + parse_E_link_ctn_new_elem(link_id); } /** * \brief Store the route by calling the set_route function of the current routing component */ -static void parse_E_route_store_route(void) { - route_t route = xbt_new0(s_route_t,1); +static void parse_E_route_store_route(void) +{ + route_t route = xbt_new0(s_route_t, 1); route->link_list = link_list; // xbt_assert1(generic_processing_units_exist(current_routing,src),"the \"%s\" processing units gateway does not exist",src); // xbt_assert1(generic_processing_units_exist(current_routing,dst),"the \"%s\" processing units gateway does not exist",dst); - xbt_assert1(current_routing->set_route,"no defined method \"set_route\" in \"%s\"",current_routing->name); - (*(current_routing->set_route))(current_routing,src,dst,route); + xbt_assert1(current_routing->set_route, + "no defined method \"set_route\" in \"%s\"", + current_routing->name); + (*(current_routing->set_route)) (current_routing, src, dst, route); link_list = NULL; src = NULL; dst = NULL; @@ -283,17 +340,20 @@ static void parse_E_route_store_route(void) { /** * \brief Store the ASroute by calling the set_ASroute function of the current routing component */ -static void parse_E_ASroute_store_route(void) { - route_extended_t e_route = xbt_new0(s_route_extended_t,1); +static void parse_E_ASroute_store_route(void) +{ + route_extended_t e_route = xbt_new0(s_route_extended_t, 1); e_route->generic_route.link_list = link_list; e_route->src_gateway = xbt_strdup(gw_src); - e_route->dst_gateway = xbt_strdup(gw_dst); + e_route->dst_gateway = xbt_strdup(gw_dst); // xbt_assert1(generic_autonomous_system_exist(current_routing,src),"the \"%s\" autonomous system does not exist",src); // xbt_assert1(generic_autonomous_system_exist(current_routing,dst),"the \"%s\" autonomous system does not exist",dst); // xbt_assert1(generic_processing_units_exist(current_routing,gw_src),"the \"%s\" processing units gateway does not exist",gw_src); // xbt_assert1(generic_processing_units_exist(current_routing,gw_dst),"the \"%s\" processing units gateway does not exist",gw_dst); - xbt_assert1(current_routing->set_ASroute,"no defined method \"set_ASroute\" in \"%s\"",current_routing->name); - (*(current_routing->set_ASroute))(current_routing,src,dst,e_route); + xbt_assert1(current_routing->set_ASroute, + "no defined method \"set_ASroute\" in \"%s\"", + current_routing->name); + (*(current_routing->set_ASroute)) (current_routing, src, dst, e_route); link_list = NULL; src = NULL; dst = NULL; @@ -304,8 +364,9 @@ static void parse_E_ASroute_store_route(void) { /** * \brief Store the bypass route by calling the set_bypassroute function of the current routing component */ -static void parse_E_bypassRoute_store_route(void) { - route_extended_t e_route = xbt_new0(s_route_extended_t,1); +static void parse_E_bypassRoute_store_route(void) +{ + route_extended_t e_route = xbt_new0(s_route_extended_t, 1); e_route->generic_route.link_list = link_list; e_route->src_gateway = xbt_strdup(gw_src); e_route->dst_gateway = xbt_strdup(gw_dst); @@ -313,8 +374,11 @@ static void parse_E_bypassRoute_store_route(void) { // xbt_assert1(generic_autonomous_system_exist(current_routing,dst),"the \"%s\" autonomous system does not exist",dst); // xbt_assert1(generic_processing_units_exist(current_routing,gw_src),"the \"%s\" processing units gateway does not exist",gw_src); // xbt_assert1(generic_processing_units_exist(current_routing,gw_dst),"the \"%s\" processing units gateway does not exist",gw_dst); - xbt_assert1(current_routing->set_bypassroute,"no defined method \"set_bypassroute\" in \"%s\"",current_routing->name); - (*(current_routing->set_bypassroute))(current_routing,src,dst,e_route); + xbt_assert1(current_routing->set_bypassroute, + "no defined method \"set_bypassroute\" in \"%s\"", + current_routing->name); + (*(current_routing->set_bypassroute)) (current_routing, src, dst, + e_route); link_list = NULL; src = NULL; dst = NULL; @@ -328,58 +392,64 @@ static void parse_E_bypassRoute_store_route(void) { * make the new structure and * set the parsing functions to allows parsing the part of the routing tree */ -static void parse_S_AS(char* AS_id,char* AS_routing) { +static void parse_S_AS(char *AS_id, char *AS_routing) +{ routing_component_t new_routing; model_type_t model = NULL; - char* wanted = AS_routing; + char *wanted = AS_routing; int cpt; /* seach the routing model */ - for (cpt=0;routing_models[cpt].name;cpt++) - if (!strcmp(wanted,routing_models[cpt].name)) - model = &routing_models[cpt]; + for (cpt = 0; routing_models[cpt].name; cpt++) + if (!strcmp(wanted, routing_models[cpt].name)) + model = &routing_models[cpt]; /* if its not exist, error */ - if( model == NULL ) { - fprintf(stderr,"Routing model %s not found. Existing models:\n",wanted); - for (cpt=0;routing_models[cpt].name;cpt++) - if (!strcmp(wanted,routing_models[cpt].name)) - fprintf(stderr," %s: %s\n",routing_models[cpt].name,routing_models[cpt].desc); + if (model == NULL) { + fprintf(stderr, "Routing model %s not found. Existing models:\n", + wanted); + for (cpt = 0; routing_models[cpt].name; cpt++) + if (!strcmp(wanted, routing_models[cpt].name)) + fprintf(stderr, " %s: %s\n", routing_models[cpt].name, + routing_models[cpt].desc); xbt_die(NULL); } /* make a new routing component */ - new_routing = (routing_component_t)(*(model->create))(); + new_routing = (routing_component_t) (*(model->create)) (); new_routing->routing = model; new_routing->hierarchy = SURF_ROUTING_NULL; new_routing->name = xbt_strdup(AS_id); new_routing->routing_sons = xbt_dict_new(); //INFO2("Routing %s for AS %s",A_surfxml_AS_routing,A_surfxml_AS_id); - - if( current_routing == NULL && global_routing->root == NULL ){ - + + if (current_routing == NULL && global_routing->root == NULL) { + /* it is the first one */ new_routing->routing_father = NULL; global_routing->root = new_routing; - - } else if( current_routing != NULL && global_routing->root != NULL ) { - - xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,AS_id), - "The AS \"%s\" already exist",AS_id); - /* it is a part of the tree */ + + } else if (current_routing != NULL && global_routing->root != NULL) { + + xbt_assert1(!xbt_dict_get_or_null + (current_routing->routing_sons, AS_id), + "The AS \"%s\" already exist", AS_id); + /* it is a part of the tree */ new_routing->routing_father = current_routing; /* set the father behavior */ - if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_RECURSIVE; + if (current_routing->hierarchy == SURF_ROUTING_NULL) + current_routing->hierarchy = SURF_ROUTING_RECURSIVE; /* add to the sons dictionary */ - xbt_dict_set(current_routing->routing_sons,AS_id,(void*)new_routing,NULL); + xbt_dict_set(current_routing->routing_sons, AS_id, + (void *) new_routing, NULL); /* add to the father element list */ - (*(current_routing->set_autonomous_system))(current_routing,AS_id); + (*(current_routing->set_autonomous_system)) (current_routing, AS_id); /* unload the prev parse rules */ - (*(current_routing->routing->unload))(); - + (*(current_routing->routing->unload)) (); + } else { - THROW0(arg_error,0,"All defined components must be belong to a AS"); + THROW0(arg_error, 0, "All defined components must be belong to a AS"); } /* set the new parse rules */ - (*(new_routing->routing->load))(); + (*(new_routing->routing->load)) (); /* set the new current component of the tree */ current_routing = new_routing; } @@ -389,15 +459,15 @@ static void parse_S_AS(char* AS_id,char* AS_routing) { */ static void parse_S_AS_XML(void) { - parse_S_AS(A_surfxml_AS_id,A_surfxml_AS_routing); + parse_S_AS(A_surfxml_AS_id, A_surfxml_AS_routing); } /* * define the routing model type of routing component from lua script */ -static void parse_S_AS_lua(char* id,char* mode) +static void parse_S_AS_lua(char *id, char *mode) { - parse_S_AS(id,mode); + parse_S_AS(id, mode); } @@ -407,23 +477,27 @@ static void parse_S_AS_lua(char* id,char* mode) * When you finish to read the routing component, other structures must be created. * the "end" method allow to do that for any routing model type */ -static void parse_E_AS(char *AS_id) { +static void parse_E_AS(char *AS_id) +{ - if( current_routing == NULL ) { - THROW1(arg_error,0,"Close AS(%s), that never open",AS_id); + if (current_routing == NULL) { + THROW1(arg_error, 0, "Close AS(%s), that never open", AS_id); } else { - network_element_info_t info = NULL; - xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,current_routing->name), - "The AS \"%s\" already exist",current_routing->name); - info = xbt_new0(s_network_element_info_t,1); - info->rc_component=current_routing->routing_father; - info->rc_type=SURF_NETWORK_ELEMENT_AS; - xbt_dict_set(global_routing->where_network_elements,current_routing->name,info,NULL); - (*(current_routing->routing->unload))(); - (*(current_routing->routing->end))(); - current_routing = current_routing->routing_father; - if( current_routing != NULL ) - (*(current_routing->routing->load))(); + network_element_info_t info = NULL; + xbt_assert1(!xbt_dict_get_or_null + (global_routing->where_network_elements, + current_routing->name), "The AS \"%s\" already exist", + current_routing->name); + info = xbt_new0(s_network_element_info_t, 1); + info->rc_component = current_routing->routing_father; + info->rc_type = SURF_NETWORK_ELEMENT_AS; + xbt_dict_set(global_routing->where_network_elements, + current_routing->name, info, NULL); + (*(current_routing->routing->unload)) (); + (*(current_routing->routing->end)) (); + current_routing = current_routing->routing_father; + if (current_routing != NULL) + (*(current_routing->routing->load)) (); } } @@ -432,7 +506,7 @@ static void parse_E_AS(char *AS_id) { */ static void parse_E_AS_XML(void) { - parse_E_AS(A_surfxml_AS_id); + parse_E_AS(A_surfxml_AS_id); } /* @@ -440,7 +514,7 @@ static void parse_E_AS_XML(void) */ static void parse_E_AS_lua(char *id) { - parse_E_AS(id); + parse_E_AS(id); } /* Aux Business methods */ @@ -454,73 +528,81 @@ static void parse_E_AS_lua(char *id) * Get the common father of the to processing units, and the first different * father in the chain */ -static xbt_dynar_t elements_father(const char* src,const char* dst) { - - xbt_assert0(src&&dst,"bad parameters for \"elements_father\" method"); - - xbt_dynar_t result = xbt_dynar_new(sizeof(char*), NULL); - +static xbt_dynar_t elements_father(const char *src, const char *dst) +{ + + xbt_assert0(src && dst, "bad parameters for \"elements_father\" method"); + + xbt_dynar_t result = xbt_dynar_new(sizeof(char *), NULL); + routing_component_t src_as, dst_as; int index_src, index_dst, index_father_src, index_father_dst; xbt_dynar_t path_src = NULL; xbt_dynar_t path_dst = NULL; routing_component_t current = NULL; - routing_component_t* current_src = NULL; - routing_component_t* current_dst = NULL; - routing_component_t* father = NULL; - + routing_component_t *current_src = NULL; + routing_component_t *current_dst = NULL; + routing_component_t *father = NULL; + /* (1) find the as where the src and dst are located */ - src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component; - dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component; - xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst); - + src_as = ((network_element_info_t) + xbt_dict_get_or_null(global_routing->where_network_elements, + src))->rc_component; + dst_as = ((network_element_info_t) + xbt_dict_get_or_null(global_routing->where_network_elements, + dst))->rc_component; + xbt_assert2(src_as + && dst_as, + "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, + dst); + /* (2) find the path to the root routing component */ path_src = xbt_dynar_new(sizeof(routing_component_t), NULL); - current = src_as; - while( current != NULL ) { - xbt_dynar_push(path_src,¤t); + current = src_as; + while (current != NULL) { + xbt_dynar_push(path_src, ¤t); current = current->routing_father; } path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL); - current = dst_as; - while( current != NULL ) { - xbt_dynar_push(path_dst,¤t); + current = dst_as; + while (current != NULL) { + xbt_dynar_push(path_dst, ¤t); current = current->routing_father; } - + /* (3) find the common father */ - index_src = (path_src->used)-1; - index_dst = (path_dst->used)-1; - current_src = xbt_dynar_get_ptr(path_src,index_src); - current_dst = xbt_dynar_get_ptr(path_dst,index_dst); - while( index_src >= 0 && index_dst >= 0 && *current_src == *current_dst ) { - current_src = xbt_dynar_get_ptr(path_src,index_src); - current_dst = xbt_dynar_get_ptr(path_dst,index_dst); + index_src = (path_src->used) - 1; + index_dst = (path_dst->used) - 1; + current_src = xbt_dynar_get_ptr(path_src, index_src); + current_dst = xbt_dynar_get_ptr(path_dst, index_dst); + while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) { + current_src = xbt_dynar_get_ptr(path_src, index_src); + current_dst = xbt_dynar_get_ptr(path_dst, index_dst); index_src--; index_dst--; } index_src++; index_dst++; - current_src = xbt_dynar_get_ptr(path_src,index_src); - current_dst = xbt_dynar_get_ptr(path_dst,index_dst); + current_src = xbt_dynar_get_ptr(path_src, index_src); + current_dst = xbt_dynar_get_ptr(path_dst, index_dst); /* (4) they are not in the same routing component, make the path */ - index_father_src = index_src+1; - index_father_dst = index_dst+1; - - if(*current_src==*current_dst) + index_father_src = index_src + 1; + index_father_dst = index_dst + 1; + + if (*current_src == *current_dst) father = current_src; else - father = xbt_dynar_get_ptr(path_src,index_father_src); - + father = xbt_dynar_get_ptr(path_src, index_father_src); + /* (5) result generation */ - xbt_dynar_push(result,father); /* first same the father of src and dst */ - xbt_dynar_push(result,current_src); /* second the first different father of src */ - xbt_dynar_push(result,current_dst); /* three the first different father of dst */ - + xbt_dynar_push(result, father); /* first same the father of src and dst */ + xbt_dynar_push(result, current_src); /* second the first different father of src */ + xbt_dynar_push(result, current_dst); /* three the first different father of dst */ + xbt_dynar_free(&path_src); xbt_dynar_free(&path_dst); - + return result; } @@ -535,76 +617,92 @@ static xbt_dynar_t elements_father(const char* src,const char* dst) { * This fuction is call by "get_route". It allow to walk through the * routing components tree. */ -static route_extended_t _get_route(const char* src,const char* dst) { - - void* link; - unsigned int cpt=0; - - DEBUG2("Solve route \"%s\" to \"%s\"",src,dst); - - xbt_assert0(src&&dst,"bad parameters for \"_get_route\" method"); - - route_extended_t e_route, e_route_cnt, e_route_src=NULL, e_route_dst=NULL; - - xbt_dynar_t elem_father_list = elements_father(src,dst); - - routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t); - routing_component_t src_father = xbt_dynar_get_as(elem_father_list, 1, routing_component_t); - routing_component_t dst_father = xbt_dynar_get_as(elem_father_list, 2, routing_component_t); - - e_route = xbt_new0(s_route_extended_t,1); +static route_extended_t _get_route(const char *src, const char *dst) +{ + + void *link; + unsigned int cpt = 0; + + DEBUG2("Solve route \"%s\" to \"%s\"", src, dst); + + xbt_assert0(src && dst, "bad parameters for \"_get_route\" method"); + + route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst = + NULL; + + xbt_dynar_t elem_father_list = elements_father(src, dst); + + routing_component_t common_father = + xbt_dynar_get_as(elem_father_list, 0, routing_component_t); + routing_component_t src_father = + xbt_dynar_get_as(elem_father_list, 1, routing_component_t); + routing_component_t dst_father = + xbt_dynar_get_as(elem_father_list, 2, routing_component_t); + + e_route = xbt_new0(s_route_extended_t, 1); e_route->src_gateway = NULL; e_route->dst_gateway = NULL; - e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - - if(src_father==dst_father) { /* SURF_ROUTING_BASE */ - - if( strcmp(src,dst) ){ - e_route_cnt = (*(common_father->get_route))(common_father,src,dst); - xbt_assert2(e_route_cnt,"no route between \"%s\" and \"%s\"",src,dst); + e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + + if (src_father == dst_father) { /* SURF_ROUTING_BASE */ + + if (strcmp(src, dst)) { + e_route_cnt = + (*(common_father->get_route)) (common_father, src, dst); + xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", src, + dst); xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) { - xbt_dynar_push(e_route->generic_route.link_list,&link); + xbt_dynar_push(e_route->generic_route.link_list, &link); } generic_free_extended_route(e_route_cnt); } - - } else { /* SURF_ROUTING_RECURSIVE */ + + } else { /* SURF_ROUTING_RECURSIVE */ route_extended_t e_route_bypass = NULL; - - if(common_father->get_bypass_route) - e_route_bypass = (*(common_father->get_bypass_route))(common_father,src,dst); - - if(e_route_bypass) - e_route_cnt = e_route_bypass; - else - e_route_cnt = (*(common_father->get_route))(common_father,src_father->name,dst_father->name); - - xbt_assert2(e_route_cnt,"no route between \"%s\" and \"%s\"",src_father->name,dst_father->name); - xbt_assert2( (e_route_cnt->src_gateway==NULL) == (e_route_cnt->dst_gateway==NULL) , - "bad gateway for route between \"%s\" and \"%s\"",src,dst); + if (common_father->get_bypass_route) + e_route_bypass = + (*(common_father->get_bypass_route)) (common_father, src, dst); - if( src != e_route_cnt->src_gateway ) { - e_route_src = _get_route(src,e_route_cnt->src_gateway); - xbt_assert2(e_route_src,"no route between \"%s\" and \"%s\"",src,e_route_cnt->src_gateway); + if (e_route_bypass) + e_route_cnt = e_route_bypass; + else + e_route_cnt = + (*(common_father->get_route)) (common_father, src_father->name, + dst_father->name); + + xbt_assert2(e_route_cnt, "no route between \"%s\" and \"%s\"", + src_father->name, dst_father->name); + + xbt_assert2((e_route_cnt->src_gateway == NULL) == + (e_route_cnt->dst_gateway == NULL), + "bad gateway for route between \"%s\" and \"%s\"", src, + dst); + + if (src != e_route_cnt->src_gateway) { + e_route_src = _get_route(src, e_route_cnt->src_gateway); + xbt_assert2(e_route_src, "no route between \"%s\" and \"%s\"", src, + e_route_cnt->src_gateway); xbt_dynar_foreach(e_route_src->generic_route.link_list, cpt, link) { - xbt_dynar_push(e_route->generic_route.link_list,&link); + xbt_dynar_push(e_route->generic_route.link_list, &link); } } - + xbt_dynar_foreach(e_route_cnt->generic_route.link_list, cpt, link) { - xbt_dynar_push(e_route->generic_route.link_list,&link); + xbt_dynar_push(e_route->generic_route.link_list, &link); } - - if( e_route_cnt->dst_gateway != dst ) { - e_route_dst = _get_route(e_route_cnt->dst_gateway,dst); - xbt_assert2(e_route_dst,"no route between \"%s\" and \"%s\"",e_route_cnt->dst_gateway,dst); + + if (e_route_cnt->dst_gateway != dst) { + e_route_dst = _get_route(e_route_cnt->dst_gateway, dst); + xbt_assert2(e_route_dst, "no route between \"%s\" and \"%s\"", + e_route_cnt->dst_gateway, dst); xbt_dynar_foreach(e_route_dst->generic_route.link_list, cpt, link) { - xbt_dynar_push(e_route->generic_route.link_list,&link); + xbt_dynar_push(e_route->generic_route.link_list, &link); } } - + e_route->src_gateway = xbt_strdup(e_route_cnt->src_gateway); e_route->dst_gateway = xbt_strdup(e_route_cnt->dst_gateway); @@ -612,10 +710,10 @@ static route_extended_t _get_route(const char* src,const char* dst) { generic_free_extended_route(e_route_cnt); generic_free_extended_route(e_route_dst); } - + xbt_dynar_free(&elem_father_list); - - return e_route; + + return e_route; } /** @@ -627,29 +725,34 @@ static route_extended_t _get_route(const char* src,const char* dst) { * walk through the routing components tree and find a route between hosts * by calling the differents "get_route" functions in each routing component */ -static xbt_dynar_t get_route(const char* src,const char* dst) { - +static xbt_dynar_t get_route(const char *src, const char *dst) +{ + route_extended_t e_route; - xbt_dynar_t elem_father_list = elements_father(src,dst); - routing_component_t common_father = xbt_dynar_get_as(elem_father_list, 0, routing_component_t); - - if(strcmp(src,dst)) - e_route = _get_route(src,dst); + xbt_dynar_t elem_father_list = elements_father(src, dst); + routing_component_t common_father = + xbt_dynar_get_as(elem_father_list, 0, routing_component_t); + + if (strcmp(src, dst)) + e_route = _get_route(src, dst); else - e_route = (*(common_father->get_route))(common_father,src,dst); - - xbt_assert2(e_route,"no route between \"%s\" and \"%s\"",src,dst); - - if(global_routing->last_route) xbt_dynar_free( &(global_routing->last_route) ); + e_route = (*(common_father->get_route)) (common_father, src, dst); + + xbt_assert2(e_route, "no route between \"%s\" and \"%s\"", src, dst); + + if (global_routing->last_route) + xbt_dynar_free(&(global_routing->last_route)); global_routing->last_route = e_route->generic_route.link_list; - - if(e_route->src_gateway) xbt_free(e_route->src_gateway); - if(e_route->dst_gateway) xbt_free(e_route->dst_gateway); - + + if (e_route->src_gateway) + xbt_free(e_route->src_gateway); + if (e_route->dst_gateway) + xbt_free(e_route->dst_gateway); + xbt_free(e_route); xbt_dynar_free(&elem_father_list); - - if( xbt_dynar_length(global_routing->last_route)==0 ) + + if (xbt_dynar_length(global_routing->last_route) == 0) return NULL; else return global_routing->last_route; @@ -663,8 +766,9 @@ static xbt_dynar_t get_route(const char* src,const char* dst) { * This fuction is call by "finalize". It allow to finalize the * AS or routing components. It delete all the structures. */ -static void _finalize(routing_component_t rc) { - if(rc) { +static void _finalize(routing_component_t rc) +{ + if (rc) { xbt_dict_cursor_t cursor = NULL; char *key; routing_component_t elem; @@ -672,11 +776,12 @@ static void _finalize(routing_component_t rc) { _finalize(elem); } xbt_dict_t tmp_sons = rc->routing_sons; - char* tmp_name = rc->name; + char *tmp_name = rc->name; xbt_dict_free(&tmp_sons); xbt_free(tmp_name); - xbt_assert1(rc->finalize,"no defined method \"finalize\" in \"%s\"",current_routing->name); - (*(rc->finalize))(rc); + xbt_assert1(rc->finalize, "no defined method \"finalize\" in \"%s\"", + current_routing->name); + (*(rc->finalize)) (rc); } } @@ -686,8 +791,9 @@ static void _finalize(routing_component_t rc) { * walk through the routing components tree and delete the structures * by calling the differents "finalize" functions in each routing component */ -static void finalize(void) { - /* delete recursibly all the tree */ +static void finalize(void) +{ + /* delete recursibly all the tree */ _finalize(global_routing->root); /* delete "where" dict */ xbt_dict_free(&(global_routing->where_network_elements)); @@ -697,29 +803,28 @@ static void finalize(void) { xbt_free(global_routing); } -static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc) +static xbt_dynar_t recursive_get_onelink_routes(routing_component_t rc) { - xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free); + xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); //adding my one link routes unsigned int cpt; void *link; - xbt_dynar_t onelink_mine = rc->get_onelink_routes (rc); - if (onelink_mine){ + xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc); + if (onelink_mine) { xbt_dynar_foreach(onelink_mine, cpt, link) { - xbt_dynar_push(ret,&link); + xbt_dynar_push(ret, &link); } } - //recursing char *key; - xbt_dict_cursor_t cursor=NULL; + xbt_dict_cursor_t cursor = NULL; routing_component_t rc_child; xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) { - xbt_dynar_t onelink_child = recursive_get_onelink_routes (rc_child); - if (onelink_child){ + xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child); + if (onelink_child) { xbt_dynar_foreach(onelink_child, cpt, link) { - xbt_dynar_push(ret,&link); + xbt_dynar_push(ret, &link); } } } @@ -728,14 +833,15 @@ static xbt_dynar_t recursive_get_onelink_routes (routing_component_t rc) static xbt_dynar_t get_onelink_routes(void) { - return recursive_get_onelink_routes (global_routing->root); + return recursive_get_onelink_routes(global_routing->root); } -static e_surf_network_element_type_t get_network_element_type(const char *name) +static e_surf_network_element_type_t get_network_element_type(const char + *name) { - network_element_info_t rc=NULL; - rc = xbt_dict_get(global_routing->where_network_elements,name); - return rc->rc_type; + network_element_info_t rc = NULL; + rc = xbt_dict_get(global_routing->where_network_elements, name); + return rc->rc_type; } /** @@ -743,10 +849,11 @@ static e_surf_network_element_type_t get_network_element_type(const char *name) * * Make a global routing structure and set all the parsing functions. */ -void routing_model_create(size_t size_of_links, void* loopback) { - +void routing_model_create(size_t size_of_links, void *loopback) +{ + /* config the uniq global routing */ - global_routing = xbt_new0(s_routing_global_t,1); + global_routing = xbt_new0(s_routing_global_t, 1); global_routing->where_network_elements = xbt_dict_new(); global_routing->root = NULL; global_routing->get_route = get_route; @@ -756,7 +863,7 @@ void routing_model_create(size_t size_of_links, void* loopback) { global_routing->loopback = loopback; global_routing->size_of_link = size_of_links; global_routing->last_route = xbt_dynar_new(size_of_links, NULL); - + /* no current routing at moment */ current_routing = NULL; @@ -764,20 +871,28 @@ void routing_model_create(size_t size_of_links, void* loopback) { surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML); surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router); - surfxml_add_callback(STag_surfxml_route_cb_list, &parse_S_route_new_and_endpoints_XML); - surfxml_add_callback(STag_surfxml_ASroute_cb_list, &parse_S_ASroute_new_and_endpoints); - surfxml_add_callback(STag_surfxml_bypassRoute_cb_list, &parse_S_bypassRoute_new_and_endpoints); - - surfxml_add_callback(ETag_surfxml_link_ctn_cb_list, &parse_E_link_ctn_new_elem_XML); - - surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_E_route_store_route); - surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &parse_E_ASroute_store_route); - surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list, &parse_E_bypassRoute_store_route); - + surfxml_add_callback(STag_surfxml_route_cb_list, + &parse_S_route_new_and_endpoints_XML); + surfxml_add_callback(STag_surfxml_ASroute_cb_list, + &parse_S_ASroute_new_and_endpoints); + surfxml_add_callback(STag_surfxml_bypassRoute_cb_list, + &parse_S_bypassRoute_new_and_endpoints); + + surfxml_add_callback(ETag_surfxml_link_ctn_cb_list, + &parse_E_link_ctn_new_elem_XML); + + surfxml_add_callback(ETag_surfxml_route_cb_list, + &parse_E_route_store_route); + surfxml_add_callback(ETag_surfxml_ASroute_cb_list, + &parse_E_ASroute_store_route); + surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list, + &parse_E_bypassRoute_store_route); + surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_S_AS_XML); surfxml_add_callback(ETag_surfxml_AS_cb_list, &parse_E_AS_XML); - surfxml_add_callback(STag_surfxml_cluster_cb_list, &routing_full_parse_Scluster); + surfxml_add_callback(STag_surfxml_cluster_cb_list, + &routing_full_parse_Scluster); surfxml_add_callback(STag_surfxml_config_cb_list, &parse_Sconfig); } @@ -791,40 +906,46 @@ void routing_model_create(size_t size_of_links, void* loopback) { typedef struct { s_routing_component_t generic_routing; - xbt_dict_t parse_routes; /* store data during the parse process */ - xbt_dict_t to_index; /* char* -> network_element_t */ + xbt_dict_t parse_routes; /* store data during the parse process */ + xbt_dict_t to_index; /* char* -> network_element_t */ xbt_dict_t bypassRoutes; route_extended_t *routing_table; -} s_routing_component_full_t,*routing_component_full_t; +} s_routing_component_full_t, *routing_component_full_t; /* Business methods */ static xbt_dynar_t full_get_onelink_routes(routing_component_t rc) { - xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free); + xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - routing_component_full_t routing = (routing_component_full_t)rc; + routing_component_full_t routing = (routing_component_full_t) rc; int table_size = xbt_dict_length(routing->to_index); xbt_dict_cursor_t c1 = NULL, c2 = NULL; char *k1, *d1, *k2, *d2; xbt_dict_foreach(routing->to_index, c1, k1, d1) { - xbt_dict_foreach (routing->to_index, c2, k2, d2) { + xbt_dict_foreach(routing->to_index, c2, k2, d2) { int *src_id = xbt_dict_get_or_null(routing->to_index, k1); int *dst_id = xbt_dict_get_or_null(routing->to_index, k2); - xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst); - route_extended_t route = TO_ROUTE_FULL(*src_id,*dst_id); - if (route){ - if (xbt_dynar_length(route->generic_route.link_list) == 1){ - void *link = *(void**)xbt_dynar_get_ptr(route->generic_route.link_list,0); - onelink_t onelink = xbt_new0 (s_onelink_t, 1); + xbt_assert2(src_id + && dst_id, + "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table", + src, dst); + route_extended_t route = TO_ROUTE_FULL(*src_id, *dst_id); + if (route) { + if (xbt_dynar_length(route->generic_route.link_list) == 1) { + void *link = + *(void **) xbt_dynar_get_ptr(route->generic_route.link_list, + 0); + onelink_t onelink = xbt_new0(s_onelink_t, 1); onelink->link_ptr = link; - if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE){ - onelink->src = xbt_strdup (k1); - onelink->dst = xbt_strdup (k2); - }else if (routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE){ - onelink->src = xbt_strdup (route->src_gateway); - onelink->dst = xbt_strdup (route->dst_gateway); + if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) { + onelink->src = xbt_strdup(k1); + onelink->dst = xbt_strdup(k2); + } else if (routing->generic_routing.hierarchy == + SURF_ROUTING_RECURSIVE) { + onelink->src = xbt_strdup(route->src_gateway); + onelink->dst = xbt_strdup(route->dst_gateway); } - xbt_dynar_push (ret, &onelink); + xbt_dynar_push(ret, &onelink); } } } @@ -832,46 +953,56 @@ static xbt_dynar_t full_get_onelink_routes(routing_component_t rc) return ret; } -static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) { - xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name); - +static route_extended_t full_get_route(routing_component_t rc, + const char *src, const char *dst) +{ + xbt_assert1(rc && src + && dst, + "Invalid params for \"get_route\" function at AS \"%s\"", + rc->name); + /* set utils vars */ - routing_component_full_t routing = (routing_component_full_t)rc; + routing_component_full_t routing = (routing_component_full_t) rc; int table_size = xbt_dict_length(routing->to_index); - - generic_src_dst_check(rc,src,dst); - int *src_id = xbt_dict_get_or_null(routing->to_index,src); - int *dst_id = xbt_dict_get_or_null(routing->to_index,dst); - xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst); + + generic_src_dst_check(rc, src, dst); + int *src_id = xbt_dict_get_or_null(routing->to_index, src); + int *dst_id = xbt_dict_get_or_null(routing->to_index, dst); + xbt_assert2(src_id + && dst_id, + "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table", + src, dst); route_extended_t e_route = NULL; route_extended_t new_e_route = NULL; - void* link; - unsigned int cpt=0; + void *link; + unsigned int cpt = 0; + + e_route = TO_ROUTE_FULL(*src_id, *dst_id); - e_route = TO_ROUTE_FULL(*src_id,*dst_id); - - if(e_route) { - new_e_route = xbt_new0(s_route_extended_t,1); + if (e_route) { + new_e_route = xbt_new0(s_route_extended_t, 1); new_e_route->src_gateway = xbt_strdup(e_route->src_gateway); new_e_route->dst_gateway = xbt_strdup(e_route->dst_gateway); - new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); + new_e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); xbt_dynar_foreach(e_route->generic_route.link_list, cpt, link) { - xbt_dynar_push(new_e_route->generic_route.link_list,&link); + xbt_dynar_push(new_e_route->generic_route.link_list, &link); } } return new_e_route; } -static void full_finalize(routing_component_t rc) { - routing_component_full_t routing = (routing_component_full_t)rc; +static void full_finalize(routing_component_t rc) +{ + routing_component_full_t routing = (routing_component_full_t) rc; int table_size = xbt_dict_length(routing->to_index); - int i,j; + int i, j; if (routing) { /* Delete routing table */ - for (i=0;irouting_table); /* Delete bypass dict */ xbt_dict_free(&routing->bypassRoutes); @@ -884,16 +1015,22 @@ static void full_finalize(routing_component_t rc) { /* Creation routing model functions */ -static void* model_full_create(void) { - routing_component_full_t new_component = xbt_new0(s_routing_component_full_t,1); - new_component->generic_routing.set_processing_unit = generic_set_processing_unit; - new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system; +static void *model_full_create(void) +{ + routing_component_full_t new_component = + xbt_new0(s_routing_component_full_t, 1); + new_component->generic_routing.set_processing_unit = + generic_set_processing_unit; + new_component->generic_routing.set_autonomous_system = + generic_set_autonomous_system; new_component->generic_routing.set_route = generic_set_route; new_component->generic_routing.set_ASroute = generic_set_ASroute; new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = full_get_route; - new_component->generic_routing.get_onelink_routes = full_get_onelink_routes; - new_component->generic_routing.get_bypass_route = generic_get_bypassroute; + new_component->generic_routing.get_onelink_routes = + full_get_onelink_routes; + new_component->generic_routing.get_bypass_route = + generic_get_bypassroute; new_component->generic_routing.finalize = full_finalize; new_component->to_index = xbt_dict_new(); new_component->bypassRoutes = xbt_dict_new(); @@ -901,73 +1038,81 @@ static void* model_full_create(void) { return new_component; } -static void model_full_load(void) { - /* use "surfxml_add_callback" to add a parse function call */ +static void model_full_load(void) +{ + /* use "surfxml_add_callback" to add a parse function call */ } -static void model_full_unload(void) { - /* use "surfxml_del_callback" to remove a parse function call */ +static void model_full_unload(void) +{ + /* use "surfxml_del_callback" to remove a parse function call */ } -static void model_full_end(void) { - +static void model_full_end(void) +{ + char *key, *end; - const char* sep = "#"; + const char *sep = "#"; int src_id, dst_id; unsigned int i, j; route_t route; route_extended_t e_route; - void* data; - + void *data; + xbt_dict_cursor_t cursor = NULL; xbt_dynar_t keys = NULL; - + /* set utils vars */ - routing_component_full_t routing = ((routing_component_full_t)current_routing); + routing_component_full_t routing = + ((routing_component_full_t) current_routing); int table_size = xbt_dict_length(routing->to_index); - + /* Create the routing table */ - routing->routing_table = xbt_new0(route_extended_t, table_size * table_size); - + routing->routing_table = + xbt_new0(route_extended_t, table_size * table_size); + /* Put the routes in position */ xbt_dict_foreach(routing->parse_routes, cursor, key, data) { keys = xbt_str_split_str(key, sep); src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10); dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10); - TO_ROUTE_FULL(src_id,dst_id) = generic_new_extended_route(current_routing->hierarchy,data,1); - xbt_dynar_free(&keys); - } + TO_ROUTE_FULL(src_id, dst_id) = + generic_new_extended_route(current_routing->hierarchy, data, 1); + xbt_dynar_free(&keys); + } - /* delete the parse table */ + /* delete the parse table */ xbt_dict_foreach(routing->parse_routes, cursor, key, data) { - route = (route_t)data; + route = (route_t) data; xbt_dynar_free(&(route->link_list)); xbt_free(data); } - + /* delete parse dict */ xbt_dict_free(&(routing->parse_routes)); /* Add the loopback if needed */ - if(current_routing->hierarchy == SURF_ROUTING_BASE) { + if (current_routing->hierarchy == SURF_ROUTING_BASE) { for (i = 0; i < table_size; i++) { e_route = TO_ROUTE_FULL(i, i); - if(!e_route) { - e_route = xbt_new0(s_route_extended_t,1); + if (!e_route) { + e_route = xbt_new0(s_route_extended_t, 1); e_route->src_gateway = NULL; e_route->dst_gateway = NULL; - e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback); + e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + xbt_dynar_push(e_route->generic_route.link_list, + &global_routing->loopback); TO_ROUTE_FULL(i, i) = e_route; } } } /* Shrink the dynar routes (save unused slots) */ - for (i=0;igeneric_route.link_list,0); + for (i = 0; i < table_size; i++) + for (j = 0; j < table_size; j++) + if (TO_ROUTE_FULL(i, j)) + xbt_dynar_shrink(TO_ROUTE_FULL(i, j)->generic_route.link_list, 0); } /* ************************************************************************** */ @@ -986,37 +1131,41 @@ typedef struct { route_extended_t *link_table; /* char* -> int* */ xbt_dict_t to_index; xbt_dict_t bypassRoutes; - /* store data during the parse process */ - xbt_dict_t parse_routes; -} s_routing_component_floyd_t,*routing_component_floyd_t; + /* store data during the parse process */ + xbt_dict_t parse_routes; +} s_routing_component_floyd_t, *routing_component_floyd_t; -static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst); +static route_extended_t floyd_get_route(routing_component_t rc, + const char *src, const char *dst); /* Business methods */ static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc) { - xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free); + xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - routing_component_floyd_t routing = (routing_component_floyd_t)rc; + routing_component_floyd_t routing = (routing_component_floyd_t) rc; //int table_size = xbt_dict_length(routing->to_index); xbt_dict_cursor_t c1 = NULL, c2 = NULL; char *k1, *d1, *k2, *d2; xbt_dict_foreach(routing->to_index, c1, k1, d1) { - xbt_dict_foreach (routing->to_index, c2, k2, d2) { - route_extended_t route = floyd_get_route (rc, k1, k2); - if (route){ - if (xbt_dynar_length(route->generic_route.link_list) == 1){ - void *link = *(void**)xbt_dynar_get_ptr(route->generic_route.link_list,0); - onelink_t onelink = xbt_new0 (s_onelink_t, 1); + xbt_dict_foreach(routing->to_index, c2, k2, d2) { + route_extended_t route = floyd_get_route(rc, k1, k2); + if (route) { + if (xbt_dynar_length(route->generic_route.link_list) == 1) { + void *link = + *(void **) xbt_dynar_get_ptr(route->generic_route.link_list, + 0); + onelink_t onelink = xbt_new0(s_onelink_t, 1); onelink->link_ptr = link; - if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE){ - onelink->src = xbt_strdup (k1); - onelink->dst = xbt_strdup (k2); - }else if (routing->generic_routing.hierarchy == SURF_ROUTING_RECURSIVE){ - onelink->src = xbt_strdup (route->src_gateway); - onelink->dst = xbt_strdup (route->dst_gateway); + if (routing->generic_routing.hierarchy == SURF_ROUTING_BASE) { + onelink->src = xbt_strdup(k1); + onelink->dst = xbt_strdup(k2); + } else if (routing->generic_routing.hierarchy == + SURF_ROUTING_RECURSIVE) { + onelink->src = xbt_strdup(route->src_gateway); + onelink->dst = xbt_strdup(route->dst_gateway); } - xbt_dynar_push (ret, &onelink); + xbt_dynar_push(ret, &onelink); } } } @@ -1024,85 +1173,104 @@ static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc) return ret; } -static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) { - xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name); - +static route_extended_t floyd_get_route(routing_component_t rc, + const char *src, const char *dst) +{ + xbt_assert1(rc && src + && dst, + "Invalid params for \"get_route\" function at AS \"%s\"", + rc->name); + /* set utils vars */ routing_component_floyd_t routing = (routing_component_floyd_t) rc; int table_size = xbt_dict_length(routing->to_index); - - generic_src_dst_check(rc,src,dst); - int *src_id = xbt_dict_get_or_null(routing->to_index,src); - int *dst_id = xbt_dict_get_or_null(routing->to_index,dst); - xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst); - + + generic_src_dst_check(rc, src, dst); + int *src_id = xbt_dict_get_or_null(routing->to_index, src); + int *dst_id = xbt_dict_get_or_null(routing->to_index, dst); + xbt_assert2(src_id + && dst_id, + "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table", + src, dst); + /* create a result route */ - route_extended_t new_e_route = xbt_new0(s_route_extended_t,1); - new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); + route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1); + new_e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); new_e_route->src_gateway = NULL; new_e_route->dst_gateway = NULL; - + int first = 1; int pred = *dst_id; int prev_pred = 0; - char *gw_src=NULL,*gw_dst=NULL, *prev_gw_src,*prev_gw_dst, *first_gw=NULL; + char *gw_src = NULL, *gw_dst = + NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL; unsigned int cpt; - void* link; + void *link; xbt_dynar_t links; - + do { prev_pred = pred; pred = TO_FLOYD_PRED(*src_id, pred); - if(pred == -1) /* if no pred in route -> no route to host */ - break; - xbt_assert2(TO_FLOYD_LINK(pred,prev_pred),"Invalid link for the route between \"%s\" or \"%s\"", src, dst); - + if (pred == -1) /* if no pred in route -> no route to host */ + break; + xbt_assert2(TO_FLOYD_LINK(pred, prev_pred), + "Invalid link for the route between \"%s\" or \"%s\"", src, + dst); + prev_gw_src = gw_src; prev_gw_dst = gw_dst; - - route_extended_t e_route = TO_FLOYD_LINK(pred,prev_pred); + + route_extended_t e_route = TO_FLOYD_LINK(pred, prev_pred); gw_src = e_route->src_gateway; gw_dst = e_route->dst_gateway; - - if(first) first_gw = gw_dst; - - if(rc->hierarchy == SURF_ROUTING_RECURSIVE && !first && strcmp(gw_dst,prev_gw_src)) { - xbt_dynar_t e_route_as_to_as = (*(global_routing->get_route))(gw_dst,prev_gw_src); - xbt_assert2(e_route_as_to_as,"no route between \"%s\" and \"%s\"",gw_dst,prev_gw_src); + + if (first) + first_gw = gw_dst; + + if (rc->hierarchy == SURF_ROUTING_RECURSIVE && !first + && strcmp(gw_dst, prev_gw_src)) { + xbt_dynar_t e_route_as_to_as = + (*(global_routing->get_route)) (gw_dst, prev_gw_src); + xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"", + gw_dst, prev_gw_src); links = e_route_as_to_as; int pos = 0; xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_insert_at(new_e_route->generic_route.link_list,pos,&link); + xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos, + &link); pos++; } } - + links = e_route->generic_route.link_list; xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_unshift(new_e_route->generic_route.link_list,&link); + xbt_dynar_unshift(new_e_route->generic_route.link_list, &link); } - first=0; - - } while(pred != *src_id); - xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")", *src_id, *dst_id,src,dst); - - if(rc->hierarchy == SURF_ROUTING_RECURSIVE) { + first = 0; + + } while (pred != *src_id); + xbt_assert4(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")", + *src_id, *dst_id, src, dst); + + if (rc->hierarchy == SURF_ROUTING_RECURSIVE) { new_e_route->src_gateway = xbt_strdup(gw_src); new_e_route->dst_gateway = xbt_strdup(first_gw); } - + return new_e_route; } -static void floyd_finalize(routing_component_t rc) { - routing_component_floyd_t routing = (routing_component_floyd_t)rc; - int i,j,table_size; +static void floyd_finalize(routing_component_t rc) +{ + routing_component_floyd_t routing = (routing_component_floyd_t) rc; + int i, j, table_size; if (routing) { table_size = xbt_dict_length(routing->to_index); /* Delete link_table */ - for (i=0;ilink_table); /* Delete bypass dict */ xbt_dict_free(&routing->bypassRoutes); @@ -1115,16 +1283,22 @@ static void floyd_finalize(routing_component_t rc) { } } -static void* model_floyd_create(void) { - routing_component_floyd_t new_component = xbt_new0(s_routing_component_floyd_t,1); - new_component->generic_routing.set_processing_unit = generic_set_processing_unit; - new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system; +static void *model_floyd_create(void) +{ + routing_component_floyd_t new_component = + xbt_new0(s_routing_component_floyd_t, 1); + new_component->generic_routing.set_processing_unit = + generic_set_processing_unit; + new_component->generic_routing.set_autonomous_system = + generic_set_autonomous_system; new_component->generic_routing.set_route = generic_set_route; new_component->generic_routing.set_ASroute = generic_set_ASroute; new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = floyd_get_route; - new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes; - new_component->generic_routing.get_bypass_route = generic_get_bypassroute; + new_component->generic_routing.get_onelink_routes = + floyd_get_onelink_routes; + new_component->generic_routing.get_bypass_route = + generic_get_bypassroute; new_component->generic_routing.finalize = floyd_finalize; new_component->to_index = xbt_dict_new(); new_component->bypassRoutes = xbt_dict_new(); @@ -1132,91 +1306,100 @@ static void* model_floyd_create(void) { return new_component; } -static void model_floyd_load(void) { - /* use "surfxml_add_callback" to add a parse function call */ +static void model_floyd_load(void) +{ + /* use "surfxml_add_callback" to add a parse function call */ } -static void model_floyd_unload(void) { - /* use "surfxml_del_callback" to remove a parse function call */ +static void model_floyd_unload(void) +{ + /* use "surfxml_del_callback" to remove a parse function call */ } -static void model_floyd_end(void) { - - routing_component_floyd_t routing = ((routing_component_floyd_t)current_routing); +static void model_floyd_end(void) +{ + + routing_component_floyd_t routing = + ((routing_component_floyd_t) current_routing); xbt_dict_cursor_t cursor = NULL; - double * cost_table; - char *key,*data, *end; + double *cost_table; + char *key, *data, *end; const char *sep = "#"; xbt_dynar_t keys; int src_id, dst_id; - unsigned int i,j,a,b,c; + unsigned int i, j, a, b, c; /* set the size of inicial table */ int table_size = xbt_dict_length(routing->to_index); - + /* Create Cost, Predecessor and Link tables */ - cost_table = xbt_new0(double, table_size*table_size); /* link cost from host to host */ - routing->predecessor_table = xbt_new0(int, table_size*table_size); /* predecessor host numbers */ - routing->link_table = xbt_new0(route_extended_t, table_size*table_size); /* actual link between src and dst */ - - /* Initialize costs and predecessors*/ - for(i = 0; ipredecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */ + routing->link_table = xbt_new0(route_extended_t, table_size * table_size); /* actual link between src and dst */ + + /* Initialize costs and predecessors */ + for (i = 0; i < table_size; i++) + for (j = 0; j < table_size; j++) { + TO_FLOYD_COST(i, j) = DBL_MAX; + TO_FLOYD_PRED(i, j) = -1; + TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */ } - /* Put the routes in position */ + /* Put the routes in position */ xbt_dict_foreach(routing->parse_routes, cursor, key, data) { keys = xbt_str_split_str(key, sep); src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10); dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10); - TO_FLOYD_LINK(src_id,dst_id) = generic_new_extended_route(current_routing->hierarchy,data,0); - TO_FLOYD_PRED(src_id,dst_id) = src_id; + TO_FLOYD_LINK(src_id, dst_id) = + generic_new_extended_route(current_routing->hierarchy, data, 0); + TO_FLOYD_PRED(src_id, dst_id) = src_id; /* set link cost */ - TO_FLOYD_COST(src_id,dst_id) = ((TO_FLOYD_LINK(src_id,dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */ + TO_FLOYD_COST(src_id, dst_id) = ((TO_FLOYD_LINK(src_id, dst_id))->generic_route.link_list)->used; /* count of links, old model assume 1 */ xbt_dynar_free(&keys); } /* Add the loopback if needed */ - if(current_routing->hierarchy == SURF_ROUTING_BASE) { + if (current_routing->hierarchy == SURF_ROUTING_BASE) { for (i = 0; i < table_size; i++) { route_extended_t e_route = TO_FLOYD_LINK(i, i); - if(!e_route) { - e_route = xbt_new0(s_route_extended_t,1); + if (!e_route) { + e_route = xbt_new0(s_route_extended_t, 1); e_route->src_gateway = NULL; e_route->dst_gateway = NULL; - e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback); - TO_FLOYD_LINK(i,i) = e_route; - TO_FLOYD_PRED(i,i) = i; - TO_FLOYD_COST(i,i) = 1; + e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + xbt_dynar_push(e_route->generic_route.link_list, + &global_routing->loopback); + TO_FLOYD_LINK(i, i) = e_route; + TO_FLOYD_PRED(i, i) = i; + TO_FLOYD_COST(i, i) = 1; } } } /* Calculate path costs */ - for(c=0;cparse_routes, cursor, key, data) { - route_t route = (route_t)data; + route_t route = (route_t) data; xbt_dynar_free(&(route->link_list)); xbt_free(data); } - + /* delete parse dict */ xbt_dict_free(&(routing->parse_routes)); @@ -1231,58 +1414,65 @@ typedef struct { s_routing_component_t generic_routing; xbt_dict_t to_index; xbt_dict_t bypassRoutes; - xbt_graph_t route_graph; /* xbt_graph */ - xbt_dict_t graph_node_map; /* map */ - xbt_dict_t route_cache; /* use in cache mode */ + xbt_graph_t route_graph; /* xbt_graph */ + xbt_dict_t graph_node_map; /* map */ + xbt_dict_t route_cache; /* use in cache mode */ int cached; xbt_dict_t parse_routes; -} s_routing_component_dijkstra_t,*routing_component_dijkstra_t; +} s_routing_component_dijkstra_t, *routing_component_dijkstra_t; typedef struct graph_node_data { - int id; - int graph_id; /* used for caching internal graph id's */ -} s_graph_node_data_t, * graph_node_data_t; + int id; + int graph_id; /* used for caching internal graph id's */ +} s_graph_node_data_t, *graph_node_data_t; typedef struct graph_node_map_element { xbt_node_t node; -} s_graph_node_map_element_t, * graph_node_map_element_t; +} s_graph_node_map_element_t, *graph_node_map_element_t; typedef struct route_cache_element { - int * pred_arr; + int *pred_arr; int size; -} s_route_cache_element_t, * route_cache_element_t; +} s_route_cache_element_t, *route_cache_element_t; /* Free functions */ -static void route_cache_elem_free(void *e) { - route_cache_element_t elm=(route_cache_element_t)e; +static void route_cache_elem_free(void *e) +{ + route_cache_element_t elm = (route_cache_element_t) e; if (elm) { xbt_free(elm->pred_arr); xbt_free(elm); } } -static void graph_node_map_elem_free(void *e) { - graph_node_map_element_t elm = (graph_node_map_element_t)e; - if(elm) { +static void graph_node_map_elem_free(void *e) +{ + graph_node_map_element_t elm = (graph_node_map_element_t) e; + if (elm) { xbt_free(elm); } } -static void graph_edge_data_free(void *e) { - route_extended_t e_route = (route_extended_t)e; - if(e_route) { +static void graph_edge_data_free(void *e) +{ + route_extended_t e_route = (route_extended_t) e; + if (e_route) { xbt_dynar_free(&(e_route->generic_route.link_list)); - if(e_route->src_gateway) xbt_free(e_route->src_gateway); - if(e_route->dst_gateway) xbt_free(e_route->dst_gateway); + if (e_route->src_gateway) + xbt_free(e_route->src_gateway); + if (e_route->dst_gateway) + xbt_free(e_route->dst_gateway); xbt_free(e_route); } } /* Utility functions */ -static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc, int id, int graph_id) { +static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc, + int id, int graph_id) +{ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; xbt_node_t node = NULL; graph_node_data_t data = NULL; @@ -1295,43 +1485,57 @@ static xbt_node_t route_graph_new_node(routing_component_dijkstra_t rc, int id, elm = xbt_new0(struct graph_node_map_element, 1); elm->node = node; - xbt_dict_set_ext(routing->graph_node_map, (char*)(&id), sizeof(int), (xbt_set_elm_t)elm, &graph_node_map_elem_free); + xbt_dict_set_ext(routing->graph_node_map, (char *) (&id), sizeof(int), + (xbt_set_elm_t) elm, &graph_node_map_elem_free); return node; } - -static graph_node_map_element_t graph_node_map_search(routing_component_dijkstra_t rc, int id) { + +static graph_node_map_element_t +graph_node_map_search(routing_component_dijkstra_t rc, int id) +{ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; - graph_node_map_element_t elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&id), sizeof(int)); + graph_node_map_element_t elm = (graph_node_map_element_t) + xbt_dict_get_or_null_ext(routing->graph_node_map, + (char *) (&id), + sizeof(int)); return elm; } /* Parsing */ -static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id, int dst_id, route_extended_t e_route ) { +static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id, + int dst_id, route_extended_t e_route) +{ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; xbt_node_t src = NULL; xbt_node_t dst = NULL; - graph_node_map_element_t src_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&src_id), sizeof(int)); - graph_node_map_element_t dst_elm = (graph_node_map_element_t)xbt_dict_get_or_null_ext(routing->graph_node_map, (char*)(&dst_id), sizeof(int)); - - if(src_elm) + graph_node_map_element_t src_elm = (graph_node_map_element_t) + xbt_dict_get_or_null_ext(routing->graph_node_map, + (char *) (&src_id), + sizeof(int)); + graph_node_map_element_t dst_elm = (graph_node_map_element_t) + xbt_dict_get_or_null_ext(routing->graph_node_map, + (char *) (&dst_id), + sizeof(int)); + + if (src_elm) src = src_elm->node; - if(dst_elm) + if (dst_elm) dst = dst_elm->node; /* add nodes if they don't exist in the graph */ - if(src_id == dst_id && src == NULL && dst == NULL) { - src = route_graph_new_node(rc,src_id, -1); + if (src_id == dst_id && src == NULL && dst == NULL) { + src = route_graph_new_node(rc, src_id, -1); dst = src; } else { - if(src == NULL) { - src = route_graph_new_node(rc,src_id, -1); + if (src == NULL) { + src = route_graph_new_node(rc, src_id, -1); } - if(dst == NULL) { - dst = route_graph_new_node(rc,dst_id, -1); + if (dst == NULL) { + dst = route_graph_new_node(rc, dst_id, -1); } } @@ -1339,7 +1543,8 @@ static void route_new_dijkstra(routing_component_dijkstra_t rc, int src_id, int xbt_graph_new_edge(routing->route_graph, src, dst, e_route); } -static void add_loopback_dijkstra(routing_component_dijkstra_t rc) { +static void add_loopback_dijkstra(routing_component_dijkstra_t rc) +{ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); @@ -1347,25 +1552,27 @@ static void add_loopback_dijkstra(routing_component_dijkstra_t rc) { xbt_node_t node = NULL; unsigned int cursor2; xbt_dynar_foreach(nodes, cursor2, node) { - xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node); + xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node); xbt_edge_t edge = NULL; unsigned int cursor; int found = 0; xbt_dynar_foreach(out_edges, cursor, edge) { xbt_node_t other_node = xbt_graph_edge_get_target(edge); - if(other_node == node) { + if (other_node == node) { found = 1; break; } } - if(!found) { - route_extended_t e_route = xbt_new0(s_route_extended_t,1); + if (!found) { + route_extended_t e_route = xbt_new0(s_route_extended_t, 1); e_route->src_gateway = NULL; e_route->dst_gateway = NULL; - e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); - xbt_dynar_push(e_route->generic_route.link_list,&global_routing->loopback); + e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + xbt_dynar_push(e_route->generic_route.link_list, + &global_routing->loopback); xbt_graph_new_edge(routing->route_graph, node, node, e_route); } } @@ -1377,84 +1584,104 @@ static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc) xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet"); } -static route_extended_t dijkstra_get_route(routing_component_t rc, const char* src,const char* dst) { - xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name); - +static route_extended_t dijkstra_get_route(routing_component_t rc, + const char *src, + const char *dst) +{ + xbt_assert1(rc && src + && dst, + "Invalid params for \"get_route\" function at AS \"%s\"", + rc->name); + /* set utils vars */ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; - - generic_src_dst_check(rc,src,dst); - int *src_id = xbt_dict_get_or_null(routing->to_index,src); - int *dst_id = xbt_dict_get_or_null(routing->to_index,dst); - xbt_assert2(src_id && dst_id, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst); - + + generic_src_dst_check(rc, src, dst); + int *src_id = xbt_dict_get_or_null(routing->to_index, src); + int *dst_id = xbt_dict_get_or_null(routing->to_index, dst); + xbt_assert2(src_id + && dst_id, + "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table", + src, dst); + /* create a result route */ - route_extended_t new_e_route = xbt_new0(s_route_extended_t,1); - new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); + route_extended_t new_e_route = xbt_new0(s_route_extended_t, 1); + new_e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); new_e_route->src_gateway = NULL; new_e_route->dst_gateway = NULL; - + int *pred_arr = NULL; int src_node_id = 0; int dst_node_id = 0; - int * nodeid = NULL; + int *nodeid = NULL; int v; route_extended_t e_route; int size = 0; unsigned int cpt; - void* link; + void *link; xbt_dynar_t links = NULL; route_cache_element_t elm = NULL; xbt_dynar_t nodes = xbt_graph_get_nodes(routing->route_graph); - + /* Use the graph_node id mapping set to quickly find the nodes */ - graph_node_map_element_t src_elm = graph_node_map_search(routing,*src_id); - graph_node_map_element_t dst_elm = graph_node_map_search(routing,*dst_id); - xbt_assert2(src_elm != NULL && dst_elm != NULL, "src %d or dst %d does not exist", *src_id, *dst_id); - src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id; - dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id; - - /* if the src and dst are the same */ /* fixed, missing in the previous version */ - if( src_node_id == dst_node_id ) { - + graph_node_map_element_t src_elm = + graph_node_map_search(routing, *src_id); + graph_node_map_element_t dst_elm = + graph_node_map_search(routing, *dst_id); + xbt_assert2(src_elm != NULL + && dst_elm != NULL, "src %d or dst %d does not exist", + *src_id, *dst_id); + src_node_id = ((graph_node_data_t) + xbt_graph_node_get_data(src_elm->node))->graph_id; + dst_node_id = ((graph_node_data_t) + xbt_graph_node_get_data(dst_elm->node))->graph_id; + + /* if the src and dst are the same *//* fixed, missing in the previous version */ + if (src_node_id == dst_node_id) { + xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t); xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t); - xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v); + xbt_edge_t edge = + xbt_graph_get_edge(routing->route_graph, node_s_v, node_e_v); + + xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, + *dst_id); - xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, *dst_id); - - e_route = (route_extended_t)xbt_graph_edge_get_data(edge); + e_route = (route_extended_t) xbt_graph_edge_get_data(edge); links = e_route->generic_route.link_list; xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_unshift(new_e_route->generic_route.link_list,&link); + xbt_dynar_unshift(new_e_route->generic_route.link_list, &link); } - + return new_e_route; } - - if(routing->cached) { + + if (routing->cached) { /*check if there is a cached predecessor list avail */ - elm = (route_cache_element_t)xbt_dict_get_or_null_ext(routing->route_cache, (char*)(&src_id), sizeof(int)); + elm = (route_cache_element_t) + xbt_dict_get_or_null_ext(routing->route_cache, (char *) (&src_id), + sizeof(int)); } - if(elm) { /* cached mode and cache hit */ + if (elm) { /* cached mode and cache hit */ pred_arr = elm->pred_arr; - } else { /* not cached mode or cache miss */ - double * cost_arr = NULL; + } else { /* not cached mode or cache miss */ + double *cost_arr = NULL; xbt_heap_t pqueue = NULL; int i = 0; int nr_nodes = xbt_dynar_length(nodes); - cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */ - pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */ + cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */ + pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */ pqueue = xbt_heap_new(nr_nodes, xbt_free); /* initialize */ cost_arr[src_node_id] = 0.0; - for(i = 0; i < nr_nodes; i++) { - if(i != src_node_id) { + for (i = 0; i < nr_nodes; i++) { + if (i != src_node_id) { cost_arr[i] = DBL_MAX; } @@ -1468,10 +1695,10 @@ static route_extended_t dijkstra_get_route(routing_component_t rc, const char* s } /* apply dijkstra using the indexes from the graph's node array */ - while(xbt_heap_size(pqueue) > 0) { - int * v_id = xbt_heap_pop(pqueue); + while (xbt_heap_size(pqueue) > 0) { + int *v_id = xbt_heap_pop(pqueue); xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t); - xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node); + xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node); xbt_edge_t edge = NULL; unsigned int cursor; @@ -1479,10 +1706,11 @@ static route_extended_t dijkstra_get_route(routing_component_t rc, const char* s xbt_node_t u_node = xbt_graph_edge_get_target(edge); graph_node_data_t data = xbt_graph_node_get_data(u_node); int u_id = data->graph_id; - route_extended_t tmp_e_route = (route_extended_t)xbt_graph_edge_get_data(edge); - int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */ + route_extended_t tmp_e_route = + (route_extended_t) xbt_graph_edge_get_data(edge); + int cost_v_u = (tmp_e_route->generic_route.link_list)->used; /* count of links, old model assume 1 */ - if(cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { + if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { pred_arr[u_id] = *v_id; cost_arr[u_id] = cost_v_u + cost_arr[*v_id]; nodeid = xbt_new0(int, 1); @@ -1498,70 +1726,82 @@ static route_extended_t dijkstra_get_route(routing_component_t rc, const char* s xbt_free(cost_arr); xbt_heap_free(pqueue); } - + /* compose route path with links */ - char *gw_src=NULL,*gw_dst=NULL, *prev_gw_src,*prev_gw_dst, *first_gw=NULL; - - for(v = dst_node_id; v != src_node_id; v = pred_arr[v]) { - xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t); + char *gw_src = NULL, *gw_dst = + NULL, *prev_gw_src, *prev_gw_dst, *first_gw = NULL; + + for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) { + xbt_node_t node_pred_v = + xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t); xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t); - xbt_edge_t edge = xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v); + xbt_edge_t edge = + xbt_graph_get_edge(routing->route_graph, node_pred_v, node_v); + + xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, + *dst_id); - xbt_assert2(edge != NULL, "no route between host %d and %d", *src_id, *dst_id); - prev_gw_src = gw_src; prev_gw_dst = gw_dst; - - e_route = (route_extended_t)xbt_graph_edge_get_data(edge); + + e_route = (route_extended_t) xbt_graph_edge_get_data(edge); gw_src = e_route->src_gateway; gw_dst = e_route->dst_gateway; - - if(v==dst_node_id) first_gw = gw_dst; - - if(rc->hierarchy == SURF_ROUTING_RECURSIVE && v!=dst_node_id && strcmp(gw_dst,prev_gw_src)) { - xbt_dynar_t e_route_as_to_as = (*(global_routing->get_route))(gw_dst,prev_gw_src); - xbt_assert2(e_route_as_to_as,"no route between \"%s\" and \"%s\"",gw_dst,prev_gw_src); + + if (v == dst_node_id) + first_gw = gw_dst; + + if (rc->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id + && strcmp(gw_dst, prev_gw_src)) { + xbt_dynar_t e_route_as_to_as = + (*(global_routing->get_route)) (gw_dst, prev_gw_src); + xbt_assert2(e_route_as_to_as, "no route between \"%s\" and \"%s\"", + gw_dst, prev_gw_src); links = e_route_as_to_as; int pos = 0; xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_insert_at(new_e_route->generic_route.link_list,pos,&link); + xbt_dynar_insert_at(new_e_route->generic_route.link_list, pos, + &link); pos++; } } - + links = e_route->generic_route.link_list; xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_unshift(new_e_route->generic_route.link_list,&link); + xbt_dynar_unshift(new_e_route->generic_route.link_list, &link); } size++; } - if(rc->hierarchy == SURF_ROUTING_RECURSIVE) { + if (rc->hierarchy == SURF_ROUTING_RECURSIVE) { new_e_route->src_gateway = xbt_strdup(gw_src); new_e_route->dst_gateway = xbt_strdup(first_gw); } - if(routing->cached && elm == NULL) { + if (routing->cached && elm == NULL) { /* add to predecessor list of the current src-host to cache */ elm = xbt_new0(struct route_cache_element, 1); elm->pred_arr = pred_arr; elm->size = size; - xbt_dict_set_ext(routing->route_cache, (char*)(&src_id), sizeof(int), (xbt_set_elm_t)elm, &route_cache_elem_free); + xbt_dict_set_ext(routing->route_cache, (char *) (&src_id), sizeof(int), + (xbt_set_elm_t) elm, &route_cache_elem_free); } - if(!routing->cached) + if (!routing->cached) xbt_free(pred_arr); - + return new_e_route; } -static void dijkstra_finalize(routing_component_t rc) { +static void dijkstra_finalize(routing_component_t rc) +{ routing_component_dijkstra_t routing = (routing_component_dijkstra_t) rc; if (routing) { - xbt_graph_free_graph(routing->route_graph, &xbt_free, &graph_edge_data_free, &xbt_free); + xbt_graph_free_graph(routing->route_graph, &xbt_free, + &graph_edge_data_free, &xbt_free); xbt_dict_free(&routing->graph_node_map); - if(routing->cached) + if (routing->cached) xbt_dict_free(&routing->route_cache); /* Delete bypass dict */ xbt_dict_free(&routing->bypassRoutes); @@ -1574,16 +1814,22 @@ static void dijkstra_finalize(routing_component_t rc) { /* Creation routing model functions */ -static void* model_dijkstra_both_create(int cached) { - routing_component_dijkstra_t new_component = xbt_new0(s_routing_component_dijkstra_t,1); - new_component->generic_routing.set_processing_unit = generic_set_processing_unit; - new_component->generic_routing.set_autonomous_system = generic_set_autonomous_system; +static void *model_dijkstra_both_create(int cached) +{ + routing_component_dijkstra_t new_component = + xbt_new0(s_routing_component_dijkstra_t, 1); + new_component->generic_routing.set_processing_unit = + generic_set_processing_unit; + new_component->generic_routing.set_autonomous_system = + generic_set_autonomous_system; new_component->generic_routing.set_route = generic_set_route; new_component->generic_routing.set_ASroute = generic_set_ASroute; new_component->generic_routing.set_bypassroute = generic_set_bypassroute; new_component->generic_routing.get_route = dijkstra_get_route; - new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes; - new_component->generic_routing.get_bypass_route = generic_get_bypassroute; + new_component->generic_routing.get_onelink_routes = + dijkstra_get_onelink_routes; + new_component->generic_routing.get_bypass_route = + generic_get_bypassroute; new_component->generic_routing.finalize = dijkstra_finalize; new_component->cached = cached; new_component->to_index = xbt_dict_new(); @@ -1592,39 +1838,45 @@ static void* model_dijkstra_both_create(int cached) { return new_component; } -static void* model_dijkstra_create(void) { +static void *model_dijkstra_create(void) +{ return model_dijkstra_both_create(0); } -static void* model_dijkstracache_create(void) { +static void *model_dijkstracache_create(void) +{ return model_dijkstra_both_create(1); } -static void model_dijkstra_both_load(void) { - /* use "surfxml_add_callback" to add a parse function call */ +static void model_dijkstra_both_load(void) +{ + /* use "surfxml_add_callback" to add a parse function call */ } -static void model_dijkstra_both_unload(void) { - /* use "surfxml_del_callback" to remove a parse function call */ +static void model_dijkstra_both_unload(void) +{ + /* use "surfxml_del_callback" to remove a parse function call */ } -static void model_dijkstra_both_end(void) { - routing_component_dijkstra_t routing = (routing_component_dijkstra_t) current_routing; - xbt_dict_cursor_t cursor = NULL; - char *key, *data, *end; - const char *sep = "#"; - xbt_dynar_t keys; +static void model_dijkstra_both_end(void) +{ + routing_component_dijkstra_t routing = + (routing_component_dijkstra_t) current_routing; + xbt_dict_cursor_t cursor = NULL; + char *key, *data, *end; + const char *sep = "#"; + xbt_dynar_t keys; xbt_node_t node = NULL; unsigned int cursor2; xbt_dynar_t nodes = NULL; int src_id, dst_id; route_t route; - + /* Create the topology graph */ routing->route_graph = xbt_graph_new_graph(1, NULL); routing->graph_node_map = xbt_dict_new(); - - if(routing->cached) + + if (routing->cached) routing->route_cache = xbt_dict_new(); /* Put the routes in position */ @@ -1632,23 +1884,24 @@ static void model_dijkstra_both_end(void) { keys = xbt_str_split_str(key, sep); src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 10); dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 10); - route_extended_t e_route = generic_new_extended_route(current_routing->hierarchy,data,0); - route_new_dijkstra(routing,src_id,dst_id,e_route); + route_extended_t e_route = + generic_new_extended_route(current_routing->hierarchy, data, 0); + route_new_dijkstra(routing, src_id, dst_id, e_route); xbt_dynar_free(&keys); } /* delete the parse table */ xbt_dict_foreach(routing->parse_routes, cursor, key, data) { - route = (route_t)data; + route = (route_t) data; xbt_dynar_free(&(route->link_list)); xbt_free(data); } - + /* delete parse dict */ xbt_dict_free(&(routing->parse_routes)); - + /* Add the loopback if needed */ - if(current_routing->hierarchy == SURF_ROUTING_BASE) + if (current_routing->hierarchy == SURF_ROUTING_BASE) add_loopback_dijkstra(routing); /* initialize graph indexes in nodes after graph has been built */ @@ -1658,7 +1911,7 @@ static void model_dijkstra_both_end(void) { graph_node_data_t data = xbt_graph_node_get_data(node); data->graph_id = cursor2; } - + } #ifdef HAVE_PCRE_LIB @@ -1669,29 +1922,31 @@ static void model_dijkstra_both_end(void) { typedef struct { s_routing_component_t generic_routing; - xbt_dict_t dict_processing_units; - xbt_dict_t dict_autonomous_systems; + xbt_dict_t dict_processing_units; + xbt_dict_t dict_autonomous_systems; xbt_dynar_t list_route; xbt_dynar_t list_ASroute; -} s_routing_component_rulebased_t,*routing_component_rulebased_t; +} s_routing_component_rulebased_t, *routing_component_rulebased_t; typedef struct s_rule_route s_rule_route_t, *rule_route_t; -typedef struct s_rule_route_extended s_rule_route_extended_t, *rule_route_extended_t; +typedef struct s_rule_route_extended s_rule_route_extended_t, + *rule_route_extended_t; struct s_rule_route { - xbt_dynar_t re_str_link; // dynar of char* - pcre* re_src; - pcre* re_dst; + xbt_dynar_t re_str_link; // dynar of char* + pcre *re_src; + pcre *re_dst; }; struct s_rule_route_extended { s_rule_route_t generic_rule_route; - char* re_src_gateway; - char* re_dst_gateway; + char *re_src_gateway; + char *re_dst_gateway; }; -static void rule_route_free(void *e) { - rule_route_t* elem = (rule_route_t*)(e); +static void rule_route_free(void *e) +{ + rule_route_t *elem = (rule_route_t *) (e); if (*elem) { xbt_dynar_free(&(*elem)->re_str_link); pcre_free((*elem)->re_src); @@ -1701,8 +1956,9 @@ static void rule_route_free(void *e) { (*elem) = NULL; } -static void rule_route_extended_free(void *e) { - rule_route_extended_t* elem = (rule_route_extended_t*)e; +static void rule_route_extended_free(void *e) +{ + rule_route_extended_t *elem = (rule_route_extended_t *) e; if (*elem) { xbt_dynar_free(&(*elem)->generic_rule_route.re_str_link); pcre_free((*elem)->generic_rule_route.re_src); @@ -1715,113 +1971,158 @@ static void rule_route_extended_free(void *e) { /* Parse routing model functions */ -static void model_rulebased_set_processing_unit(routing_component_t rc, const char* name) { - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; - xbt_dict_set(routing->dict_processing_units, name, (void*)(-1), NULL); +static void model_rulebased_set_processing_unit(routing_component_t rc, + const char *name) +{ + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; + xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL); } -static void model_rulebased_set_autonomous_system(routing_component_t rc, const char* name) { - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; - xbt_dict_set(routing->dict_autonomous_systems, name, (void*)(-1), NULL); +static void model_rulebased_set_autonomous_system(routing_component_t rc, + const char *name) +{ + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; + xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1), + NULL); } -static void model_rulebased_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) { - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; - rule_route_t ruleroute = xbt_new0(s_rule_route_t,1); +static void model_rulebased_set_route(routing_component_t rc, + const char *src, const char *dst, + route_t route) +{ + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; + rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1); const char *error; int erroffset; - ruleroute->re_src = pcre_compile(src,0,&error,&erroffset,NULL); - xbt_assert3(ruleroute->re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, src, error); - ruleroute->re_dst = pcre_compile(dst,0,&error,&erroffset,NULL); - xbt_assert3(ruleroute->re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, dst, error); + ruleroute->re_src = pcre_compile(src, 0, &error, &erroffset, NULL); + xbt_assert3(ruleroute->re_src, + "PCRE compilation failed at offset %d (\"%s\"): %s\n", + erroffset, src, error); + ruleroute->re_dst = pcre_compile(dst, 0, &error, &erroffset, NULL); + xbt_assert3(ruleroute->re_src, + "PCRE compilation failed at offset %d (\"%s\"): %s\n", + erroffset, dst, error); ruleroute->re_str_link = route->link_list; - xbt_dynar_push(routing->list_route,&ruleroute); + xbt_dynar_push(routing->list_route, &ruleroute); xbt_free(route); } -static void model_rulebased_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) { - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; - rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t,1); +static void model_rulebased_set_ASroute(routing_component_t rc, + const char *src, const char *dst, + route_extended_t route) +{ + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; + rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1); const char *error; int erroffset; - ruleroute_e->generic_rule_route.re_src = pcre_compile(src,0,&error,&erroffset,NULL); - xbt_assert3(ruleroute_e->generic_rule_route.re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, src, error); - ruleroute_e->generic_rule_route.re_dst = pcre_compile(dst,0,&error,&erroffset,NULL); - xbt_assert3(ruleroute_e->generic_rule_route.re_src,"PCRE compilation failed at offset %d (\"%s\"): %s\n", erroffset, dst, error); - ruleroute_e->generic_rule_route.re_str_link = route->generic_route.link_list; + ruleroute_e->generic_rule_route.re_src = + pcre_compile(src, 0, &error, &erroffset, NULL); + xbt_assert3(ruleroute_e->generic_rule_route.re_src, + "PCRE compilation failed at offset %d (\"%s\"): %s\n", + erroffset, src, error); + ruleroute_e->generic_rule_route.re_dst = + pcre_compile(dst, 0, &error, &erroffset, NULL); + xbt_assert3(ruleroute_e->generic_rule_route.re_src, + "PCRE compilation failed at offset %d (\"%s\"): %s\n", + erroffset, dst, error); + ruleroute_e->generic_rule_route.re_str_link = + route->generic_route.link_list; ruleroute_e->re_src_gateway = route->src_gateway; ruleroute_e->re_dst_gateway = route->dst_gateway; - xbt_dynar_push(routing->list_ASroute,&ruleroute_e); + xbt_dynar_push(routing->list_ASroute, &ruleroute_e); xbt_free(route->src_gateway); xbt_free(route->dst_gateway); xbt_free(route); } -static void model_rulebased_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) { +static void model_rulebased_set_bypassroute(routing_component_t rc, + const char *src, + const char *dst, + route_extended_t e_route) +{ xbt_die("bypass routing not supported for Route-Based model"); } -#define BUFFER_SIZE 4096 /* result buffer size */ -#define OVECCOUNT 30 /* should be a multiple of 3 */ +#define BUFFER_SIZE 4096 /* result buffer size */ +#define OVECCOUNT 30 /* should be a multiple of 3 */ -static char* remplace(char* value, const char** src_list, int src_size, const char** dst_list, int dst_size ) { +static char *remplace(char *value, const char **src_list, int src_size, + const char **dst_list, int dst_size) +{ char result_result[BUFFER_SIZE]; int i_result_buffer; - int value_length = (int)strlen(value); - int number=0; - - int i=0; + int value_length = (int) strlen(value); + int number = 0; + + int i = 0; i_result_buffer = 0; do { - if( value[i] == '$' ) { - i++; // skip $ - + if (value[i] == '$') { + i++; // skip $ + // find the number int number_length = 0; - while( '0' <= value[i+number_length] && value[i+number_length] <= '9' ) { + while ('0' <= value[i + number_length] + && value[i + number_length] <= '9') { number_length++; } - xbt_assert2( number_length!=0, "bad string parameter, no number indication, at offset: %d (\"%s\")",i,value); - + xbt_assert2(number_length != 0, + "bad string parameter, no number indication, at offset: %d (\"%s\")", + i, value); + // solve number - number = atoi(value+i); - i=i+number_length; - xbt_assert2(i+2= number, "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d",i,value,param_size,number); - - const char* param = param_list[number]; + i = i + 3; + + xbt_assert4(param_size >= number, + "bad string parameter, not enough length param_size, at offset: %d (\"%s\") %d %d", + i, value, param_size, number); + + const char *param = param_list[number]; int size = strlen(param); int cp; - for(cp = 0; cp < size; cp++ ) { + for (cp = 0; cp < size; cp++) { result_result[i_result_buffer] = param[cp]; i_result_buffer++; - if( i_result_buffer >= BUFFER_SIZE ) break; + if (i_result_buffer >= BUFFER_SIZE) + break; } } else { result_result[i_result_buffer] = value[i]; i_result_buffer++; - i++; // next char + i++; // next char } - - } while(iname); +static route_extended_t rulebased_get_route(routing_component_t rc, + const char *src, + const char *dst) +{ + xbt_assert1(rc && src + && dst, + "Invalid params for \"get_route\" function at AS \"%s\"", + rc->name); /* set utils vars */ - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; int are_processing_units; xbt_dynar_t rule_list; - if( xbt_dict_get_or_null(routing->dict_processing_units,src) && xbt_dict_get_or_null(routing->dict_processing_units,dst) ) { + if (xbt_dict_get_or_null(routing->dict_processing_units, src) + && xbt_dict_get_or_null(routing->dict_processing_units, dst)) { are_processing_units = 1; rule_list = routing->list_route; - } else if( xbt_dict_get_or_null(routing->dict_autonomous_systems,src) && xbt_dict_get_or_null(routing->dict_autonomous_systems,dst) ) { + } else if (xbt_dict_get_or_null(routing->dict_autonomous_systems, src) + && xbt_dict_get_or_null(routing->dict_autonomous_systems, + dst)) { are_processing_units = 0; - rule_list = routing->list_ASroute; + rule_list = routing->list_ASroute; } else - xbt_assert2(NULL, "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table",src,dst); + xbt_assert2(NULL, + "Ask for route \"from\"(%s) or \"to\"(%s) no found in the local table", + src, dst); int rc_src = -1; int rc_dst = -1; - int src_length = (int)strlen(src); - int dst_length = (int)strlen(dst); - - xbt_dynar_t links_list = xbt_dynar_new(global_routing->size_of_link,NULL); - + int src_length = (int) strlen(src); + int dst_length = (int) strlen(dst); + + xbt_dynar_t links_list = + xbt_dynar_new(global_routing->size_of_link, NULL); + rule_route_t ruleroute; unsigned int cpt; int ovector_src[OVECCOUNT]; int ovector_dst[OVECCOUNT]; - const char** list_src = NULL; - const char** list_dst = NULL; + const char **list_src = NULL; + const char **list_dst = NULL; xbt_dynar_foreach(rule_list, cpt, ruleroute) { - rc_src = pcre_exec(ruleroute->re_src,NULL,src,src_length,0,0,ovector_src,OVECCOUNT); - if( rc_src >= 0 ) { - rc_dst = pcre_exec(ruleroute->re_dst,NULL,dst,dst_length,0,0,ovector_dst,OVECCOUNT); - if( rc_dst >= 0 ) { - xbt_assert1(!pcre_get_substring_list(src,ovector_src,rc_src,&list_src),"error solving substring list for src \"%s\"",src); - xbt_assert1(!pcre_get_substring_list(dst,ovector_dst,rc_dst,&list_dst),"error solving substring list for src \"%s\"",dst); - char* link_name; + rc_src = + pcre_exec(ruleroute->re_src, NULL, src, src_length, 0, 0, + ovector_src, OVECCOUNT); + if (rc_src >= 0) { + rc_dst = + pcre_exec(ruleroute->re_dst, NULL, dst, dst_length, 0, 0, + ovector_dst, OVECCOUNT); + if (rc_dst >= 0) { + xbt_assert1(!pcre_get_substring_list + (src, ovector_src, rc_src, &list_src), + "error solving substring list for src \"%s\"", src); + xbt_assert1(!pcre_get_substring_list + (dst, ovector_dst, rc_dst, &list_dst), + "error solving substring list for src \"%s\"", dst); + char *link_name; xbt_dynar_foreach(ruleroute->re_str_link, cpt, link_name) { - char* new_link_name = remplace(link_name,list_src,rc_src,list_dst,rc_dst); - void* link = xbt_dict_get_or_null(surf_network_model->resource_set, new_link_name); + char *new_link_name = + remplace(link_name, list_src, rc_src, list_dst, rc_dst); + void *link = + xbt_dict_get_or_null(surf_network_model->resource_set, + new_link_name); if (link) - xbt_dynar_push(links_list,&link); + xbt_dynar_push(links_list, &link); else - THROW1(mismatch_error,0,"Link %s not found", new_link_name); + THROW1(mismatch_error, 0, "Link %s not found", new_link_name); xbt_free(new_link_name); } } } - if( rc_src >= 0 && rc_dst >= 0 ) break; + if (rc_src >= 0 && rc_dst >= 0) + break; } - + route_extended_t new_e_route = NULL; - if(rc_src >= 0 && rc_dst >= 0) { - new_e_route = xbt_new0(s_route_extended_t,1); + if (rc_src >= 0 && rc_dst >= 0) { + new_e_route = xbt_new0(s_route_extended_t, 1); new_e_route->generic_route.link_list = links_list; - } else if( !strcmp(src,dst) && are_processing_units ) { - new_e_route = xbt_new0(s_route_extended_t,1); - xbt_dynar_push(links_list,&(global_routing->loopback)); + } else if (!strcmp(src, dst) && are_processing_units) { + new_e_route = xbt_new0(s_route_extended_t, 1); + xbt_dynar_push(links_list, &(global_routing->loopback)); new_e_route->generic_route.link_list = links_list; - } else { + } else { xbt_dynar_free(&link_list); } - if(!are_processing_units && new_e_route) - { - rule_route_extended_t ruleroute_extended = (rule_route_extended_t)ruleroute; - new_e_route->src_gateway = remplace(ruleroute_extended->re_src_gateway,list_src,rc_src,list_dst,rc_dst); - new_e_route->dst_gateway = remplace(ruleroute_extended->re_dst_gateway,list_src,rc_src,list_dst,rc_dst); + if (!are_processing_units && new_e_route) { + rule_route_extended_t ruleroute_extended = + (rule_route_extended_t) ruleroute; + new_e_route->src_gateway = + remplace(ruleroute_extended->re_src_gateway, list_src, rc_src, + list_dst, rc_dst); + new_e_route->dst_gateway = + remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src, + list_dst, rc_dst); } - - if(list_src) pcre_free_substring_list(list_src); - if(list_dst) pcre_free_substring_list(list_dst); - + + if (list_src) + pcre_free_substring_list(list_src); + if (list_dst) + pcre_free_substring_list(list_dst); + return new_e_route; } -static route_extended_t rulebased_get_bypass_route(routing_component_t rc, const char* src,const char* dst) { +static route_extended_t rulebased_get_bypass_route(routing_component_t rc, + const char *src, + const char *dst) +{ return NULL; } -static void rulebased_finalize(routing_component_t rc) { - routing_component_rulebased_t routing = (routing_component_rulebased_t) rc; +static void rulebased_finalize(routing_component_t rc) +{ + routing_component_rulebased_t routing = + (routing_component_rulebased_t) rc; if (routing) { xbt_dict_free(&routing->dict_processing_units); xbt_dict_free(&routing->dict_autonomous_systems); @@ -1926,37 +2263,49 @@ static void rulebased_finalize(routing_component_t rc) { } /* Creation routing model functions */ -static void* model_rulebased_create(void) { - routing_component_rulebased_t new_component = xbt_new0(s_routing_component_rulebased_t,1); - new_component->generic_routing.set_processing_unit = model_rulebased_set_processing_unit; - new_component->generic_routing.set_autonomous_system = model_rulebased_set_autonomous_system; +static void *model_rulebased_create(void) +{ + routing_component_rulebased_t new_component = + xbt_new0(s_routing_component_rulebased_t, 1); + new_component->generic_routing.set_processing_unit = + model_rulebased_set_processing_unit; + new_component->generic_routing.set_autonomous_system = + model_rulebased_set_autonomous_system; new_component->generic_routing.set_route = model_rulebased_set_route; new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute; - new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute; - new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes; + new_component->generic_routing.set_bypassroute = + model_rulebased_set_bypassroute; + new_component->generic_routing.get_onelink_routes = + rulebased_get_onelink_routes; new_component->generic_routing.get_route = rulebased_get_route; - new_component->generic_routing.get_bypass_route = NULL; //rulebased_get_bypass_route; + new_component->generic_routing.get_bypass_route = NULL; //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->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free); - new_component->list_ASroute = xbt_dynar_new(sizeof(rule_route_extended_t), &rule_route_extended_free); + 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), + &rule_route_extended_free); return new_component; } -static void model_rulebased_load(void) { - /* use "surfxml_add_callback" to add a parse function call */ +static void model_rulebased_load(void) +{ + /* use "surfxml_add_callback" to add a parse function call */ } -static void model_rulebased_unload(void) { - /* use "surfxml_del_callback" to remove a parse function call */ +static void model_rulebased_unload(void) +{ + /* use "surfxml_del_callback" to remove a parse function call */ } -static void model_rulebased_end(void) { +static void model_rulebased_end(void) +{ } -#endif /* HAVE_PCRE_LIB */ +#endif /* HAVE_PCRE_LIB */ /* ************************************************************************** */ /* ******************************* NO ROUTING ******************************* */ @@ -1964,43 +2313,73 @@ static void model_rulebased_end(void) { /* Routing model structure */ typedef struct { s_routing_component_t generic_routing; -} s_routing_component_none_t,*routing_component_none_t; +} s_routing_component_none_t, *routing_component_none_t; /* Business methods */ -static xbt_dynar_t none_get_onelink_routes(routing_component_t rc){ +static xbt_dynar_t none_get_onelink_routes(routing_component_t rc) +{ return NULL; } -static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){ + +static route_extended_t none_get_route(routing_component_t rc, + const char *src, const char *dst) +{ return NULL; } -static route_extended_t none_get_bypass_route(routing_component_t rc, const char* src,const char* dst){ + +static route_extended_t none_get_bypass_route(routing_component_t rc, + const char *src, + const char *dst) +{ return NULL; } -static void none_finalize(routing_component_t rc) { + +static void none_finalize(routing_component_t rc) +{ xbt_free(rc); } -static void none_set_processing_unit(routing_component_t rc, const char* name) {} -static void none_set_autonomous_system(routing_component_t rc, const char* name) {} +static void none_set_processing_unit(routing_component_t rc, + const char *name) +{ +} + +static void none_set_autonomous_system(routing_component_t rc, + const char *name) +{ +} /* Creation routing model functions */ -static void* model_none_create(void) { - routing_component_none_t new_component = xbt_new0(s_routing_component_none_t,1); - new_component->generic_routing.set_processing_unit = none_set_processing_unit; - new_component->generic_routing.set_autonomous_system = none_set_autonomous_system; +static void *model_none_create(void) +{ + routing_component_none_t new_component = + xbt_new0(s_routing_component_none_t, 1); + new_component->generic_routing.set_processing_unit = + none_set_processing_unit; + new_component->generic_routing.set_autonomous_system = + none_set_autonomous_system; new_component->generic_routing.set_route = NULL; new_component->generic_routing.set_ASroute = NULL; new_component->generic_routing.set_bypassroute = NULL; new_component->generic_routing.get_route = none_get_route; - new_component->generic_routing.get_onelink_routes = none_get_onelink_routes; + new_component->generic_routing.get_onelink_routes = + none_get_onelink_routes; new_component->generic_routing.get_bypass_route = none_get_bypass_route; new_component->generic_routing.finalize = none_finalize; return new_component; } -static void model_none_load(void) {} -static void model_none_unload(void) {} -static void model_none_end(void) {} +static void model_none_load(void) +{ +} + +static void model_none_unload(void) +{ +} + +static void model_none_end(void) +{ +} /* ************************************************** */ /* ********** PATERN FOR NEW ROUTING **************** */ @@ -2046,268 +2425,326 @@ static void model_none_end(void) {} // static void model_NEW_end(void) {} /* mandatory */ /* ************************************************************************** */ -/* ************************* GENERIC PARSE FUNCTIONS ************************ */ +/* ************************* GENERIC PARSE FUNCTIONS ************************ */ -static void generic_set_processing_unit(routing_component_t rc, const char* name) { - DEBUG1("Load process unit \"%s\"",name); +static void generic_set_processing_unit(routing_component_t rc, + const char *name) +{ + DEBUG1("Load process unit \"%s\"", name); model_type_t modeltype = rc->routing; - int *id = xbt_new0(int,1); + int *id = xbt_new0(int, 1); xbt_dict_t _to_index; - if(modeltype==&routing_models[SURF_MODEL_FULL]) - _to_index = ((routing_component_full_t)rc)->to_index; - - else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) - _to_index = ((routing_component_floyd_t)rc)->to_index; - - else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) - _to_index = ((routing_component_dijkstra_t)rc)->to_index; - - else xbt_die("\"generic_set_processing_unit\" not supported"); + if (modeltype == &routing_models[SURF_MODEL_FULL]) + _to_index = ((routing_component_full_t) rc)->to_index; + + else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) + _to_index = ((routing_component_floyd_t) rc)->to_index; + + else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) + _to_index = ((routing_component_dijkstra_t) rc)->to_index; + + else + xbt_die("\"generic_set_processing_unit\" not supported"); *id = xbt_dict_length(_to_index); - xbt_dict_set(_to_index,name,id,xbt_free); + xbt_dict_set(_to_index, name, id, xbt_free); } -static void generic_set_autonomous_system(routing_component_t rc, const char* name) { - DEBUG1("Load Autonomous system \"%s\"",name); +static void generic_set_autonomous_system(routing_component_t rc, + const char *name) +{ + DEBUG1("Load Autonomous system \"%s\"", name); model_type_t modeltype = rc->routing; - int *id = xbt_new0(int,1); + int *id = xbt_new0(int, 1); xbt_dict_t _to_index; - if(modeltype==&routing_models[SURF_MODEL_FULL]) - _to_index = ((routing_component_full_t)rc)->to_index; - - else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) - _to_index = ((routing_component_floyd_t)rc)->to_index; - - else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) - _to_index = ((routing_component_dijkstra_t)rc)->to_index; - - else xbt_die("\"generic_set_autonomous_system\" not supported"); + if (modeltype == &routing_models[SURF_MODEL_FULL]) + _to_index = ((routing_component_full_t) rc)->to_index; + + else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) + _to_index = ((routing_component_floyd_t) rc)->to_index; + + else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) + _to_index = ((routing_component_dijkstra_t) rc)->to_index; + + else + xbt_die("\"generic_set_autonomous_system\" not supported"); *id = xbt_dict_length(_to_index); - xbt_dict_set(_to_index,name,id,xbt_free); + xbt_dict_set(_to_index, name, id, xbt_free); } -static void generic_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) { - DEBUG2("Load Route from \"%s\" to \"%s\"",src,dst); +static void generic_set_route(routing_component_t rc, const char *src, + const char *dst, route_t route) +{ + DEBUG2("Load Route from \"%s\" to \"%s\"", src, dst); model_type_t modeltype = rc->routing; xbt_dict_t _parse_routes; xbt_dict_t _to_index; char *route_name; int *src_id, *dst_id; - - if(modeltype==&routing_models[SURF_MODEL_FULL]) { - _parse_routes = ((routing_component_full_t)rc)->parse_routes; - _to_index = ((routing_component_full_t)rc)->to_index; - - } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) { - _parse_routes = ((routing_component_floyd_t)rc)->parse_routes; - _to_index = ((routing_component_floyd_t)rc)->to_index; - - } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) { - _parse_routes = ((routing_component_dijkstra_t)rc)->parse_routes; - _to_index = ((routing_component_dijkstra_t)rc)->to_index; - - } else xbt_die("\"generic_set_route\" not supported"); + + if (modeltype == &routing_models[SURF_MODEL_FULL]) { + _parse_routes = ((routing_component_full_t) rc)->parse_routes; + _to_index = ((routing_component_full_t) rc)->to_index; + + } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) { + _parse_routes = ((routing_component_floyd_t) rc)->parse_routes; + _to_index = ((routing_component_floyd_t) rc)->to_index; + + } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) { + _parse_routes = ((routing_component_dijkstra_t) rc)->parse_routes; + _to_index = ((routing_component_dijkstra_t) rc)->to_index; + + } else + xbt_die("\"generic_set_route\" not supported"); src_id = xbt_dict_get_or_null(_to_index, src); dst_id = xbt_dict_get_or_null(_to_index, dst); - - xbt_assert2(src_id&&dst_id,"Network elements %s or %s not found", src, dst); - route_name = bprintf("%d#%d",*src_id,*dst_id); - - xbt_assert2(xbt_dynar_length(route->link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst); - xbt_assert2(!xbt_dict_get_or_null(_parse_routes,route_name), - "The route between \"%s\" and \"%s\" already exist",src,dst); + + xbt_assert2(src_id + && dst_id, "Network elements %s or %s not found", src, dst); + route_name = bprintf("%d#%d", *src_id, *dst_id); + + xbt_assert2(xbt_dynar_length(route->link_list) > 0, + "Invalid count of links, must be greater than zero (%s,%s)", + src, dst); + xbt_assert2(!xbt_dict_get_or_null(_parse_routes, route_name), + "The route between \"%s\" and \"%s\" already exist", src, + dst); xbt_dict_set(_parse_routes, route_name, route, NULL); xbt_free(route_name); } -static void generic_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) { - DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway); +static void generic_set_ASroute(routing_component_t rc, const char *src, + const char *dst, route_extended_t e_route) +{ + DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src, + e_route->src_gateway, dst, e_route->dst_gateway); model_type_t modeltype = rc->routing; xbt_dict_t _parse_routes; xbt_dict_t _to_index; char *route_name; int *src_id, *dst_id; - - if(modeltype==&routing_models[SURF_MODEL_FULL]) { - _parse_routes = ((routing_component_full_t)rc)->parse_routes; - _to_index = ((routing_component_full_t)rc)->to_index; - - } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) { - _parse_routes = ((routing_component_floyd_t)rc)->parse_routes; - _to_index = ((routing_component_floyd_t)rc)->to_index; - - } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) { - _parse_routes = ((routing_component_dijkstra_t)rc)->parse_routes; - _to_index = ((routing_component_dijkstra_t)rc)->to_index; - - } else xbt_die("\"generic_set_route\" not supported"); - + + if (modeltype == &routing_models[SURF_MODEL_FULL]) { + _parse_routes = ((routing_component_full_t) rc)->parse_routes; + _to_index = ((routing_component_full_t) rc)->to_index; + + } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) { + _parse_routes = ((routing_component_floyd_t) rc)->parse_routes; + _to_index = ((routing_component_floyd_t) rc)->to_index; + + } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) { + _parse_routes = ((routing_component_dijkstra_t) rc)->parse_routes; + _to_index = ((routing_component_dijkstra_t) rc)->to_index; + + } else + xbt_die("\"generic_set_route\" not supported"); + src_id = xbt_dict_get_or_null(_to_index, src); dst_id = xbt_dict_get_or_null(_to_index, dst); - - xbt_assert2(src_id&&dst_id,"Network elements %s or %s not found", src, dst); - route_name = bprintf("%d#%d",*src_id,*dst_id); - - xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst); - xbt_assert4(!xbt_dict_get_or_null(_parse_routes,route_name), - "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",src,e_route->src_gateway,dst,e_route->dst_gateway); - + + xbt_assert2(src_id + && dst_id, "Network elements %s or %s not found", src, dst); + route_name = bprintf("%d#%d", *src_id, *dst_id); + + xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0, + "Invalid count of links, must be greater than zero (%s,%s)", + src, dst); + xbt_assert4(!xbt_dict_get_or_null(_parse_routes, route_name), + "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist", + src, e_route->src_gateway, dst, e_route->dst_gateway); + xbt_dict_set(_parse_routes, route_name, e_route, NULL); xbt_free(route_name); } -static void generic_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) { - DEBUG2("Load bypassRoute from \"%s\" to \"%s\"",src,dst); +static void generic_set_bypassroute(routing_component_t rc, + const char *src, const char *dst, + route_extended_t e_route) +{ + DEBUG2("Load bypassRoute from \"%s\" to \"%s\"", src, dst); model_type_t modeltype = rc->routing; xbt_dict_t dict_bypassRoutes; char *route_name; - if(modeltype==&routing_models[SURF_MODEL_FULL]) { - dict_bypassRoutes = ((routing_component_full_t)rc)->bypassRoutes; - } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) { - dict_bypassRoutes = ((routing_component_floyd_t)rc)->bypassRoutes; - } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) { - dict_bypassRoutes = ((routing_component_dijkstra_t)rc)->bypassRoutes; - } else xbt_die("\"generic_set_bypassroute\" not supported"); - route_name = bprintf("%s#%s",src,dst); - xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list)>0, "Invalid count of links, must be greater than zero (%s,%s)",src,dst); - xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes,route_name), - "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",src,e_route->src_gateway,dst,e_route->dst_gateway); - - route_extended_t new_e_route = generic_new_extended_route(SURF_ROUTING_RECURSIVE,e_route,0); - xbt_dynar_free( &(e_route->generic_route.link_list) ); + if (modeltype == &routing_models[SURF_MODEL_FULL]) { + dict_bypassRoutes = ((routing_component_full_t) rc)->bypassRoutes; + } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) { + dict_bypassRoutes = ((routing_component_floyd_t) rc)->bypassRoutes; + } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) { + dict_bypassRoutes = ((routing_component_dijkstra_t) rc)->bypassRoutes; + } else + xbt_die("\"generic_set_bypassroute\" not supported"); + route_name = bprintf("%s#%s", src, dst); + xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0, + "Invalid count of links, must be greater than zero (%s,%s)", + src, dst); + xbt_assert4(!xbt_dict_get_or_null(dict_bypassRoutes, route_name), + "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist", + src, e_route->src_gateway, dst, e_route->dst_gateway); + + route_extended_t new_e_route = + generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 0); + xbt_dynar_free(&(e_route->generic_route.link_list)); xbt_free(e_route); - - xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, (void(*)(void*))generic_free_extended_route ); + + xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, + (void (*)(void *)) generic_free_extended_route); xbt_free(route_name); } /* ************************************************************************** */ /* *********************** GENERIC BUSINESS METHODS ************************* */ -static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc) +static xbt_dynar_t generic_get_onelink_routes(routing_component_t rc) { xbt_die("\"generic_get_onelink_routes\" not implemented yet"); } -static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst) { +static route_extended_t generic_get_bypassroute(routing_component_t rc, + const char *src, + const char *dst) +{ model_type_t modeltype = rc->routing; xbt_dict_t dict_bypassRoutes; - - if(modeltype==&routing_models[SURF_MODEL_FULL]) { - dict_bypassRoutes = ((routing_component_full_t)rc)->bypassRoutes; - } else if(modeltype==&routing_models[SURF_MODEL_FLOYD]) { - dict_bypassRoutes = ((routing_component_floyd_t)rc)->bypassRoutes; - } else if(modeltype==&routing_models[SURF_MODEL_DIJKSTRA]|| - modeltype==&routing_models[SURF_MODEL_DIJKSTRACACHE]) { - dict_bypassRoutes = ((routing_component_dijkstra_t)rc)->bypassRoutes; - } else xbt_die("\"generic_get_bypassroute\" not supported"); - + + if (modeltype == &routing_models[SURF_MODEL_FULL]) { + dict_bypassRoutes = ((routing_component_full_t) rc)->bypassRoutes; + } else if (modeltype == &routing_models[SURF_MODEL_FLOYD]) { + dict_bypassRoutes = ((routing_component_floyd_t) rc)->bypassRoutes; + } else if (modeltype == &routing_models[SURF_MODEL_DIJKSTRA] || + modeltype == &routing_models[SURF_MODEL_DIJKSTRACACHE]) { + dict_bypassRoutes = ((routing_component_dijkstra_t) rc)->bypassRoutes; + } else + xbt_die("\"generic_get_bypassroute\" not supported"); + routing_component_t src_as, dst_as; int index_src, index_dst; xbt_dynar_t path_src = NULL; xbt_dynar_t path_dst = NULL; routing_component_t current = NULL; - routing_component_t* current_src = NULL; - routing_component_t* current_dst = NULL; + routing_component_t *current_src = NULL; + routing_component_t *current_dst = NULL; /* (1) find the as where the src and dst are located */ - src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component; - dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component; - xbt_assert2(src_as&&dst_as, "Ask for route \"from\"(%s) or \"to\"(%s) no found",src,dst); - + src_as = ((network_element_info_t) + xbt_dict_get_or_null(global_routing->where_network_elements, + src))->rc_component; + dst_as = ((network_element_info_t) + xbt_dict_get_or_null(global_routing->where_network_elements, + dst))->rc_component; + xbt_assert2(src_as + && dst_as, + "Ask for route \"from\"(%s) or \"to\"(%s) no found", src, + dst); + /* (2) find the path to the root routing component */ path_src = xbt_dynar_new(sizeof(routing_component_t), NULL); - current = src_as; - while( current != NULL ) { - xbt_dynar_push(path_src,¤t); + current = src_as; + while (current != NULL) { + xbt_dynar_push(path_src, ¤t); current = current->routing_father; } path_dst = xbt_dynar_new(sizeof(routing_component_t), NULL); - current = dst_as; - while( current != NULL ) { - xbt_dynar_push(path_dst,¤t); + current = dst_as; + while (current != NULL) { + xbt_dynar_push(path_dst, ¤t); current = current->routing_father; } /* (3) find the common father */ - index_src = (path_src->used)-1; - index_dst = (path_dst->used)-1; - current_src = xbt_dynar_get_ptr(path_src,index_src); - current_dst = xbt_dynar_get_ptr(path_dst,index_dst); - while( index_src >= 0 && index_dst >= 0 && *current_src == *current_dst ) { - routing_component_t *tmp_src,*tmp_dst; + index_src = (path_src->used) - 1; + index_dst = (path_dst->used) - 1; + current_src = xbt_dynar_get_ptr(path_src, index_src); + current_dst = xbt_dynar_get_ptr(path_dst, index_dst); + while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) { + routing_component_t *tmp_src, *tmp_dst; tmp_src = xbt_dynar_pop_ptr(path_src); tmp_dst = xbt_dynar_pop_ptr(path_dst); index_src--; index_dst--; - current_src = xbt_dynar_get_ptr(path_src,index_src); - current_dst = xbt_dynar_get_ptr(path_dst,index_dst); + current_src = xbt_dynar_get_ptr(path_src, index_src); + current_dst = xbt_dynar_get_ptr(path_dst, index_dst); } - - int max_index_src = (path_src->used)-1; - int max_index_dst = (path_dst->used)-1; - - int max_index = max(max_index_src,max_index_dst); + + int max_index_src = (path_src->used) - 1; + int max_index_dst = (path_dst->used) - 1; + + int max_index = max(max_index_src, max_index_dst); int i, max; - - route_extended_t e_route_bypass = NULL; - - for( max=0;max<=max_index;max++) - { - for(i=0;iname, - (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,max)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name); + + route_extended_t e_route_bypass = NULL; + + for (max = 0; max <= max_index; max++) { + for (i = 0; i < max; i++) { + if (i <= max_index_src && max <= max_index_dst) { + char *route_name = bprintf("%s#%s", + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_src, i)))->name, + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_dst, max)))->name); + e_route_bypass = + xbt_dict_get_or_null(dict_bypassRoutes, route_name); xbt_free(route_name); } - if( e_route_bypass ) break; - if( max <= max_index_src && i <= max_index_dst ) { - char* route_name = bprintf("%s#%s", - (*(routing_component_t*)(xbt_dynar_get_ptr(path_src,max)))->name, - (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,i)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name); + if (e_route_bypass) + break; + if (max <= max_index_src && i <= max_index_dst) { + char *route_name = bprintf("%s#%s", + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_src, max)))->name, + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_dst, i)))->name); + e_route_bypass = + xbt_dict_get_or_null(dict_bypassRoutes, route_name); xbt_free(route_name); } - if( e_route_bypass ) break; + if (e_route_bypass) + break; } - - if( e_route_bypass ) break; - - if( max <= max_index_src && max <= max_index_dst ) { - char* route_name = bprintf("%s#%s", - (*(routing_component_t*)(xbt_dynar_get_ptr(path_src,max)))->name, - (*(routing_component_t*)(xbt_dynar_get_ptr(path_dst,max)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes,route_name); + + if (e_route_bypass) + break; + + if (max <= max_index_src && max <= max_index_dst) { + char *route_name = bprintf("%s#%s", + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_src, max)))->name, + (*(routing_component_t *) + (xbt_dynar_get_ptr + (path_dst, max)))->name); + e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name); xbt_free(route_name); } - if( e_route_bypass ) break; + if (e_route_bypass) + break; } xbt_dynar_free(&path_src); xbt_dynar_free(&path_dst); - + route_extended_t new_e_route = NULL; - - if(e_route_bypass) { - void* link; - unsigned int cpt=0; - new_e_route = xbt_new0(s_route_extended_t,1); + + if (e_route_bypass) { + void *link; + unsigned int cpt = 0; + new_e_route = xbt_new0(s_route_extended_t, 1); new_e_route->src_gateway = xbt_strdup(e_route_bypass->src_gateway); new_e_route->dst_gateway = xbt_strdup(e_route_bypass->dst_gateway); - new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); + new_e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); xbt_dynar_foreach(e_route_bypass->generic_route.link_list, cpt, link) { - xbt_dynar_push(new_e_route->generic_route.link_list,&link); + xbt_dynar_push(new_e_route->generic_route.link_list, &link); } } @@ -2317,406 +2754,441 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc, const ch /* ************************************************************************** */ /* ************************* GENERIC AUX FUNCTIONS ************************** */ -static route_extended_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, void* data, int order) { - +static route_extended_t +generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, + void *data, int order) +{ + char *link_name; route_extended_t e_route, new_e_route; route_t route; unsigned int cpt; xbt_dynar_t links, links_id; - - new_e_route = xbt_new0(s_route_extended_t,1); - new_e_route->generic_route.link_list = xbt_dynar_new(global_routing->size_of_link,NULL); + + new_e_route = xbt_new0(s_route_extended_t, 1); + new_e_route->generic_route.link_list = + xbt_dynar_new(global_routing->size_of_link, NULL); new_e_route->src_gateway = NULL; new_e_route->dst_gateway = NULL; - xbt_assert0(hierarchy == SURF_ROUTING_BASE || hierarchy == SURF_ROUTING_RECURSIVE, - "the hierarchy type is not defined"); - - if(hierarchy == SURF_ROUTING_BASE ) { - - route = (route_t)data; + xbt_assert0(hierarchy == SURF_ROUTING_BASE + || hierarchy == SURF_ROUTING_RECURSIVE, + "the hierarchy type is not defined"); + + if (hierarchy == SURF_ROUTING_BASE) { + + route = (route_t) data; links = route->link_list; - - } else if(hierarchy == SURF_ROUTING_RECURSIVE ) { - e_route = (route_extended_t)data; - xbt_assert0(e_route->src_gateway&&e_route->dst_gateway,"bad gateway, is null"); + } else if (hierarchy == SURF_ROUTING_RECURSIVE) { + + e_route = (route_extended_t) data; + xbt_assert0(e_route->src_gateway + && e_route->dst_gateway, "bad gateway, is null"); links = e_route->generic_route.link_list; - + /* remeber not erase the gateway names */ new_e_route->src_gateway = e_route->src_gateway; new_e_route->dst_gateway = e_route->dst_gateway; } - + links_id = new_e_route->generic_route.link_list; - + xbt_dynar_foreach(links, cpt, link_name) { - - void* link = xbt_dict_get_or_null(surf_network_model->resource_set, link_name); - if (link) - { - if( order ) - xbt_dynar_push(links_id,&link); + + void *link = + xbt_dict_get_or_null(surf_network_model->resource_set, link_name); + if (link) { + if (order) + xbt_dynar_push(links_id, &link); else - xbt_dynar_unshift(links_id,&link); - } - else - THROW1(mismatch_error,0,"Link %s not found", link_name); + xbt_dynar_unshift(links_id, &link); + } else + THROW1(mismatch_error, 0, "Link %s not found", link_name); } - + return new_e_route; } -static void generic_free_route(route_t route) { - if(route) { +static void generic_free_route(route_t route) +{ + if (route) { xbt_dynar_free(&(route->link_list)); xbt_free(route); } } -static void generic_free_extended_route(route_extended_t e_route) { - if(e_route) { +static void generic_free_extended_route(route_extended_t e_route) +{ + if (e_route) { xbt_dynar_free(&(e_route->generic_route.link_list)); - if(e_route->src_gateway) xbt_free(e_route->src_gateway); - if(e_route->dst_gateway) xbt_free(e_route->dst_gateway); + if (e_route->src_gateway) + xbt_free(e_route->src_gateway); + if (e_route->dst_gateway) + xbt_free(e_route->dst_gateway); xbt_free(e_route); } } -static routing_component_t generic_as_exist(routing_component_t find_from, routing_component_t to_find) { +static routing_component_t generic_as_exist(routing_component_t find_from, + routing_component_t to_find) +{ //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK xbt_dict_cursor_t cursor = NULL; char *key; - int found=0; + int found = 0; routing_component_t elem; xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) { - if( to_find == elem || generic_as_exist(elem,to_find) ){ - found=1; + if (to_find == elem || generic_as_exist(elem, to_find)) { + found = 1; break; } } - if(found) return to_find; + if (found) + return to_find; return NULL; } -static routing_component_t generic_autonomous_system_exist(routing_component_t rc, char* element) { +static routing_component_t +generic_autonomous_system_exist(routing_component_t rc, char *element) +{ //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK routing_component_t element_as, result, elem; xbt_dict_cursor_t cursor = NULL; char *key; - element_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,element))->rc_component; - result = ((routing_component_t)-1); - if(element_as!=rc) - result = generic_as_exist(rc,element_as); - - int found=0; - if(result) - { + element_as = ((network_element_info_t) + xbt_dict_get_or_null + (global_routing->where_network_elements, + element))->rc_component; + result = ((routing_component_t) - 1); + if (element_as != rc) + result = generic_as_exist(rc, element_as); + + int found = 0; + if (result) { xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) { - found = !strcmp(elem->name,element); - if( found ) break; + found = !strcmp(elem->name, element); + if (found) + break; } - if( found ) return element_as; + if (found) + return element_as; } return NULL; } -static routing_component_t generic_processing_units_exist(routing_component_t rc, char* element) { +static routing_component_t +generic_processing_units_exist(routing_component_t rc, char *element) +{ routing_component_t element_as; - element_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,element))->rc_component; - if(element_as==rc) return element_as; - return generic_as_exist(rc,element_as); -} - -static void generic_src_dst_check(routing_component_t rc, const char* src, const char* dst) { - - routing_component_t src_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,src))->rc_component; - routing_component_t dst_as = ((network_element_info_t)xbt_dict_get_or_null(global_routing->where_network_elements,dst))->rc_component; - - xbt_assert3(src_as != NULL && dst_as != NULL, - "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",src,dst,rc->name); + element_as = ((network_element_info_t) + xbt_dict_get_or_null + (global_routing->where_network_elements, + element))->rc_component; + if (element_as == rc) + return element_as; + return generic_as_exist(rc, element_as); +} + +static void generic_src_dst_check(routing_component_t rc, const char *src, + const char *dst) +{ + + routing_component_t src_as = ((network_element_info_t) + xbt_dict_get_or_null + (global_routing->where_network_elements, + src))->rc_component; + routing_component_t dst_as = ((network_element_info_t) + xbt_dict_get_or_null + (global_routing->where_network_elements, + dst))->rc_component; + + xbt_assert3(src_as != NULL && dst_as != NULL, + "Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"", + src, dst, rc->name); xbt_assert4(src_as == dst_as, - "The src(%s in %s) and dst(%s in %s) are in differents AS",src,src_as->name,dst,dst_as->name); + "The src(%s in %s) and dst(%s in %s) are in differents AS", + src, src_as->name, dst, dst_as->name); xbt_assert2(rc == dst_as, - "The routing component of src and dst is not the same as the network elements belong (%s==%s)",rc->name,dst_as->name); + "The routing component of src and dst is not the same as the network elements belong (%s==%s)", + rc->name, dst_as->name); } static void parse_Sconfig(void) { - //TODO - DEBUG0("WARNING tag config not yet implemented."); + //TODO + DEBUG0("WARNING tag config not yet implemented."); } static void routing_full_parse_Scluster(void) { - static int AX_ptr = 0; - - char *cluster_id = A_surfxml_cluster_id; - char *cluster_prefix = A_surfxml_cluster_prefix; - char *cluster_suffix = A_surfxml_cluster_suffix; - char *cluster_radical = A_surfxml_cluster_radical; - char *cluster_power = A_surfxml_cluster_power; - char *cluster_bw = A_surfxml_cluster_bw; - char *cluster_lat = A_surfxml_cluster_lat; - char *cluster_bb_bw = A_surfxml_cluster_bb_bw; - char *cluster_bb_lat = A_surfxml_cluster_bb_lat; - char *host_id, *groups, *link_id; - char *router_id, *link_router, *link_backbone, *route_src_dst; - unsigned int iter; - int start, end, i; - xbt_dynar_t radical_elements; - xbt_dynar_t radical_ends; - #ifndef HAVE_PCRE_LIB - xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL); - char *route_src,*route_dst; - int j; - #endif - - static unsigned int surfxml_buffer_stack_stack_ptr = 1; - static unsigned int surfxml_buffer_stack_stack[1024]; - - surfxml_buffer_stack_stack[0]= 0; - - surfxml_bufferstack_push(1); - - SURFXML_BUFFER_SET(AS_id, cluster_id); + static int AX_ptr = 0; + + char *cluster_id = A_surfxml_cluster_id; + char *cluster_prefix = A_surfxml_cluster_prefix; + char *cluster_suffix = A_surfxml_cluster_suffix; + char *cluster_radical = A_surfxml_cluster_radical; + char *cluster_power = A_surfxml_cluster_power; + char *cluster_bw = A_surfxml_cluster_bw; + char *cluster_lat = A_surfxml_cluster_lat; + char *cluster_bb_bw = A_surfxml_cluster_bb_bw; + char *cluster_bb_lat = A_surfxml_cluster_bb_lat; + char *host_id, *groups, *link_id; + char *router_id, *link_router, *link_backbone, *route_src_dst; + unsigned int iter; + int start, end, i; + xbt_dynar_t radical_elements; + xbt_dynar_t radical_ends; +#ifndef HAVE_PCRE_LIB + xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL); + char *route_src, *route_dst; + int j; +#endif + + static unsigned int surfxml_buffer_stack_stack_ptr = 1; + static unsigned int surfxml_buffer_stack_stack[1024]; + + surfxml_buffer_stack_stack[0] = 0; + + surfxml_bufferstack_push(1); + + SURFXML_BUFFER_SET(AS_id, cluster_id); #ifdef HAVE_PCRE_LIB - SURFXML_BUFFER_SET(AS_routing, "RuleBased"); - DEBUG1("",cluster_id); + SURFXML_BUFFER_SET(AS_routing, "RuleBased"); + DEBUG1("", cluster_id); #else - SURFXML_BUFFER_SET(AS_routing, "Full"); - DEBUG1("",cluster_id); + SURFXML_BUFFER_SET(AS_routing, "Full"); + DEBUG1("", cluster_id); +#endif + SURFXML_START_TAG(AS); + + radical_elements = xbt_str_split(cluster_radical, ","); + xbt_dynar_foreach(radical_elements, iter, groups) { + radical_ends = xbt_str_split(groups, "-"); + switch (xbt_dynar_length(radical_ends)) { + case 1: + surf_parse_get_int(&start, + xbt_dynar_get_as(radical_ends, 0, char *)); + host_id = bprintf("%s_%d%s", cluster_prefix, start, cluster_suffix); +#ifndef HAVE_PCRE_LIB + xbt_dynar_push_as(tab_elements_num, int, start); +#endif + link_id = bprintf("%s_link_%d", cluster_id, start); + + DEBUG2("", host_id, cluster_power); + SURFXML_BUFFER_SET(host_id, host_id); + SURFXML_BUFFER_SET(host_power, cluster_power); + SURFXML_BUFFER_SET(host_availability, "1.0"); + SURFXML_BUFFER_SET(host_availability_file, ""); + A_surfxml_host_state = A_surfxml_host_state_ON; + SURFXML_BUFFER_SET(host_state_file, ""); + SURFXML_START_TAG(host); + SURFXML_END_TAG(host); + + DEBUG3("", link_id, + cluster_bw, cluster_lat); + SURFXML_BUFFER_SET(link_id, link_id); + SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); + SURFXML_BUFFER_SET(link_latency, cluster_lat); + SURFXML_BUFFER_SET(link_bandwidth_file, ""); + SURFXML_BUFFER_SET(link_latency_file, ""); + A_surfxml_link_state = A_surfxml_link_state_ON; + SURFXML_BUFFER_SET(link_state_file, ""); + A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; + SURFXML_START_TAG(link); + SURFXML_END_TAG(link); + + break; + + case 2: + + surf_parse_get_int(&start, + xbt_dynar_get_as(radical_ends, 0, char *)); + surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *)); + DEBUG2("Create hosts and links from %d to %d", start, end); + for (i = start; i <= end; i++) { + host_id = bprintf("%s_%d%s", cluster_prefix, i, cluster_suffix); +#ifndef HAVE_PCRE_LIB + xbt_dynar_push_as(tab_elements_num, int, i); #endif - SURFXML_START_TAG(AS); - - radical_elements = xbt_str_split(cluster_radical, ","); - xbt_dynar_foreach(radical_elements, iter, groups) - { - radical_ends = xbt_str_split(groups, "-"); - switch (xbt_dynar_length(radical_ends)) - { - case 1: - surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *)); - host_id = bprintf("%s_%d%s", cluster_prefix, start, cluster_suffix); - #ifndef HAVE_PCRE_LIB - xbt_dynar_push_as(tab_elements_num, int, start); - #endif - link_id = bprintf("%s_link_%d", cluster_id, start); - - DEBUG2("",host_id,cluster_power); - SURFXML_BUFFER_SET(host_id, host_id); - SURFXML_BUFFER_SET(host_power, cluster_power); - SURFXML_BUFFER_SET(host_availability, "1.0"); - SURFXML_BUFFER_SET(host_availability_file, ""); - A_surfxml_host_state = A_surfxml_host_state_ON; - SURFXML_BUFFER_SET(host_state_file, ""); - SURFXML_START_TAG(host); - SURFXML_END_TAG(host); - - DEBUG3("",link_id,cluster_bw,cluster_lat); - SURFXML_BUFFER_SET(link_id, link_id); - SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); - SURFXML_BUFFER_SET(link_latency, cluster_lat); - SURFXML_BUFFER_SET(link_bandwidth_file, ""); - SURFXML_BUFFER_SET(link_latency_file, ""); - A_surfxml_link_state = A_surfxml_link_state_ON; - SURFXML_BUFFER_SET(link_state_file, ""); - A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; - SURFXML_START_TAG(link); - SURFXML_END_TAG(link); - - break; - - case 2: - - surf_parse_get_int(&start, xbt_dynar_get_as(radical_ends, 0, char *)); - surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *)); - DEBUG2("Create hosts and links from %d to %d",start,end); - for (i = start; i <= end; i++) - { - host_id = bprintf("%s_%d%s", cluster_prefix, i, cluster_suffix); - #ifndef HAVE_PCRE_LIB - xbt_dynar_push_as(tab_elements_num, int, i); - #endif - link_id = bprintf("%s_link_%d", cluster_id, i); - - DEBUG2("",host_id,cluster_power); - SURFXML_BUFFER_SET(host_id, host_id); - SURFXML_BUFFER_SET(host_power, cluster_power); - SURFXML_BUFFER_SET(host_availability, "1.0"); - SURFXML_BUFFER_SET(host_availability_file, ""); - A_surfxml_host_state = A_surfxml_host_state_ON; - SURFXML_BUFFER_SET(host_state_file, ""); - SURFXML_START_TAG(host); - SURFXML_END_TAG(host); - - DEBUG3("",link_id,cluster_bw,cluster_lat); - SURFXML_BUFFER_SET(link_id, link_id); - SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); - SURFXML_BUFFER_SET(link_latency, cluster_lat); - SURFXML_BUFFER_SET(link_bandwidth_file, ""); - SURFXML_BUFFER_SET(link_latency_file, ""); - A_surfxml_link_state = A_surfxml_link_state_ON; - SURFXML_BUFFER_SET(link_state_file, ""); - A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; - SURFXML_START_TAG(link); - SURFXML_END_TAG(link); - } - break; - - default: - DEBUG0("Malformed radical"); - } - - xbt_dynar_free(&radical_ends); - } - - DEBUG0(" "); - router_id = bprintf("%s_%s_router%s",cluster_prefix,cluster_id,cluster_suffix); - link_router = bprintf("%s_link_%s_router",cluster_id,cluster_id); - link_backbone = bprintf("%s_backbone",cluster_id); - - DEBUG1("",router_id); - SURFXML_BUFFER_SET(router_id, router_id);; - SURFXML_START_TAG(router); - SURFXML_END_TAG(router); - - DEBUG3("",link_router,cluster_bw,cluster_lat); - SURFXML_BUFFER_SET(link_id, link_router); - SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); - SURFXML_BUFFER_SET(link_latency, cluster_lat); - SURFXML_BUFFER_SET(link_bandwidth_file, ""); - SURFXML_BUFFER_SET(link_latency_file, ""); - A_surfxml_link_state = A_surfxml_link_state_ON; - SURFXML_BUFFER_SET(link_state_file, ""); - A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; - SURFXML_START_TAG(link); - SURFXML_END_TAG(link); - - DEBUG3("",link_backbone,cluster_bb_bw,cluster_bb_lat); - SURFXML_BUFFER_SET(link_id, link_backbone); - SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw); - SURFXML_BUFFER_SET(link_latency, cluster_bb_lat); - SURFXML_BUFFER_SET(link_bandwidth_file, ""); - SURFXML_BUFFER_SET(link_latency_file, ""); - A_surfxml_link_state = A_surfxml_link_state_ON; - SURFXML_BUFFER_SET(link_state_file, ""); - A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; - SURFXML_START_TAG(link); - SURFXML_END_TAG(link); - - char *new_suffix = bprintf("%s",""); - - radical_elements = xbt_str_split(cluster_suffix, "."); - xbt_dynar_foreach(radical_elements, iter, groups) - { - if(strcmp(groups,"")) - { - new_suffix = bprintf("%s\\.%s",new_suffix,groups); - } - } - route_src_dst = bprintf("%s_(.*)%s",cluster_prefix,new_suffix); - - DEBUG0(" "); + link_id = bprintf("%s_link_%d", cluster_id, i); + + DEBUG2("", host_id, cluster_power); + SURFXML_BUFFER_SET(host_id, host_id); + SURFXML_BUFFER_SET(host_power, cluster_power); + SURFXML_BUFFER_SET(host_availability, "1.0"); + SURFXML_BUFFER_SET(host_availability_file, ""); + A_surfxml_host_state = A_surfxml_host_state_ON; + SURFXML_BUFFER_SET(host_state_file, ""); + SURFXML_START_TAG(host); + SURFXML_END_TAG(host); + + DEBUG3("", link_id, + cluster_bw, cluster_lat); + SURFXML_BUFFER_SET(link_id, link_id); + SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); + SURFXML_BUFFER_SET(link_latency, cluster_lat); + SURFXML_BUFFER_SET(link_bandwidth_file, ""); + SURFXML_BUFFER_SET(link_latency_file, ""); + A_surfxml_link_state = A_surfxml_link_state_ON; + SURFXML_BUFFER_SET(link_state_file, ""); + A_surfxml_link_sharing_policy = + A_surfxml_link_sharing_policy_SHARED; + SURFXML_START_TAG(link); + SURFXML_END_TAG(link); + } + break; + + default: + DEBUG0("Malformed radical"); + } + + xbt_dynar_free(&radical_ends); + } + + DEBUG0(" "); + router_id = + bprintf("%s_%s_router%s", cluster_prefix, cluster_id, + cluster_suffix); + link_router = bprintf("%s_link_%s_router", cluster_id, cluster_id); + link_backbone = bprintf("%s_backbone", cluster_id); + + DEBUG1("", router_id); + SURFXML_BUFFER_SET(router_id, router_id);; + SURFXML_START_TAG(router); + SURFXML_END_TAG(router); + + DEBUG3("", link_router, + cluster_bw, cluster_lat); + SURFXML_BUFFER_SET(link_id, link_router); + SURFXML_BUFFER_SET(link_bandwidth, cluster_bw); + SURFXML_BUFFER_SET(link_latency, cluster_lat); + SURFXML_BUFFER_SET(link_bandwidth_file, ""); + SURFXML_BUFFER_SET(link_latency_file, ""); + A_surfxml_link_state = A_surfxml_link_state_ON; + SURFXML_BUFFER_SET(link_state_file, ""); + A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; + SURFXML_START_TAG(link); + SURFXML_END_TAG(link); + + DEBUG3("", link_backbone, + cluster_bb_bw, cluster_bb_lat); + SURFXML_BUFFER_SET(link_id, link_backbone); + SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw); + SURFXML_BUFFER_SET(link_latency, cluster_bb_lat); + SURFXML_BUFFER_SET(link_bandwidth_file, ""); + SURFXML_BUFFER_SET(link_latency_file, ""); + A_surfxml_link_state = A_surfxml_link_state_ON; + SURFXML_BUFFER_SET(link_state_file, ""); + A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED; + SURFXML_START_TAG(link); + SURFXML_END_TAG(link); + + char *new_suffix = bprintf("%s", ""); + + radical_elements = xbt_str_split(cluster_suffix, "."); + xbt_dynar_foreach(radical_elements, iter, groups) { + if (strcmp(groups, "")) { + new_suffix = bprintf("%s\\.%s", new_suffix, groups); + } + } + route_src_dst = bprintf("%s_(.*)%s", cluster_prefix, new_suffix); + + DEBUG0(" "); #ifdef HAVE_PCRE_LIB - DEBUG2("",route_src_dst,route_src_dst); - SURFXML_BUFFER_SET(route_src, route_src_dst); - SURFXML_BUFFER_SET(route_dst, route_src_dst); - SURFXML_START_TAG(route); + DEBUG2("", route_src_dst, route_src_dst); + SURFXML_BUFFER_SET(route_src, route_src_dst); + SURFXML_BUFFER_SET(route_dst, route_src_dst); + SURFXML_START_TAG(route); - DEBUG1("",cluster_id); - SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src",cluster_id)); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); + DEBUG1("", cluster_id); + SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id)); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); - DEBUG1("",cluster_id); - SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone",cluster_id)); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); + DEBUG1("", cluster_id); + SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id)); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); - DEBUG1("",cluster_id); - SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst",cluster_id)); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); + DEBUG1("", cluster_id); + SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id)); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); - DEBUG0(""); - SURFXML_END_TAG(route); + DEBUG0(""); + SURFXML_END_TAG(route); #else - for(i=0 ; i<=xbt_dynar_length(tab_elements_num) ; i++) - { - for(j=0 ; j<=xbt_dynar_length(tab_elements_num) ; j++) - { - if(i == xbt_dynar_length(tab_elements_num)) - { - route_src = router_id; - } - else - { - route_src = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,i,int),cluster_suffix); - } - - if(j == xbt_dynar_length(tab_elements_num)) - { - route_dst = router_id; - } - else - { - route_dst = bprintf("%s_%d%s",cluster_prefix,xbt_dynar_get_as(tab_elements_num,j,int),cluster_suffix); - } - - DEBUG2("",route_src,route_dst); - SURFXML_BUFFER_SET(route_src, route_src); - SURFXML_BUFFER_SET(route_dst, route_dst); - SURFXML_START_TAG(route); - - if(i == xbt_dynar_length(tab_elements_num)) - { - route_src = link_router; - } - else - { - route_src = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,i,int)); - } - - if(j == xbt_dynar_length(tab_elements_num)) - { - route_dst = link_router; - } - else - { - route_dst = bprintf("%s_link_%d",cluster_id,xbt_dynar_get_as(tab_elements_num,j,int)); - } - - DEBUG1("",route_src); - SURFXML_BUFFER_SET(link_ctn_id, route_src); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); - - DEBUG1("",cluster_id); - SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone",cluster_id)); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); - - DEBUG1("",route_dst); - SURFXML_BUFFER_SET(link_ctn_id, route_dst); - SURFXML_START_TAG(link_ctn); - SURFXML_END_TAG(link_ctn); - - DEBUG0(""); - SURFXML_END_TAG(route); - } - } - xbt_dynar_free(&tab_elements_num); + for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) { + for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) { + if (i == xbt_dynar_length(tab_elements_num)) { + route_src = router_id; + } else { + route_src = + bprintf("%s_%d%s", cluster_prefix, + xbt_dynar_get_as(tab_elements_num, i, int), + cluster_suffix); + } + + if (j == xbt_dynar_length(tab_elements_num)) { + route_dst = router_id; + } else { + route_dst = + bprintf("%s_%d%s", cluster_prefix, + xbt_dynar_get_as(tab_elements_num, j, int), + cluster_suffix); + } + + DEBUG2("", route_src, route_dst); + SURFXML_BUFFER_SET(route_src, route_src); + SURFXML_BUFFER_SET(route_dst, route_dst); + SURFXML_START_TAG(route); + + if (i == xbt_dynar_length(tab_elements_num)) { + route_src = link_router; + } else { + route_src = + bprintf("%s_link_%d", cluster_id, + xbt_dynar_get_as(tab_elements_num, i, int)); + } + + if (j == xbt_dynar_length(tab_elements_num)) { + route_dst = link_router; + } else { + route_dst = + bprintf("%s_link_%d", cluster_id, + xbt_dynar_get_as(tab_elements_num, j, int)); + } + + DEBUG1("", route_src); + SURFXML_BUFFER_SET(link_ctn_id, route_src); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); + + DEBUG1("", cluster_id); + SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id)); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); + + DEBUG1("", route_dst); + SURFXML_BUFFER_SET(link_ctn_id, route_dst); + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); + + DEBUG0(""); + SURFXML_END_TAG(route); + } + } + xbt_dynar_free(&tab_elements_num); #endif - DEBUG0(""); - SURFXML_END_TAG(AS); - DEBUG0(" "); + DEBUG0(""); + SURFXML_END_TAG(AS); + DEBUG0(" "); - surfxml_bufferstack_pop(1); + surfxml_bufferstack_pop(1); } /* @@ -2726,9 +3198,9 @@ static void routing_full_parse_Scluster(void) /* * calling parse_S_AS_lua with lua values */ -void routing_AS_init(const char* AS_id,const char* AS_routing) +void routing_AS_init(const char *AS_id, const char *AS_routing) { - parse_S_AS_lua((char*)AS_id,(char*)AS_routing); + parse_S_AS_lua((char *) AS_id, (char *) AS_routing); } /* @@ -2736,32 +3208,32 @@ void routing_AS_init(const char* AS_id,const char* AS_routing) */ void routing_AS_end(const char *AS_id) { - parse_E_AS_lua((char*)AS_id); + parse_E_AS_lua((char *) AS_id); } /* * add a host to the network element list */ -void routing_add_host(const char* host_id) +void routing_add_host(const char *host_id) { - parse_S_host_lua((char*)host_id); + parse_S_host_lua((char *) host_id); } /* * Set a new link on the actual list of link for a route or ASroute */ -void routing_add_link(const char* link_id) +void routing_add_link(const char *link_id) { - parse_E_link_c_ctn_new_elem_lua((char*)link_id); + parse_E_link_c_ctn_new_elem_lua((char *) link_id); } /* *Set the endpoints for a route */ -void routing_set_route(const char* src_id,const char *dst_id) +void routing_set_route(const char *src_id, const char *dst_id) { - parse_S_route_new_and_endpoints_lua((char*)src_id,(char*)dst_id); + parse_S_route_new_and_endpoints_lua((char *) src_id, (char *) dst_id); } /* @@ -2769,5 +3241,5 @@ void routing_set_route(const char* src_id,const char *dst_id) */ void routing_store_route(void) { - parse_E_route_store_route(); + parse_E_route_store_route(); } diff --git a/src/surf/surfxml_parse.c b/src/surf/surfxml_parse.c index a9512d8f0e..bf528308dd 100644 --- a/src/surf/surfxml_parse.c +++ b/src/surf/surfxml_parse.c @@ -151,8 +151,10 @@ void surf_parse_free_callbacks(void) void surf_parse_reset_parser(void) { surf_parse_free_callbacks(); - STag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_platform_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_platform_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_platform_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); @@ -161,28 +163,42 @@ void surf_parse_reset_parser(void) ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_link_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_link_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_link_ctn_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_link_ctn_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_process_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_process_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_argument_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_argument_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_trace_connect_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_trace_connect_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_trace_connect_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_trace_connect_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_ASroute_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_ASroute_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_bypassRoute_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_bypassRoute_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - STag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); - ETag_surfxml_cluster_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_ASroute_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_ASroute_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_bypassRoute_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_bypassRoute_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + STag_surfxml_cluster_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); + ETag_surfxml_cluster_cb_list = + xbt_dynar_new(sizeof(void_f_void_t), NULL); STag_surfxml_config_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); ETag_surfxml_config_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); } @@ -221,23 +237,39 @@ void STag_surfxml_platform(void) void type##Tag_surfxml_##name(void) \ { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); } - parse_method(E,platform); -parse_method(S,host); parse_method(E,host); -parse_method(S,router); parse_method(E,router); -parse_method(S,link); parse_method(E,link); -parse_method(S,route); parse_method(E,route); -parse_method(S,link_ctn); parse_method(E,link_ctn); -parse_method(S,process); parse_method(E,process); -parse_method(S,argument); parse_method(E,argument); -parse_method(S,prop); parse_method(E,prop); -parse_method(S,trace); parse_method(E,trace); -parse_method(S,trace_connect); parse_method(E,trace_connect); -parse_method(S,random); parse_method(E,random); -parse_method(S,AS); parse_method(E,AS); -parse_method(S,ASroute); parse_method(E,ASroute); -parse_method(S,bypassRoute); parse_method(E,bypassRoute); -parse_method(S,cluster); parse_method(E,cluster); -parse_method(S,config); parse_method(E,config); +parse_method(E, platform); +parse_method(S, host); +parse_method(E, host); +parse_method(S, router); +parse_method(E, router); +parse_method(S, link); +parse_method(E, link); +parse_method(S, route); +parse_method(E, route); +parse_method(S, link_ctn); +parse_method(E, link_ctn); +parse_method(S, process); +parse_method(E, process); +parse_method(S, argument); +parse_method(E, argument); +parse_method(S, prop); +parse_method(E, prop); +parse_method(S, trace); +parse_method(E, trace); +parse_method(S, trace_connect); +parse_method(E, trace_connect); +parse_method(S, random); +parse_method(E, random); +parse_method(S, AS); +parse_method(E, AS); +parse_method(S, ASroute); +parse_method(E, ASroute); +parse_method(S, bypassRoute); +parse_method(E, bypassRoute); +parse_method(S, cluster); +parse_method(E, cluster); +parse_method(S, config); +parse_method(E, config); /* Open and Close parse file */ @@ -247,7 +279,7 @@ void surf_parse_open(const char *file) if (!file) { if (!warned) { WARN0 - ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code."); + ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code."); warned = 1; } return; @@ -305,13 +337,13 @@ void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) xbt_dynar_push(cb_list, &function); } -void surfxml_del_callback(xbt_dynar_t* p_cb_list, void_f_void_t function) +void surfxml_del_callback(xbt_dynar_t * p_cb_list, void_f_void_t function) { xbt_dynar_t new_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL); unsigned int it; void_f_void_t func; - xbt_dynar_foreach(*p_cb_list,it,func) { - if( func != function ) + xbt_dynar_foreach(*p_cb_list, it, func) { + if (func != function) xbt_dynar_push(new_cb_list, &func); } xbt_dynar_free(p_cb_list); @@ -341,13 +373,14 @@ static void init_data(void) trace_connect_list_link_avail = xbt_dict_new(); trace_connect_list_bandwidth = xbt_dict_new(); trace_connect_list_latency = xbt_dict_new(); - + surfxml_add_callback(STag_surfxml_random_cb_list, &init_randomness); surfxml_add_callback(ETag_surfxml_random_cb_list, &add_randomness); surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties); surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_Stag_trace); surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_Etag_trace); - surfxml_add_callback(STag_surfxml_trace_connect_cb_list, &parse_Stag_trace_connect); + surfxml_add_callback(STag_surfxml_trace_connect_cb_list, + &parse_Stag_trace_connect); } static void free_data(void) @@ -385,7 +418,7 @@ void parse_properties(void) { char *value = NULL; if (!current_property_set) - current_property_set = xbt_dict_new(); // Maybe, it should be make a error + current_property_set = xbt_dict_new(); // Maybe, it should be make a error value = xbt_strdup(A_surfxml_prop_value); xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free); } @@ -413,8 +446,8 @@ static void parse_Etag_trace(void) trace = NULL; else trace = - tmgr_trace_new_from_string(trace_id, surfxml_pcdata, - trace_periodicity); + tmgr_trace_new_from_string(trace_id, surfxml_pcdata, + trace_periodicity); } xbt_dict_set(traces_set_list, trace_id, (void *) trace, NULL); } @@ -484,7 +517,8 @@ double get_cpu_power(const char *power) return power_scale; } -double random_min, random_max, random_mean, random_std_deviation, random_generator; +double random_min, random_max, random_mean, random_std_deviation, + random_generator; char *random_id; static void init_randomness(void) @@ -493,29 +527,37 @@ static void init_randomness(void) surf_parse_get_double(&random_min, A_surfxml_random_min); surf_parse_get_double(&random_max, A_surfxml_random_max); surf_parse_get_double(&random_mean, A_surfxml_random_mean); - surf_parse_get_double(&random_std_deviation, A_surfxml_random_std_deviation); + surf_parse_get_double(&random_std_deviation, + A_surfxml_random_std_deviation); random_generator = A_surfxml_random_generator; } static void add_randomness(void) { /* If needed aditional properties can be added by using the prop tag */ - random_data_t random = random_new(random_generator, 0, random_min, random_max, random_mean, random_std_deviation); - xbt_dict_set(random_data_list, random_id, (void *) random, &xbt_free_ref); + random_data_t random = + random_new(random_generator, 0, random_min, random_max, random_mean, + random_std_deviation); + xbt_dict_set(random_data_list, random_id, (void *) random, + &xbt_free_ref); } /** * create CPU resource via CPU Model */ void surf_host_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - return surf_cpu_model->extension.cpu. - create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties); + return surf_cpu_model->extension.cpu.create_resource(name, power_peak, + power_scale, + power_trace, + state_initial, + state_trace, + cpu_properties); } /** @@ -523,32 +565,44 @@ void surf_host_create_resource(char *name, double power_peak, */ void surf_wsL07_host_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - surf_workstation_model->extension.workstation. - cpu_create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties); + surf_workstation_model->extension.workstation.cpu_create_resource(name, + power_peak, + power_scale, + power_trace, + state_initial, + state_trace, + cpu_properties); } + /** * create link resource via network Model */ void surf_link_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t policy, - xbt_dict_t properties) -{ - return surf_network_model->extension.network. - create_resource(name,bw_initial,bw_trace,lat_initial,lat_trace, - state_initial,state_trace,policy,properties); + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t policy, + xbt_dict_t properties) +{ + return surf_network_model->extension.network.create_resource(name, + bw_initial, + bw_trace, + lat_initial, + lat_trace, + state_initial, + state_trace, + policy, + properties); } /** @@ -556,19 +610,20 @@ void surf_link_create_resource(char *name, */ void surf_wsL07_link_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) -{ - return surf_workstation_model->extension.workstation. - link_create_resource(name,bw_initial,bw_trace,lat_initial,lat_trace, - state_initial,state_trace,policy,properties); + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties) +{ + return surf_workstation_model->extension.workstation. + link_create_resource(name, bw_initial, bw_trace, lat_initial, + lat_trace, state_initial, state_trace, policy, + properties); } /** @@ -576,39 +631,39 @@ void surf_wsL07_link_create_resource(char *name, *init new routing model component */ -void surf_AS_new(const char* AS_id, const char *AS_mode) +void surf_AS_new(const char *AS_id, const char *AS_mode) { - routing_AS_init(AS_id,AS_mode); + routing_AS_init(AS_id, AS_mode); } -void surf_AS_finalize(const char* AS_id) +void surf_AS_finalize(const char *AS_id) { - routing_AS_end(AS_id); + routing_AS_end(AS_id); } /* * add host to the network element list */ -void surf_route_add_host(const char* host_id) +void surf_route_add_host(const char *host_id) { - routing_add_host(host_id); + routing_add_host(host_id); } /** * set route */ -void surf_routing_add_route(const char *src_id,const char *dst_id,xbt_dynar_t links_id) -{ - unsigned int i; - const char * link_id; - routing_set_route(src_id,dst_id); - xbt_dynar_foreach(links_id,i,link_id) - { - routing_add_link(link_id); - } +void surf_routing_add_route(const char *src_id, const char *dst_id, + xbt_dynar_t links_id) +{ + unsigned int i; + const char *link_id; + routing_set_route(src_id, dst_id); + xbt_dynar_foreach(links_id, i, link_id) { + routing_add_link(link_id); + } - //store the route - routing_store_route(); + //store the route + routing_store_route(); } /** @@ -616,16 +671,15 @@ void surf_routing_add_route(const char *src_id,const char *dst_id,xbt_dynar_t li */ void surf_add_host_traces(void) { - return surf_cpu_model->extension.cpu.add_traces(); + return surf_cpu_model->extension.cpu.add_traces(); } void surf_add_link_traces(void) { - return surf_network_model->extension.network.add_traces(); + return surf_network_model->extension.network.add_traces(); } void surf_wsL07_add_traces(void) { - return surf_workstation_model->extension.workstation.add_traces(); + return surf_workstation_model->extension.workstation.add_traces(); } - diff --git a/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index 03827df497..6a4d8bdacb 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -82,8 +82,8 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, } xbt_dynar_push(trace->event_list, &event); last_event = - xbt_dynar_get_ptr(trace->event_list, - xbt_dynar_length(trace->event_list) - 1); + xbt_dynar_get_ptr(trace->event_list, + xbt_dynar_length(trace->event_list) - 1); } if (last_event) last_event->delta = periodicity; @@ -100,7 +100,7 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, tmgr_trace_t tmgr_trace_new(const char *filename) { - char *tstr = NULL; + char *tstr = NULL; FILE *f = NULL; tmgr_trace_t trace = NULL; @@ -116,8 +116,8 @@ tmgr_trace_t tmgr_trace_new(const char *filename) } f = surf_fopen(filename, "r"); - xbt_assert2(f!=NULL, "Cannot open file '%s' (path=%s)", filename, - xbt_str_join(surf_path,":")); + xbt_assert2(f != NULL, "Cannot open file '%s' (path=%s)", filename, + xbt_str_join(surf_path, ":")); tstr = xbt_str_from_file(f); fclose(f); diff --git a/src/surf/trace_mgr_private.h b/src/surf/trace_mgr_private.h index c3c6120182..5f72a84b5f 100644 --- a/src/surf/trace_mgr_private.h +++ b/src/surf/trace_mgr_private.h @@ -31,4 +31,4 @@ typedef struct tmgr_history { xbt_heap_t heap; } s_tmgr_history_t; -#endif /* _SURF_TMGR_PRIVATE_H */ +#endif /* _SURF_TMGR_PRIVATE_H */ diff --git a/src/surf/workstation.c b/src/surf/workstation.c index ba94803a1b..4d6fd9adca 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -19,8 +19,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, surf_model_t surf_workstation_model = NULL; -static workstation_CLM03_t workstation_new(const char *name, - void *cpu) +static workstation_CLM03_t workstation_new(const char *name, void *cpu) { workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1); @@ -40,8 +39,9 @@ void create_workstations(void) char *name = NULL; void *cpu = NULL; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) { - workstation_new(name, cpu); + xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, + cpu) { + workstation_new(name, cpu); } } @@ -111,8 +111,8 @@ static void ws_update_actions_state(double now, double delta) } static void ws_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ } @@ -120,13 +120,13 @@ static void ws_update_resource_state(void *id, static surf_action_t ws_execute(void *workstation, double size) { return surf_cpu_model->extension.cpu. - execute(((workstation_CLM03_t) workstation)->cpu, size); + execute(((workstation_CLM03_t) workstation)->cpu, size); } static surf_action_t ws_action_sleep(void *workstation, double duration) { return surf_cpu_model->extension.cpu. - sleep(((workstation_CLM03_t) workstation)->cpu, duration); + sleep(((workstation_CLM03_t) workstation)->cpu, duration); } static void ws_action_suspend(surf_action_t action) @@ -158,7 +158,8 @@ static int ws_action_is_suspended(surf_action_t action) DIE_IMPOSSIBLE; } -static void ws_action_set_max_duration(surf_action_t action, double duration) +static void ws_action_set_max_duration(surf_action_t action, + double duration) { if (action->model_type == surf_network_model) surf_network_model->set_max_duration(action, duration); @@ -183,7 +184,8 @@ static int ws_get_latency_limited(surf_action_t action) { if (action->model_type == surf_network_model) return surf_network_model->get_latency_limited(action); - INFO0("You tried to ask if a non network action is limited by latency, aborting..."); + INFO0 + ("You tried to ask if a non network action is limited by latency, aborting..."); DIE_IMPOSSIBLE; } #endif @@ -198,40 +200,40 @@ static double ws_action_get_remains(surf_action_t action) } static surf_action_t ws_communicate(void *workstation_src, - void *workstation_dst, double size, - double rate) + void *workstation_dst, double size, + double rate) { workstation_CLM03_t src = (workstation_CLM03_t) workstation_src; workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst; return surf_network_model->extension.network. - communicate(surf_resource_name(src->cpu), surf_resource_name(dst->cpu), - size, rate); + communicate(surf_resource_name(src->cpu), + surf_resource_name(dst->cpu), size, rate); } static e_surf_resource_state_t ws_get_state(void *workstation) { return surf_cpu_model->extension.cpu. - get_state(((workstation_CLM03_t) workstation)->cpu); + get_state(((workstation_CLM03_t) workstation)->cpu); } static double ws_get_speed(void *workstation, double load) { return surf_cpu_model->extension.cpu. - get_speed(((workstation_CLM03_t) workstation)->cpu, load); + get_speed(((workstation_CLM03_t) workstation)->cpu, load); } static double ws_get_available_speed(void *workstation) { return surf_cpu_model->extension.cpu. - get_available_speed(((workstation_CLM03_t) - workstation)->cpu); + get_available_speed(((workstation_CLM03_t) + workstation)->cpu); } static surf_action_t ws_execute_parallel_task(int workstation_nb, - void **workstation_list, - double *computation_amount, - double *communication_amount, - double amount, double rate) + void **workstation_list, + double *computation_amount, + double *communication_amount, + double amount, double rate) { THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ } @@ -240,8 +242,8 @@ static surf_action_t ws_execute_parallel_task(int workstation_nb, /* returns an array of network_link_CM02_t */ static xbt_dynar_t ws_get_route(void *src, void *dst) { - return surf_network_model->extension.network.get_route(surf_resource_name(src), - surf_resource_name(src)); + return surf_network_model->extension. + network.get_route(surf_resource_name(src), surf_resource_name(src)); } static double ws_get_link_bandwidth(const void *link) @@ -280,11 +282,12 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->action_state_set = ws_action_state_set; surf_workstation_model->model_private->resource_used = ws_resource_used; - surf_workstation_model->model_private->share_resources = ws_share_resources; + surf_workstation_model->model_private->share_resources = + ws_share_resources; surf_workstation_model->model_private->update_actions_state = - ws_update_actions_state; + ws_update_actions_state; surf_workstation_model->model_private->update_resource_state = - ws_update_resource_state; + ws_update_resource_state; surf_workstation_model->model_private->finalize = ws_finalize; surf_workstation_model->suspend = ws_action_suspend; @@ -302,19 +305,21 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->extension.workstation.get_state = ws_get_state; surf_workstation_model->extension.workstation.get_speed = ws_get_speed; surf_workstation_model->extension.workstation.get_available_speed = - ws_get_available_speed; + ws_get_available_speed; - surf_workstation_model->extension.workstation.communicate = ws_communicate; + surf_workstation_model->extension.workstation.communicate = + ws_communicate; surf_workstation_model->extension.workstation.get_route = ws_get_route; surf_workstation_model->extension.workstation.execute_parallel_task = - ws_execute_parallel_task; + ws_execute_parallel_task; surf_workstation_model->extension.workstation.get_link_bandwidth = - ws_get_link_bandwidth; + ws_get_link_bandwidth; surf_workstation_model->extension.workstation.get_link_latency = - ws_get_link_latency; - surf_workstation_model->extension.workstation.link_shared = ws_link_shared; + ws_get_link_latency; + surf_workstation_model->extension.workstation.link_shared = + ws_link_shared; surf_workstation_model->extension.workstation.get_properties = - ws_get_properties; + ws_get_properties; } diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 54b74271c6..b176ce8bb1 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -79,8 +79,12 @@ static void ptask_update_action_bound(surf_action_workstation_L07_t action) for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { - xbt_dynar_t route = global_routing->get_route(surf_resource_name(action->workstation_list[i]), - surf_resource_name(action->workstation_list[j])); + xbt_dynar_t route = + global_routing->get_route(surf_resource_name + (action->workstation_list[i]), + surf_resource_name(action-> + workstation_list + [j])); double lat = 0.0; @@ -89,8 +93,9 @@ static void ptask_update_action_bound(surf_action_workstation_L07_t action) lat += link->lat_current; } lat_current = - MAX(lat_current, - lat * action->communication_amount[i * workstation_nb + j]); + MAX(lat_current, + lat * action->communication_amount[i * workstation_nb + + j]); } } } @@ -118,7 +123,8 @@ static int ptask_action_unref(surf_action_t action) xbt_swag_remove(action, action->state_set); if (((surf_action_workstation_L07_t) action)->variable) lmm_variable_free(ptask_maxmin_system, - ((surf_action_workstation_L07_t) action)->variable); + ((surf_action_workstation_L07_t) + action)->variable); free(((surf_action_workstation_L07_t) action)->workstation_list); free(((surf_action_workstation_L07_t) action)->communication_amount); free(((surf_action_workstation_L07_t) action)->computation_amount); @@ -151,7 +157,8 @@ static void ptask_action_suspend(surf_action_t action) static void ptask_action_resume(surf_action_t action) { - surf_action_workstation_L07_t act = (surf_action_workstation_L07_t) action; + surf_action_workstation_L07_t act = + (surf_action_workstation_L07_t) action; XBT_IN1("(%p)", act); if (act->suspended != 2) { @@ -166,7 +173,8 @@ static int ptask_action_is_suspended(surf_action_t action) return (((surf_action_workstation_L07_t) action)->suspended == 1); } -static void ptask_action_set_max_duration(surf_action_t action, double duration) +static void ptask_action_set_max_duration(surf_action_t action, + double duration) { /* FIXME: should inherit */ XBT_IN2("(%p,%g)", action, duration); action->max_duration = duration; @@ -174,7 +182,8 @@ static void ptask_action_set_max_duration(surf_action_t action, double duration) } -static void ptask_action_set_priority(surf_action_t action, double priority) +static void ptask_action_set_priority(surf_action_t action, + double priority) { /* FIXME: should inherit */ XBT_IN2("(%p,%g)", action, priority); action->priority = priority; @@ -207,7 +216,7 @@ static double ptask_share_resources(double now) surf_action_workstation_L07_t action = NULL; xbt_swag_t running_actions = - surf_workstation_model->states.running_action_set; + surf_workstation_model->states.running_action_set; double min = generic_maxmin_share_resources(running_actions, xbt_swag_offset(s_action, variable), @@ -239,7 +248,7 @@ static void ptask_update_actions_state(double now, double delta) surf_action_workstation_L07_t action = NULL; surf_action_workstation_L07_t next_action = NULL; xbt_swag_t running_actions = - surf_workstation_model->states.running_action_set; + surf_workstation_model->states.running_action_set; xbt_swag_foreach_safe(action, next_action, running_actions) { deltap = delta; @@ -311,7 +320,8 @@ static void ptask_update_actions_state(double now, double delta) SURF_RESOURCE_OFF))) { DEBUG1("Action (%p) Failed!!", action); action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, SURF_ACTION_FAILED); + surf_action_state_set((surf_action_t) action, + SURF_ACTION_FAILED); break; } } @@ -321,8 +331,8 @@ static void ptask_update_actions_state(double now, double delta) } static void ptask_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) + tmgr_trace_event_t event_type, + double value, double date) { cpu_L07_t cpu = id; link_L07_t nw_link = id; @@ -364,8 +374,8 @@ static void ptask_update_resource_state(void *id, } return; } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) { - DEBUG3("Updating cpu %s (%p) with value %g", surf_resource_name(cpu), cpu, - value); + DEBUG3("Updating cpu %s (%p) with value %g", surf_resource_name(cpu), + cpu, value); if (event_type == cpu->power_event) { cpu->power_current = value; lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint, @@ -429,10 +439,12 @@ static double ptask_get_available_speed(void *cpu) } static surf_action_t ptask_execute_parallel_task(int workstation_nb, - void **workstation_list, - double *computation_amount, - double *communication_amount, - double amount, double rate) + void **workstation_list, + double + *computation_amount, double + *communication_amount, + double amount, + double rate) { surf_action_workstation_L07_t action = NULL; int i, j; @@ -450,15 +462,18 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { link_L07_t link; - xbt_dynar_t route = global_routing->get_route(surf_resource_name(workstation_list[i]), - surf_resource_name(workstation_list[j])); + xbt_dynar_t route = + global_routing->get_route(surf_resource_name + (workstation_list[i]), + surf_resource_name(workstation_list + [j])); double lat = 0.0; if (communication_amount[i * workstation_nb + j] > 0) xbt_dynar_foreach(route, cpt, link) { lat += link->lat_current; - xbt_dict_set(ptask_parallel_task_link_set, link->generic_resource.name, - link, NULL); + xbt_dict_set(ptask_parallel_task_link_set, + link->generic_resource.name, link, NULL); } latency = MAX(latency, lat); } @@ -472,10 +487,10 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, nb_host++; action = - surf_action_new(sizeof(s_surf_action_workstation_L07_t), amount, - surf_workstation_model, 0); - DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", action, - workstation_nb, nb_link); + surf_action_new(sizeof(s_surf_action_workstation_L07_t), amount, + surf_workstation_model, 0); + DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", + action, workstation_nb, nb_link); action->suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ action->workstation_nb = workstation_nb; @@ -486,9 +501,9 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, action->rate = rate; action->variable = - lmm_variable_new(ptask_maxmin_system, action, 1.0, - (action->rate > 0) ? action->rate : -1.0, - workstation_nb + nb_link); + lmm_variable_new(ptask_maxmin_system, action, 1.0, + (action->rate > 0) ? action->rate : -1.0, + workstation_nb + nb_link); if (action->latency > 0) lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0); @@ -501,8 +516,11 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, for (i = 0; i < workstation_nb; i++) { for (j = 0; j < workstation_nb; j++) { link_L07_t link; - xbt_dynar_t route = global_routing->get_route(surf_resource_name(workstation_list[i]), - surf_resource_name(workstation_list[j])); + xbt_dynar_t route = + global_routing->get_route(surf_resource_name + (workstation_list[i]), + surf_resource_name(workstation_list + [j])); if (communication_amount[i * workstation_nb + j] == 0.0) continue; @@ -532,12 +550,13 @@ static surf_action_t ptask_execute(void *cpu, double size) communication_amount[0] = 0.0; computation_amount[0] = size; - return ptask_execute_parallel_task(1, workstation_list, computation_amount, - communication_amount, 1, -1); + return ptask_execute_parallel_task(1, workstation_list, + computation_amount, + communication_amount, 1, -1); } static surf_action_t ptask_communicate(void *src, void *dst, double size, - double rate) + double rate) { void **workstation_list = xbt_new0(void *, 2); double *computation_amount = xbt_new0(double, 2); @@ -549,8 +568,8 @@ static surf_action_t ptask_communicate(void *src, void *dst, double size, communication_amount[1] = size; res = ptask_execute_parallel_task(2, workstation_list, - computation_amount, communication_amount, - 1, rate); + computation_amount, + communication_amount, 1, rate); return res; } @@ -572,7 +591,8 @@ static surf_action_t ptask_action_sleep(void *cpu, double duration) static xbt_dynar_t ptask_get_route(void *src, void *dst) { - return global_routing->get_route( surf_resource_name(src), surf_resource_name(dst)); + return global_routing->get_route(surf_resource_name(src), + surf_resource_name(dst)); } static double ptask_get_link_bandwidth(const void *link) @@ -595,14 +615,16 @@ static int ptask_link_shared(const void *link) /**************************************/ static cpu_L07_t ptask_cpu_new(const char *name, double power_scale, - double power_initial, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, xbt_dict_t cpu_properties) + double power_initial, + tmgr_trace_t power_trace, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1); xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name), - "Host '%s' declared several times in the platform file.", name); + "Host '%s' declared several times in the platform file.", + name); cpu->generic_resource.model = surf_workstation_model; cpu->type = SURF_WORKSTATION_RESOURCE_CPU; @@ -616,16 +638,16 @@ static cpu_L07_t ptask_cpu_new(const char *name, double power_scale, cpu->power_current = power_initial; if (power_trace) cpu->power_event = - tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); cpu->state_current = state_initial; if (state_trace) cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); + tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); cpu->constraint = - lmm_constraint_new(ptask_maxmin_system, cpu, - cpu->power_current * cpu->power_scale); + lmm_constraint_new(ptask_maxmin_system, cpu, + cpu->power_current * cpu->power_scale); xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu, surf_resource_free); @@ -656,34 +678,37 @@ static void ptask_parse_cpu_init(void) current_property_set = xbt_dict_new(); ptask_cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace, - state_initial, state_trace, current_property_set); + state_initial, state_trace, current_property_set); } static void ptask_cpu_create_resource(char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) + double power_scale, + tmgr_trace_t power_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { - ptask_cpu_new(xbt_strdup(name),power_peak,power_scale,power_trace, - state_initial,state_trace,cpu_properties); + ptask_cpu_new(xbt_strdup(name), power_peak, power_scale, power_trace, + state_initial, state_trace, cpu_properties); } static link_L07_t ptask_link_new(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties) { link_L07_t nw_link = xbt_new0(s_link_L07_t, 1); - xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_set, name), - "Link '%s' declared several times in the platform file.", name); + xbt_assert1(!xbt_dict_get_or_null + (surf_network_model->resource_set, name), + "Link '%s' declared several times in the platform file.", + name); nw_link->generic_resource.model = surf_workstation_model; nw_link->generic_resource.properties = properties; @@ -692,18 +717,19 @@ static link_L07_t ptask_link_new(char *name, nw_link->bw_current = bw_initial; if (bw_trace) nw_link->bw_event = - tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link); + tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link); nw_link->state_current = state_initial; nw_link->lat_current = lat_initial; if (lat_trace) nw_link->lat_event = - tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link); + tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link); if (state_trace) nw_link->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link); + tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link); nw_link->constraint = - lmm_constraint_new(ptask_maxmin_system, nw_link, nw_link->bw_current); + lmm_constraint_new(ptask_maxmin_system, nw_link, + nw_link->bw_current); if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(nw_link->constraint); @@ -740,7 +766,8 @@ static void ptask_parse_link_init(void) else if (A_surfxml_link_state == A_surfxml_link_state_OFF) state_initial_link = SURF_RESOURCE_OFF; - if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED) + if (A_surfxml_link_sharing_policy == + A_surfxml_link_sharing_policy_SHARED) policy_initial_link = SURF_LINK_SHARED; else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE) @@ -750,24 +777,25 @@ static void ptask_parse_link_init(void) current_property_set = xbt_dict_new(); ptask_link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace, - state_initial_link, state_trace, policy_initial_link, - current_property_set); + state_initial_link, state_trace, policy_initial_link, + current_property_set); } static void ptask_link_create_resource(char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_resource_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + policy, xbt_dict_t properties) { - ptask_link_new(name, bw_initial, bw_trace, - lat_initial, lat_trace, state_initial, state_trace,policy, xbt_dict_new()); + ptask_link_new(name, bw_initial, bw_trace, + lat_initial, lat_trace, state_initial, state_trace, + policy, xbt_dict_new()); } @@ -782,40 +810,45 @@ static void ptask_add_traces(void) /* Connect traces relative to cpu */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm); + cpu_L07_t host = + surf_model_resource_by_name(surf_workstation_model, elm); xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->state_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm); + cpu_L07_t host = + surf_model_resource_by_name(surf_workstation_model, elm); xbt_assert1(host, "Host %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + host->power_event = + tmgr_history_add_trace(history, trace, 0.0, 0, host); } /* Connect traces relative to network */ xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_L07_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert1(link, "Link %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); - link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); + link->state_event = + tmgr_history_add_trace(history, trace, 0.0, 0, link); } xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_L07_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert1(link, "Link %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); @@ -826,7 +859,7 @@ static void ptask_add_traces(void) xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); link_L07_t link = - xbt_dict_get_or_null(surf_network_model->resource_set, elm); + xbt_dict_get_or_null(surf_network_model->resource_set, elm); xbt_assert1(link, "Link %s undefined", elm); xbt_assert1(trace, "Trace %s undefined", trace_name); @@ -863,47 +896,54 @@ static void ptask_model_init_internal(void) surf_workstation_model->get_remains = ptask_action_get_remains; surf_workstation_model->name = "Workstation ptask_L07"; - surf_workstation_model->model_private->resource_used = ptask_resource_used; - surf_workstation_model->model_private->share_resources = ptask_share_resources; + surf_workstation_model->model_private->resource_used = + ptask_resource_used; + surf_workstation_model->model_private->share_resources = + ptask_share_resources; surf_workstation_model->model_private->update_actions_state = - ptask_update_actions_state; + ptask_update_actions_state; surf_workstation_model->model_private->update_resource_state = - ptask_update_resource_state; + ptask_update_resource_state; surf_workstation_model->model_private->finalize = ptask_finalize; surf_workstation_model->extension.workstation.execute = ptask_execute; surf_workstation_model->extension.workstation.sleep = ptask_action_sleep; surf_workstation_model->extension.workstation.get_state = - ptask_resource_get_state; - surf_workstation_model->extension.workstation.get_speed = ptask_get_speed; + ptask_resource_get_state; + surf_workstation_model->extension.workstation.get_speed = + ptask_get_speed; surf_workstation_model->extension.workstation.get_available_speed = - ptask_get_available_speed; - surf_workstation_model->extension.workstation.communicate = ptask_communicate; - surf_workstation_model->extension.workstation.get_route = ptask_get_route; + ptask_get_available_speed; + surf_workstation_model->extension.workstation.communicate = + ptask_communicate; + surf_workstation_model->extension.workstation.get_route = + ptask_get_route; surf_workstation_model->extension.workstation.execute_parallel_task = - ptask_execute_parallel_task; + ptask_execute_parallel_task; surf_workstation_model->extension.workstation.get_link_bandwidth = - ptask_get_link_bandwidth; + ptask_get_link_bandwidth; surf_workstation_model->extension.workstation.get_link_latency = - ptask_get_link_latency; - surf_workstation_model->extension.workstation.link_shared = ptask_link_shared; + ptask_get_link_latency; + surf_workstation_model->extension.workstation.link_shared = + ptask_link_shared; surf_workstation_model->extension.workstation.get_properties = - surf_resource_properties; + surf_resource_properties; surf_workstation_model->extension.workstation.link_create_resource = - ptask_link_create_resource; + ptask_link_create_resource; surf_workstation_model->extension.workstation.cpu_create_resource = - ptask_cpu_create_resource; - surf_workstation_model->extension.workstation.add_traces = ptask_add_traces; + ptask_cpu_create_resource; + surf_workstation_model->extension.workstation.add_traces = + ptask_add_traces; if (!ptask_maxmin_system) ptask_maxmin_system = lmm_system_new(); routing_model_create(sizeof(link_L07_t), ptask_link_new(xbt_strdup("__loopback__"), - 498000000, NULL, 0.000015, NULL, - SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE, - NULL)); + 498000000, NULL, 0.000015, NULL, + SURF_RESOURCE_ON, NULL, + SURF_LINK_FATPIPE, NULL)); } diff --git a/src/swag_unit.c b/src/swag_unit.c index b4bc834c07..ec82ffbd69 100644 --- a/src/swag_unit.c +++ b/src/swag_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 219 "xbt/swag.c" +#line 224 "xbt/swag.c" typedef struct { diff --git a/src/win32/compiler/borland.h b/src/win32/compiler/borland.h index 89d944bcc5..0c873a24aa 100644 --- a/src/win32/compiler/borland.h +++ b/src/win32/compiler/borland.h @@ -21,78 +21,78 @@ /* No header file. */ #if defined(HAVE_DLFCN_H) - #undef HAVE_DLFCN_H -#endif +#undef HAVE_DLFCN_H +#endif /* Defined if the compiler has the header file. */ #if !defined(HAVE_ERRNO_H) - #define HAVE_ERRNO_H 1 +#define HAVE_ERRNO_H 1 #endif /* No header file. */ #if defined(HAVE_EXECINFO_H) - #undef HAVE_EXECINFO_H +#undef HAVE_EXECINFO_H #endif /* No header file. */ #if defined(HAVE_INTTYPES_H) - #undef HAVE_INTTYPES_H +#undef HAVE_INTTYPES_H #endif /* Defined if compiler has the header file. */ #if !defined(HAVE_MEMORY_H) - #define HAVE_MEMORY_H 1 +#define HAVE_MEMORY_H 1 #endif /* No header file. */ #if defined(HAVE_PTHREAD_H) - #undef HAVE_PTHREAD_H +#undef HAVE_PTHREAD_H #endif /* No header file. */ #if defined(HAVE_STDINT_H) - #undef HAVE_STDINT_H +#undef HAVE_STDINT_H #endif /* The compiler has the header file. */ #if !defined(HAVE_STDLIB_H) - #define HAVE_STDLIB_H 1 +#define HAVE_STDLIB_H 1 #endif /* No header file. */ #if defined(HAVE_STRINGS_H) - #undef HAVE_STRINGS_H +#undef HAVE_STRINGS_H #endif /* The compiler has the header file. */ #if !defined(HAVE_STRING_H) - #define HAVE_STRING_H 1 +#define HAVE_STRING_H 1 #endif /* No header file. */ #if defined(HAVE_SYS_SOCKET_H) - #undef HAVE_SYS_SOCKET_H +#undef HAVE_SYS_SOCKET_H #endif /* The compiler has header file. */ #if !defined(HAVE_SYS_STAT_H) - #define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_STAT_H 1 #endif /* No header file. */ #if defined(HAVE_SYS_TIME_H) - #undef HAVE_SYS_TIME_H 1 +#undef HAVE_SYS_TIME_H 1 #endif /* The compiler has the header file. */ #if !defined(HAVE_SYS_TYPES_H) - #define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 #endif /* No header file. */ #if defined(HAVE_UNISTD_H) - #undef HAVE_UNISTD_H +#undef HAVE_UNISTD_H #endif /* @@ -100,12 +100,12 @@ * Process the case of afx.h */ #if !defined(HAVE_WINDOWS_H) - #define HAVE_WINDOWS_H 1 +#define HAVE_WINDOWS_H 1 #endif /* The compiler has the header file. */ #if !defined(HAVE_WINSOCK2_H) - #define HAVE_WINSOCK2_H +#define HAVE_WINSOCK2_H #endif /* @@ -113,12 +113,12 @@ * Trouble if winsock2.h exists ? */ #if !defined(HAVE_WINSOCK_H) - #define HAVE_WINSOCK_H 1 +#define HAVE_WINSOCK_H 1 #endif /* The compiler has the header file */ #if !defined(HAVE_SIGNAL_H) - #define HAVE_SIGNAL_H 1 +#define HAVE_SIGNAL_H 1 #endif /* @@ -127,72 +127,72 @@ /* No `getcontext' function. */ #if defined(HAVE_GETCONTEXT) - #undef HAVE_GETCONTEXT +#undef HAVE_GETCONTEXT #endif /* No `getdtablesize' function. */ #if defined(HAVE_GETDTABLESIZE) - #undef HAVE_GETDTABLESIZE +#undef HAVE_GETDTABLESIZE #endif /* No `gettimeofday' function. */ #if defined(HAVE_GETTIMEOFDAY) - #undef HAVE_GETTIMEOFDAY +#undef HAVE_GETTIMEOFDAY #endif /* No `makecontext' function. */ #if defined(HAVE_MAKECONTEXT) - #undef HAVE_MAKECONTEXT +#undef HAVE_MAKECONTEXT #endif /* No 'popen' function. */ #if defined(HAVE_POPEN) - #undef HAVE_POPEN +#undef HAVE_POPEN #endif /* No `readv' function. */ #if defined(HAVE_READV) - #undef HAVE_READV +#undef HAVE_READV #endif /* No `setcontext' function. */ #if defined(HAVE_SETCONTEXT) - #undef HAVE_SETCONTEXT +#undef HAVE_SETCONTEXT #endif /* No 'signal' function */ #if defined(HAVE_SIGNAL) - #undef HAVE_SIGNAL +#undef HAVE_SIGNAL #endif /* The compiler has `snprintf' function. */ #if !defined(HAVE_SNPRINTF) - #define HAVE_SNPRINTF 1 +#define HAVE_SNPRINTF 1 #endif /* No `swapcontext' function. */ #if defined(HAVE_SWAPCONTEXT) - #undef HAVE_SWAPCONTEXT +#undef HAVE_SWAPCONTEXT #endif /* No `sysconf' function. */ #if defined(HAVE_SYSCONF) - #undef HAVE_SYSCONF +#undef HAVE_SYSCONF #endif /* No `usleep' function. */ #if defined(HAVE_USLEEP) - #undef HAVE_USLEEP +#undef HAVE_USLEEP #endif /* The compiler has the `vsnprintf' function. */ #if !defined(HAVE_VSNPRINTF) - #define HAVE_VSNPRINTF 1 +#define HAVE_VSNPRINTF 1 #endif /* enable the asprintf replacement */ #if !defined(NEED_ASPRINTF) - #define NEED_ASPRINTF 1 +#define NEED_ASPRINTF 1 #endif /*#ifdef NEED_ASPRINTF @@ -202,32 +202,32 @@ /* enable the vasprintf replacement */ #if !defined(NEED_VASPRINTF) - #define NEED_VASPRINTF 1 +#define NEED_VASPRINTF 1 #endif /* "disable the snprintf replacement ( this function is broken on system v only" */ /* FIXME TO ANALYZE */ #if defined(PREFER_PORTABLE_SNPRINTF) - #undef PREFER_PORTABLE_SNPRINTF +#undef PREFER_PORTABLE_SNPRINTF #endif #if !defined(PREFER_PORTABLE_SNPRINTF) - #define PREFER_PORTABLE_SNPRINTF +#define PREFER_PORTABLE_SNPRINTF #endif /* The maximal size of any scalar on this arch */ #if !defined(SIZEOF_MAX) - #define SIZEOF_MAX 8 +#define SIZEOF_MAX 8 #endif /* Define to 1 if you have the ANSI C header files. */ #if !defined(STDC_HEADERS) - #define STDC_HEADERS 1 +#define STDC_HEADERS 1 #endif #if defined(TIME_WITH_SYS_TIME) - #undef TIME_WITH_SYS_TIME +#undef TIME_WITH_SYS_TIME #endif /* @@ -236,14 +236,14 @@ /* Define to 1 if you have the `pthread' library (-lpthread). */ #if defined(HAVE_LIBPTHREAD) - #undef HAVE_LIBPTHREAD +#undef HAVE_LIBPTHREAD #endif /* * package informations ? */ - - + + /* Defined if arrays in struct can straddle struct alignment boundaries. This is like than the structure compaction above, but this time, the argument to be compacted is an array whom each element would be normally compacted. @@ -252,7 +252,7 @@ is allowed to come just after i. Note that GRAS only support architecture presenting this caracteristic so far. */ #if defined(GRAS_ARRAY_STRADDLE_STRUCT) - #undef GRAS_ARRAY_STRADDLE_STRUCT +#undef GRAS_ARRAY_STRADDLE_STRUCT #endif /* Defined if structures are compacted when possible. Consider this structure: @@ -260,7 +260,7 @@ struct s {double d; int i; char c;}; If it is allowed, the char is placed just after the int. If not, it has to be on the 8 bytes boundary imposed by the double. For now, GRAS requires the structures to be compacted. */ #if defined(GRAS_STRUCT_COMPACT) - #undef GRAS_STRUCT_COMPACT +#undef GRAS_STRUCT_COMPACT #endif /* Name of package */ @@ -284,10 +284,10 @@ the double. For now, GRAS requires the structures to be compacted. */ /* * macro */ - + /* define if big endian */ #if !defined(GRAS_BIGENDIAN) - #define GRAS_BIGENDIAN 0 +#define GRAS_BIGENDIAN 0 #endif /* Defined if structures are compacted when possible. Consider this structure: @@ -295,28 +295,28 @@ struct s {double d; int i; char c;}; If it is allowed, the char is placed just after the int. If not, it has to be on the 8 bytes boundary imposed by the double. For now, GRAS requires the structures to be compacted. */ #if defined(GRAS_STRUCT_COMPACT) - #define GRAS_STRUCT_COMPACT 1 +#define GRAS_STRUCT_COMPACT 1 #endif /* defines the GRAS architecture signature of this machine */ #if defined(GRAS_THISARCH) - #undef GRAS_THISARCH +#undef GRAS_THISARCH #endif #define GRAS_THISARCH 0 - + /* Path to the addr2line tool */ #if defined(ADDR2LINE) - #undef ADDR2LINE +#undef ADDR2LINE #endif #if !defined(HAVE_VA_COPY) - #define HAVE_VA_COPY 1 +#define HAVE_VA_COPY 1 #endif /* This macro is not defined in borland stdarg.h include file, adds it. */ -#define va_copy(dest,src) ((dest)=(src)) +#define va_copy(dest,src) ((dest)=(src)) /* Predefined possible va_copy() implementation (id: ASP) */ #define __VA_COPY_USE_ASP(d, s) do { *(d) = *(s); } while (0) @@ -353,26 +353,26 @@ the double. For now, GRAS requires the structures to be compacted. */ #define __VA_COPY_USE __VA_COPY_USE_C99 #ifndef _XBT_CALL - #if defined(_XBT_DESIGNATED_DLL) - #define _XBT_CALL __cdecl __export - #elif defined(_RTLDLL) - #define _XBT_CALL __cdecl __import - #else - #define _XBT_CALL __cdecl - #endif +#if defined(_XBT_DESIGNATED_DLL) +#define _XBT_CALL __cdecl __export +#elif defined(_RTLDLL) +#define _XBT_CALL __cdecl __import +#else +#define _XBT_CALL __cdecl +#endif #endif /* auto enable thread safety and exceptions: */ #ifndef _CPPUNWIND - #define _XBT_HAS_NO_EXCEPTIONS +#define _XBT_HAS_NO_EXCEPTIONS #endif #if defined ( __MT__ ) && !defined (_NOTHREADS) && !defined (_REENTRANT) - #define _REENTRANT 1 +#define _REENTRANT 1 #endif #if(__BORLANDC__>= 0x500) - #define _XBT_HAS_NAMESPACES +#define _XBT_HAS_NAMESPACES #endif @@ -384,7 +384,7 @@ the double. For now, GRAS requires the structures to be compacted. */ #include /* no unistd.h header file. */ -#define YY_NO_UNISTD_H +#define YY_NO_UNISTD_H /* * Replace winsock2.h,ws2tcpip.h and winsock.h header files */ #include @@ -395,7 +395,7 @@ typedef unsigned int uint32_t; /* Choose setjmp as exception implementation */ #ifndef __EX_MCTX_SJLJ__ #define __EX_MCTX_SJLJ__ -#endif +#endif /* this is used in context managment. */ #ifdef CONTEXT_UCONTEXT @@ -409,4 +409,4 @@ typedef unsigned int uint32_t; -#endif /* #ifndef __XBT_BORLAND_COMPILER_CONFIG_H__ */ +#endif /* #ifndef __XBT_BORLAND_COMPILER_CONFIG_H__ */ diff --git a/src/win32/compiler/select_compiler_features.h b/src/win32/compiler/select_compiler_features.h index 2c044a76fa..0c213606b8 100644 --- a/src/win32/compiler/select_compiler_features.h +++ b/src/win32/compiler/select_compiler_features.h @@ -16,15 +16,15 @@ /* Borland compilers */ #if defined (__BORLANDC__) #define _XBT_COMPILER_NAME "Borland C/C++" - #define _XBT_COMPILER_VENDOR "Inprise Corporation" +#define _XBT_COMPILER_VENDOR "Inprise Corporation" #define _XBT_BORLAND_COMPILER 2 /* version macro : __BORLANDC__ */ /* version format : ? */ #define _XBT_COMPILER_VERSION __BORLANDC__ #define _XBT_COMPILER_VERSION_FORMAT "?" - #undef _XBT_COMPILER_RESOLVED - #define _XBT_COMPILER_RESOLVED 1 +#undef _XBT_COMPILER_RESOLVED +#define _XBT_COMPILER_RESOLVED 1 #endif /* Microsoft Visual C++ compiler */ @@ -43,15 +43,15 @@ #endif #define _XBT_COMPILER_NAME "GCC" - #define _XBT_COMPILER_VENDOR "GNU" +#define _XBT_COMPILER_VENDOR "GNU" #define _XBT_GCC_COMPILER 2 /* version macro : __GNUC_VERSION__ */ /* version format : VVRRPP (VV = Version, RR = Revision, PP = Patch) */ #define _XBT_COMPILER_VERSION __GNUC_VERSION__ #define _XBT_COMPILER_VERSION_FORMAT "VVRRPP (VV = Version, RR = Revision, PP = Patch)" - #undef _XBT_COMPILER_RESOLVED - #define _XBT_COMPILER_RESOLVED 1 +#undef _XBT_COMPILER_RESOLVED +#define _XBT_COMPILER_RESOLVED 1 #endif @@ -74,4 +74,4 @@ -#endif /* #ifndef __XBT_SELECT_FEATURES_COMPILER_H__ */ +#endif /* #ifndef __XBT_SELECT_FEATURES_COMPILER_H__ */ diff --git a/src/win32/compiler/visualc.h b/src/win32/compiler/visualc.h index 37d93ecd57..57c86a602d 100644 --- a/src/win32/compiler/visualc.h +++ b/src/win32/compiler/visualc.h @@ -16,12 +16,12 @@ #include #ifdef _WIN32_WINNT - #if _WIN32_WINNT < 0x0400 - #undef _WIN32_WINNT - #define _WIN32_WINNT 0x0400 - #endif +#if _WIN32_WINNT < 0x0400 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0400 +#endif #else - #define _WIN32_WINNT 0x0400 +#define _WIN32_WINNT 0x0400 #endif /* @@ -30,83 +30,83 @@ /* No header file. */ #if defined(HAVE_DLFCN_H) - #undef HAVE_DLFCN_H -#endif +#undef HAVE_DLFCN_H +#endif /* Defined if the compiler has the header file. */ #if !defined(HAVE_ERRNO_H) - #define HAVE_ERRNO_H 1 +#define HAVE_ERRNO_H 1 #endif /* No header file. */ #if defined(HAVE_EXECINFO_H) - #undef HAVE_EXECINFO_H +#undef HAVE_EXECINFO_H #endif /* No header file. */ #if defined(HAVE_INTTYPES_H) - #undef HAVE_INTTYPES_H +#undef HAVE_INTTYPES_H #endif /* Defined if compiler has the header file. */ #if !defined(HAVE_MEMORY_H) - #define HAVE_MEMORY_H 1 +#define HAVE_MEMORY_H 1 #endif /* No header file. */ #if defined(HAVE_PTHREAD_H) - #undef HAVE_PTHREAD_H +#undef HAVE_PTHREAD_H #endif /* No header file. */ #if defined(HAVE_STDINT_H) - #undef HAVE_STDINT_H +#undef HAVE_STDINT_H #endif /* The compiler has the header file. */ #if !defined(HAVE_STDLIB_H) - #define HAVE_STDLIB_H 1 +#define HAVE_STDLIB_H 1 #endif /* No header file. */ #if defined(HAVE_STRINGS_H) - #undef HAVE_STRINGS_H +#undef HAVE_STRINGS_H #endif /* The compiler has the header file. */ #if !defined(HAVE_STRING_H) - #define HAVE_STRING_H 1 +#define HAVE_STRING_H 1 #endif /* No header file. */ #if defined(HAVE_SYS_SOCKET_H) - #undef HAVE_SYS_SOCKET_H +#undef HAVE_SYS_SOCKET_H #endif /* The compiler has header file. */ #if !defined(HAVE_SYS_STAT_H) - #define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_STAT_H 1 #endif /* No header file. */ #if defined(HAVE_SYS_TIME_H) - #undef HAVE_SYS_TIME_H 1 +#undef HAVE_SYS_TIME_H 1 #endif /* The compiler has the header file. */ #if !defined(HAVE_SYS_TYPES_H) - #define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 #endif /* No header file. */ #if defined(HAVE_UNISTD_H) - #undef HAVE_UNISTD_H +#undef HAVE_UNISTD_H #endif /* The compiler has the header file */ #if !defined(HAVE_SIGNAL_H) - #define HAVE_SIGNAL_H 1 +#define HAVE_SIGNAL_H 1 #endif /* @@ -115,42 +115,42 @@ /* No `getcontext' function. */ #if defined(HAVE_GETCONTEXT) - #undef HAVE_GETCONTEXT +#undef HAVE_GETCONTEXT #endif /* No `getdtablesize' function. */ #if defined(HAVE_GETDTABLESIZE) - #undef HAVE_GETDTABLESIZE +#undef HAVE_GETDTABLESIZE #endif /* No `gettimeofday' function. */ #if defined(HAVE_GETTIMEOFDAY) - #undef HAVE_GETTIMEOFDAY +#undef HAVE_GETTIMEOFDAY #endif /* No `makecontext' function. */ #if defined(HAVE_MAKECONTEXT) - #undef HAVE_MAKECONTEXT +#undef HAVE_MAKECONTEXT #endif /* No 'popen' function. */ #if defined(HAVE_POPEN) - #undef HAVE_POPEN +#undef HAVE_POPEN #endif /* No `readv' function. */ #if defined(HAVE_READV) - #undef HAVE_READV +#undef HAVE_READV #endif /* No `setcontext' function. */ #if defined(HAVE_SETCONTEXT) - #undef HAVE_SETCONTEXT +#undef HAVE_SETCONTEXT #endif /* No 'signal' function */ #if defined(HAVE_SIGNAL) - #undef HAVE_SIGNAL +#undef HAVE_SIGNAL #endif /* "disable the snprintf replacement ( this function is broken on system v only" */ @@ -158,21 +158,21 @@ #ifdef PREFER_PORTABLE_SNPRINTF -# undef PREFER_PORTABLE_SNPRINTF 1 +# undef PREFER_PORTABLE_SNPRINTF 1 #endif /* The compiler has `snprintf' function. */ -#if _MSC_VER >= 1400 +#if _MSC_VER >= 1400 # ifndef HAVE_SNPRINTF # define HAVE_SNPRINTF 1 # ifndef PREFER_PORTABLE_SNPRINTF # define snprintf _snprintf # endif # endif -#else +#else # ifdef HAVE_SNPRINTF - #undef HAVE_SNPRINTF +#undef HAVE_SNPRINTF # endif #endif @@ -180,48 +180,48 @@ /* No `swapcontext' function. */ #if defined(HAVE_SWAPCONTEXT) - #undef HAVE_SWAPCONTEXT +#undef HAVE_SWAPCONTEXT #endif /* No `sysconf' function. */ #if defined(HAVE_SYSCONF) - #undef HAVE_SYSCONF +#undef HAVE_SYSCONF #endif /* No `usleep' function. */ #if defined(HAVE_USLEEP) - #undef HAVE_USLEEP +#undef HAVE_USLEEP #endif /* The compiler has the `vsnprintf' function. */ #ifndef HAVE_VSNPRINTF - #define HAVE_VSNPRINTF 1 +#define HAVE_VSNPRINTF 1 #endif /* disable the asprintf replacement */ #ifndef NEED_ASPRINTF - #define NEED_ASPRINTF +#define NEED_ASPRINTF #endif /* disable the vasprintf replacement */ #ifndef NEED_VASPRINTF - #define NEED_VASPRINTF +#define NEED_VASPRINTF #endif /* The maximal size of any scalar on this arch */ #if !defined(SIZEOF_MAX) - #define SIZEOF_MAX 8 +#define SIZEOF_MAX 8 #endif /* Define to 1 if you have the ANSI C header files. */ #if !defined(STDC_HEADERS) - #define STDC_HEADERS 1 +#define STDC_HEADERS 1 #endif #if defined(TIME_WITH_SYS_TIME) - #undef TIME_WITH_SYS_TIME +#undef TIME_WITH_SYS_TIME #endif /* @@ -230,14 +230,14 @@ /* Define to 1 if you have the `pthread' library (-lpthread). */ #if defined(HAVE_LIBPTHREAD) - #undef HAVE_LIBPTHREAD +#undef HAVE_LIBPTHREAD #endif /* * package informations ? */ - - + + /* Defined if arrays in struct can straddle struct alignment boundaries. This is like than the structure compaction above, but this time, the argument to be compacted is an array whom each element would be normally compacted. @@ -246,7 +246,7 @@ is allowed to come just after i. Note that GRAS only support architecture presenting this caracteristic so far. */ #if defined(GRAS_ARRAY_STRADDLE_STRUCT) - #undef GRAS_ARRAY_STRADDLE_STRUCT +#undef GRAS_ARRAY_STRADDLE_STRUCT #endif /* Defined if structures are compacted when possible. Consider this structure: @@ -254,7 +254,7 @@ struct s {double d; int i; char c;}; If it is allowed, the char is placed just after the int. If not, it has to be on the 8 bytes boundary imposed by the double. For now, GRAS requires the structures to be compacted. */ #if defined(GRAS_STRUCT_COMPACT) - #undef GRAS_STRUCT_COMPACT +#undef GRAS_STRUCT_COMPACT #endif /* Name of package */ @@ -278,10 +278,10 @@ the double. For now, GRAS requires the structures to be compacted. */ /* * macro */ - + /* define if big endian */ #if !defined(GRAS_BIGENDIAN) - #define GRAS_BIGENDIAN 0 +#define GRAS_BIGENDIAN 0 #endif /* Defined if structures are compacted when possible. Consider this structure: @@ -289,81 +289,81 @@ struct s {double d; int i; char c;}; If it is allowed, the char is placed just after the int. If not, it has to be on the 8 bytes boundary imposed by the double. For now, GRAS requires the structures to be compacted. */ #if defined(GRAS_STRUCT_COMPACT) - #define GRAS_STRUCT_COMPACT 1 +#define GRAS_STRUCT_COMPACT 1 #endif /* defines the GRAS architecture signature of this machine */ #if defined(GRAS_THISARCH) - #undef GRAS_THISARCH +#undef GRAS_THISARCH #endif #define GRAS_THISARCH 3 - + /* Path to the addr2line tool */ #if defined(ADDR2LINE) - #undef ADDR2LINE +#undef ADDR2LINE #endif #ifndef __VISUALC__ - #if !defined(HAVE_VA_COPY) - #define HAVE_VA_COPY 1 - #endif +#if !defined(HAVE_VA_COPY) +#define HAVE_VA_COPY 1 +#endif - /* This macro is not defined in borland stdarg.h include file, adds it. */ - #ifndef va_copy(dest,src) - #define va_copy(dest,src) ((dest)=(src)) - #endif + /* This macro is not defined in borland stdarg.h include file, adds it. */ +#ifndef va_copy(dest,src) +#define va_copy(dest,src) ((dest)=(src)) +#endif - #ifndef __VA_COPY_USE_ASP(d, s) - /* Predefined possible va_copy() implementation (id: ASP) */ - #define __VA_COPY_USE_ASP(d, s) do { *(d) = *(s); } while (0) - #endif +#ifndef __VA_COPY_USE_ASP(d, s) + /* Predefined possible va_copy() implementation (id: ASP) */ +#define __VA_COPY_USE_ASP(d, s) do { *(d) = *(s); } while (0) +#endif - #ifndef __VA_COPY_USE_ASS(d, s) - /* Predefined possible va_copy() implementation (id: ASS) */ - #define __VA_COPY_USE_ASS(d, s) do { (d) = (s); } while (0) - #endif +#ifndef __VA_COPY_USE_ASS(d, s) + /* Predefined possible va_copy() implementation (id: ASS) */ +#define __VA_COPY_USE_ASS(d, s) do { (d) = (s); } while (0) +#endif - #ifndef __VA_COPY_USE_C99(d, s) - /* Predefined possible va_copy() implementation (id: C99) */ - #define __VA_COPY_USE_C99(d, s) va_copy((d), (s)) - #endif +#ifndef __VA_COPY_USE_C99(d, s) + /* Predefined possible va_copy() implementation (id: C99) */ +#define __VA_COPY_USE_C99(d, s) va_copy((d), (s)) +#endif - #ifndef __VA_COPY_USE_CPP(d, s) - /* Predefined possible va_copy() implementation (id: CPP) */ - #define __VA_COPY_USE_CPP(d, s) memcpy((void *)(d), (void *)(s), sizeof(*(s))) - #endif +#ifndef __VA_COPY_USE_CPP(d, s) + /* Predefined possible va_copy() implementation (id: CPP) */ +#define __VA_COPY_USE_CPP(d, s) memcpy((void *)(d), (void *)(s), sizeof(*(s))) +#endif - #ifndef __VA_COPY_USE_CPS(d, s) - /* Predefined possible va_copy() implementation (id: CPS) */ - #define __VA_COPY_USE_CPS(d, s) memcpy((void *)&(d), (void *)&(s), sizeof(s)) - #endif +#ifndef __VA_COPY_USE_CPS(d, s) + /* Predefined possible va_copy() implementation (id: CPS) */ +#define __VA_COPY_USE_CPS(d, s) memcpy((void *)&(d), (void *)&(s), sizeof(s)) +#endif - #ifndef __VA_COPY_USE_GCB(d, s) - /* Predefined possible va_copy() implementation (id: GCB) */ - #define __VA_COPY_USE_GCB(d, s) __builtin_va_copy((d), (s)) - #endif +#ifndef __VA_COPY_USE_GCB(d, s) + /* Predefined possible va_copy() implementation (id: GCB) */ +#define __VA_COPY_USE_GCB(d, s) __builtin_va_copy((d), (s)) +#endif - #ifndef __VA_COPY_USE_GCH(d, s) - /* Predefined possible va_copy() implementation (id: GCH) */ - #define __VA_COPY_USE_GCH(d, s) __va_copy((d), (s)) - #endif - /* Predefined possible va_copy() implementation (id: GCM) */ - #define __VA_COPY_USE_GCM(d, s) VA_COPY((d), (s)) +#ifndef __VA_COPY_USE_GCH(d, s) + /* Predefined possible va_copy() implementation (id: GCH) */ +#define __VA_COPY_USE_GCH(d, s) __va_copy((d), (s)) +#endif + /* Predefined possible va_copy() implementation (id: GCM) */ +#define __VA_COPY_USE_GCM(d, s) VA_COPY((d), (s)) - /* Optional va_copy() implementation activation */ - #ifndef HAVE_VA_COPY - #define va_copy(d, s) __VA_COPY_USE(d, s) - #endif + /* Optional va_copy() implementation activation */ +#ifndef HAVE_VA_COPY +#define va_copy(d, s) __VA_COPY_USE(d, s) +#endif - /* Define to id of used va_copy() implementation */ - #ifndef __VA_COPY_USE - #define __VA_COPY_USE __VA_COPY_USE_C99 - #endif + /* Define to id of used va_copy() implementation */ +#ifndef __VA_COPY_USE +#define __VA_COPY_USE __VA_COPY_USE_C99 +#endif #endif /* xbt contexts are based on our threads implementation */ @@ -379,22 +379,22 @@ the double. For now, GRAS requires the structures to be compacted. */ #ifndef _XBT_CALL - #if defined(_XBT_DESIGNATED_DLL) - #define _XBT_CALL __cdecl __export - #elif defined(_RTLDLL) - #define _XBT_CALL __cdecl __import - #else - #define _XBT_CALL __cdecl - #endif +#if defined(_XBT_DESIGNATED_DLL) +#define _XBT_CALL __cdecl __export +#elif defined(_RTLDLL) +#define _XBT_CALL __cdecl __import +#else +#define _XBT_CALL __cdecl +#endif #endif /* auto enable thread safety and exceptions: */ #ifndef _CPPUNWIND - #define _XBT_HAS_NO_EXCEPTIONS +#define _XBT_HAS_NO_EXCEPTIONS #endif #if defined ( __MT__ ) && !defined (_NOTHREADS) && !defined (_REENTRANT) - #define _REENTRANT 1 +#define _REENTRANT 1 #endif @@ -406,7 +406,7 @@ the double. For now, GRAS requires the structures to be compacted. */ #include /* no unistd.h header file. */ -#define YY_NO_UNISTD_H +#define YY_NO_UNISTD_H /* * Replace winsock2.h,ws2tcpip.h and winsock.h header files */ #include @@ -415,7 +415,7 @@ the double. For now, GRAS requires the structures to be compacted. */ /* Choose setjmp as exception implementation */ #ifndef __EX_MCTX_SJLJ__ #define __EX_MCTX_SJLJ__ -#endif +#endif @@ -435,4 +435,4 @@ typedef unsigned int mode_t; typedef unsigned int uint32_t; -#endif /* #ifndef __XBT_VISUALC_COMPILER_CONFIG_H__ */ +#endif /* #ifndef __XBT_VISUALC_COMPILER_CONFIG_H__ */ diff --git a/src/win32/config.h b/src/win32/config.h index c276c69546..85b3f6c6c4 100644 --- a/src/win32/config.h +++ b/src/win32/config.h @@ -17,17 +17,17 @@ #if defined(_XBT_BORLAND_COMPILER) - # include +# include #elif defined(__GNUC__) - /* data comes from autoconf when using gnuc (cross-compiling?) */ - # include "gras_config.h" - #ifndef _XBT_WIN32 - typedef unsigned int uint32_t; - #endif + /* data comes from autoconf when using gnuc (cross-compiling?) */ +# include "gras_config.h" +#ifndef _XBT_WIN32 +typedef unsigned int uint32_t; +#endif #elif defined(_XBT_VISUALC_COMPILER) - # include +# include # else - # error "Unknown compiler - please report the problems to the main simgrid mailing list (http://gforge.inria.fr/mail/?group_id=12)" +# error "Unknown compiler - please report the problems to the main simgrid mailing list (http://gforge.inria.fr/mail/?group_id=12)" #endif typedef int socklen_t; @@ -38,33 +38,33 @@ typedef int socklen_t; #define AC_SOCKET_INVALID ((unsigned int) ~0) #ifdef SD_BOTH - #define tcp_close(s) (shutdown( s, SD_BOTH ), closesocket(s)) +#define tcp_close(s) (shutdown( s, SD_BOTH ), closesocket(s)) #else - #define tcp_close( s ) closesocket( s ) +#define tcp_close( s ) closesocket( s ) #endif #ifndef _XBT_VISUALC_COMPILER - #ifndef EWOULDBLOCK - #define EWOULDBLOCK WSAEWOULDBLOCK - #endif - #ifndef EINPROGRESS - #define EINPROGRESS WSAEINPROGRESS - #endif - #ifndef ETIMEDOUT - #define ETIMEDOUT WSAETIMEDOUT - #endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef EINPROGRESS +#define EINPROGRESS WSAEINPROGRESS +#endif +#ifndef ETIMEDOUT +#define ETIMEDOUT WSAETIMEDOUT +#endif #endif #ifdef sock_errno - #undef sock_errno +#undef sock_errno #endif #define sock_errno WSAGetLastError() #ifdef sock_errstr - #undef sock_errstr +#undef sock_errstr #endif #define sock_errstr(err) gras_wsa_err2string(err) @@ -72,17 +72,17 @@ typedef int socklen_t; const char *gras_wsa_err2string(int errcode); #ifdef S_IRGRP - #undef S_IRGRP +#undef S_IRGRP #endif #define S_IRGRP 0 #ifdef S_IWGRP - #undef S_IWGRP +#undef S_IWGRP #endif #define S_IWGRP 0 -#endif /* #ifndef __XBT_WIN32_CONFIG_H__ */ +#endif /* #ifndef __XBT_WIN32_CONFIG_H__ */ diff --git a/src/win32/platform/select_platform_features.h b/src/win32/platform/select_platform_features.h index 93f536616d..da9a167e51 100644 --- a/src/win32/platform/select_platform_features.h +++ b/src/win32/platform/select_platform_features.h @@ -15,62 +15,62 @@ /* * win32 or win64 (__XBT_WIN32 is defined for win32 and win64 applications, __TOS_WIN__ is defined by xlC). -*/ +*/ /* If the platform is not resolved _XBT_PLATFORM_ID is set to zero. */ #define _XBT_PLATFORM_ID 0 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__TOS_WIN__) - #undef _XBT_PLATFORM_ID - #define _XBT_WIN32_PLATFORM 1 - #define _XBT_PLATFORM_ID _XBT_WIN32_PLATFORM - #define _XBT_PLATFORM_NAME "Windows 32 bits platform" +#undef _XBT_PLATFORM_ID +#define _XBT_WIN32_PLATFORM 1 +#define _XBT_PLATFORM_ID _XBT_WIN32_PLATFORM +#define _XBT_PLATFORM_NAME "Windows 32 bits platform" /* * win64. */ #elif defined(_WIN64) - #undef _XBT_PLATFORM_ID - #ifdef _XBT_WIN32_PLATFORM - #undef _XBT_WIN32_PLATFORM - #endif - - #define _XBT_PLATFORM_NAME "Windows 64 bits platform" - #define _XBT_WIN64_PLATFORM 2 - #define _XBT_PLATFORM_ID _XBT_WIN64_PLATFORM +#undef _XBT_PLATFORM_ID +#ifdef _XBT_WIN32_PLATFORM +#undef _XBT_WIN32_PLATFORM +#endif + +#define _XBT_PLATFORM_NAME "Windows 64 bits platform" +#define _XBT_WIN64_PLATFORM 2 +#define _XBT_PLATFORM_ID _XBT_WIN64_PLATFORM /* * win16. */ #elif defined(_WIN16) - #undef _XBT_PLATFORM_ID - #define _XBT_WIN16_PLATFORM 3 - #define _XBT_PLATFORM_NAME "Windows 16 bits platform" - #define _XBT_PLATFORM_ID _XBT_WIN16_PLATFORM +#undef _XBT_PLATFORM_ID +#define _XBT_WIN16_PLATFORM 3 +#define _XBT_PLATFORM_NAME "Windows 16 bits platform" +#define _XBT_PLATFORM_ID _XBT_WIN16_PLATFORM /* * wince. */ #elif defined(UNDER_CE) - #undef _XBT_PLATFORM_ID - #define __XBT_WINCE_PLATFORM 4 - #define _XBT_PLATFORM_ID _XBT_WINCE_PLATFORM - #define _XBT_PLATFORM_NAME "Windows CE bits platform" +#undef _XBT_PLATFORM_ID +#define __XBT_WINCE_PLATFORM 4 +#define _XBT_PLATFORM_ID _XBT_WINCE_PLATFORM +#define _XBT_PLATFORM_NAME "Windows CE bits platform" #elif defined(linux) || defined(__linux) || defined(__linux__) /* linux. */ - #undef _XBT_PLATFORM_ID - #define __XBT_LINUX_PLATFORM 5 - #define _XBT_PLATFORM_ID _XBT_LINUX_PLATFORM - #define _XBT_PLATFORM_NAME "Linux platform" - +#undef _XBT_PLATFORM_ID +#define __XBT_LINUX_PLATFORM 5 +#define _XBT_PLATFORM_ID _XBT_LINUX_PLATFORM +#define _XBT_PLATFORM_NAME "Linux platform" + #elif defined (_XBT_ASSERT_CONFIG) - // This must come last - generate an error if we don't - // resolve the platform: - #error "Unknown platform - please configure (simgrid.gforge.inria.fr/xbt/libs/config/config.htm#configuring) and report the results to the main simgrid mailing list (simgrid.gforge.inra.fr/more/mailing_lists.htm#main)" + // This must come last - generate an error if we don't + // resolve the platform: +#error "Unknown platform - please configure (simgrid.gforge.inria.fr/xbt/libs/config/config.htm#configuring) and report the results to the main simgrid mailing list (simgrid.gforge.inra.fr/more/mailing_lists.htm#main)" #endif #if defined(_XBT_WIN32_PLATFORM) || defined(_XBT_WIN64_PLATFORM) || defined(_XBT_WIN16_PLATFORM) || defined(_XBT_WINCE_PLATFORM) #ifndef _XBT_WIN32 - #define _XBT_WIN32 +#define _XBT_WIN32 #endif #endif @@ -82,7 +82,7 @@ #define _xbt_get_platform_name() _XBT_PLATFORM_NAME /* Returns the platform id. */ -#define _xbt_get_platform_id() _XBT_PLATFORM_ID +#define _xbt_get_platform_id() _XBT_PLATFORM_ID /* Returns true if the platform is Windows 32 bits. */ #define _xbt_is_win32() (_XBT_PLATFORM_ID == 1) @@ -102,4 +102,4 @@ -#endif /* #define __XBT_SELECT_PLATFORM_FEATURES_H__ */ +#endif /* #define __XBT_SELECT_PLATFORM_FEATURES_H__ */ diff --git a/src/xbt/backtrace_linux.c b/src/xbt/backtrace_linux.c index da489dc102..29dd7f7a1a 100644 --- a/src/xbt/backtrace_linux.c +++ b/src/xbt/backtrace_linux.c @@ -101,7 +101,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) e->bt_strings = xbt_new(char *, 1); e->bt_strings[0] = - bprintf("(binary '%s' not found the path)", xbt_binary_name); + bprintf("(binary '%s' not found the path)", xbt_binary_name); return; } xbt_dynar_free(&path); @@ -112,8 +112,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) binary_name = xbt_strdup(xbt_binary_name); } cmd = curr = - xbt_new(char, - strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used); + xbt_new(char, + strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used); curr += sprintf(curr, "%s -f -e %s ", ADDR2LINE, binary_name); free(binary_name); @@ -151,17 +151,20 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) fgets_res = fgets(line_func, 1024, pipe); if (fgets_res == NULL) THROW2(system_error, 0, - "Cannot run fgets to look for symbol %d, addr %s", i, addrs[i]); + "Cannot run fgets to look for symbol %d, addr %s", i, + addrs[i]); line_func[strlen(line_func) - 1] = '\0'; fgets_res = fgets(line_pos, 1024, pipe); if (fgets_res == NULL) THROW2(system_error, 0, - "Cannot run fgets to look for symbol %d, addr %s", i, addrs[i]); + "Cannot run fgets to look for symbol %d, addr %s", i, + addrs[i]); line_pos[strlen(line_pos) - 1] = '\0'; if (strcmp("??", line_func)) { DEBUG2("Found static symbol %s() at %s", line_func, line_pos); - e->bt_strings[i] = bprintf("** In %s() at %s", line_func, line_pos); + e->bt_strings[i] = + bprintf("** In %s() at %s", line_func, line_pos); } else { /* Damn. The symbol is in a dynamic library. Let's get wild */ char *maps_name; @@ -207,7 +210,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) if (found) { DEBUG3("%#lx in [%#lx-%#lx]", addr, first, last); DEBUG0 - ("Symbol found, map lines not further displayed (even if looking for next ones)"); + ("Symbol found, map lines not further displayed (even if looking for next ones)"); } } fclose(maps); @@ -215,7 +218,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) if (!found) { VERB0 - ("Problem while reading the maps file. Following backtrace will be mangled."); + ("Problem while reading the maps file. Following backtrace will be mangled."); DEBUG1("No dynamic. Static symbol: %s", backtrace_syms[i]); e->bt_strings[i] = bprintf("** In ?? (%s)", backtrace_syms[i]); continue; @@ -270,7 +273,8 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) /* check whether the trick worked */ if (strcmp("??", line_func)) { DEBUG2("Found dynamic symbol %s() at %s", line_func, line_pos); - e->bt_strings[i] = bprintf("** In %s() at %s", line_func, line_pos); + e->bt_strings[i] = + bprintf("** In %s() at %s", line_func, line_pos); } else { /* damn, nothing to do here. Let's print the raw address */ DEBUG1("Dynamic symbol not found. Raw address = %s", @@ -283,8 +287,10 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) /* Mask the bottom of the stack */ if (!strncmp("main", line_func, strlen("main")) || - !strncmp("xbt_thread_context_wrapper", line_func, strlen("xbt_thread_context_wrapper"))|| - !strncmp("smx_ctx_sysv_wrapper",line_func,strlen("smx_ctx_sysv_wrapper"))) { + !strncmp("xbt_thread_context_wrapper", line_func, + strlen("xbt_thread_context_wrapper")) + || !strncmp("smx_ctx_sysv_wrapper", line_func, + strlen("smx_ctx_sysv_wrapper"))) { int j; for (j = i + 1; j < e->used; j++) diff --git a/src/xbt/backtrace_windows.c b/src/xbt/backtrace_windows.c index e65821630c..90f84abf04 100644 --- a/src/xbt/backtrace_windows.c +++ b/src/xbt/backtrace_windows.c @@ -86,27 +86,29 @@ void xbt_backtrace_preinit(void) /* get the pointers to debug help library exported functions */ fun_initialize = - (fun_initialize_t) GetProcAddress(hlp_dbg_instance, "SymInitialize"); + (fun_initialize_t) GetProcAddress(hlp_dbg_instance, "SymInitialize"); fun_cleanup = - (fun_cleanup_t) GetProcAddress(hlp_dbg_instance, "SymCleanup"); + (fun_cleanup_t) GetProcAddress(hlp_dbg_instance, "SymCleanup"); fun_function_table_access = - (fun_function_table_access_t) GetProcAddress(hlp_dbg_instance, - "SymFunctionTableAccess"); + (fun_function_table_access_t) GetProcAddress(hlp_dbg_instance, + "SymFunctionTableAccess"); fun_get_line_from_addr = - (fun_get_line_from_addr_t) GetProcAddress(hlp_dbg_instance, - "SymGetLineFromAddr"); + (fun_get_line_from_addr_t) GetProcAddress(hlp_dbg_instance, + "SymGetLineFromAddr"); fun_get_module_base = - (fun_get_module_base_t) GetProcAddress(hlp_dbg_instance, - "SymGetModuleBase"); + (fun_get_module_base_t) GetProcAddress(hlp_dbg_instance, + "SymGetModuleBase"); fun_get_options = - (fun_get_options_t) GetProcAddress(hlp_dbg_instance, "SymGetOptions"); + (fun_get_options_t) GetProcAddress(hlp_dbg_instance, + "SymGetOptions"); fun_get_sym_from_addr = - (fun_get_sym_from_addr_t) GetProcAddress(hlp_dbg_instance, - "SymGetSymFromAddr"); + (fun_get_sym_from_addr_t) GetProcAddress(hlp_dbg_instance, + "SymGetSymFromAddr"); fun_set_options = - (fun_set_options_t) GetProcAddress(hlp_dbg_instance, "SymSetOptions"); + (fun_set_options_t) GetProcAddress(hlp_dbg_instance, + "SymSetOptions"); fun_stack_walk = - (fun_stack_walk_t) GetProcAddress(hlp_dbg_instance, "StackWalk"); + (fun_stack_walk_t) GetProcAddress(hlp_dbg_instance, "StackWalk"); /* Check that everything worked well */ if (!fun_initialize || @@ -202,9 +204,8 @@ int backtrace(void **buffer, int size) IMAGEHLP_SYMBOL *pSym; unsigned long offset = 0; IMAGEHLP_LINE line_info = { 0 }; - byte - __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + - sizeof(ULONG64) - 1) / sizeof(ULONG64)]; + byte __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + + sizeof(ULONG64) - 1) / sizeof(ULONG64)]; CONTEXT context = { CONTEXT_FULL }; GetThreadContext(GetCurrentThread(), &context); @@ -212,12 +213,12 @@ int backtrace(void **buffer, int size) /* ebp points on stack base */ /* esp points on stack pointer, ie on last stacked element (current element) */ _asm call $ + 5 - _asm pop eax - _asm mov context.Eip, eax - _asm mov eax, esp - _asm mov context.Esp, eax - _asm mov context.Ebp, ebp - if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) { + _asm pop eax + _asm mov context.Eip, eax + _asm mov eax, esp + _asm mov context.Esp, eax + _asm mov context.Ebp, ebp + if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) { errno = EINVAL; return 0; } @@ -293,9 +294,8 @@ char **backtrace_symbols(void *const *buffer, int size) unsigned long offset = 0; IMAGEHLP_LINE line_info = { 0 }; IMAGEHLP_MODULE module = { 0 }; - byte - __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + - sizeof(ULONG64) - 1) / sizeof(ULONG64)]; + byte __buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + + sizeof(ULONG64) - 1) / sizeof(ULONG64)]; if ((NULL == hlp_dbg_instance) || (size <= 0) || (NULL == buffer)) { errno = EINVAL; @@ -321,10 +321,11 @@ char **backtrace_symbols(void *const *buffer, int size) if ((*fun_get_sym_from_addr) (process_handle, stack_frame->AddrPC.Offset, &offset, pSym)) { if ((*fun_get_line_from_addr) - (process_handle, stack_frame->AddrPC.Offset, &offset, &line_info)) { + (process_handle, stack_frame->AddrPC.Offset, &offset, + &line_info)) { strings[pos] = - bprintf("** In %s() at %s:%d", pSym->Name, line_info.FileName, - (int) line_info.LineNumber); + bprintf("** In %s() at %s:%d", pSym->Name, + line_info.FileName, (int) line_info.LineNumber); } else { strings[pos] = bprintf("** In %s()", pSym->Name); } diff --git a/src/xbt/config.c b/src/xbt/config.c index 22e5729e4a..ea1a296d2b 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -45,7 +45,7 @@ typedef struct { } s_xbt_cfgelm_t, *xbt_cfgelm_t; static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] = - { "int", "double", "string", "peer", "any" }; + { "int", "double", "string", "peer", "any" }; /* Internal stuff used in cache to free a variable */ static void xbt_cfgelm_free(void *data); @@ -126,9 +126,10 @@ void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg) size = xbt_dynar_length(variable->content); printf - ("%d_to_%d_%s. Actual size=%d. prerm=%p,postset=%p, List of values:\n", - variable->min, variable->max, xbt_cfgelm_type_name[variable->type], - size, variable->cb_rm, variable->cb_set); + ("%d_to_%d_%s. Actual size=%d. prerm=%p,postset=%p, List of values:\n", + variable->min, variable->max, + xbt_cfgelm_type_name[variable->type], size, variable->cb_rm, + variable->cb_set); switch (variable->type) { @@ -202,9 +203,9 @@ void xbt_cfgelm_free(void *data) void xbt_cfg_register(xbt_cfg_t * cfg, - const char *name, const char *desc, e_xbt_cfgelm_type_t type, - void *default_value, int min, int max, xbt_cfg_cb_t cb_set, - xbt_cfg_cb_t cb_rm) + const char *name, const char *desc, + e_xbt_cfgelm_type_t type, void *default_value, int min, + int max, xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm) { xbt_cfgelm_t res; @@ -222,7 +223,8 @@ xbt_cfg_register(xbt_cfg_t * cfg, res = xbt_new(s_xbt_cfgelm_t, 1); DEBUG8("Register cfg elm %s (%s) (%d to %d %s (=%d) @%p in set %p)", - name, desc, min, max, xbt_cfgelm_type_name[type], type, res, *cfg); + name, desc, min, max, xbt_cfgelm_type_name[type], type, res, + *cfg); res->desc = xbt_strdup(desc); res->type = type; @@ -307,7 +309,8 @@ void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry) *(tok++) = '\0'; min = strtol(tok, &tok, 10); - xbt_assert1(tok, "Invalid minimum in config element descriptor %s", entry); + xbt_assert1(tok, "Invalid minimum in config element descriptor %s", + entry); xbt_assert2(strcmp(tok, "_to_"), "Invalid config element descriptor : %s%s", @@ -315,7 +318,8 @@ void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry) tok += strlen("_to_"); max = strtol(tok, &tok, 10); - xbt_assert1(tok, "Invalid maximum in config element descriptor %s", entry); + xbt_assert1(tok, "Invalid maximum in config element descriptor %s", + entry); xbt_assert2(*(tok++) == '_', "Invalid config element descriptor: %s%s", entry, @@ -414,14 +418,16 @@ void xbt_cfg_check(xbt_cfg_t cfg) xbt_dict_cursor_free(&cursor); THROW4(mismatch_error, 0, "Config elem %s needs at least %d %s, but there is only %d values.", - name, variable->min, xbt_cfgelm_type_name[variable->type], size); + name, variable->min, xbt_cfgelm_type_name[variable->type], + size); } if (variable->max > 0 && variable->max < size) { xbt_dict_cursor_free(&cursor); THROW4(mismatch_error, 0, "Config elem %s accepts at most %d %s, but there is %d values.", - name, variable->max, xbt_cfgelm_type_name[variable->type], size); + name, variable->max, xbt_cfgelm_type_name[variable->type], + size); } } @@ -429,7 +435,8 @@ void xbt_cfg_check(xbt_cfg_t cfg) } static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, - const char *name, e_xbt_cfgelm_type_t type) + const char *name, + e_xbt_cfgelm_type_t type) { xbt_cfgelm_t res = NULL; @@ -496,7 +503,8 @@ void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa) if (e.category == not_found_error) { xbt_ex_free(e); THROW1(not_found_error, 0, - "Can't set the property '%s' since it's not registered", name); + "Can't set the property '%s' since it's not registered", + name); } RETHROW; } @@ -716,53 +724,69 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options) * This is useful to change the default value of a variable while allowing * users to override it with command line arguments */ -void xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, int val) { +void xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, int val) +{ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int); if (variable->isdefault) - xbt_cfg_set_int(cfg, name,val); + xbt_cfg_set_int(cfg, name, val); else - DEBUG2("Do not override configuration variable '%s' with value '%d' because it was already set.",name,val); + DEBUG2 + ("Do not override configuration variable '%s' with value '%d' because it was already set.", + name, val); } + /** @brief Set an integer value to \a name within \a cfg if it wasn't changed yet * * This is useful to change the default value of a variable while allowing * users to override it with command line arguments */ -void xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, double val) { +void xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, double val) +{ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double); if (variable->isdefault) xbt_cfg_set_double(cfg, name, val); else - DEBUG2("Do not override configuration variable '%s' with value '%lf' because it was already set.",name,val); + DEBUG2 + ("Do not override configuration variable '%s' with value '%lf' because it was already set.", + name, val); } + /** @brief Set a string value to \a name within \a cfg if it wasn't changed yet * * This is useful to change the default value of a variable while allowing * users to override it with command line arguments */ -void xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name, const char* val) { +void xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name, + const char *val) +{ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string); if (variable->isdefault) - xbt_cfg_set_string(cfg, name,val); + xbt_cfg_set_string(cfg, name, val); else - DEBUG2("Do not override configuration variable '%s' with value '%s' because it was already set.",name,val); + DEBUG2 + ("Do not override configuration variable '%s' with value '%s' because it was already set.", + name, val); } + /** @brief Set a peer value to \a name within \a cfg if it wasn't changed yet * * This is useful to change the default value of a variable while allowing * users to override it with command line arguments */ -void xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name, const char* host, int port) { +void xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name, + const char *host, int port) +{ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer); if (variable->isdefault) xbt_cfg_set_peer(cfg, name, host, port); else - DEBUG3("Do not override configuration variable '%s' with value '%s:%d' because it was already set.", - name,host,port); + DEBUG3 + ("Do not override configuration variable '%s' with value '%s:%d' because it was already set.", + name, host, port); } /** @brief Set or add an integer value to \a name within \a cfg @@ -819,7 +843,8 @@ void xbt_cfg_set_double(xbt_cfg_t cfg, const char *name, double val) xbt_dynar_set(variable->content, 0, &val); } else { - if (variable->max && xbt_dynar_length(variable->content) == variable->max) + if (variable->max + && xbt_dynar_length(variable->content) == variable->max) THROW3(mismatch_error, 0, "Cannot add value %f to the config element %s since it's already full (size=%d)", val, name, variable->max); @@ -848,8 +873,8 @@ void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, const char *val) VERB2("Configuration setting: %s=%s", name, val); variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string); DEBUG5("Variable: %d to %d %s (=%d) @%p", - variable->min, variable->max, xbt_cfgelm_type_name[variable->type], - variable->type, variable); + variable->min, variable->max, + xbt_cfgelm_type_name[variable->type], variable->type, variable); if (variable->max == 1) { if (xbt_dynar_length(variable->content)) { @@ -863,7 +888,8 @@ void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, const char *val) xbt_dynar_set(variable->content, 0, &newval); } else { - if (variable->max && xbt_dynar_length(variable->content) == variable->max) + if (variable->max + && xbt_dynar_length(variable->content) == variable->max) THROW3(mismatch_error, 0, "Cannot add value %s to the config element %s since it's already full (size=%d)", name, val, variable->max); @@ -887,7 +913,8 @@ void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, const char *val) */ void -xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, const char *peer, int port) +xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, const char *peer, + int port) { xbt_cfgelm_t variable; xbt_peer_t val = xbt_peer_new(peer, port); @@ -902,7 +929,8 @@ xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, const char *peer, int port) xbt_dynar_set(variable->content, 0, &val); } else { - if (variable->max && xbt_dynar_length(variable->content) == variable->max) + if (variable->max + && xbt_dynar_length(variable->content) == variable->max) THROW4(mismatch_error, 0, "Cannot add value %s:%d to the config element %s since it's already full (size=%d)", peer, port, name, variable->max); @@ -1027,7 +1055,8 @@ void xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name, const char *val) */ void -xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name, const char *peer, int port) +xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name, const char *peer, + int port) { xbt_cfgelm_t variable; unsigned int cpt; @@ -1128,8 +1157,8 @@ int xbt_cfg_get_int(xbt_cfg_t cfg, const char *name) if (xbt_dynar_length(variable->content) > 1) { WARN2 - ("You asked for the first value of the config element '%s', but there is %lu values", - name, xbt_dynar_length(variable->content)); + ("You asked for the first value of the config element '%s', but there is %lu values", + name, xbt_dynar_length(variable->content)); } return xbt_dynar_get_as(variable->content, 0, int); @@ -1154,8 +1183,8 @@ double xbt_cfg_get_double(xbt_cfg_t cfg, const char *name) if (xbt_dynar_length(variable->content) > 1) { WARN2 - ("You asked for the first value of the config element '%s', but there is %lu values\n", - name, xbt_dynar_length(variable->content)); + ("You asked for the first value of the config element '%s', but there is %lu values\n", + name, xbt_dynar_length(variable->content)); } return xbt_dynar_get_as(variable->content, 0, double); @@ -1180,8 +1209,8 @@ char *xbt_cfg_get_string(xbt_cfg_t cfg, const char *name) if (xbt_dynar_length(variable->content) > 1) { WARN2 - ("You asked for the first value of the config element '%s', but there is %lu values\n", - name, xbt_dynar_length(variable->content)); + ("You asked for the first value of the config element '%s', but there is %lu values\n", + name, xbt_dynar_length(variable->content)); } else if (xbt_dynar_length(variable->content) == 0) { return NULL; } @@ -1203,7 +1232,8 @@ char *xbt_cfg_get_string(xbt_cfg_t cfg, const char *name) * \warning the returned value is the actual content of the config set */ -void xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name, char **peer, int *port) +void xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name, char **peer, + int *port) { xbt_cfgelm_t variable; xbt_peer_t val; @@ -1212,8 +1242,8 @@ void xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name, char **peer, int *port) if (xbt_dynar_length(variable->content) > 1) { WARN2 - ("You asked for the first value of the config element '%s', but there is %lu values\n", - name, xbt_dynar_length(variable->content)); + ("You asked for the first value of the config element '%s', but there is %lu values\n", + name, xbt_dynar_length(variable->content)); } val = xbt_dynar_get_as(variable->content, 0, xbt_peer_t); @@ -1385,7 +1415,8 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_dynar_t dyn; xbt_cfg_t myset = make_set(); - xbt_cfg_set_parse(myset, "peername:veloce user:foo\nuser:bar\tuser:toto"); + xbt_cfg_set_parse(myset, + "peername:veloce user:foo\nuser:bar\tuser:toto"); xbt_cfg_set_parse(myset, "speed:42"); xbt_cfg_check(myset); dyn = xbt_cfg_get_dynar(myset, "user"); @@ -1395,16 +1426,16 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_dynar_length(dyn)); if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo")) - xbt_test_fail1("Dynar[0] = %s, I expected foo", - xbt_dynar_get_as(dyn, 0, char *)); + xbt_test_fail1("Dynar[0] = %s, I expected foo", + xbt_dynar_get_as(dyn, 0, char *)); if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar")) - xbt_test_fail1("Dynar[1] = %s, I expected bar", - xbt_dynar_get_as(dyn, 1, char *)); + xbt_test_fail1("Dynar[1] = %s, I expected bar", + xbt_dynar_get_as(dyn, 1, char *)); if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto")) - xbt_test_fail1("Dynar[2] = %s, I expected toto", - xbt_dynar_get_as(dyn, 2, char *)); + xbt_test_fail1("Dynar[2] = %s, I expected toto", + xbt_dynar_get_as(dyn, 2, char *)); xbt_cfg_free(&myset); } @@ -1424,4 +1455,4 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_cfg_free(&myset); } } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/cunit.c b/src/xbt/cunit.c index 4572af1b57..97f37ea5c3 100644 --- a/src/xbt/cunit.c +++ b/src/xbt/cunit.c @@ -72,7 +72,7 @@ static void xbt_test_test_dump(xbt_test_test_t test) test, test->file, test->line, test->title, test->failed ? "failed" : "not failed"); xbt_dynar_foreach(test->logs, it_log, log) - xbt_test_log_dump(log); + xbt_test_log_dump(log); } else fprintf(stderr, " test=NULL\n"); } @@ -101,7 +101,7 @@ static void xbt_test_unit_dump(xbt_test_unit_t unit) (unit->enabled ? "enabled" : "disabled")); if (unit->enabled) xbt_dynar_foreach(unit->tests, it_test, test) - xbt_test_test_dump(test); + xbt_test_test_dump(test); } else { fprintf(stderr, " unit=NULL\n"); } @@ -164,11 +164,12 @@ xbt_test_suite_t xbt_test_suite_new(const char *name, const char *fmt, ...) if (!_xbt_test_suites) _xbt_test_suites = - xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free); + xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free); va_start(ap, fmt); vres = vasprintf(&suite->title, fmt, ap); - suite->units = xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free); + suite->units = + xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free); va_end(ap); suite->name = name; suite->enabled = 1; @@ -191,7 +192,7 @@ xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, if (_xbt_test_suites) xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - if (!strcmp(suite->name, name)) + if (!strcmp(suite->name, name)) return suite; va_start(ap, fmt); @@ -213,7 +214,7 @@ void xbt_test_suite_dump(xbt_test_suite_t suite) suite->enabled ? "enabled" : "disabled"); if (suite->enabled) xbt_dynar_foreach(suite->units, it_unit, unit) - xbt_test_unit_dump(unit); + xbt_test_unit_dump(unit); } else { fprintf(stderr, "TESTSUITE IS NULL!\n"); } @@ -280,7 +281,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) suite_title[i++] = '\n'; suite_title[80] = '\0'; - sprintf(suite_title + 40 - (suite_len + 4) / 2, "[ %s ]", suite->title); + sprintf(suite_title + 40 - (suite_len + 4) / 2, "[ %s ]", + suite->title); suite_title[40 + (suite_len + 5) / 2] = '='; if (!suite->enabled) snprintf(suite_title + 70, 11, " DISABLED "); @@ -297,8 +299,10 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) unit->test_expect = 0; /* display unit title */ - vres = asprintf(&cp, " Unit: %s ......................................" - "......................................", unit->title); + vres = + asprintf(&cp, + " Unit: %s ......................................" + "......................................", unit->title); cp[70] = '\0'; fprintf(stderr, "%s", cp); free(cp); @@ -341,9 +345,10 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) fprintf(stderr, " %s: %s [%s:%d]\n", (test->ignored ? " SKIP" : (test->expected_failure - ? (test->failed ? "EFAIL" : "EPASS") : (test->failed ? - " FAIL" : - " PASS"))), + ? (test-> + failed ? "EFAIL" : "EPASS") : (test->failed ? + " FAIL" : + " PASS"))), test->title, file, line); if ((test->expected_failure && !test->failed) @@ -432,7 +437,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) first = 0; } if (suite->unit_failed) { - fprintf(stderr, "%s%d failed", (first ? "" : ", "), suite->unit_failed); + fprintf(stderr, "%s%d failed", (first ? "" : ", "), + suite->unit_failed); first = 0; } if (suite->unit_ignore) { @@ -458,7 +464,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite) first = 0; } if (suite->test_failed) { - fprintf(stderr, "%s%d failed", (first ? "" : ", "), suite->test_failed); + fprintf(stderr, "%s%d failed", (first ? "" : ", "), + suite->test_failed); first = 0; } if (suite->test_ignore) { @@ -550,7 +557,7 @@ static void apply_selection(char *selection) unsigned int it; for (it = 0; it < xbt_dynar_length(_xbt_test_suites); it++) { xbt_test_suite_t thissuite = - xbt_dynar_get_as(_xbt_test_suites, it, xbt_test_suite_t); + xbt_dynar_get_as(_xbt_test_suites, it, xbt_test_suite_t); if (!strcmp(suitename, thissuite->name)) { /* Do not disable the whole suite when we just want to disable a child */ if (enabling || (unitname[0] == '\0')) @@ -563,10 +570,12 @@ static void apply_selection(char *selection) } else { /* act on one child only */ unsigned int it2_unit; /* search it, first (we won't reuse it for external loop which gets broken) */ - for (it2_unit = 0; it2_unit < xbt_dynar_length(thissuite->units); + for (it2_unit = 0; + it2_unit < xbt_dynar_length(thissuite->units); it2_unit++) { xbt_test_unit_t thisunit = - xbt_dynar_get_as(thissuite->units, it2_unit, xbt_test_unit_t); + xbt_dynar_get_as(thissuite->units, it2_unit, + xbt_test_unit_t); if (!strcmp(thisunit->name, unitname)) { thisunit->enabled = enabling; break; @@ -603,7 +612,7 @@ void xbt_test_dump(char *selection) xbt_test_suite_t suite; xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - xbt_test_suite_dump(suite); + xbt_test_suite_dump(suite); } else { printf(" No suite defined."); } @@ -620,7 +629,7 @@ int xbt_test_run(char *selection) /* Run all the suites */ xbt_dynar_foreach(_xbt_test_suites, it_suite, suite) - xbt_test_suite_run(suite); + xbt_test_suite_run(suite); /* Display some more statistics */ fprintf(stderr, "\n\n TOTAL: Suites: %.0f%% ok (%d suites: ", @@ -630,7 +639,8 @@ int xbt_test_run(char *selection) (double) _xbt_test_nb_suites) * 100.0) : 100.0, _xbt_test_nb_suites); if (_xbt_test_nb_suites != _xbt_test_suite_failed) { - fprintf(stderr, "%d ok", _xbt_test_nb_suites - _xbt_test_suite_failed); + fprintf(stderr, "%d ok", + _xbt_test_nb_suites - _xbt_test_suite_failed); first = 0; } if (_xbt_test_suite_failed) { @@ -772,7 +782,8 @@ void xbt_test_expect_failure(void) xbt_assert1(xbt_dynar_length(_xbt_test_current_unit->tests), "Cannot expect the failure of a test before declaring it (broken unit: %s)", _xbt_test_current_unit->title); - test = xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t); + test = + xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t); test->expected_failure = 1; } @@ -784,7 +795,8 @@ void xbt_test_skip(void) "Test skiped even before being declared (broken unit: %s)", _xbt_test_current_unit->title); - test = xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t); + test = + xbt_dynar_getlast_as(_xbt_test_current_unit->tests, xbt_test_test_t); test->ignored = 1; } @@ -833,4 +845,4 @@ XBT_TEST_UNIT("expect", test_expected_failure, "expected failures") xbt_test_fail0("EXPECTED FAILURE"); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 708cffbc2f..6920797ffc 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -95,7 +95,8 @@ XBT_INLINE unsigned int xbt_dict_size(xbt_dict_t dict) /** * Returns the hash code of a string. */ -static XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, int str_len) +static XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, + int str_len) { @@ -116,7 +117,8 @@ static XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, int str_len) while (bp < be) { /* multiply by the 32 bit FNV magic prime mod 2^32 */ hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24); + (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + + (hash << 24); /* xor the bottom with the current octet */ hash ^= (unsigned int) *bp++; @@ -151,7 +153,8 @@ static XBT_INLINE unsigned int xbt_dict_hash(const char *str) while (*str) { /* multiply by the 32 bit FNV magic prime mod 2^32 */ hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24); + (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + + (hash << 24); /* xor the bottom with the current byte */ hash ^= (unsigned int) *str++; @@ -180,8 +183,8 @@ static void xbt_dict_rehash(xbt_dict_t dict) register xbt_dictelm_t *pprev; currcell = - (xbt_dictelm_t *) xbt_realloc((char *) dict->table, - newsize * sizeof(xbt_dictelm_t)); + (xbt_dictelm_t *) xbt_realloc((char *) dict->table, + newsize * sizeof(xbt_dictelm_t)); memset(&currcell[oldsize], 0, oldsize * sizeof(xbt_dictelm_t)); /* zero second half */ dict->table_size = --newsize; dict->table = currcell; @@ -285,7 +288,8 @@ XBT_INLINE void xbt_dict_set_ext(xbt_dict_t dict, * null terminated string. */ XBT_INLINE void xbt_dict_set(xbt_dict_t dict, - const char *key, void *data, void_f_pvoid_t free_ctn) + const char *key, void *data, + void_f_pvoid_t free_ctn) { xbt_dict_set_ext(dict, key, strlen(key), data, free_ctn); @@ -301,7 +305,8 @@ XBT_INLINE void xbt_dict_set(xbt_dict_t dict, * * Search the given \a key. Throws not_found_error when not found. */ -XBT_INLINE void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len) +XBT_INLINE void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, + int key_len) { @@ -326,7 +331,8 @@ XBT_INLINE void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len) /** * \brief like xbt_dict_get_ext(), but returning NULL when not found */ -void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len) +void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, + int key_len) { unsigned int hash_code = xbt_dict_hash_ext(key, key_len); @@ -352,7 +358,8 @@ void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len) * * Returns NULL if the object cannot be found */ -char *xbt_dict_get_key(xbt_dict_t dict, const void*data) { +char *xbt_dict_get_key(xbt_dict_t dict, const void *data) +{ int i; xbt_dictelm_t current; @@ -430,7 +437,8 @@ XBT_INLINE void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key) * * Remove the entry associated with the given \a key (throws not_found) */ -XBT_INLINE void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len) +XBT_INLINE void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, + int key_len) { @@ -492,19 +500,22 @@ XBT_INLINE void xbt_dict_remove(xbt_dict_t dict, const char *key) * of data, as long as its length is provided in \a key_len. */ XBT_INLINE void xbt_dicti_set(xbt_dict_t dict, - uintptr_t key, uintptr_t data) { + uintptr_t key, uintptr_t data) +{ - unsigned int hash_code = xbt_dict_hash_ext((void*)&key, sizeof(uintptr_t)); + unsigned int hash_code = + xbt_dict_hash_ext((void *) &key, sizeof(uintptr_t)); xbt_dictelm_t current, previous = NULL; xbt_assert(dict); - DEBUG5("ADD %zu->%zu; hash = %d, size = %d, & = %d", key, data, hash_code, - dict->table_size, hash_code & dict->table_size); + DEBUG5("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)) )) { + (hash_code != current->hash_code + || sizeof(uintptr_t) != current->key_len + || (((uintptr_t) key) != ((uintptr_t) current->key)))) { current = current->next; } @@ -526,7 +537,7 @@ XBT_INLINE void xbt_dicti_set(xbt_dict_t dict, if (current->content != NULL && current->free_f != NULL) { current->free_f(current->content); } - current->content = (void*)data; + current->content = (void *) data; current->free_f = NULL; } } @@ -540,37 +551,43 @@ XBT_INLINE void xbt_dicti_set(xbt_dict_t dict, * * Mixing uintptr_t keys with regular keys in the same dict is discouraged */ -XBT_INLINE uintptr_t xbt_dicti_get(xbt_dict_t dict, uintptr_t key) { +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)); + 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)) )) { + (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) (current->content); } /** Remove a uintptr_t key from the dict */ -XBT_INLINE void xbt_dicti_remove(xbt_dict_t dict, uintptr_t key) { +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)); + 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)) )) { + (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; } @@ -637,12 +654,13 @@ void xbt_dict_dump_output_string(void *s) { fputs(s, stdout); } + /** * \brief test if the dict is empty or not */ XBT_INLINE int xbt_dict_is_empty(xbt_dict_t dict) { - return (xbt_dict_size(dict) == 0); + return (xbt_dict_size(dict) == 0); } /** @@ -746,7 +764,8 @@ void xbt_dict_dump_sizes(xbt_dict_t dict) * This is an internal XBT function called during the lib initialization. * It can be used several times to recreate the mallocator, for example when you switch to MC mode */ -void xbt_dict_preinit(void) { +void xbt_dict_preinit(void) +{ if (dict_mallocator != NULL) { /* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */ xbt_mallocator_free(dict_mallocator); @@ -754,13 +773,13 @@ void xbt_dict_preinit(void) { } dict_mallocator = xbt_mallocator_new(256, - dict_mallocator_new_f, - dict_mallocator_free_f, - dict_mallocator_reset_f); + 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_elm_mallocator_new_f, + dict_elm_mallocator_free_f, + dict_elm_mallocator_reset_f); } /** @@ -831,7 +850,8 @@ static void debuged_add_ext(xbt_dict_t head, const char *key, { char *data = xbt_strdup(data_to_fill); - xbt_test_log2("Add %s under %s", PRINTF_STR(data_to_fill), PRINTF_STR(key)); + xbt_test_log2("Add %s under %s", PRINTF_STR(data_to_fill), + PRINTF_STR(key)); xbt_dict_set(head, key, data, &free); if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) { @@ -921,8 +941,8 @@ static void search_not_found(xbt_dict_t head, const char *data) TRY { data = xbt_dict_get(head, data); - THROW1(unknown_error, 0, "Found something which shouldn't be there (%s)", - data); + THROW1(unknown_error, 0, + "Found something which shouldn't be there (%s)", data); } CATCH(e) { if (e.category != not_found_error) xbt_test_exception(e); @@ -946,7 +966,7 @@ static void count(xbt_dict_t dict, int length) length); xbt_dict_foreach(dict, cursor, key, data) - effective++; + effective++; xbt_test_assert2(effective == length, "Effective length(%d) != %d.", effective, length); @@ -956,21 +976,24 @@ static void count(xbt_dict_t dict, int length) static void count_check_get_key(xbt_dict_t dict, int length) { xbt_dict_cursor_t cursor; - char *key,*key2; + char *key, *key2; void *data; int effective = 0; - xbt_test_add1("Count elements (expecting %d), and test the getkey function", length); + xbt_test_add1 + ("Count elements (expecting %d), and test the getkey function", + length); xbt_test_assert2(xbt_dict_length(dict) == length, "Announced length(%d) != %d.", xbt_dict_length(dict), length); xbt_dict_foreach(dict, cursor, key, data) { effective++; - key2 = xbt_dict_get_key(dict,data); - xbt_assert2(!strcmp(key,key2), - "The data was registered under %s instead of %s as expected",key2,key); + key2 = xbt_dict_get_key(dict, data); + xbt_assert2(!strcmp(key, key2), + "The data was registered under %s instead of %s as expected", + key2, key); } xbt_test_assert2(effective == length, "Effective length(%d) != %d.", @@ -983,7 +1006,7 @@ xbt_dict_t head = NULL; char *data; -XBT_TEST_UNIT("basic", test_dict_basic,"Basic usage: change, retrieve, traverse") +XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse") { xbt_test_add0("Traversal the null dictionary"); traverse(head); @@ -1085,7 +1108,7 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") xbt_dict_free(&head); xbt_test_add0 - ("Remove each data manually (traversing the resulting dictionary each time)"); + ("Remove each data manually (traversing the resulting dictionary each time)"); fill(&head); debuged_remove(head, "12a"); traverse(head); @@ -1124,7 +1147,8 @@ XBT_TEST_UNIT("remove", test_dict_remove, "Removing some values") } traverse(head); - xbt_test_add0("Free dict, create new fresh one, and then reset the dict"); + xbt_test_add0 + ("Free dict, create new fresh one, and then reset the dict"); xbt_dict_free(&head); fill(&head); xbt_dict_reset(head); @@ -1166,8 +1190,9 @@ XBT_TEST_UNIT("nulldata", test_dict_nulldata, "NULL data management") xbt_dict_free(&head); } -static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) { - uintptr_t stored_data = 0; +static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) +{ + uintptr_t stored_data = 0; xbt_test_log2("Add %zu under %zu", data, key); xbt_dicti_set(head, key, data); @@ -1176,8 +1201,9 @@ static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data) { fflush(stdout); } stored_data = xbt_dicti_get(head, key); - xbt_test_assert3(stored_data==data, - "Retrieved data (%zu) is not what I just stored (%zu) under key %zu",stored_data,data,key); + xbt_test_assert3(stored_data == data, + "Retrieved data (%zu) is not what I just stored (%zu) under key %zu", + stored_data, data, key); } XBT_TEST_UNIT("dicti", test_dict_scalar, "Scalar data and key management") @@ -1232,9 +1258,11 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") for (i = 0; i < 10; i++) { xbt_test_add2("CRASH test number %d (%d to go)", i + 1, 10 - i - 1); - xbt_test_log0("Fill the struct, count its elems and frees the structure"); - xbt_test_log1("using 1000 elements with %d chars long randomized keys.", - SIZEOFKEY); + xbt_test_log0 + ("Fill the struct, count its elems and frees the structure"); + xbt_test_log1 + ("using 1000 elements with %d chars long randomized keys.", + SIZEOFKEY); head = xbt_dict_new(); /* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */ nb = 0; @@ -1278,7 +1306,8 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") } /*xbt_dict_dump(head,(void (*)(void*))&printf); */ - xbt_test_add0("Count the elements (retrieving the key and data for each)"); + xbt_test_add0 + ("Count the elements (retrieving the key and data for each)"); i = countelems(head); xbt_test_log1("There is %d elements", i); @@ -1294,7 +1323,8 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") "with get, key=%s != data=%s", key, (char *) data); data = xbt_dict_get_ext(head, key, strlen(key)); xbt_test_assert2(!strcmp(key, (char *) data), - "with get_ext, key=%s != data=%s", key, (char *) data); + "with get_ext, key=%s != data=%s", key, + (char *) data); } } free(key); @@ -1339,9 +1369,10 @@ XBT_TEST_UNIT("multicrash", test_dict_multicrash, "Multi-dict crash test") xbt_test_add0("Generic multicache CRASH test"); - xbt_test_log4(" Fill the struct and frees it %d times, using %d elements, " - "depth of multicache=%d, key size=%d", - NB_TEST, NB_ELM, DEPTH, KEY_SIZE); + xbt_test_log4 + (" Fill the struct and frees it %d times, using %d elements, " + "depth of multicache=%d, key size=%d", NB_TEST, NB_ELM, DEPTH, + KEY_SIZE); for (l = 0; l < DEPTH; l++) { key = xbt_malloc(KEY_SIZE); @@ -1393,4 +1424,4 @@ XBT_TEST_UNIT("multicrash", test_dict_multicrash, "Multi-dict crash test") xbt_dynar_free(&keys); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/dict_cursor.c b/src/xbt/dict_cursor.c index 807e59197e..d7d354369e 100644 --- a/src/xbt/dict_cursor.c +++ b/src/xbt/dict_cursor.c @@ -86,7 +86,8 @@ XBT_INLINE void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor) * @param dict on what to let the cursor iterate * @param[out] cursor dest address */ -XBT_INLINE void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t * cursor) +XBT_INLINE void xbt_dict_cursor_first(const xbt_dict_t dict, + xbt_dict_cursor_t * cursor) { DEBUG0("xbt_dict_cursor_first"); if (!*cursor) { @@ -141,7 +142,7 @@ XBT_INLINE void xbt_dict_cursor_step(xbt_dict_cursor_t cursor) * @returns true if it's ok, false if there is no more data */ XBT_INLINE int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t * cursor, - char **key, void **data) + char **key, void **data) { xbt_dictelm_t current; @@ -194,16 +195,14 @@ XBT_INLINE void *xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor) * @param free_ctn the function to free the new data */ XBT_INLINE void xbt_dict_cursor_set_data(xbt_dict_cursor_t cursor, - void *data, void_f_pvoid_t free_ctn) + void *data, + void_f_pvoid_t free_ctn) { __cursor_not_null(cursor); - if(cursor->current->free_f) + if (cursor->current->free_f) cursor->current->free_f(cursor->current->content); - + cursor->current->content = data; cursor->current->free_f = free_ctn; return; } - - - diff --git a/src/xbt/dict_elm.c b/src/xbt/dict_elm.c index 9297ce5607..4129989c27 100644 --- a/src/xbt/dict_elm.c +++ b/src/xbt/dict_elm.c @@ -30,9 +30,9 @@ xbt_dictelm_t xbt_dictelm_new(const char *key, { xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator); - element->dictielem = 0; /* please free the key on free */ + element->dictielem = 0; /* please free the key on free */ element->key = xbt_new(char, key_len + 1); - memcpy((void *)element->key, (void *)key, key_len); + memcpy((void *) element->key, (void *) key, key_len); element->key[key_len] = '\0'; element->key_len = key_len; @@ -45,16 +45,18 @@ xbt_dictelm_t xbt_dictelm_new(const char *key, return element; } -xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code, uintptr_t content) { +xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code, + uintptr_t content) +{ xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator); - element->key = (void*)key; + element->key = (void *) key; - element->dictielem = 1; /* please DONT free the key on free */ + 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->content = (void *) content; element->free_f = NULL; element->next = NULL; diff --git a/src/xbt/dict_multi.c b/src/xbt/dict_multi.c index 1536b55e18..30ae0e153e 100644 --- a/src/xbt/dict_multi.c +++ b/src/xbt/dict_multi.c @@ -46,7 +46,8 @@ xbt_multidict_set_ext(xbt_dict_t mdict, DEBUG2("xbt_multidict_set(%p,%d)", mdict, keys_len); - for (i = 0, thislevel = mdict; i < keys_len - 1; i++, thislevel = nextlevel) { + for (i = 0, thislevel = mdict; i < keys_len - 1; + i++, thislevel = nextlevel) { xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); @@ -60,7 +61,8 @@ xbt_multidict_set_ext(xbt_dict_t mdict, /* make sure the dict of next level exists */ nextlevel = xbt_dict_new(); VERB1("Create a dict (%p)", nextlevel); - xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict); + xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, + &_free_dict); } } @@ -127,7 +129,8 @@ void *xbt_multidict_get_ext(xbt_dict_t mdict, DEBUG2("xbt_multidict_get(%p, %ld)", mdict, xbt_dynar_length(keys)); - for (i = 0, thislevel = mdict; i < keys_len - 1; i++, thislevel = nextlevel) { + for (i = 0, thislevel = mdict; i < keys_len - 1; + i++, thislevel = nextlevel) { xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); @@ -176,7 +179,8 @@ void *xbt_multidict_get(xbt_dict_t mdict, xbt_dynar_t keys) */ void -xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens) +xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, + xbt_dynar_t lens) { xbt_dict_t thislevel, nextlevel = NULL; int i; @@ -190,7 +194,8 @@ xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens) xbt_assert0(xbt_dynar_length(keys), "Can't remove a zero-long key set in a multidict"); - for (i = 0, thislevel = mdict; i < keys_len - 1; i++, thislevel = nextlevel) { + for (i = 0, thislevel = mdict; i < keys_len - 1; + i++, thislevel = nextlevel) { xbt_dynar_get_cpy(keys, i, &thiskey); xbt_dynar_get_cpy(lens, i, &thislen); diff --git a/src/xbt/dict_private.h b/src/xbt/dict_private.h index 0096394024..c1b6402a69 100644 --- a/src/xbt/dict_private.h +++ b/src/xbt/dict_private.h @@ -51,8 +51,9 @@ extern void dict_elm_mallocator_reset_f(void *elem); 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_dictielm_new(uintptr_t key, unsigned int hash_code, uintptr_t content); +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); -#endif /* _XBT_DICT_PRIVATE_H_ */ +#endif /* _XBT_DICT_PRIVATE_H_ */ diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index e289e655f0..bead04b141 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -53,7 +53,8 @@ static XBT_INLINE void _check_inbound_idx(xbt_dynar_t dynar, int idx) } } -static XBT_INLINE void _check_sloppy_inbound_idx(xbt_dynar_t dynar, int idx) +static XBT_INLINE void _check_sloppy_inbound_idx(xbt_dynar_t dynar, + int idx) { if (idx > dynar->used) { _dynar_unlock(dynar); @@ -74,13 +75,13 @@ static XBT_INLINE void _check_populated_dynar(xbt_dynar_t dynar) 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_clear_mem(void *const ptr, const unsigned long length) { memset(ptr, 0, length); } static XBT_INLINE - void _xbt_dynar_expand(xbt_dynar_t const dynar, const unsigned long nb) + void _xbt_dynar_expand(xbt_dynar_t const dynar, const unsigned long nb) { const unsigned long old_size = dynar->size; @@ -93,7 +94,7 @@ static XBT_INLINE const unsigned long used_length = used * elmsize; const unsigned long new_size = - nb > (2 * (old_size + 1)) ? nb : (2 * (old_size + 1)); + nb > (2 * (old_size + 1)) ? nb : (2 * (old_size + 1)); const unsigned long new_length = new_size * elmsize; char *const new_data = (char *) xbt_malloc0(elmsize * new_size); @@ -113,7 +114,7 @@ static XBT_INLINE } static XBT_INLINE - void *_xbt_dynar_elm(const xbt_dynar_t dynar, const unsigned long idx) + void *_xbt_dynar_elm(const xbt_dynar_t dynar, const unsigned long idx) { char *const data = (char *) dynar->data; const unsigned long elmsize = dynar->elmsize; @@ -122,7 +123,7 @@ static XBT_INLINE } static XBT_INLINE - void + void _xbt_dynar_get_elm(void *const dst, const xbt_dynar_t dynar, const unsigned long idx) { @@ -132,7 +133,7 @@ _xbt_dynar_get_elm(void *const dst, } static XBT_INLINE - void + void _xbt_dynar_put_elm(const xbt_dynar_t dynar, const unsigned long idx, const void *const src) { @@ -143,7 +144,7 @@ _xbt_dynar_put_elm(const xbt_dynar_t dynar, } static XBT_INLINE - void + void _xbt_dynar_remove_at(xbt_dynar_t const dynar, const unsigned long idx, void *const object) { @@ -173,7 +174,8 @@ _xbt_dynar_remove_at(xbt_dynar_t const dynar, if (nb_shift) { offset = nb_shift * dynar->elmsize; - memmove(_xbt_dynar_elm(dynar, idx), _xbt_dynar_elm(dynar, idx + 1), offset); + memmove(_xbt_dynar_elm(dynar, idx), _xbt_dynar_elm(dynar, idx + 1), + offset); } dynar->used--; @@ -182,7 +184,8 @@ _xbt_dynar_remove_at(xbt_dynar_t const dynar, void xbt_dynar_dump(xbt_dynar_t dynar) { INFO5("Dynar dump: size=%lu; used=%lu; elmsize=%lu; data=%p; free_f=%p", - dynar->size, dynar->used, dynar->elmsize, dynar->data, dynar->free_f); + dynar->size, dynar->used, dynar->elmsize, dynar->data, + dynar->free_f); } /** @brief Constructor @@ -216,7 +219,8 @@ xbt_dynar_new(const unsigned long elmsize, void_f_pvoid_t const free_f) * */ xbt_dynar_t -xbt_dynar_new_sync(const unsigned long elmsize, void_f_pvoid_t const free_f) +xbt_dynar_new_sync(const unsigned long elmsize, + void_f_pvoid_t const free_f) { xbt_dynar_t res = xbt_dynar_new(elmsize, free_f); res->mutex = xbt_mutex_init(); @@ -342,7 +346,7 @@ XBT_INLINE unsigned long xbt_dynar_length(const xbt_dynar_t dynar) XBT_INLINE int xbt_dynar_is_empty(const xbt_dynar_t dynar) { - return (xbt_dynar_length(dynar) == 0); + return (xbt_dynar_length(dynar) == 0); } /** @brief Retrieve a copy of the Nth element of a dynar. @@ -372,7 +376,8 @@ xbt_dynar_get_cpy(const xbt_dynar_t dynar, * \warning The returned value is the actual content of the dynar. * Make a copy before fooling with it. */ -XBT_INLINE void *xbt_dynar_get_ptr(const xbt_dynar_t dynar, const unsigned long idx) +XBT_INLINE void *xbt_dynar_get_ptr(const xbt_dynar_t dynar, + const unsigned long idx) { void *res; @@ -411,7 +416,8 @@ _xbt_dynar_set(xbt_dynar_t dynar, * * If you want to free the previous content, use xbt_dynar_replace(). */ -XBT_INLINE void xbt_dynar_set(xbt_dynar_t dynar, const int idx, const void *const src) +XBT_INLINE void xbt_dynar_set(xbt_dynar_t dynar, const int idx, + const void *const src) { _dynar_lock(dynar); @@ -542,7 +548,8 @@ unsigned int xbt_dynar_search(xbt_dynar_t const dynar, void *const elem) } _dynar_unlock(dynar); - THROW2(not_found_error, 0, "Element %p not part of dynar %p", elem, dynar); + THROW2(not_found_error, 0, "Element %p not part of dynar %p", elem, + dynar); } /** @brief Returns a boolean indicating whether the element is part of the dynar */ @@ -582,11 +589,13 @@ XBT_INLINE void *xbt_dynar_push_ptr(xbt_dynar_t const dynar) } /** @brief Add an element at the end of the dynar */ -XBT_INLINE void xbt_dynar_push(xbt_dynar_t const dynar, const void *const src) +XBT_INLINE void xbt_dynar_push(xbt_dynar_t const dynar, + const void *const src) { _dynar_lock(dynar); /* checks done in xbt_dynar_insert_at_ptr */ - memcpy(_xbt_dynar_insert_at_ptr(dynar, dynar->used), src, dynar->elmsize); + memcpy(_xbt_dynar_insert_at_ptr(dynar, dynar->used), src, + dynar->elmsize); _dynar_unlock(dynar); } @@ -623,7 +632,8 @@ XBT_INLINE void xbt_dynar_pop(xbt_dynar_t const dynar, void *const dst) * * This is less efficient than xbt_dynar_push() */ -XBT_INLINE void xbt_dynar_unshift(xbt_dynar_t const dynar, const void *const src) +XBT_INLINE void xbt_dynar_unshift(xbt_dynar_t const dynar, + const void *const src) { /* sanity checks done by insert_at */ @@ -662,7 +672,8 @@ static void _dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op) * operation, so make sure your function don't call any function * from xbt_dynar_* on it, or you'll get a deadlock. */ -XBT_INLINE void xbt_dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op) +XBT_INLINE void xbt_dynar_map(const xbt_dynar_t dynar, + void_f_pvoid_t const op) { _sanity_check_dynar(dynar); @@ -678,7 +689,8 @@ XBT_INLINE void xbt_dynar_map(const xbt_dynar_t dynar, void_f_pvoid_t const op) * * This function can be used while traversing without problem. */ -XBT_INLINE void xbt_dynar_cursor_rm(xbt_dynar_t dynar, unsigned int *const cursor) +XBT_INLINE void xbt_dynar_cursor_rm(xbt_dynar_t dynar, + unsigned int *const cursor) { _xbt_dynar_remove_at(dynar, (*cursor)--, NULL); @@ -702,13 +714,15 @@ XBT_INLINE void xbt_dynar_cursor_unlock(xbt_dynar_t dynar) * Remark: if the elements stored in the dynar are structures, the compar_fn * function has to retrieve the field to sort first. */ -XBT_INLINE void xbt_dynar_sort(xbt_dynar_t dynar, int_f_cpvoid_cpvoid_t compar_fn){ +XBT_INLINE void xbt_dynar_sort(xbt_dynar_t dynar, + int_f_cpvoid_cpvoid_t compar_fn) +{ - _dynar_lock(dynar); + _dynar_lock(dynar); - qsort(dynar->data, dynar->used, dynar->elmsize, compar_fn); + qsort(dynar->data, dynar->used, dynar->elmsize, compar_fn); - _dynar_unlock(dynar); + _dynar_unlock(dynar); } #ifdef SIMGRID_TEST @@ -732,13 +746,13 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") xbt_dynar_foreach(d, cursor, i) { xbt_assert0(0, "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1 - ("==== Push %d int, set them again 3 times, traverse them, shift them", - NB_ELEM); + ("==== Push %d int, set them again 3 times, traverse them, shift them", + NB_ELEM); /* Populate_ints [doxygen cruft] */ /* 1. Populate the dynar */ d = xbt_dynar_new(sizeof(int), NULL); @@ -796,9 +810,9 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") } /* 5. Free the resources */ - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Unshift/pop %d int", NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); @@ -813,14 +827,14 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") i, cpt); xbt_test_log2("Pop %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1 - ("==== Push %d int, insert 1000 int in the middle, shift everything", - NB_ELEM); + ("==== Push %d int, insert 1000 int in the middle, shift everything", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) { xbt_dynar_push_as(d, int, cpt); @@ -850,11 +864,12 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") "The retrieved value is not the same than the injected one at the end (%d!=%d)", i, cpt); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ - xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest", NB_ELEM); + xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) xbt_dynar_push_as(d, int, cpt); @@ -865,9 +880,9 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") "Remove a bad value. Got %d, expected %d", i, cpt); DEBUG2("remove %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ } /*******************************************************************************/ @@ -883,11 +898,12 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") xbt_test_add0("==== Traverse the empty dynar"); d = xbt_dynar_new(sizeof(int), NULL); xbt_dynar_foreach(d, cursor, cpt) { - xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar"); + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Push/shift 5000 doubles"); d = xbt_dynar_new(sizeof(double), NULL); @@ -908,9 +924,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Unshift/pop 5000 doubles"); d = xbt_dynar_new(sizeof(double), NULL); @@ -925,14 +941,14 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0 - ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); + ("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); d = xbt_dynar_new(sizeof(double), NULL); for (cpt = 0; cpt < 5000; cpt++) { d1 = (double) cpt; @@ -965,9 +981,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") "The retrieved value is not the same than the injected one at the end (%f!=%f)", d1, d2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest"); @@ -982,9 +998,9 @@ XBT_TEST_UNIT("double", test_dynar_double, "Dynars of doubles") xbt_test_assert2(d1 == d2, "Remove a bad value. Got %f, expected %f", d2, d1); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ } @@ -1004,11 +1020,12 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") xbt_test_add0("==== Traverse the empty dynar"); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); xbt_dynar_foreach(d, iter, s1) { - xbt_test_assert0(FALSE, "Damnit, there is something in the empty dynar"); + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Push %d strings, set them again 3 times, shift them", NB_ELEM); @@ -1043,9 +1060,9 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") buf, s2); free(s2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add1("==== Unshift, traverse and pop %d strings", NB_ELEM); d = xbt_dynar_new(sizeof(char **), &xbt_free_ref); @@ -1071,14 +1088,14 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") free(s2); } /* 4. Free the resources */ - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ xbt_test_add2 - ("==== Push %d strings, insert %d strings in the middle, shift everything", - NB_ELEM, NB_ELEM / 5); + ("==== Push %d strings, insert %d strings in the middle, shift everything", + NB_ELEM, NB_ELEM / 5); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); for (cpt = 0; cpt < NB_ELEM; cpt++) { sprintf(buf, "%d", cpt); @@ -1115,13 +1132,13 @@ XBT_TEST_UNIT("string", test_dynar_string, "Dynars of strings") buf, s2); free(s2); } - xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ - xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ - /* in your code is naturally the way to go outside a regression test */ + xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */ + xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */ + /* in your code is naturally the way to go outside a regression test */ - xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest", NB_ELEM, - 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5)); + xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest", + NB_ELEM, 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5)); d = xbt_dynar_new(sizeof(char *), &xbt_free_ref); for (cpt = 0; cpt < NB_ELEM; cpt++) { sprintf(buf, "%d", cpt); @@ -1175,7 +1192,7 @@ static void poper_f(void *a) } -XBT_TEST_UNIT("synchronized int", test_dynar_sync_int,"Synchronized dynars of integers") +XBT_TEST_UNIT("synchronized int", test_dynar_sync_int, "Synchronized dynars of integers") { /* Vars_decl [doxygen cruft] */ xbt_dynar_t d; @@ -1183,11 +1200,11 @@ XBT_TEST_UNIT("synchronized int", test_dynar_sync_int,"Synchronized dynars of in xbt_test_add0("==== Have a pusher and a popper on the dynar"); d = xbt_dynar_new_sync(sizeof(int), NULL); - pusher = xbt_thread_create("pusher", pusher_f, d,0/*not joinable*/); - poper = xbt_thread_create("poper", poper_f, d,0/*not joinable*/); + pusher = xbt_thread_create("pusher", pusher_f, d, 0 /*not joinable */ ); + poper = xbt_thread_create("poper", poper_f, d, 0 /*not joinable */ ); xbt_thread_join(pusher); xbt_thread_join(poper); xbt_dynar_free(&d); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/error.c b/src/xbt/error.c index 24abc680c5..95bd978d78 100644 --- a/src/xbt/error.c +++ b/src/xbt/error.c @@ -15,19 +15,27 @@ * \return the printable name of an error code * */ -const char *xbt_error_name(xbt_error_t errcode) { +const char *xbt_error_name(xbt_error_t errcode) +{ switch (errcode) { - case no_error: return "success"; - case old_mismatch_error: return "mismatch"; - case old_system_error: return "system"; - case old_network_error: return "network"; - case old_timeout_error: return "timeout"; - case old_thread_error: return "thread"; - case old_unknown_error: return "unclassified"; - default: - return "SEVERE ERROR in error repporting module"; + case no_error: + return "success"; + case old_mismatch_error: + return "mismatch"; + case old_system_error: + return "system"; + case old_network_error: + return "network"; + case old_timeout_error: + return "timeout"; + case old_thread_error: + return "thread"; + case old_unknown_error: + return "unclassified"; + default: + return "SEVERE ERROR in error repporting module"; } } @@ -44,12 +52,14 @@ XBT_LOG_DEFAULT_CATEGORY(xbt); * * If you want to pass arguments to the format, you can always write xbt_assert1(0,"fmt",args) */ -void xbt_die (const char *msg) { - CRITICAL1("%s",msg); +void xbt_die(const char *msg) +{ + CRITICAL1("%s", msg); xbt_abort(); } /** @brief Kill the program in silence */ -void xbt_abort(void) { +void xbt_abort(void) +{ abort(); } diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 9ba09f4afd..35b8b276ac 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -176,10 +176,10 @@ void __xbt_ex_terminate_default(xbt_ex_t * e) /* the externally visible API */ XBT_EXPORT_NO_IMPORT(ex_ctx_cb_t) __xbt_ex_ctx = &__xbt_ex_ctx_default; XBT_EXPORT_NO_IMPORT(ex_term_cb_t) __xbt_ex_terminate = - &__xbt_ex_terminate_default; + &__xbt_ex_terminate_default; - void xbt_ex_free(xbt_ex_t e) +void xbt_ex_free(xbt_ex_t e) { int i; @@ -422,7 +422,7 @@ static void good_example(void) cp3 = mallocex(SMALLAMOUNT); strcpy(cp1, "foo"); strcpy(cp2, "bar"); - } TRY_CLEANUP { /*04 */ + } TRY_CLEANUP { /*04 */ printf("cp3=%s", cp3 == NULL /*02 */ ? "" : cp3); if (cp3 != NULL) free(cp3); @@ -437,4 +437,4 @@ static void good_example(void) } /* end_of_good_example */ } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/ex_interface.h b/src/xbt/ex_interface.h index 6723c05225..f1ebf47e87 100644 --- a/src/xbt/ex_interface.h +++ b/src/xbt/ex_interface.h @@ -18,4 +18,4 @@ void xbt_ex_display(xbt_ex_t * e); /* Change raw libc symbols to file names and line numbers */ void xbt_ex_setup_backtrace(xbt_ex_t * e); -#endif /* _XBT_EX_INTERFACE_H_ */ +#endif /* _XBT_EX_INTERFACE_H_ */ diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index a11b4168bb..c3d4ffb905 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -509,7 +509,8 @@ xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i) * These are internal XBT functions called by xbt_preinit/postexit(). * It can be used several times to recreate the mallocator, for example when you switch to MC mode */ -void xbt_fifo_preinit(void) { +void xbt_fifo_preinit(void) +{ if (item_mallocator != NULL) { /* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */ xbt_mallocator_free(item_mallocator); @@ -521,7 +522,8 @@ void xbt_fifo_preinit(void) { fifo_item_mallocator_reset_f); } -void xbt_fifo_postexit(void) { +void xbt_fifo_postexit(void) +{ if (item_mallocator != NULL) { xbt_mallocator_free(item_mallocator); item_mallocator = NULL; diff --git a/src/xbt/fifo_private.h b/src/xbt/fifo_private.h index 0259380fe5..9c40bed38f 100644 --- a/src/xbt/fifo_private.h +++ b/src/xbt/fifo_private.h @@ -46,4 +46,4 @@ typedef struct xbt_fifo { /* return NULL; */ /* } */ -#endif /* _XBT_FIFO_PRIVATE_H */ +#endif /* _XBT_FIFO_PRIVATE_H */ diff --git a/src/xbt/graph.c b/src/xbt/graph.c index f776c5e5c6..2079dfc7da 100644 --- a/src/xbt/graph.c +++ b/src/xbt/graph.c @@ -78,7 +78,8 @@ xbt_edge_t xbt_graph_new_edge(xbt_graph_t g, return edge; } -xbt_edge_t xbt_graph_get_edge(xbt_graph_t g, xbt_node_t src, xbt_node_t dst) +xbt_edge_t xbt_graph_get_edge(xbt_graph_t g, xbt_node_t src, + xbt_node_t dst) { xbt_edge_t edge; unsigned int cursor; @@ -149,11 +150,11 @@ void xbt_graph_free_graph(xbt_graph_t g, } xbt_dynar_foreach(g->nodes, cursor, node) - free(node); + free(node); xbt_dynar_free(&(g->nodes)); xbt_dynar_foreach(g->edges, cursor, edge) - free(edge); + free(edge); xbt_dynar_free(&(g->edges)); if (graph_free_function) (*graph_free_function) (g->data); @@ -190,7 +191,7 @@ void xbt_graph_free_node(xbt_graph_t g, xbt_node_t n, cursor = 0; xbt_dynar_foreach(g->nodes, cursor, node) - if (node == n) + if (node == n) xbt_dynar_cursor_rm(g->nodes, &cursor); xbt_dynar_free(&(n->in)); @@ -450,7 +451,7 @@ xbt_edge_t *xbt_graph_spanning_tree_prim(xbt_graph_t g) node->xbtdata = (void *) 1; edge_list = node->out; xbt_dynar_foreach(edge_list, cursor, e) - xbt_heap_push(heap, e, -(e->length)); + xbt_heap_push(heap, e, -(e->length)); while ((edge = xbt_heap_pop(heap))) { if ((edge->src->xbtdata) && (edge->dst->xbtdata)) @@ -504,10 +505,10 @@ xbt_node_t *xbt_graph_topo_sort(xbt_graph_t g) sorted = xbt_malloc(n * sizeof(xbt_node_t)); xbt_dynar_foreach(g->nodes, cursor, node) - node->xbtdata = xbt_new0(int, 1); + node->xbtdata = xbt_new0(int, 1); xbt_dynar_foreach(g->nodes, cursor, node) - xbt_graph_depth_visit(g, node, sorted, &idx); + xbt_graph_depth_visit(g, node, sorted, &idx); xbt_dynar_foreach(g->nodes, cursor, node) { free(node->xbtdata); @@ -574,8 +575,10 @@ static void __parse_node(void) if (__parse_node_label_and_data) node->data = __parse_node_label_and_data(node, A_graphxml_node_label, A_graphxml_node_data); - xbt_graph_parse_get_double(&(node->position_x), A_graphxml_node_position_x); - xbt_graph_parse_get_double(&(node->position_y), A_graphxml_node_position_y); + xbt_graph_parse_get_double(&(node->position_x), + A_graphxml_node_position_x); + xbt_graph_parse_get_double(&(node->position_y), + A_graphxml_node_position_y); xbt_dict_set(parsed_nodes, A_graphxml_node_name, (void *) node, NULL); } diff --git a/src/xbt/graph_private.h b/src/xbt/graph_private.h index 9958c8df58..09e9232ffb 100644 --- a/src/xbt/graph_private.h +++ b/src/xbt/graph_private.h @@ -47,7 +47,7 @@ typedef struct xbt_graph { } s_xbt_graph_t; void xbt_floyd_algorithm(xbt_graph_t g, double *adj, double *d, xbt_node_t * p); -void xbt_graph_depth_visit(xbt_graph_t g, xbt_node_t n, xbt_node_t * sorted, - int *idx); +void xbt_graph_depth_visit(xbt_graph_t g, xbt_node_t n, + xbt_node_t * sorted, int *idx); -#endif /* _XBT_GRAPH_PRIVATE_H */ +#endif /* _XBT_GRAPH_PRIVATE_H */ diff --git a/src/xbt/graphxml.c b/src/xbt/graphxml.c index 18b7e5cb52..d26d5300d4 100644 --- a/src/xbt/graphxml.c +++ b/src/xbt/graphxml.c @@ -1054,7 +1054,7 @@ int xbt_graph_parse__flex_debug = 0; #define YY_RESTORE_YY_MORE_OFFSET char *xbt_graph_parse_text; /* Validating XML processor for src/xbt/graphxml.dtd. - * Generated 2010/10/01 22:34:14. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/xbt/graphxml.l b/src/xbt/graphxml.l index f716dc5b0f..297db21279 100644 --- a/src/xbt/graphxml.l +++ b/src/xbt/graphxml.l @@ -1,5 +1,5 @@ /* Validating XML processor for src/xbt/graphxml.dtd. - * Generated 2010/10/01 22:34:14. + * Generated 2010/10/11 11:35:07. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. diff --git a/src/xbt/graphxml_parse.c b/src/xbt/graphxml_parse.c index 01198fa8f8..698591907f 100644 --- a/src/xbt/graphxml_parse.c +++ b/src/xbt/graphxml_parse.c @@ -84,19 +84,19 @@ void xbt_graph_parse_open(const char *file) { if (!file) { WARN0 - ("I hope you know what you're doing... you just gave me a NULL pointer!"); + ("I hope you know what you're doing... you just gave me a NULL pointer!"); return; } if (!xbt_graph_input_buffer_stack) xbt_graph_input_buffer_stack = - xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL); + xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL); if (!xbt_graph_file_to_parse_stack) xbt_graph_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL); xbt_graph_file_to_parse = fopen(file, "r"); /* FIXME should use something like surf_fopen */ xbt_assert1((xbt_graph_file_to_parse), "Unable to open \"%s\"\n", file); xbt_graph_input_buffer = - xbt_graph_parse__create_buffer(xbt_graph_file_to_parse, 10); + xbt_graph_parse__create_buffer(xbt_graph_file_to_parse, 10); xbt_graph_parse__switch_to_buffer(xbt_graph_input_buffer); xbt_graph_parse_lineno = 1; } diff --git a/src/xbt/heap.c b/src/xbt/heap.c index 2829fe5e58..2eced61e99 100644 --- a/src/xbt/heap.c +++ b/src/xbt/heap.c @@ -25,7 +25,8 @@ * * Creates a new heap. */ -XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func) +XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, + void_f_pvoid_t const free_func) { xbt_heap_t H = xbt_new0(struct xbt_heap, 1); H->size = init_size; @@ -41,7 +42,9 @@ XBT_INLINE xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func * \param update_callback function to call on each element to update its index when needed. */ XBT_INLINE void xbt_heap_set_update_callback(xbt_heap_t H, - void (*update_callback) (void *, int)) + void (*update_callback) (void + *, + int)) { H->update_callback = update_callback; } @@ -90,7 +93,8 @@ void xbt_heap_push(xbt_heap_t H, void *content, double key) if (count > size) { H->size = 2 * size + 1; H->items = - (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem)); + (void *) realloc(H->items, + (H->size) * sizeof(struct xbt_heapItem)); } item = &(H->items[count - 1]); @@ -124,10 +128,12 @@ void *xbt_heap_pop(xbt_heap_t H) if (H->count < H->size / 4 && H->size > 16) { H->size = H->size / 2 + 1; H->items = - (void *) realloc(H->items, (H->size) * sizeof(struct xbt_heapItem)); + (void *) realloc(H->items, + (H->size) * sizeof(struct xbt_heapItem)); } - if(H->update_callback) H->update_callback(max, -1); + if (H->update_callback) + H->update_callback(max, -1); return max; } @@ -198,10 +204,12 @@ static void xbt_heap_maxHeapify(xbt_heap_t H) struct xbt_heapItem tmp = H->items[i]; H->items[i] = H->items[greatest]; H->items[greatest] = tmp; - if(H->update_callback) H->update_callback(CONTENT(H, i), i); + if (H->update_callback) + H->update_callback(CONTENT(H, i), i); i = greatest; } else { - if(H->update_callback) H->update_callback(CONTENT(H, i), i); + if (H->update_callback) + H->update_callback(CONTENT(H, i), i); return; } } @@ -220,10 +228,11 @@ static void xbt_heap_increaseKey(xbt_heap_t H, int i) struct xbt_heapItem tmp = H->items[i]; H->items[i] = H->items[PARENT(i)]; H->items[PARENT(i)] = tmp; - if(H->update_callback) H->update_callback(CONTENT(H, i), i); + if (H->update_callback) + H->update_callback(CONTENT(H, i), i); i = PARENT(i); } - if(H->update_callback) H->update_callback(CONTENT(H, i), i); + if (H->update_callback) + H->update_callback(CONTENT(H, i), i); return; } - diff --git a/src/xbt/heap_private.h b/src/xbt/heap_private.h index 521b17d280..f6b4d98617 100644 --- a/src/xbt/heap_private.h +++ b/src/xbt/heap_private.h @@ -35,4 +35,4 @@ typedef struct xbt_heap { static void xbt_heap_maxHeapify(xbt_heap_t H); static void xbt_heap_increaseKey(xbt_heap_t H, int i); -#endif /* _XBT_HEAP_PRIVATE_H */ +#endif /* _XBT_HEAP_PRIVATE_H */ diff --git a/src/xbt/log.c b/src/xbt/log.c index 31b809ffe1..334d289ebf 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -24,7 +24,7 @@ #include "xbt/dynar.h" XBT_PUBLIC_DATA(int) (*xbt_pid) (); -int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */ +int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */ /** \addtogroup XBT_log * @@ -463,7 +463,7 @@ This is on our TODO list for quite a while now, but your help would be welcome here, too. - *//*' */ + *//*' */ xbt_log_appender_t xbt_log_default_appender = NULL; /* set in log_init */ @@ -506,10 +506,10 @@ const char *xbt_log_priority_names[8] = { s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = { NULL /*parent */ , NULL /* firstChild */ , NULL /* nextSibling */ , - "root", xbt_log_priority_uninitialized /* threshold */ , - 0 /* isThreshInherited */ , - NULL /* appender */ , NULL /* layout */ , - 0 /* additivity */ + "root", xbt_log_priority_uninitialized /* threshold */ , + 0 /* isThreshInherited */ , + NULL /* appender */ , NULL /* layout */ , + 0 /* additivity */ }; XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)"); @@ -524,7 +524,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, /* create the default appender and install it in the root category, which were already created (damnit. Too slow little beetle) */ -void xbt_log_preinit(void) { +void xbt_log_preinit(void) +{ xbt_log_default_appender = xbt_log_appender_file_new(NULL); xbt_log_default_layout = xbt_log_layout_simple_new(NULL); _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender; @@ -535,7 +536,8 @@ void xbt_log_preinit(void) { * * xbt_log_control_set() is called on each string we got from cmd line */ -void xbt_log_init(int *argc, char **argv) { +void xbt_log_init(int *argc, char **argv) +{ int i, j; char *opt; @@ -552,8 +554,8 @@ void xbt_log_init(int *argc, char **argv) { if (strncmp(argv[i], "--log=", strlen("--log="))) WARN2 - ("Option %.*s is deprecated and will disapear in the future. Use --log instead.", - (int) (strchr(argv[i], '=') - argv[i]), argv[i]); + ("Option %.*s is deprecated and will disapear in the future. Use --log instead.", + (int) (strchr(argv[i], '=') - argv[i]), argv[i]); opt = strchr(argv[i], '='); opt++; @@ -672,7 +674,6 @@ static void _xbt_log_cat_apply_set(xbt_log_category_t category, DEBUG2("Set %p as appender of category '%s'", setting->appender, category->name); } - #undef _xbt_log_cat_init } @@ -708,7 +709,8 @@ int _xbt_log_cat_init(xbt_log_category_t category, DEBUG3("Set %s (%s) as father of %s ", category->parent->name, (category->parent->threshold == xbt_log_priority_uninitialized ? - "uninited" : xbt_log_priority_names[category->parent->threshold]), + "uninited" : xbt_log_priority_names[category-> + parent->threshold]), category->name); xbt_log_parent_set(category, category->parent); @@ -797,7 +799,8 @@ void xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent) if (parent->threshold == xbt_log_priority_uninitialized) { - _xbt_log_cat_init(parent, xbt_log_priority_uninitialized /* ignored */ ); + _xbt_log_cat_init(parent, + xbt_log_priority_uninitialized /* ignored */ ); } cat->threshold = parent->threshold; @@ -899,7 +902,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) *p -= 'a' - 'A'; } } - if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES") || !strcmp(neweq, "1")) { + if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES") + || !strcmp(neweq, "1")) { set->additivity = 1; } else { set->additivity = 0; @@ -921,7 +925,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) } else { char buff[512]; snprintf(buff, min(512, eq - dot), "%s", dot + 1); - THROW1(arg_error, 0, "Unknown setting of the log category: '%s'", buff); + THROW1(arg_error, 0, "Unknown setting of the log category: '%s'", + buff); } set->catname = (char *) xbt_malloc(dot - name + 1); @@ -990,8 +995,8 @@ void xbt_log_control_set(const char *control_string) DEBUG1("Parse log settings '%s'", control_string); /* Special handling of no_loc request, which asks for any file localization to be omitted (for tesh runs) */ - if (!strcmp(control_string,"no_loc")) { - xbt_log_no_loc=1; + if (!strcmp(control_string, "no_loc")) { + xbt_log_no_loc = 1; return; } /* some initialization if this is the first time that this get called */ @@ -1013,7 +1018,8 @@ void xbt_log_control_set(const char *control_string) xbt_log_category_t cat = NULL; set = _xbt_log_parse_setting(str); - cat = _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname); + cat = + _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname); if (cat) { DEBUG0("Apply directly"); @@ -1042,8 +1048,9 @@ void xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app) void xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay) { if (!cat->appender) { - VERB1("No appender to category %s. Setting the file appender as default", - cat->name); + VERB1 + ("No appender to category %s. Setting the file appender as default", + cat->name); xbt_log_appender_set(cat, xbt_log_appender_file_new(NULL)); } if (cat->layout && cat != &_XBT_LOGV(root)) { diff --git a/src/xbt/log_private.h b/src/xbt/log_private.h index 204e5cb21c..5ae1d5a626 100644 --- a/src/xbt/log_private.h +++ b/src/xbt/log_private.h @@ -36,4 +36,4 @@ XBT_PUBLIC(void) xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent); -#endif /* LOG_PRIVATE_H */ +#endif /* LOG_PRIVATE_H */ diff --git a/src/xbt/mallocator.c b/src/xbt/mallocator.c index 93e6a5ba5f..51c9b75aea 100644 --- a/src/xbt/mallocator.c +++ b/src/xbt/mallocator.c @@ -12,7 +12,7 @@ #include "mallocator_private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_mallocator, xbt, "Mallocators"); -extern int _surf_do_model_check; /* kill mallocators when this is true */ +extern int _surf_do_model_check; /* kill mallocators when this is true */ /** * \brief Constructor @@ -44,7 +44,7 @@ xbt_mallocator_t xbt_mallocator_new(int size, xbt_assert0(new_f != NULL && free_f != NULL && reset_f != NULL, "invalid parameter"); - /* Let's force 0 size mallocator! (Dirty hack, blame Martin :) )*/ + /* Let's force 0 size mallocator! (Dirty hack, blame Martin :) ) */ /* mallocators and memory mess introduced by model-checking do not mix well together: * The mallocator will give standard memory when we are using raw memory (so these blocks are killed on restore) @@ -52,13 +52,13 @@ xbt_mallocator_t xbt_mallocator_new(int size, */ if (_surf_do_model_check) size = 0; - + m = xbt_new0(s_xbt_mallocator_t, 1); VERB1("Create mallocator %p", m); if (XBT_LOG_ISENABLED(xbt_mallocator, xbt_log_priority_verbose)) xbt_backtrace_display_current(); - m->objects = xbt_new0(void *, _surf_do_model_check?1:size); + m->objects = xbt_new0(void *, _surf_do_model_check ? 1 : size); m->max_size = size; m->current_size = 0; m->new_f = new_f; @@ -82,7 +82,8 @@ void xbt_mallocator_free(xbt_mallocator_t m) int i; xbt_assert0(m != NULL, "Invalid parameter"); - VERB3("Frees mallocator %p (size:%d/%d)", m, m->current_size, m->max_size); + VERB3("Frees mallocator %p (size:%d/%d)", m, m->current_size, + m->max_size); for (i = 0; i < m->current_size; i++) { (*(m->free_f)) (m->objects[i]); } @@ -146,8 +147,8 @@ void xbt_mallocator_release(xbt_mallocator_t m, void *object) if (m->current_size < m->max_size) { /* there is enough place to push the object */ DEBUG3 - ("Store deleted object in mallocator %p for further use (size:%d/%d)", - m, m->current_size, m->max_size); + ("Store deleted object in mallocator %p for further use (size:%d/%d)", + m, m->current_size, m->max_size); m->objects[m->current_size++] = object; } else { /* otherwise we don't have a choice, we must free the object */ diff --git a/src/xbt/mallocator_private.h b/src/xbt/mallocator_private.h index dd46527802..928b3e5584 100644 --- a/src/xbt/mallocator_private.h +++ b/src/xbt/mallocator_private.h @@ -18,4 +18,4 @@ typedef struct s_xbt_mallocator { void_f_pvoid_t reset_f; /* function to call when an object is released by the user */ } s_xbt_mallocator_t; -#endif /* _XBT_MALLOCATOR_PRIVATE_H__ */ +#endif /* _XBT_MALLOCATOR_PRIVATE_H__ */ diff --git a/src/xbt/mmalloc/attach.c b/src/xbt/mmalloc/attach.c index db06a3c470..2674bed7c2 100644 --- a/src/xbt/mmalloc/attach.c +++ b/src/xbt/mmalloc/attach.c @@ -21,11 +21,11 @@ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include -#include /* After sys/types.h, at least for dpx/2. */ +#include /* After sys/types.h, at least for dpx/2. */ #include #include #ifdef HAVE_UNISTD_H -#include /* Prototypes for lseek */ +#include /* Prototypes for lseek */ #endif #include "mmprivate.h" @@ -36,7 +36,7 @@ Boston, MA 02111-1307, USA. */ /* Forward declarations/prototypes for local functions */ -static struct mdesc *reuse (int fd); +static struct mdesc *reuse(int fd); /* Initialize access to a mmalloc managed region. @@ -68,10 +68,11 @@ static struct mdesc *reuse (int fd); On failure returns NULL. */ -void * mmalloc_attach (int fd, void *baseaddr) { +void *mmalloc_attach(int fd, void *baseaddr) +{ struct mdesc mtemp; struct mdesc *mdp; - void* mbase; + void *mbase; struct stat sbuf; /* First check to see if FD is a valid file descriptor, and if so, see @@ -81,13 +82,12 @@ void * mmalloc_attach (int fd, void *baseaddr) { obsolete version, or any other reason, then we fail to attach to this file. */ - if (fd >= 0) - { - if (fstat (fd, &sbuf) < 0) + if (fd >= 0) { + if (fstat(fd, &sbuf) < 0) return (NULL); else if (sbuf.st_size > 0) - return ((void*) reuse (fd)); + return ((void *) reuse(fd)); } /* If the user provided NULL BASEADDR then fail */ @@ -100,19 +100,19 @@ void * mmalloc_attach (int fd, void *baseaddr) { then initialize the fields that we know values for. */ mdp = &mtemp; - memset ((char *) mdp, 0, sizeof (mtemp)); - strncpy (mdp -> magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE); - mdp -> headersize = sizeof (mtemp); - mdp -> version = MMALLOC_VERSION; - mdp -> morecore = __mmalloc_mmap_morecore; - mdp -> fd = fd; - mdp -> base = mdp -> breakval = mdp -> top = baseaddr; + memset((char *) mdp, 0, sizeof(mtemp)); + strncpy(mdp->magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE); + mdp->headersize = sizeof(mtemp); + mdp->version = MMALLOC_VERSION; + mdp->morecore = __mmalloc_mmap_morecore; + mdp->fd = fd; + mdp->base = mdp->breakval = mdp->top = baseaddr; /* If we have not been passed a valid open file descriptor for the file to map to, then we go for an anonymous map */ - if(mdp -> fd < 0) - mdp -> flags |= MMALLOC_ANONYMOUS; + if (mdp->fd < 0) + mdp->flags |= MMALLOC_ANONYMOUS; /* If we have not been passed a valid open file descriptor for the file to map to, then open /dev/zero and use that to map to. */ @@ -122,25 +122,22 @@ void * mmalloc_attach (int fd, void *baseaddr) { fails, then close the file descriptor if it was opened by us, and arrange to return a NULL. */ - if ((mbase = mdp -> morecore (mdp, sizeof (mtemp))) != NULL) - { - memcpy (mbase, mdp, sizeof (mtemp)); + if ((mbase = mdp->morecore(mdp, sizeof(mtemp))) != NULL) { + memcpy(mbase, mdp, sizeof(mtemp)); // mdp = (struct mdesc *) mbase; - } - else - { + } else { abort(); // mdp = NULL; } - { /* create the mutex within that heap */ - void*old_heap=mmalloc_get_current_heap(); + { /* create the mutex within that heap */ + void *old_heap = mmalloc_get_current_heap(); mmalloc_set_current_heap(mbase); - mdp->mutex =xbt_os_mutex_init(); + mdp->mutex = xbt_os_mutex_init(); mmalloc_set_current_heap(old_heap); } - return ((void*) mbase); + return ((void *) mbase); } /* Given an valid file descriptor on an open file, test to see if that file @@ -166,43 +163,39 @@ void * mmalloc_attach (int fd, void *baseaddr) { Returns a pointer to the malloc descriptor if successful, or NULL if unsuccessful for some reason. */ -static struct mdesc * -reuse (int fd) +static struct mdesc *reuse(int fd) { struct mdesc mtemp; struct mdesc *mdp = NULL; - if (lseek (fd, 0L, SEEK_SET) != 0) + if (lseek(fd, 0L, SEEK_SET) != 0) return NULL; - if (read (fd, (char *) &mtemp, sizeof (mtemp)) != sizeof (mtemp)) + if (read(fd, (char *) &mtemp, sizeof(mtemp)) != sizeof(mtemp)) return NULL; - if (mtemp.headersize != sizeof (mtemp)) + if (mtemp.headersize != sizeof(mtemp)) return NULL; - if (strcmp (mtemp.magic, MMALLOC_MAGIC) != 0) + if (strcmp(mtemp.magic, MMALLOC_MAGIC) != 0) return NULL; if (mtemp.version > MMALLOC_VERSION) return NULL; mtemp.fd = fd; - if (__mmalloc_remap_core (&mtemp) == mtemp.base) - { + if (__mmalloc_remap_core(&mtemp) == mtemp.base) { mdp = (struct mdesc *) mtemp.base; - mdp -> fd = fd; - mdp -> morecore = __mmalloc_mmap_morecore; - mdp->mutex =xbt_os_mutex_init(); - if (mdp -> mfree_hook != NULL) - { - mmcheckf ((void*) mdp, (void (*) (void)) NULL, 1); + mdp->fd = fd; + mdp->morecore = __mmalloc_mmap_morecore; + mdp->mutex = xbt_os_mutex_init(); + if (mdp->mfree_hook != NULL) { + mmcheckf((void *) mdp, (void (*)(void)) NULL, 1); } } - { /* create the mutex within that heap */ - void*old_heap=mmalloc_get_current_heap(); + { /* create the mutex within that heap */ + void *old_heap = mmalloc_get_current_heap(); mmalloc_set_current_heap(mdp); - mdp->mutex =xbt_os_mutex_init(); + mdp->mutex = xbt_os_mutex_init(); mmalloc_set_current_heap(old_heap); } return (mdp); } - diff --git a/src/xbt/mmalloc/detach.c b/src/xbt/mmalloc/detach.c index dbf4d34b29..b8d2320cc4 100644 --- a/src/xbt/mmalloc/detach.c +++ b/src/xbt/mmalloc/detach.c @@ -10,7 +10,7 @@ /* 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 /* close */ +#include /* close */ #include #include "mmprivate.h" @@ -28,35 +28,31 @@ region we are about to unmap, so we first make a local copy of it on the stack and use the copy. */ -void* -mmalloc_detach (void *md) +void *mmalloc_detach(void *md) { struct mdesc mtemp; - if (md != NULL) - { - - mtemp = *(struct mdesc *) md; - xbt_os_mutex_destroy(((struct mdesc*)md)->mutex); - - /* Now unmap all the pages associated with this region by asking for a - negative increment equal to the current size of the region. */ - - if ((mtemp.morecore (&mtemp, (char*)mtemp.base - (char*)mtemp.breakval)) == NULL) - { - /* Deallocating failed. Update the original malloc descriptor - with any changes */ - *(struct mdesc *) md = mtemp; - } - else - { - if (mtemp.flags & MMALLOC_DEVZERO) - { - close (mtemp.fd); - } - md = NULL; - } + if (md != NULL) { + + mtemp = *(struct mdesc *) md; + xbt_os_mutex_destroy(((struct mdesc *) md)->mutex); + + /* Now unmap all the pages associated with this region by asking for a + negative increment equal to the current size of the region. */ + + if ((mtemp.morecore(&mtemp, + (char *) mtemp.base - (char *) mtemp.breakval)) == + NULL) { + /* Deallocating failed. Update the original malloc descriptor + with any changes */ + *(struct mdesc *) md = mtemp; + } else { + if (mtemp.flags & MMALLOC_DEVZERO) { + close(mtemp.fd); + } + md = NULL; } + } return (md); } diff --git a/src/xbt/mmalloc/keys.c b/src/xbt/mmalloc/keys.c index 8f168b8d7b..7613923c57 100644 --- a/src/xbt/mmalloc/keys.c +++ b/src/xbt/mmalloc/keys.c @@ -26,31 +26,27 @@ #include "mmprivate.h" -int -mmalloc_setkey (void *md, int keynum, void *key) +int mmalloc_setkey(void *md, int keynum, void *key) { struct mdesc *mdp = (struct mdesc *) md; int result = 0; LOCK(mdp); - if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) - { - mdp -> keys [keynum] = key; - result++; - } + if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) { + mdp->keys[keynum] = key; + result++; + } UNLOCK(mdp); return (result); } -void* -mmalloc_getkey (void *md, int keynum) +void *mmalloc_getkey(void *md, int keynum) { struct mdesc *mdp = (struct mdesc *) md; - void* keyval = NULL; + void *keyval = NULL; - if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) - { - keyval = mdp -> keys [keynum]; - } + if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) { + keyval = mdp->keys[keynum]; + } return (keyval); } diff --git a/src/xbt/mmalloc/mcalloc.c b/src/xbt/mmalloc/mcalloc.c index 92f7eb16e3..f80953f85a 100644 --- a/src/xbt/mmalloc/mcalloc.c +++ b/src/xbt/mmalloc/mcalloc.c @@ -7,22 +7,20 @@ /* 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 /* GCC on HP/UX needs this before string.h. */ -#include /* Prototypes for memcpy, memmove, memset, etc */ +#include /* GCC on HP/UX needs this before string.h. */ +#include /* Prototypes for memcpy, memmove, memset, etc */ #include "mmprivate.h" /* Allocate an array of NMEMB elements each SIZE bytes long. The entire array is initialized to zeros. */ -void * -mcalloc (void *md, register size_t nmemb, register size_t size) +void *mcalloc(void *md, register size_t nmemb, register size_t size) { - register void* result; + register void *result; - if ((result = mmalloc (md, nmemb * size)) != NULL) - { - memset (result, 0, nmemb * size); - } + if ((result = mmalloc(md, nmemb * size)) != NULL) { + memset(result, 0, nmemb * size); + } return (result); } diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index 76b990143e..aae9149512 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -15,177 +15,155 @@ /* Return memory to the heap. Like `mfree' but don't call a mfree_hook if there is one. */ -void -__mmalloc_free (struct mdesc *mdp, void *ptr) +void __mmalloc_free(struct mdesc *mdp, void *ptr) { int type; size_t block; register size_t i; struct list *prev, *next; - block = BLOCK (ptr); + block = BLOCK(ptr); - if ((char*)ptr < (char*)mdp->heapbase || block > mdp->heapsize ) { + if ((char *) ptr < (char *) mdp->heapbase || block > mdp->heapsize) { printf("Ouch, this pointer is not mine. I refuse to free it.\n"); return; } - type = mdp -> heapinfo[block].busy.type; - switch (type) - { + type = mdp->heapinfo[block].busy.type; + switch (type) { case 0: /* Get as many statistics as early as we can. */ - mdp -> heapstats.chunks_used--; - mdp -> heapstats.bytes_used -= - mdp -> heapinfo[block].busy.info.size * BLOCKSIZE; - mdp -> heapstats.bytes_free += - mdp -> heapinfo[block].busy.info.size * BLOCKSIZE; + mdp->heapstats.chunks_used--; + mdp->heapstats.bytes_used -= + mdp->heapinfo[block].busy.info.size * BLOCKSIZE; + mdp->heapstats.bytes_free += + mdp->heapinfo[block].busy.info.size * BLOCKSIZE; /* Find the free cluster previous to this one in the free list. - Start searching at the last block referenced; this may benefit - programs with locality of allocation. */ - i = mdp -> heapindex; - if (i > block) - { - while (i > block) - { - i = mdp -> heapinfo[i].free.prev; + Start searching at the last block referenced; this may benefit + programs with locality of allocation. */ + i = mdp->heapindex; + if (i > block) { + while (i > block) { + i = mdp->heapinfo[i].free.prev; } - } - else - { - do - { - i = mdp -> heapinfo[i].free.next; + } else { + do { + i = mdp->heapinfo[i].free.next; } while ((i != 0) && (i < block)); - i = mdp -> heapinfo[i].free.prev; + i = mdp->heapinfo[i].free.prev; } /* Determine how to link this block into the free list. */ - if (block == i + mdp -> heapinfo[i].free.size) - { + if (block == i + mdp->heapinfo[i].free.size) { /* Coalesce this block with its predecessor. */ - mdp -> heapinfo[i].free.size += - mdp -> heapinfo[block].busy.info.size; + mdp->heapinfo[i].free.size += mdp->heapinfo[block].busy.info.size; block = i; - } - else - { + } else { /* Really link this block back into the free list. */ - mdp -> heapinfo[block].free.size = - mdp -> heapinfo[block].busy.info.size; - mdp -> heapinfo[block].free.next = mdp -> heapinfo[i].free.next; - mdp -> heapinfo[block].free.prev = i; - mdp -> heapinfo[i].free.next = block; - mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev = block; - mdp -> heapstats.chunks_free++; + mdp->heapinfo[block].free.size = mdp->heapinfo[block].busy.info.size; + mdp->heapinfo[block].free.next = mdp->heapinfo[i].free.next; + mdp->heapinfo[block].free.prev = i; + mdp->heapinfo[i].free.next = block; + mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block; + mdp->heapstats.chunks_free++; } /* Now that the block is linked in, see if we can coalesce it - with its successor (by deleting its successor from the list - and adding in its size). */ - if (block + mdp -> heapinfo[block].free.size == - mdp -> heapinfo[block].free.next) - { - mdp -> heapinfo[block].free.size - += mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.size; - mdp -> heapinfo[block].free.next - = mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.next; - mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev = block; - mdp -> heapstats.chunks_free--; + with its successor (by deleting its successor from the list + and adding in its size). */ + if (block + mdp->heapinfo[block].free.size == + mdp->heapinfo[block].free.next) { + mdp->heapinfo[block].free.size + += mdp->heapinfo[mdp->heapinfo[block].free.next].free.size; + mdp->heapinfo[block].free.next + = mdp->heapinfo[mdp->heapinfo[block].free.next].free.next; + mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev = block; + mdp->heapstats.chunks_free--; } /* Now see if we can return stuff to the system. */ /* blocks = mdp -> heapinfo[block].free.size; - if (blocks >= FINAL_FREE_BLOCKS && block + blocks == mdp -> heaplimit - && mdp -> morecore (mdp, 0) == ADDRESS (block + blocks)) - { - register size_t bytes = blocks * BLOCKSIZE; - mdp -> heaplimit -= blocks; - mdp -> morecore (mdp, -bytes); - mdp -> heapinfo[mdp -> heapinfo[block].free.prev].free.next - = mdp -> heapinfo[block].free.next; - mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev - = mdp -> heapinfo[block].free.prev; - block = mdp -> heapinfo[block].free.prev; - mdp -> heapstats.chunks_free--; - mdp -> heapstats.bytes_free -= bytes; - }*/ + if (blocks >= FINAL_FREE_BLOCKS && block + blocks == mdp -> heaplimit + && mdp -> morecore (mdp, 0) == ADDRESS (block + blocks)) + { + register size_t bytes = blocks * BLOCKSIZE; + mdp -> heaplimit -= blocks; + mdp -> morecore (mdp, -bytes); + mdp -> heapinfo[mdp -> heapinfo[block].free.prev].free.next + = mdp -> heapinfo[block].free.next; + mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev + = mdp -> heapinfo[block].free.prev; + block = mdp -> heapinfo[block].free.prev; + mdp -> heapstats.chunks_free--; + mdp -> heapstats.bytes_free -= bytes; + } */ /* Set the next search to begin at this block. */ - mdp -> heapindex = block; + mdp->heapindex = block; break; default: /* Do some of the statistics. */ - mdp -> heapstats.chunks_used--; - mdp -> heapstats.bytes_used -= 1 << type; - mdp -> heapstats.chunks_free++; - mdp -> heapstats.bytes_free += 1 << type; + mdp->heapstats.chunks_used--; + mdp->heapstats.bytes_used -= 1 << type; + mdp->heapstats.chunks_free++; + mdp->heapstats.bytes_free += 1 << type; /* Get the address of the first free fragment in this block. */ prev = (struct list *) - ((char*) ADDRESS(block) + - ( mdp -> heapinfo[block].busy.info.frag.first << type)); + ((char *) ADDRESS(block) + + (mdp->heapinfo[block].busy.info.frag.first << type)); - if (mdp -> heapinfo[block].busy.info.frag.nfree == - (BLOCKSIZE >> type) - 1) - { + if (mdp->heapinfo[block].busy.info.frag.nfree == + (BLOCKSIZE >> type) - 1) { /* If all fragments of this block are free, remove them - from the fragment list and free the whole block. */ + from the fragment list and free the whole block. */ next = prev; - for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i) - { - next = next -> next; + for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i) { + next = next->next; } - prev -> prev -> next = next; - if (next != NULL) - { - next -> prev = prev -> prev; + prev->prev->next = next; + if (next != NULL) { + next->prev = prev->prev; } - mdp -> heapinfo[block].busy.type = 0; - mdp -> heapinfo[block].busy.info.size = 1; + mdp->heapinfo[block].busy.type = 0; + mdp->heapinfo[block].busy.info.size = 1; /* Keep the statistics accurate. */ - mdp -> heapstats.chunks_used++; - mdp -> heapstats.bytes_used += BLOCKSIZE; - mdp -> heapstats.chunks_free -= BLOCKSIZE >> type; - mdp -> heapstats.bytes_free -= BLOCKSIZE; + mdp->heapstats.chunks_used++; + mdp->heapstats.bytes_used += BLOCKSIZE; + mdp->heapstats.chunks_free -= BLOCKSIZE >> type; + mdp->heapstats.bytes_free -= BLOCKSIZE; - mfree ((void*) mdp, (void*) ADDRESS(block)); - } - else if (mdp -> heapinfo[block].busy.info.frag.nfree != 0) - { + mfree((void *) mdp, (void *) ADDRESS(block)); + } else if (mdp->heapinfo[block].busy.info.frag.nfree != 0) { /* If some fragments of this block are free, link this - fragment into the fragment list after the first free - fragment of this block. */ + fragment into the fragment list after the first free + fragment of this block. */ next = (struct list *) ptr; - next -> next = prev -> next; - next -> prev = prev; - prev -> next = next; - if (next -> next != NULL) - { - next -> next -> prev = next; + next->next = prev->next; + next->prev = prev; + prev->next = next; + if (next->next != NULL) { + next->next->prev = next; } - ++mdp -> heapinfo[block].busy.info.frag.nfree; - } - else - { + ++mdp->heapinfo[block].busy.info.frag.nfree; + } else { /* No fragments of this block are free, so link this - fragment into the fragment list and announce that - it is the first free fragment of this block. */ + fragment into the fragment list and announce that + it is the first free fragment of this block. */ prev = (struct list *) ptr; - mdp -> heapinfo[block].busy.info.frag.nfree = 1; - mdp -> heapinfo[block].busy.info.frag.first = - RESIDUAL (ptr, BLOCKSIZE) >> type; - prev -> next = mdp -> fraghead[type].next; - prev -> prev = &mdp -> fraghead[type]; - prev -> prev -> next = prev; - if (prev -> next != NULL) - { - prev -> next -> prev = prev; + mdp->heapinfo[block].busy.info.frag.nfree = 1; + mdp->heapinfo[block].busy.info.frag.first = + RESIDUAL(ptr, BLOCKSIZE) >> type; + prev->next = mdp->fraghead[type].next; + prev->prev = &mdp->fraghead[type]; + prev->prev->next = prev; + if (prev->next != NULL) { + prev->next->prev = prev; } } break; @@ -194,26 +172,26 @@ __mmalloc_free (struct mdesc *mdp, void *ptr) /* Return memory to the heap. */ -void mfree (void *md, void *ptr) { +void mfree(void *md, void *ptr) +{ struct mdesc *mdp; register struct alignlist *l; if (ptr != NULL) { - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); LOCK(mdp); - for (l = mdp -> aligned_blocks; l != NULL; l = l -> next) { - if (l -> aligned == ptr) { - l -> aligned = NULL; /* Mark the slot in the list as free. */ - ptr = l -> exact; + for (l = mdp->aligned_blocks; l != NULL; l = l->next) { + if (l->aligned == ptr) { + l->aligned = NULL; /* Mark the slot in the list as free. */ + ptr = l->exact; break; } } - if (mdp -> mfree_hook != NULL) { - (*mdp -> mfree_hook) (mdp, ptr); + if (mdp->mfree_hook != NULL) { + (*mdp->mfree_hook) (mdp, ptr); } else { - __mmalloc_free (mdp, ptr); + __mmalloc_free(mdp, ptr); } UNLOCK(mdp); } } - diff --git a/src/xbt/mmalloc/mm.c b/src/xbt/mmalloc/mm.c index a096061fbf..8c9b3b8792 100644 --- a/src/xbt/mmalloc/mm.c +++ b/src/xbt/mmalloc/mm.c @@ -13,7 +13,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #ifdef HAVE_UNISTD_H -#include /* Prototypes for lseek, sbrk (maybe) */ +#include /* Prototypes for lseek, sbrk (maybe) */ #endif #include "mcalloc.c" #include "mfree.c" diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index 82da344a4d..a9928e0e37 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -8,78 +8,94 @@ #include "mmprivate.h" -static void *__mmalloc_current_heap=NULL; /* The heap we are currently using. */ +static void *__mmalloc_current_heap = NULL; /* The heap we are currently using. */ #include "xbt_modinter.h" -void* mmalloc_get_current_heap(void) { +void *mmalloc_get_current_heap(void) +{ return __mmalloc_current_heap; } -void mmalloc_set_current_heap(void *new_heap) { - __mmalloc_current_heap=new_heap; + +void mmalloc_set_current_heap(void *new_heap) +{ + __mmalloc_current_heap = new_heap; } #ifdef MMALLOC_WANT_OVERIDE_LEGACY -void *malloc(size_t n) { +void *malloc(size_t n) +{ #ifdef HAVE_MMAP - if (!__mmalloc_current_heap) mmalloc_preinit(); + if (!__mmalloc_current_heap) + mmalloc_preinit(); #endif void *ret = mmalloc(__mmalloc_current_heap, n); return ret; } -void *calloc(size_t nmemb, size_t size) { +void *calloc(size_t nmemb, size_t size) +{ size_t total_size = nmemb * size; #ifdef HAVE_MMAP - if (!__mmalloc_current_heap) mmalloc_preinit(); + if (!__mmalloc_current_heap) + mmalloc_preinit(); #endif void *ret = mmalloc(__mmalloc_current_heap, total_size); /* Fill the allocated memory with zeroes to mimic calloc behaviour */ - memset(ret,'\0', total_size); + memset(ret, '\0', total_size); return ret; } -void *realloc(void *p, size_t s) { +void *realloc(void *p, size_t s) +{ void *ret = NULL; #ifdef HAVE_MMAP - if (!__mmalloc_current_heap) mmalloc_preinit(); + if (!__mmalloc_current_heap) + mmalloc_preinit(); #endif if (s) { - if (p) - ret = mrealloc(__mmalloc_current_heap, p,s); - else - ret = mmalloc(__mmalloc_current_heap,s); + if (p) + ret = mrealloc(__mmalloc_current_heap, p, s); + else + ret = mmalloc(__mmalloc_current_heap, s); } else { - if (p) - mfree(__mmalloc_current_heap,p); + if (p) + mfree(__mmalloc_current_heap, p); } return ret; } -void free(void *p) { +void free(void *p) +{ return mfree(__mmalloc_current_heap, p); } #endif /* Make sure it works with md==NULL */ -#define HEAP_OFFSET 40960000 /* Safety gap from the heap's break address */ +#define HEAP_OFFSET 40960000 /* Safety gap from the heap's break address */ -void *mmalloc_get_default_md(void) { +void *mmalloc_get_default_md(void) +{ xbt_assert(__mmalloc_default_mdp); return __mmalloc_default_mdp; } /* Initialize the default malloc descriptor. */ -void mmalloc_preinit(void) { - if(!__mmalloc_default_mdp) __mmalloc_default_mdp = mmalloc_attach(-1, (char *)sbrk(0) + HEAP_OFFSET); +void mmalloc_preinit(void) +{ + if (!__mmalloc_default_mdp) + __mmalloc_default_mdp = + mmalloc_attach(-1, (char *) sbrk(0) + HEAP_OFFSET); xbt_assert(__mmalloc_default_mdp != NULL); } -void mmalloc_postexit(void) { + +void mmalloc_postexit(void) +{ /* Do not detach the default mdp or ldl won't be able to free the memory it allocated since we're in memory */ // mmalloc_detach(__mmalloc_default_mdp); } diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index 7d8f8ef083..5abbcd2e41 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -10,103 +10,99 @@ /* 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 /* Prototypes for memcpy, memmove, memset, etc */ +#include /* Prototypes for memcpy, memmove, memset, etc */ #include #include "mmprivate.h" /* Prototypes for local functions */ -static int initialize (struct mdesc *mdp); -static void* morecore (struct mdesc *mdp, size_t size); -static void* align (struct mdesc *mdp, size_t size); +static int initialize(struct mdesc *mdp); +static void *morecore(struct mdesc *mdp, size_t size); +static void *align(struct mdesc *mdp, size_t size); /* Aligned allocation. */ -static void* align (struct mdesc *mdp, size_t size) { - void* result; +static void *align(struct mdesc *mdp, size_t size) +{ + void *result; unsigned long int adj; - result = mdp -> morecore (mdp, size); - adj = RESIDUAL (result, BLOCKSIZE); - if (adj != 0) - { + result = mdp->morecore(mdp, size); + adj = RESIDUAL(result, BLOCKSIZE); + if (adj != 0) { adj = BLOCKSIZE - adj; - mdp -> morecore (mdp, adj); - result = (char*) result + adj; + mdp->morecore(mdp, adj); + result = (char *) result + adj; } return (result); } /* Set everything up and remember that we have. */ -static int initialize (struct mdesc *mdp) +static int initialize(struct mdesc *mdp) { - mdp -> heapsize = HEAP / BLOCKSIZE; - mdp -> heapinfo = (malloc_info *) - align (mdp, mdp -> heapsize * sizeof (malloc_info)); - if (mdp -> heapinfo == NULL) - { + mdp->heapsize = HEAP / BLOCKSIZE; + mdp->heapinfo = (malloc_info *) + align(mdp, mdp->heapsize * sizeof(malloc_info)); + if (mdp->heapinfo == NULL) { return (0); } - memset ((void*)mdp -> heapinfo, 0, mdp -> heapsize * sizeof (malloc_info)); - mdp -> heapinfo[0].free.size = 0; - mdp -> heapinfo[0].free.next = mdp -> heapinfo[0].free.prev = 0; - mdp -> heapindex = 0; - mdp -> heapbase = (void*) mdp -> heapinfo; - mdp -> flags |= MMALLOC_INITIALIZED; + memset((void *) mdp->heapinfo, 0, mdp->heapsize * sizeof(malloc_info)); + mdp->heapinfo[0].free.size = 0; + mdp->heapinfo[0].free.next = mdp->heapinfo[0].free.prev = 0; + mdp->heapindex = 0; + mdp->heapbase = (void *) mdp->heapinfo; + mdp->flags |= MMALLOC_INITIALIZED; return (1); } /* Get neatly aligned memory, initializing or growing the heap info table as necessary. */ -static void* morecore (struct mdesc *mdp, size_t size) +static void *morecore(struct mdesc *mdp, size_t size) { - void* result; + void *result; malloc_info *newinfo, *oldinfo; size_t newsize; - result = align (mdp, size); - if (result == NULL) - { + result = align(mdp, size); + if (result == NULL) { return (NULL); } /* Check if we need to grow the info table. */ - if ((size_t) BLOCK ((char*) result + size) > mdp -> heapsize) - { - newsize = mdp -> heapsize; - while ((size_t) BLOCK ((char*) result + size) > newsize) - { + if ((size_t) BLOCK((char *) result + size) > mdp->heapsize) { + newsize = mdp->heapsize; + while ((size_t) BLOCK((char *) result + size) > newsize) { newsize *= 2; } - newinfo = (malloc_info *) align (mdp, newsize * sizeof (malloc_info)); - if (newinfo == NULL) - { - mdp -> morecore (mdp, -size); + newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info)); + if (newinfo == NULL) { + mdp->morecore(mdp, -size); return (NULL); } - memset ((void*) newinfo, 0, newsize * sizeof (malloc_info)); - memcpy ((void*) newinfo, (void*) mdp -> heapinfo, - mdp -> heapsize * sizeof (malloc_info)); - oldinfo = mdp -> heapinfo; - newinfo[BLOCK (oldinfo)].busy.type = 0; - newinfo[BLOCK (oldinfo)].busy.info.size - = BLOCKIFY (mdp -> heapsize * sizeof (malloc_info)); - mdp -> heapinfo = newinfo; - __mmalloc_free (mdp, (void*)oldinfo); - mdp -> heapsize = newsize; + memset((void *) newinfo, 0, newsize * sizeof(malloc_info)); + memcpy((void *) newinfo, (void *) mdp->heapinfo, + mdp->heapsize * sizeof(malloc_info)); + oldinfo = mdp->heapinfo; + newinfo[BLOCK(oldinfo)].busy.type = 0; + newinfo[BLOCK(oldinfo)].busy.info.size + = BLOCKIFY(mdp->heapsize * sizeof(malloc_info)); + mdp->heapinfo = newinfo; + __mmalloc_free(mdp, (void *) oldinfo); + mdp->heapsize = newsize; } - mdp -> heaplimit = BLOCK ((char*) result + size); + mdp->heaplimit = BLOCK((char *) result + size); return (result); } /* Allocate memory from the heap. */ -void* mmalloc (void *md, size_t size) { +void *mmalloc(void *md, size_t size) +{ struct mdesc *mdp; - void* result; + void *result; size_t block, blocks, lastblocks, start; register size_t i; struct list *next; @@ -116,190 +112,170 @@ void* mmalloc (void *md, size_t size) { * glibc malloc does not use this trick but return a constant pointer, but my hack is quicker to implement ;) */ if (size == 0) - size=1; + size = 1; - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); LOCK(mdp); // printf("(%s) Mallocing %d bytes on %p (default: %p)...",xbt_thread_self_name(),size,mdp,__mmalloc_default_mdp);fflush(stdout); - if (mdp -> mmalloc_hook != NULL) { - void * res = ((*mdp -> mmalloc_hook) (md, size)); + if (mdp->mmalloc_hook != NULL) { + void *res = ((*mdp->mmalloc_hook) (md, size)); UNLOCK(mdp); return res; } - if (!(mdp -> flags & MMALLOC_INITIALIZED)) { - if (!initialize (mdp)) { + if (!(mdp->flags & MMALLOC_INITIALIZED)) { + if (!initialize(mdp)) { UNLOCK(mdp); return (NULL); } } - if (size < sizeof (struct list)) { - size = sizeof (struct list); + if (size < sizeof(struct list)) { + size = sizeof(struct list); } /* Determine the allocation policy based on the request size. */ - if (size <= BLOCKSIZE / 2) - { + if (size <= BLOCKSIZE / 2) { /* Small allocation to receive a fragment of a block. - Determine the logarithm to base two of the fragment size. */ + Determine the logarithm to base two of the fragment size. */ log = 1; --size; - while ((size /= 2) != 0) - { + while ((size /= 2) != 0) { ++log; } /* Look in the fragment lists for a - free fragment of the desired size. */ - next = mdp -> fraghead[log].next; - if (next != NULL) - { + free fragment of the desired size. */ + next = mdp->fraghead[log].next; + if (next != NULL) { /* There are free fragments of this size. - Pop a fragment out of the fragment list and return it. - Update the block's nfree and first counters. */ - result = (void*) next; - next -> prev -> next = next -> next; - if (next -> next != NULL) - { - next -> next -> prev = next -> prev; + Pop a fragment out of the fragment list and return it. + Update the block's nfree and first counters. */ + result = (void *) next; + next->prev->next = next->next; + if (next->next != NULL) { + next->next->prev = next->prev; } - block = BLOCK (result); - if (--mdp -> heapinfo[block].busy.info.frag.nfree != 0) - { - mdp -> heapinfo[block].busy.info.frag.first = - RESIDUAL (next -> next, BLOCKSIZE) >> log; + block = BLOCK(result); + if (--mdp->heapinfo[block].busy.info.frag.nfree != 0) { + mdp->heapinfo[block].busy.info.frag.first = + RESIDUAL(next->next, BLOCKSIZE) >> log; } /* Update the statistics. */ - mdp -> heapstats.chunks_used++; - mdp -> heapstats.bytes_used += 1 << log; - mdp -> heapstats.chunks_free--; - mdp -> heapstats.bytes_free -= 1 << log; - } - else - { + mdp->heapstats.chunks_used++; + mdp->heapstats.bytes_used += 1 << log; + mdp->heapstats.chunks_free--; + mdp->heapstats.bytes_free -= 1 << log; + } else { /* No free fragments of the desired size, so get a new block - and break it into fragments, returning the first. */ + and break it into fragments, returning the first. */ UNLOCK(mdp); //printf("(%s) No free fragment...",xbt_thread_self_name()); - result = mmalloc (md, BLOCKSIZE); + result = mmalloc(md, BLOCKSIZE); //printf("(%s) Fragment: %p...",xbt_thread_self_name(),result); LOCK(mdp); - if (result == NULL) - { + if (result == NULL) { UNLOCK(mdp); return (NULL); } /* Link all fragments but the first into the free list. */ - for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i) - { - next = (struct list *) ((char*) result + (i << log)); - next -> next = mdp -> fraghead[log].next; - next -> prev = &mdp -> fraghead[log]; - next -> prev -> next = next; - if (next -> next != NULL) - { - next -> next -> prev = next; + for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i) { + next = (struct list *) ((char *) result + (i << log)); + next->next = mdp->fraghead[log].next; + next->prev = &mdp->fraghead[log]; + next->prev->next = next; + if (next->next != NULL) { + next->next->prev = next; } } /* Initialize the nfree and first counters for this block. */ - block = BLOCK (result); - mdp -> heapinfo[block].busy.type = log; - mdp -> heapinfo[block].busy.info.frag.nfree = i - 1; - mdp -> heapinfo[block].busy.info.frag.first = i - 1; - - mdp -> heapstats.chunks_free += (BLOCKSIZE >> log) - 1; - mdp -> heapstats.bytes_free += BLOCKSIZE - (1 << log); - mdp -> heapstats.bytes_used -= BLOCKSIZE - (1 << log); + block = BLOCK(result); + mdp->heapinfo[block].busy.type = log; + mdp->heapinfo[block].busy.info.frag.nfree = i - 1; + mdp->heapinfo[block].busy.info.frag.first = i - 1; + + mdp->heapstats.chunks_free += (BLOCKSIZE >> log) - 1; + mdp->heapstats.bytes_free += BLOCKSIZE - (1 << log); + mdp->heapstats.bytes_used -= BLOCKSIZE - (1 << log); } - } - else - { + } else { /* Large allocation to receive one or more blocks. - Search the free list in a circle starting at the last place visited. - If we loop completely around without finding a large enough - space we will have to get more memory from the system. */ + Search the free list in a circle starting at the last place visited. + If we loop completely around without finding a large enough + space we will have to get more memory from the system. */ blocks = BLOCKIFY(size); start = block = MALLOC_SEARCH_START; - while (mdp -> heapinfo[block].free.size < blocks) - { - block = mdp -> heapinfo[block].free.next; - if (block == start) - { + while (mdp->heapinfo[block].free.size < blocks) { + block = mdp->heapinfo[block].free.next; + if (block == start) { /* Need to get more from the system. Check to see if - the new core will be contiguous with the final free - block; if so we don't need to get as much. */ - block = mdp -> heapinfo[0].free.prev; - lastblocks = mdp -> heapinfo[block].free.size; - if (mdp -> heaplimit != 0 && - block + lastblocks == mdp -> heaplimit && - mdp -> morecore (mdp, 0) == ADDRESS(block + lastblocks) && - (morecore (mdp, (blocks - lastblocks) * BLOCKSIZE)) != NULL) - { + the new core will be contiguous with the final free + block; if so we don't need to get as much. */ + block = mdp->heapinfo[0].free.prev; + lastblocks = mdp->heapinfo[block].free.size; + if (mdp->heaplimit != 0 && + block + lastblocks == mdp->heaplimit && + mdp->morecore(mdp, 0) == ADDRESS(block + lastblocks) && + (morecore(mdp, (blocks - lastblocks) * BLOCKSIZE)) != NULL) { /* Which block we are extending (the `final free - block' referred to above) might have changed, if - it got combined with a freed info table. */ - block = mdp -> heapinfo[0].free.prev; + block' referred to above) might have changed, if + it got combined with a freed info table. */ + block = mdp->heapinfo[0].free.prev; - mdp -> heapinfo[block].free.size += (blocks - lastblocks); - mdp -> heapstats.bytes_free += - (blocks - lastblocks) * BLOCKSIZE; + mdp->heapinfo[block].free.size += (blocks - lastblocks); + mdp->heapstats.bytes_free += (blocks - lastblocks) * BLOCKSIZE; continue; } result = morecore(mdp, blocks * BLOCKSIZE); - if (result == NULL) - { + if (result == NULL) { UNLOCK(mdp); return (NULL); } - block = BLOCK (result); - mdp -> heapinfo[block].busy.type = 0; - mdp -> heapinfo[block].busy.info.size = blocks; - mdp -> heapstats.chunks_used++; - mdp -> heapstats.bytes_used += blocks * BLOCKSIZE; + block = BLOCK(result); + mdp->heapinfo[block].busy.type = 0; + mdp->heapinfo[block].busy.info.size = blocks; + mdp->heapstats.chunks_used++; + mdp->heapstats.bytes_used += blocks * BLOCKSIZE; UNLOCK(mdp); return (result); } } /* At this point we have found a suitable free list entry. - Figure out how to remove what we need from the list. */ + Figure out how to remove what we need from the list. */ result = ADDRESS(block); - if (mdp -> heapinfo[block].free.size > blocks) - { + if (mdp->heapinfo[block].free.size > blocks) { /* The block we found has a bit left over, - so relink the tail end back into the free list. */ - mdp -> heapinfo[block + blocks].free.size - = mdp -> heapinfo[block].free.size - blocks; - mdp -> heapinfo[block + blocks].free.next - = mdp -> heapinfo[block].free.next; - mdp -> heapinfo[block + blocks].free.prev - = mdp -> heapinfo[block].free.prev; - mdp -> heapinfo[mdp -> heapinfo[block].free.prev].free.next - = mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev - = mdp -> heapindex = block + blocks; - } - else - { + so relink the tail end back into the free list. */ + mdp->heapinfo[block + blocks].free.size + = mdp->heapinfo[block].free.size - blocks; + mdp->heapinfo[block + blocks].free.next + = mdp->heapinfo[block].free.next; + mdp->heapinfo[block + blocks].free.prev + = mdp->heapinfo[block].free.prev; + mdp->heapinfo[mdp->heapinfo[block].free.prev].free.next + = mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev + = mdp->heapindex = block + blocks; + } else { /* The block exactly matches our requirements, - so just remove it from the list. */ - mdp -> heapinfo[mdp -> heapinfo[block].free.next].free.prev - = mdp -> heapinfo[block].free.prev; - mdp -> heapinfo[mdp -> heapinfo[block].free.prev].free.next - = mdp -> heapindex = mdp -> heapinfo[block].free.next; - mdp -> heapstats.chunks_free--; + so just remove it from the list. */ + mdp->heapinfo[mdp->heapinfo[block].free.next].free.prev + = mdp->heapinfo[block].free.prev; + mdp->heapinfo[mdp->heapinfo[block].free.prev].free.next + = mdp->heapindex = mdp->heapinfo[block].free.next; + mdp->heapstats.chunks_free--; } - mdp -> heapinfo[block].busy.type = 0; - mdp -> heapinfo[block].busy.info.size = blocks; - mdp -> heapstats.chunks_used++; - mdp -> heapstats.bytes_used += blocks * BLOCKSIZE; - mdp -> heapstats.bytes_free -= blocks * BLOCKSIZE; + mdp->heapinfo[block].busy.type = 0; + mdp->heapinfo[block].busy.info.size = blocks; + mdp->heapstats.chunks_used++; + mdp->heapstats.bytes_used += blocks * BLOCKSIZE; + mdp->heapstats.bytes_free -= blocks * BLOCKSIZE; } //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout); UNLOCK(mdp); diff --git a/src/xbt/mmalloc/mmap-sup.c b/src/xbt/mmalloc/mmap-sup.c index 4388ff962e..3b48e726e0 100644 --- a/src/xbt/mmalloc/mmap-sup.c +++ b/src/xbt/mmalloc/mmap-sup.c @@ -10,11 +10,11 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef MAP_ANONYMOUS - #define MAP_ANONYMOUS MAP_ANON +#define MAP_ANONYMOUS MAP_ANON #endif #ifdef HAVE_UNISTD_H -#include /* Prototypes for lseek */ +#include /* Prototypes for lseek */ #endif #include #include @@ -33,7 +33,7 @@ static size_t pagesize; #if NEED_DECLARATION_GETPAGESIZE -extern int getpagesize (void); +extern int getpagesize(void); #endif #define PAGE_ALIGN(addr) (void*) (((long)(addr) + pagesize - 1) & \ @@ -61,109 +61,96 @@ extern int getpagesize (void); amount to either add to or subtract from the existing region. Works like sbrk(), but using mmap(). */ -void* -__mmalloc_mmap_morecore (struct mdesc *mdp, int size) +void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size) { ssize_t test = 0; - void* result = NULL; - off_t foffset; /* File offset at which new mapping will start */ - size_t mapbytes; /* Number of bytes to map */ - void* moveto; /* Address where we wish to move "break value" to */ - void* mapto; /* Address we actually mapped to */ - char buf = 0; /* Single byte to write to extend mapped file */ + void *result = NULL; + off_t foffset; /* File offset at which new mapping will start */ + size_t mapbytes; /* Number of bytes to map */ + void *moveto; /* Address where we wish to move "break value" to */ + void *mapto; /* Address we actually mapped to */ + char buf = 0; /* Single byte to write to extend mapped file */ if (pagesize == 0) pagesize = getpagesize(); - if (size == 0) - { + if (size == 0) { /* Just return the current "break" value. */ - result = mdp -> breakval; - } - else if (size < 0) - { + result = mdp->breakval; + } else if (size < 0) { /* We are deallocating memory. If the amount requested would cause - us to try to deallocate back past the base of the mmap'd region - then do nothing, and return NULL. Otherwise, deallocate the - memory and return the old break value. */ - if (((char*)mdp -> breakval) + size >= (char*)mdp -> base) - { - result = (void*) mdp -> breakval; - mdp -> breakval = (char*) mdp->breakval + size; - moveto = PAGE_ALIGN (mdp -> breakval); - munmap (moveto, (size_t) (((char*)mdp -> top) - ((char*)moveto)) - 1); - mdp -> top = moveto; - } - } - else - { + us to try to deallocate back past the base of the mmap'd region + then do nothing, and return NULL. Otherwise, deallocate the + memory and return the old break value. */ + if (((char *) mdp->breakval) + size >= (char *) mdp->base) { + result = (void *) mdp->breakval; + mdp->breakval = (char *) mdp->breakval + size; + moveto = PAGE_ALIGN(mdp->breakval); + munmap(moveto, + (size_t) (((char *) mdp->top) - ((char *) moveto)) - 1); + mdp->top = moveto; + } + } else { /* We are allocating memory. Make sure we have an open file - descriptor if not working with anonymous memory. */ - if ( !(mdp->flags & MMALLOC_ANONYMOUS) && mdp -> fd < 0) - { - result = NULL; - } - else if ((char*)mdp -> breakval + size > (char*)mdp -> top) - { - /* The request would move us past the end of the currently - mapped memory, so map in enough more memory to satisfy - the request. This means we also have to grow the mapped-to - file by an appropriate amount, since mmap cannot be used - to extend a file. */ - moveto = PAGE_ALIGN ((char*)mdp -> breakval + size); - mapbytes = (char*)moveto - (char*)mdp -> top; - foffset = (char*)mdp -> top - (char*)mdp -> base; - - if( mdp -> fd > 0){ - /* FIXME: Test results of lseek() and write() */ - lseek (mdp -> fd, foffset + mapbytes - 1, SEEK_SET); - test = write (mdp -> fd, &buf, 1); + descriptor if not working with anonymous memory. */ + if (!(mdp->flags & MMALLOC_ANONYMOUS) && mdp->fd < 0) { + result = NULL; + } else if ((char *) mdp->breakval + size > (char *) mdp->top) { + /* The request would move us past the end of the currently + mapped memory, so map in enough more memory to satisfy + the request. This means we also have to grow the mapped-to + file by an appropriate amount, since mmap cannot be used + to extend a file. */ + moveto = PAGE_ALIGN((char *) mdp->breakval + size); + mapbytes = (char *) moveto - (char *) mdp->top; + foffset = (char *) mdp->top - (char *) mdp->base; + + if (mdp->fd > 0) { + /* FIXME: Test results of lseek() and write() */ + lseek(mdp->fd, foffset + mapbytes - 1, SEEK_SET); + test = write(mdp->fd, &buf, 1); } - - /* Let's call mmap. Note that it is possible that mdp->top - is 0. In this case mmap will choose the address for us */ - mapto = mmap (mdp->top, mapbytes, PROT_READ | PROT_WRITE, - MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) | MAP_FIXED, - MAP_ANON_OR_FD(mdp), foffset); - - if (mapto != (void*) -1){ - - if(mdp -> top == 0) - mdp -> base = mdp -> breakval = mapto; - - mdp -> top = PAGE_ALIGN ((char*)mdp -> breakval + size); - result = (void*) mdp -> breakval; - mdp -> breakval = (char*)mdp->breakval + size; + + /* Let's call mmap. Note that it is possible that mdp->top + is 0. In this case mmap will choose the address for us */ + mapto = mmap(mdp->top, mapbytes, PROT_READ | PROT_WRITE, + MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) | + MAP_FIXED, MAP_ANON_OR_FD(mdp), foffset); + + if (mapto != (void *) -1) { + + if (mdp->top == 0) + mdp->base = mdp->breakval = mapto; + + mdp->top = PAGE_ALIGN((char *) mdp->breakval + size); + result = (void *) mdp->breakval; + mdp->breakval = (char *) mdp->breakval + size; } - } - else - { - result = (void*) mdp -> breakval; - mdp -> breakval = (char*)mdp->breakval + size; - } + } else { + result = (void *) mdp->breakval; + mdp->breakval = (char *) mdp->breakval + size; + } } return (result); } -void* -__mmalloc_remap_core (struct mdesc *mdp) +void *__mmalloc_remap_core(struct mdesc *mdp) { - void* base; + void *base; /* FIXME: Quick hack, needs error checking and other attention. */ - base = mmap (mdp -> base, (char*)mdp -> top - (char*)mdp -> base, - PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE_OR_SHARED (mdp) | MAP_FIXED, - mdp -> fd, 0); - return ((void*) base); + base = mmap(mdp->base, (char *) mdp->top - (char *) mdp->base, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE_OR_SHARED(mdp) | MAP_FIXED, mdp->fd, 0); + return ((void *) base); } -void* -mmalloc_findbase (int size) +void *mmalloc_findbase(int size) { int fd; int flags; - void* base = NULL; + void *base = NULL; #ifdef MAP_ANONYMOUS flags = MAP_PRIVATE | MAP_ANONYMOUS; @@ -174,32 +161,26 @@ mmalloc_findbase (int size) #else flags = MAP_PRIVATE; #endif - fd = open ("/dev/zero", O_RDWR); - if (fd != -1) - { - return ((void*) NULL); - } + fd = open("/dev/zero", O_RDWR); + if (fd != -1) { + return ((void *) NULL); + } #endif - base = mmap (0, size, PROT_READ | PROT_WRITE, flags, fd, 0); - if (base != (void*) -1) - { - munmap (base, (size_t) size); - } - if (fd != -1) - { - close (fd); - } - if (base == 0) - { - /* Don't allow mapping at address zero. We use that value - to signal an error return, and besides, it is useful to - catch NULL pointers if it is unmapped. Instead start - at the next page boundary. */ - base = (void*)(long) getpagesize (); - } - else if (base == (void*) -1) - { - base = NULL; - } - return ((void*) base); + base = mmap(0, size, PROT_READ | PROT_WRITE, flags, fd, 0); + if (base != (void *) -1) { + munmap(base, (size_t) size); + } + if (fd != -1) { + close(fd); + } + if (base == 0) { + /* Don't allow mapping at address zero. We use that value + to signal an error return, and besides, it is useful to + catch NULL pointers if it is unmapped. Instead start + at the next page boundary. */ + base = (void *) (long) getpagesize(); + } else if (base == (void *) -1) { + base = NULL; + } + return ((void *) base); } diff --git a/src/xbt/mmalloc/mmcheck.c b/src/xbt/mmalloc/mmcheck.c index 3467c1c0e0..46b48a6aec 100644 --- a/src/xbt/mmalloc/mmcheck.c +++ b/src/xbt/mmalloc/mmcheck.c @@ -16,12 +16,12 @@ can specify an alternate function to be called instead (and probably will want to). */ -extern void abort (void); +extern void abort(void); /* Arbitrary magical numbers. */ -#define MAGICWORD (unsigned int) 0xfedabeeb /* Active chunk */ -#define MAGICWORDFREE (unsigned int) 0xdeadbeef /* Inactive chunk */ +#define MAGICWORD (unsigned int) 0xfedabeeb /* Active chunk */ +#define MAGICWORDFREE (unsigned int) 0xdeadbeef /* Inactive chunk */ #define MAGICBYTE ((char) 0xd7) /* Each memory allocation is bounded by a header structure and a trailer @@ -33,90 +33,82 @@ extern void abort (void); user's allocation area. The magic word can be tested to detect buffer underruns and the magic byte can be tested to detect overruns. */ -struct hdr - { - size_t size; /* Exact size requested by user. */ - unsigned long int magic; /* Magic number to check header integrity. */ - }; +struct hdr { + size_t size; /* Exact size requested by user. */ + unsigned long int magic; /* Magic number to check header integrity. */ +}; -static void checkhdr (struct mdesc *mdp, const struct hdr *hdr); -static void mfree_check (void* md, void* ptr); -static void* mmalloc_check (void* md, size_t size); -static void* mrealloc_check (void* md, void* ptr, size_t size); +static void checkhdr(struct mdesc *mdp, const struct hdr *hdr); +static void mfree_check(void *md, void *ptr); +static void *mmalloc_check(void *md, size_t size); +static void *mrealloc_check(void *md, void *ptr, size_t size); /* Check the magicword and magicbyte, and if either is corrupted then call the emergency abort function specified for the heap in use. */ -static void -checkhdr (struct mdesc *mdp, const struct hdr *hdr) +static void checkhdr(struct mdesc *mdp, const struct hdr *hdr) { - if (hdr -> magic != MAGICWORD || - ((char *) &hdr[1])[hdr -> size] != MAGICBYTE) - { - (*mdp -> abortfunc)(); - } + if (hdr->magic != MAGICWORD || + ((char *) &hdr[1])[hdr->size] != MAGICBYTE) { + (*mdp->abortfunc) (); + } } -static void -mfree_check (void *md, void *ptr) +static void mfree_check(void *md, void *ptr) { struct hdr *hdr = ((struct hdr *) ptr) - 1; struct mdesc *mdp; - mdp = MD_TO_MDP (md); - checkhdr (mdp, hdr); - hdr -> magic = MAGICWORDFREE; - mdp -> mfree_hook = NULL; - mfree (md, (void*)hdr); - mdp -> mfree_hook = mfree_check; + mdp = MD_TO_MDP(md); + checkhdr(mdp, hdr); + hdr->magic = MAGICWORDFREE; + mdp->mfree_hook = NULL; + mfree(md, (void *) hdr); + mdp->mfree_hook = mfree_check; } -static void* -mmalloc_check (void *md, size_t size) +static void *mmalloc_check(void *md, size_t size) { struct hdr *hdr; struct mdesc *mdp; size_t nbytes; - mdp = MD_TO_MDP (md); - mdp -> mmalloc_hook = NULL; - nbytes = sizeof (struct hdr) + size + 1; - hdr = (struct hdr *) mmalloc (md, nbytes); - mdp -> mmalloc_hook = mmalloc_check; - if (hdr != NULL) - { - hdr -> size = size; - hdr -> magic = MAGICWORD; - hdr++; - *((char *) hdr + size) = MAGICBYTE; - } - return ((void*) hdr); + mdp = MD_TO_MDP(md); + mdp->mmalloc_hook = NULL; + nbytes = sizeof(struct hdr) + size + 1; + hdr = (struct hdr *) mmalloc(md, nbytes); + mdp->mmalloc_hook = mmalloc_check; + if (hdr != NULL) { + hdr->size = size; + hdr->magic = MAGICWORD; + hdr++; + *((char *) hdr + size) = MAGICBYTE; + } + return ((void *) hdr); } -static void* -mrealloc_check (void* md, void* ptr, size_t size) +static void *mrealloc_check(void *md, void *ptr, size_t size) { struct hdr *hdr = ((struct hdr *) ptr) - 1; struct mdesc *mdp; size_t nbytes; - mdp = MD_TO_MDP (md); - checkhdr (mdp, hdr); - mdp -> mfree_hook = NULL; - mdp -> mmalloc_hook = NULL; - mdp -> mrealloc_hook = NULL; - nbytes = sizeof (struct hdr) + size + 1; - hdr = (struct hdr *) mrealloc (md, (void*) hdr, nbytes); - mdp -> mfree_hook = mfree_check; - mdp -> mmalloc_hook = mmalloc_check; - mdp -> mrealloc_hook = mrealloc_check; - if (hdr != NULL) - { - hdr -> size = size; - hdr++; - *((char *) hdr + size) = MAGICBYTE; - } - return ((void*) hdr); + mdp = MD_TO_MDP(md); + checkhdr(mdp, hdr); + mdp->mfree_hook = NULL; + mdp->mmalloc_hook = NULL; + mdp->mrealloc_hook = NULL; + nbytes = sizeof(struct hdr) + size + 1; + hdr = (struct hdr *) mrealloc(md, (void *) hdr, nbytes); + mdp->mfree_hook = mfree_check; + mdp->mmalloc_hook = mmalloc_check; + mdp->mrealloc_hook = mrealloc_check; + if (hdr != NULL) { + hdr->size = size; + hdr++; + *((char *) hdr + size) = MAGICBYTE; + } + return ((void *) hdr); } /* Turn on default checking for mmalloc/mrealloc/mfree, for the heap specified @@ -149,37 +141,32 @@ mrealloc_check (void* md, void* ptr, size_t size) Returns non-zero if checking is successfully enabled, zero otherwise. */ -int -mmcheckf (void *md, void (*func)(void), int force) +int mmcheckf(void *md, void (*func) (void), int force) { struct mdesc *mdp; int rtnval; - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); /* We can safely set or update the abort function at any time, regardless of whether or not we successfully do anything else. */ - mdp -> abortfunc = (func != NULL ? func : abort); + mdp->abortfunc = (func != NULL ? func : abort); /* If we haven't yet called mmalloc the first time for this heap, or if we have hooks that were previously installed, then allow the hooks to be initialized or updated. */ if (force || - !(mdp -> flags & MMALLOC_INITIALIZED) || - (mdp -> mfree_hook != NULL)) - { - mdp -> mfree_hook = mfree_check; - mdp -> mmalloc_hook = mmalloc_check; - mdp -> mrealloc_hook = mrealloc_check; - mdp -> flags |= MMALLOC_MMCHECK_USED; - rtnval = 1; - } - else - { - rtnval = 0; - } + !(mdp->flags & MMALLOC_INITIALIZED) || (mdp->mfree_hook != NULL)) { + mdp->mfree_hook = mfree_check; + mdp->mmalloc_hook = mmalloc_check; + mdp->mrealloc_hook = mrealloc_check; + mdp->flags |= MMALLOC_MMCHECK_USED; + rtnval = 1; + } else { + rtnval = 0; + } return (rtnval); } @@ -187,11 +174,10 @@ mmcheckf (void *md, void (*func)(void), int force) /* This routine is for backwards compatibility only, in case there are still callers to the original mmcheck function. */ -int -mmcheck (void *md, void (*func) (void)) +int mmcheck(void *md, void (*func) (void)) { int rtnval; - rtnval = mmcheckf (md, func, 0); + rtnval = mmcheckf(md, func, 0); return (rtnval); } diff --git a/src/xbt/mmalloc/mmemalign.c b/src/xbt/mmalloc/mmemalign.c index 690496afad..f475076d49 100644 --- a/src/xbt/mmalloc/mmemalign.c +++ b/src/xbt/mmalloc/mmemalign.c @@ -9,41 +9,34 @@ #include "mmprivate.h" -void * -mmemalign (void *md, size_t alignment, size_t size) +void *mmemalign(void *md, size_t alignment, size_t size) { - void* result; + void *result; unsigned long int adj; struct alignlist *l; struct mdesc *mdp; - if ((result = mmalloc (md, size + alignment - 1)) != NULL) - { - adj = RESIDUAL (result, alignment); - if (adj != 0) - { - mdp = MD_TO_MDP (md); - for (l = mdp -> aligned_blocks; l != NULL; l = l -> next) - { - if (l -> aligned == NULL) - { + if ((result = mmalloc(md, size + alignment - 1)) != NULL) { + adj = RESIDUAL(result, alignment); + if (adj != 0) { + mdp = MD_TO_MDP(md); + for (l = mdp->aligned_blocks; l != NULL; l = l->next) { + if (l->aligned == NULL) { /* This slot is free. Use it. */ break; } } - if (l == NULL) - { - l = (struct alignlist *) mmalloc (md, sizeof (struct alignlist)); - if (l == NULL) - { - mfree (md, result); + if (l == NULL) { + l = (struct alignlist *) mmalloc(md, sizeof(struct alignlist)); + if (l == NULL) { + mfree(md, result); return (NULL); } - l -> next = mdp -> aligned_blocks; - mdp -> aligned_blocks = l; + l->next = mdp->aligned_blocks; + mdp->aligned_blocks = l; } - l -> exact = result; - result = l -> aligned = (char*) result + alignment - adj; + l->exact = result; + result = l->aligned = (char *) result + alignment - adj; } } return (result); diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index e92aec96d9..fd566b1a92 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -29,10 +29,10 @@ # define MIN(A, B) ((A) < (B) ? (A) : (B)) #endif -#define MMALLOC_MAGIC "mmalloc" /* Mapped file magic number */ -#define MMALLOC_MAGIC_SIZE 8 /* Size of magic number buf */ -#define MMALLOC_VERSION 1 /* Current mmalloc version */ -#define MMALLOC_KEYS 16 /* Keys for application use */ +#define MMALLOC_MAGIC "mmalloc" /* Mapped file magic number */ +#define MMALLOC_MAGIC_SIZE 8 /* Size of magic number buf */ +#define MMALLOC_VERSION 1 /* Current mmalloc version */ +#define MMALLOC_KEYS 16 /* Keys for application use */ /* The allocator divides the heap into blocks of fixed size; large requests receive one or more whole blocks, and small requests @@ -84,51 +84,44 @@ const char *xbt_thread_self_name(void); /* Data structure giving per-block information. */ -typedef union - { - /* Heap information for a busy block. */ - struct - { - /* Zero for a large block, or positive giving the - logarithm to the base two of the fragment size. */ - int type; - union - { - struct - { - size_t nfree; /* Free fragments in a fragmented block. */ - size_t first; /* First free fragment of the block. */ - } frag; - /* Size (in blocks) of a large cluster. */ - size_t size; - } info; - } busy; - /* Heap information for a free block (that may be the first of - a free cluster). */ - struct - { - size_t size; /* Size (in blocks) of a free cluster. */ - size_t next; /* Index of next free cluster. */ - size_t prev; /* Index of previous free cluster. */ - } free; - } malloc_info; +typedef union { + /* Heap information for a busy block. */ + struct { + /* Zero for a large block, or positive giving the + logarithm to the base two of the fragment size. */ + int type; + union { + struct { + size_t nfree; /* Free fragments in a fragmented block. */ + size_t first; /* First free fragment of the block. */ + } frag; + /* Size (in blocks) of a large cluster. */ + size_t size; + } info; + } busy; + /* Heap information for a free block (that may be the first of + a free cluster). */ + struct { + size_t size; /* Size (in blocks) of a free cluster. */ + size_t next; /* Index of next free cluster. */ + size_t prev; /* Index of previous free cluster. */ + } free; +} malloc_info; /* List of blocks allocated with `mmemalign' (or `mvalloc'). */ -struct alignlist - { - struct alignlist *next; - void* aligned; /* The address that mmemaligned returned. */ - void* exact; /* The address that malloc returned. */ - }; +struct alignlist { + struct alignlist *next; + void *aligned; /* The address that mmemaligned returned. */ + void *exact; /* The address that malloc returned. */ +}; /* Doubly linked lists of free fragments. */ -struct list - { - struct list *next; - struct list *prev; - }; +struct list { + struct list *next; + struct list *prev; +}; /* Statistics available to the user. FIXME: By design, the internals of the malloc package are no longer @@ -136,14 +129,13 @@ struct list to be via some other mechanism, such as mmstat_ where the return value is the the user is interested in. */ -struct mstats - { - size_t bytes_total; /* Total size of the heap. */ - size_t chunks_used; /* Chunks allocated by the user. */ - size_t bytes_used; /* Byte total of user-allocated chunks. */ - size_t chunks_free; /* Chunks in the free list. */ - size_t bytes_free; /* Byte total of chunks in the free list. */ - }; +struct mstats { + size_t bytes_total; /* Total size of the heap. */ + size_t chunks_used; /* Chunks allocated by the user. */ + size_t bytes_used; /* Byte total of user-allocated chunks. */ + size_t chunks_free; /* Chunks in the free list. */ + size_t bytes_free; /* Byte total of chunks in the free list. */ +}; /* Internal structure that defines the format of the malloc-descriptor. This gets written to the base address of the region that mmalloc is @@ -178,8 +170,8 @@ struct mdesc { FIXME: For mapped regions shared by more than one process, this needs to be maintained on a per-process basis. */ - void* (*morecore) (struct mdesc *mdp, int size); - + void *(*morecore) (struct mdesc * mdp, int size); + /* Pointer to the function that causes an abort when the memory checking features are activated. By default this is set to abort(), but can be set to another function by the application using mmalloc(). @@ -192,25 +184,25 @@ struct mdesc { FIXME: For mapped regions shared by more than one process, this needs to be maintained on a per-process basis. */ - void (*mfree_hook) (void* mdp, void* ptr); + void (*mfree_hook) (void *mdp, void *ptr); /* Debugging hook for `malloc'. FIXME: For mapped regions shared by more than one process, this needs to be maintained on a per-process basis. */ - void* (*mmalloc_hook) (void* mdp, size_t size); + void *(*mmalloc_hook) (void *mdp, size_t size); /* Debugging hook for realloc. FIXME: For mapped regions shared by more than one process, this needs to be maintained on a per-process basis. */ - void* (*mrealloc_hook) (void* mdp, void* ptr, size_t size); + void *(*mrealloc_hook) (void *mdp, void *ptr, size_t size); /* Number of info entries. */ size_t heapsize; /* Pointer to first block of the heap (base of the first block). */ - void* heapbase; + void *heapbase; /* Current search index for the heap table. */ /* Search index in the info table. */ @@ -242,17 +234,17 @@ struct mdesc { is the location where the bookkeeping data for mmap and for malloc begins. */ - void* base; + void *base; /* The current location in the memory region for this malloc heap which represents the end of memory in use. */ - void* breakval; + void *breakval; /* The end of the current memory region for this malloc heap. This is the first location past the end of mapped memory. */ - void* top; + void *top; /* Open file descriptor for the file to which this malloc heap is mapped. This will always be a valid file descriptor, since /dev/zero is used @@ -264,20 +256,20 @@ struct mdesc { /* An array of keys to data within the mapped region, for use by the application. */ - void* keys[MMALLOC_KEYS]; + void *keys[MMALLOC_KEYS]; }; /* Bits to look at in the malloc descriptor flags word */ -#define MMALLOC_DEVZERO (1 << 0) /* Have mapped to /dev/zero */ -#define MMALLOC_ANONYMOUS (1 << 1) /* Use anonymous mapping */ -#define MMALLOC_INITIALIZED (1 << 2) /* Initialized mmalloc */ -#define MMALLOC_MMCHECK_USED (1 << 3) /* mmcheckf() called already */ +#define MMALLOC_DEVZERO (1 << 0) /* Have mapped to /dev/zero */ +#define MMALLOC_ANONYMOUS (1 << 1) /* Use anonymous mapping */ +#define MMALLOC_INITIALIZED (1 << 2) /* Initialized mmalloc */ +#define MMALLOC_MMCHECK_USED (1 << 3) /* mmcheckf() called already */ /* Internal version of `mfree' used in `morecore'. */ -extern void __mmalloc_free (struct mdesc *mdp, void* ptr); +extern void __mmalloc_free(struct mdesc *mdp, void *ptr); /* A default malloc descriptor for the single sbrk() managed region. */ @@ -286,17 +278,17 @@ extern struct mdesc *__mmalloc_default_mdp; /* Initialize the first use of the default malloc descriptor, which uses an sbrk() region. */ -extern struct mdesc *__mmalloc_create_default_mdp (void); +extern struct mdesc *__mmalloc_create_default_mdp(void); /* Grow or shrink a contiguous mapped region using mmap(). Works much like sbrk(), only faster */ -extern void* __mmalloc_mmap_morecore (struct mdesc *mdp, int size); +extern void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size); /* Remap a mmalloc region that was previously mapped. */ -extern void* __mmalloc_remap_core (struct mdesc *mdp); +extern void *__mmalloc_remap_core(struct mdesc *mdp); /* Macro to convert from a user supplied malloc descriptor to pointer to the internal malloc descriptor. If the user supplied descriptor is NULL, then @@ -309,4 +301,4 @@ extern void* __mmalloc_remap_core (struct mdesc *mdp); ? __mmalloc_default_mdp \ : (struct mdesc *) (md)) -#endif /* __MMPRIVATE_H */ +#endif /* __MMPRIVATE_H */ diff --git a/src/xbt/mmalloc/mmstats.c b/src/xbt/mmalloc/mmstats.c index c65e488c9a..4342d191f9 100644 --- a/src/xbt/mmalloc/mmstats.c +++ b/src/xbt/mmalloc/mmstats.c @@ -16,18 +16,16 @@ None of the internal mmalloc structures should be externally visible outside the library. */ -struct mstats -mmstats (void *md) +struct mstats mmstats(void *md) { struct mstats result; struct mdesc *mdp; - mdp = MD_TO_MDP (md); - result.bytes_total = - (char*) mdp -> top - (char*)mdp; - result.chunks_used = mdp -> heapstats.chunks_used; - result.bytes_used = mdp -> heapstats.bytes_used; - result.chunks_free = mdp -> heapstats.chunks_free; - result.bytes_free = mdp -> heapstats.bytes_free; + mdp = MD_TO_MDP(md); + result.bytes_total = (char *) mdp->top - (char *) mdp; + result.chunks_used = mdp->heapstats.chunks_used; + result.bytes_used = mdp->heapstats.bytes_used; + result.chunks_free = mdp->heapstats.chunks_free; + result.bytes_free = mdp->heapstats.bytes_free; return (result); } diff --git a/src/xbt/mmalloc/mmtrace.c b/src/xbt/mmalloc/mmtrace.c index 9ffb465c2c..38219f3fb2 100644 --- a/src/xbt/mmalloc/mmtrace.c +++ b/src/xbt/mmalloc/mmtrace.c @@ -14,103 +14,99 @@ #include #include "mmprivate.h" -static void tr_break (void); -static void tr_freehook (void*md, void*ptr); -static void* tr_mallochook (void* md, size_t size); -static void* tr_reallochook (void* md, void* ptr, size_t size); +static void tr_break(void); +static void tr_freehook(void *md, void *ptr); +static void *tr_mallochook(void *md, size_t size); +static void *tr_reallochook(void *md, void *ptr, size_t size); #ifndef __GNU_LIBRARY__ -extern char *getenv (); +extern char *getenv(); #endif static FILE *mallstream; -#if 0 /* FIXME: Disabled for now. */ +#if 0 /* FIXME: Disabled for now. */ static char mallenv[] = "MALLOC_TRACE"; -static char mallbuf[BUFSIZ]; /* Buffer for the output. */ +static char mallbuf[BUFSIZ]; /* Buffer for the output. */ #endif /* Address to breakpoint on accesses to... */ -static void* mallwatch; +static void *mallwatch; /* Old hook values. */ -static void (*old_mfree_hook) (void* md, void* ptr); -static void* (*old_mmalloc_hook) (void* md, size_t size); -static void* (*old_mrealloc_hook) (void* md, void* ptr, size_t size); +static void (*old_mfree_hook) (void *md, void *ptr); +static void *(*old_mmalloc_hook) (void *md, size_t size); +static void *(*old_mrealloc_hook) (void *md, void *ptr, size_t size); /* This function is called when the block being alloc'd, realloc'd, or freed has an address matching the variable "mallwatch". In a debugger, set "mallwatch" to the address of interest, then put a breakpoint on tr_break. */ -static void -tr_break (void) +static void tr_break(void) { } -static void -tr_freehook (void *md, void *ptr) +static void tr_freehook(void *md, void *ptr) { struct mdesc *mdp; - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); /* Be sure to print it first. */ - fprintf (mallstream, "- %08lx\n", (unsigned long) ptr); + fprintf(mallstream, "- %08lx\n", (unsigned long) ptr); if (ptr == mallwatch) - tr_break (); - mdp -> mfree_hook = old_mfree_hook; - mfree (md, ptr); - mdp -> mfree_hook = tr_freehook; + tr_break(); + mdp->mfree_hook = old_mfree_hook; + mfree(md, ptr); + mdp->mfree_hook = tr_freehook; } -static void* -tr_mallochook (void* md, size_t size) +static void *tr_mallochook(void *md, size_t size) { - void* hdr; + void *hdr; struct mdesc *mdp; - mdp = MD_TO_MDP (md); - mdp -> mmalloc_hook = old_mmalloc_hook; - hdr = (void*) mmalloc (md, size); - mdp -> mmalloc_hook = tr_mallochook; + mdp = MD_TO_MDP(md); + mdp->mmalloc_hook = old_mmalloc_hook; + hdr = (void *) mmalloc(md, size); + mdp->mmalloc_hook = tr_mallochook; /* We could be printing a NULL here; that's OK. */ - fprintf (mallstream, "+ %p 0x%lx\n", hdr, (unsigned long)size); + fprintf(mallstream, "+ %p 0x%lx\n", hdr, (unsigned long) size); if (hdr == mallwatch) - tr_break (); + tr_break(); return (hdr); } -static void* -tr_reallochook (void *md, void *ptr, size_t size) +static void *tr_reallochook(void *md, void *ptr, size_t size) { - void* hdr; + void *hdr; struct mdesc *mdp; - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); if (ptr == mallwatch) - tr_break (); - - mdp -> mfree_hook = old_mfree_hook; - mdp -> mmalloc_hook = old_mmalloc_hook; - mdp -> mrealloc_hook = old_mrealloc_hook; - hdr = (void*) mrealloc (md, ptr, size); - mdp -> mfree_hook = tr_freehook; - mdp -> mmalloc_hook = tr_mallochook; - mdp -> mrealloc_hook = tr_reallochook; + tr_break(); + + mdp->mfree_hook = old_mfree_hook; + mdp->mmalloc_hook = old_mmalloc_hook; + mdp->mrealloc_hook = old_mrealloc_hook; + hdr = (void *) mrealloc(md, ptr, size); + mdp->mfree_hook = tr_freehook; + mdp->mmalloc_hook = tr_mallochook; + mdp->mrealloc_hook = tr_reallochook; if (hdr == NULL) /* Failed realloc. */ - fprintf (mallstream, "! %p 0x%lx\n", ptr, (unsigned long) size); + fprintf(mallstream, "! %p 0x%lx\n", ptr, (unsigned long) size); else - fprintf (mallstream, "< %p\n> %p 0x%lx\n", ptr, - hdr, (unsigned long) size); + fprintf(mallstream, "< %p\n> %p 0x%lx\n", ptr, + hdr, (unsigned long) size); if (hdr == mallwatch) - tr_break (); + tr_break(); return hdr; } @@ -120,34 +116,29 @@ tr_reallochook (void *md, void *ptr, size_t size) that the debugging user wants us to stop on. When patching mallwatch, don't forget to set a breakpoint on tr_break! */ -int -mmtrace (void) +int mmtrace(void) { -#if 0 /* FIXME! This is disabled for now until we figure out how to - maintain a stack of hooks per heap, since we might have other - hooks (such as set by mmcheck/mmcheckf) active also. */ +#if 0 /* FIXME! This is disabled for now until we figure out how to + maintain a stack of hooks per heap, since we might have other + hooks (such as set by mmcheck/mmcheckf) active also. */ char *mallfile; - mallfile = getenv (mallenv); - if (mallfile != NULL || mallwatch != NULL) - { - mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "w"); - if (mallstream != NULL) - { - /* Be sure it doesn't mmalloc its buffer! */ - setbuf (mallstream, mallbuf); - fprintf (mallstream, "= Start\n"); - old_mfree_hook = mdp -> mfree_hook; - mdp -> mfree_hook = tr_freehook; - old_mmalloc_hook = mdp -> mmalloc_hook; - mdp -> mmalloc_hook = tr_mallochook; - old_mrealloc_hook = mdp -> mrealloc_hook; - mdp -> mrealloc_hook = tr_reallochook; - } + mallfile = getenv(mallenv); + if (mallfile != NULL || mallwatch != NULL) { + mallstream = fopen(mallfile != NULL ? mallfile : "/dev/null", "w"); + if (mallstream != NULL) { + /* Be sure it doesn't mmalloc its buffer! */ + setbuf(mallstream, mallbuf); + fprintf(mallstream, "= Start\n"); + old_mfree_hook = mdp->mfree_hook; + mdp->mfree_hook = tr_freehook; + old_mmalloc_hook = mdp->mmalloc_hook; + mdp->mmalloc_hook = tr_mallochook; + old_mrealloc_hook = mdp->mrealloc_hook; + mdp->mrealloc_hook = tr_reallochook; } - -#endif /* 0 */ + } +#endif /* 0 */ return (1); } - diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index fd8eb8242f..38f2031945 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -8,7 +8,7 @@ /* 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 /* Prototypes for memcpy, memmove, memset, etc */ +#include /* Prototypes for memcpy, memmove, memset, etc */ #include "mmprivate.h" @@ -19,120 +19,113 @@ new region. This module has incestuous knowledge of the internals of both mfree and mmalloc. */ -void* mrealloc (void *md, void *ptr, size_t size) { +void *mrealloc(void *md, void *ptr, size_t size) +{ struct mdesc *mdp; - void* result; + void *result; int type; size_t block, blocks, oldlimit; if (size == 0) { - mfree (md, ptr); - return (mmalloc (md, 0)); + mfree(md, ptr); + return (mmalloc(md, 0)); } else if (ptr == NULL) { - return (mmalloc (md, size)); + return (mmalloc(md, size)); } - mdp = MD_TO_MDP (md); + mdp = MD_TO_MDP(md); //printf("(%s)realloc %p to %d...",xbt_thread_self_name(),ptr,(int)size); - if ((char*)ptr < (char*)mdp->heapbase || BLOCK(ptr) > mdp->heapsize ) { - printf("FIXME. Ouch, this pointer is not mine. I will malloc it instead of reallocing it. (please report this bug)\n"); - result = mmalloc(md,size); + if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) { + printf + ("FIXME. Ouch, this pointer is not mine. I will malloc it instead of reallocing it. (please report this bug)\n"); + result = mmalloc(md, size); abort(); return result; } LOCK(mdp); - if (mdp -> mrealloc_hook != NULL) - { + if (mdp->mrealloc_hook != NULL) { UNLOCK(mdp); - return ((*mdp -> mrealloc_hook) (md, ptr, size)); + return ((*mdp->mrealloc_hook) (md, ptr, size)); } - block = BLOCK (ptr); + block = BLOCK(ptr); - type = mdp -> heapinfo[block].busy.type; - switch (type) - { + type = mdp->heapinfo[block].busy.type; + switch (type) { case 0: /* Maybe reallocate a large block to a small fragment. */ - if (size <= BLOCKSIZE / 2) - { + if (size <= BLOCKSIZE / 2) { UNLOCK(mdp); //printf("(%s) alloc large block...",xbt_thread_self_name()); - result = mmalloc (md, size); - if (result != NULL) - { - memcpy (result, ptr, size); - mfree (md, ptr); + result = mmalloc(md, size); + if (result != NULL) { + memcpy(result, ptr, size); + mfree(md, ptr); return (result); } } /* The new size is a large allocation as well; - see if we can hold it in place. */ + see if we can hold it in place. */ LOCK(mdp); - blocks = BLOCKIFY (size); - if (blocks < mdp -> heapinfo[block].busy.info.size) - { + blocks = BLOCKIFY(size); + if (blocks < mdp->heapinfo[block].busy.info.size) { /* The new size is smaller; return excess memory to the free list. */ //printf("(%s) return excess memory...",xbt_thread_self_name()); - mdp -> heapinfo[block + blocks].busy.type = 0; - mdp -> heapinfo[block + blocks].busy.info.size - = mdp -> heapinfo[block].busy.info.size - blocks; - mdp -> heapinfo[block].busy.info.size = blocks; - mfree (md, ADDRESS (block + blocks)); + mdp->heapinfo[block + blocks].busy.type = 0; + mdp->heapinfo[block + blocks].busy.info.size + = mdp->heapinfo[block].busy.info.size - blocks; + mdp->heapinfo[block].busy.info.size = blocks; + mfree(md, ADDRESS(block + blocks)); result = ptr; - } - else if (blocks == mdp -> heapinfo[block].busy.info.size) - { + } else if (blocks == mdp->heapinfo[block].busy.info.size) { /* No size change necessary. */ result = ptr; - } - else - { + } else { /* Won't fit, so allocate a new region that will. - Free the old region first in case there is sufficient - adjacent free space to grow without moving. */ - blocks = mdp -> heapinfo[block].busy.info.size; + Free the old region first in case there is sufficient + adjacent free space to grow without moving. */ + blocks = mdp->heapinfo[block].busy.info.size; /* Prevent free from actually returning memory to the system. */ - oldlimit = mdp -> heaplimit; - mdp -> heaplimit = 0; - mfree (md, ptr); - mdp -> heaplimit = oldlimit; + oldlimit = mdp->heaplimit; + mdp->heaplimit = 0; + mfree(md, ptr); + mdp->heaplimit = oldlimit; UNLOCK(mdp); - result = mmalloc (md, size); + result = mmalloc(md, size); if (result == NULL) { - mmalloc (md, blocks * BLOCKSIZE); + mmalloc(md, blocks * BLOCKSIZE); return (NULL); } if (ptr != result) - memmove (result, ptr, blocks * BLOCKSIZE); + memmove(result, ptr, blocks * BLOCKSIZE); LOCK(mdp); } break; default: /* Old size is a fragment; type is logarithm - to base two of the fragment size. */ + to base two of the fragment size. */ if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type)) { /* The new size is the same kind of fragment. */ //printf("(%s) new size is same kind of fragment...",xbt_thread_self_name()); result = ptr; } else { /* The new size is different; allocate a new space, - and copy the lesser of the new size and the old. */ + and copy the lesser of the new size and the old. */ //printf("(%s) new size is different...",xbt_thread_self_name()); UNLOCK(mdp); - result = mmalloc (md, size); + result = mmalloc(md, size); if (result == NULL) return (NULL); - memcpy (result, ptr, MIN (size, (size_t) 1 << type)); - mfree (md, ptr); + memcpy(result, ptr, MIN(size, (size_t) 1 << type)); + mfree(md, ptr); } break; } diff --git a/src/xbt/mmalloc/mvalloc.c b/src/xbt/mmalloc/mvalloc.c index d3cd4d079e..93caf739dc 100644 --- a/src/xbt/mmalloc/mvalloc.c +++ b/src/xbt/mmalloc/mvalloc.c @@ -18,23 +18,22 @@ static size_t cache_pagesize; #if NEED_DECLARATION_GETPAGESIZE -extern int getpagesize PARAMS ((void)); +extern int getpagesize PARAMS((void)); #endif -void* -mvalloc (void *md, size_t size) +void *mvalloc(void *md, size_t size) { - if (cache_pagesize == 0) - { - cache_pagesize = getpagesize (); - } + if (cache_pagesize == 0) { + cache_pagesize = getpagesize(); + } - return (mmemalign (md, cache_pagesize, size)); + return (mmemalign(md, cache_pagesize, size)); } /* Useless prototype to make gcc happy */ -void* valloc (size_t size); +void *valloc(size_t size); -void* valloc (size_t size) { - return mvalloc (NULL, size); +void *valloc(size_t size) +{ + return mvalloc(NULL, size); } diff --git a/src/xbt/mmalloc/sbrk-sup.c b/src/xbt/mmalloc/sbrk-sup.c index 52c8230bfb..522cbfcab2 100644 --- a/src/xbt/mmalloc/sbrk-sup.c +++ b/src/xbt/mmalloc/sbrk-sup.c @@ -8,16 +8,16 @@ /* 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 /* Prototypes for sbrk (maybe) */ +#include /* Prototypes for sbrk (maybe) */ -#include /* Prototypes for memcpy, memmove, memset, etc */ +#include /* Prototypes for memcpy, memmove, memset, etc */ #include "xbt.h" #include "mmprivate.h" -static void* sbrk_morecore (struct mdesc *mdp, int size); +static void *sbrk_morecore(struct mdesc *mdp, int size); #if NEED_DECLARATION_SBRK -extern void* sbrk (int size); +extern void *sbrk(int size); #endif /* The mmalloc() package can use a single implicit malloc descriptor @@ -30,22 +30,17 @@ struct mdesc *__mmalloc_default_mdp; /* Use sbrk() to get more core. */ -static void* -sbrk_morecore (mdp, size) - struct mdesc *mdp; - int size; +static void *sbrk_morecore(mdp, size) +struct mdesc *mdp; +int size; { - void* result; - - if ((result = sbrk (size)) == (void*) -1) - { - result = NULL; - } - else - { - mdp -> breakval = (char*)mdp -> breakval + size; - mdp -> top = (char*)mdp -> top + size; - } + void *result; + + if ((result = sbrk(size)) == (void *) -1) { + result = NULL; + } else { + mdp->breakval = (char *) mdp->breakval + size; + mdp->top = (char *) mdp->top + size; + } return (result); } - diff --git a/src/xbt/mmalloc/test/mmalloc_test.c b/src/xbt/mmalloc/test/mmalloc_test.c index 656b66d675..2f384e73b4 100644 --- a/src/xbt/mmalloc/test/mmalloc_test.c +++ b/src/xbt/mmalloc/test/mmalloc_test.c @@ -11,11 +11,12 @@ #define BUFFSIZE 204800 #define TESTSIZE 100 -int main() { - void *A,*B; - int fd1,fd2; - void *heapA,*heapB; - void * pointers[TESTSIZE]; +int main() +{ + void *A, *B; + int fd1, fd2; + void *heapA, *heapB; + void *pointers[TESTSIZE]; /* unlink("heap1"); fd1=open("heap1",O_CREAT|O_RDWR,S_IRWXU|S_IRWXG|S_IRWXO); @@ -25,28 +26,28 @@ int main() { assert(fd1>0); */ - heapA = mmalloc_attach(-1,sbrk(0) + BUFFSIZE); - if (heapA==NULL) { + heapA = mmalloc_attach(-1, sbrk(0) + BUFFSIZE); + if (heapA == NULL) { perror("attach 1 failed"); - fprintf(stderr,"bye\n"); + fprintf(stderr, "bye\n"); exit(1); } - fprintf(stderr,"HeapA=%p\n",heapA); - + fprintf(stderr, "HeapA=%p\n", heapA); + int i, size; - for(i = 0; i < TESTSIZE; i++){ - size = rand () % 1000; - pointers[i] = mmalloc(heapA,size); - fprintf(stderr,"%d bytes allocated at %p\n",size, pointers[i]); + for (i = 0; i < TESTSIZE; i++) { + size = rand() % 1000; + pointers[i] = mmalloc(heapA, size); + fprintf(stderr, "%d bytes allocated at %p\n", size, pointers[i]); } char c; - scanf("%c",&c); + scanf("%c", &c); + + for (i = 0; i < TESTSIZE; i++) { + mfree(heapA, pointers[i]); + } - for(i = 0; i < TESTSIZE; i++){ - mfree(heapA,pointers[i]); - } - - fprintf(stderr,"Ok bye bye\n"); + fprintf(stderr, "Ok bye bye\n"); return 0; } diff --git a/src/xbt/set.c b/src/xbt/set.c index c5d84656da..6967ddd8d1 100644 --- a/src/xbt/set.c +++ b/src/xbt/set.c @@ -77,7 +77,8 @@ static int _xbt_set_get_id(xbt_set_t set) * if elm->name_len <= 0, it is recomputed. If >0, it's used as is; * elm->ID is attributed automatically. */ -void xbt_set_add(xbt_set_t set, xbt_set_elm_t elm, void_f_pvoid_t free_func) +void xbt_set_add(xbt_set_t set, xbt_set_elm_t elm, + void_f_pvoid_t free_func) { int found = 1; @@ -107,13 +108,14 @@ void xbt_set_add(xbt_set_t set, xbt_set_elm_t elm, void_f_pvoid_t free_func) if (found) { if (elm == found_in_dict) { DEBUG2 - ("Ignoring request to insert the same element twice (key %s ; id %d)", - elm->name, elm->ID); + ("Ignoring request to insert the same element twice (key %s ; id %d)", + elm->name, elm->ID); return; } else { elm->ID = found_in_dict->ID; DEBUG2("Reinsertion of key %s (id %d)", elm->name, elm->ID); - xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, free_func); + xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, + free_func); xbt_dynar_set(set->dynar, elm->ID, &elm); return; } @@ -152,7 +154,8 @@ void xbt_set_remove_by_name(xbt_set_t set, const char *key) * \param key name of the element to remove * \param key_len length of \a name */ -void xbt_set_remove_by_name_ext(xbt_set_t set, const char *key, int key_len) +void xbt_set_remove_by_name_ext(xbt_set_t set, const char *key, + int key_len) { xbt_set_elm_t elm = xbt_set_get_by_name_ext(set, key, key_len); xbt_set_remove(set, elm); @@ -261,7 +264,8 @@ void xbt_set_cursor_first(xbt_set_t set, xbt_set_cursor_t * cursor) if (!*cursor) { DEBUG0("Create the cursor on first use"); *cursor = xbt_new(s_xbt_set_cursor_t, 1); - xbt_assert0(*cursor, "Malloc error during the creation of the cursor"); + xbt_assert0(*cursor, + "Malloc error during the creation of the cursor"); } (*cursor)->set = set; @@ -292,7 +296,8 @@ void xbt_set_cursor_step(xbt_set_cursor_t cursor) * * \return true if it's ok, false if there is no more data */ -int xbt_set_cursor_get_or_free(xbt_set_cursor_t * curs, xbt_set_elm_t * elm) +int xbt_set_cursor_get_or_free(xbt_set_cursor_t * curs, + xbt_set_elm_t * elm) { xbt_set_cursor_t cursor; @@ -381,7 +386,8 @@ static void search_name(xbt_set_t head, const char *key) THROW2(mismatch_error, 0, "The key (%s) is not the one expected (%s)", key, elm->name); if (strcmp(elm->name, elm->data)) - THROW2(mismatch_error, 0, "The name (%s) != data (%s)", key, elm->name); + THROW2(mismatch_error, 0, "The name (%s) != data (%s)", key, + elm->name); fflush(stdout); } @@ -414,7 +420,8 @@ static void traverse(xbt_set_t set) xbt_test_assert0(elm, "Dude ! Got a null elm during traversal!"); xbt_test_log3("Id(%d): %s->%s\n", elm->ID, elm->name, elm->data); xbt_test_assert2(!strcmp(elm->name, elm->data), - "Key(%s) != value(%s). Abording", elm->name, elm->data); + "Key(%s) != value(%s). Abording", elm->name, + elm->data); } } @@ -425,8 +432,8 @@ static void search_not_found(xbt_set_t set, const char *data) xbt_test_add1("Search %s (expected not to be found)", data); TRY { xbt_set_get_by_name(set, data); - THROW1(unknown_error, 0, "Found something which shouldn't be there (%s)", - data); + THROW1(unknown_error, 0, + "Found something which shouldn't be there (%s)", data); } CATCH(e) { if (e.category != not_found_error) xbt_test_exception(e); @@ -545,4 +552,4 @@ XBT_TEST_UNIT("remove", test_set_remove, "Removing some values") xbt_test_assert1(elm->ID == 1, "elm->ID is %d but should be 1", elm->ID); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/setset.c b/src/xbt/setset.c index 1e0dd05561..7ab1933f3a 100644 --- a/src/xbt/setset.c +++ b/src/xbt/setset.c @@ -7,17 +7,17 @@ /*The function ffs doesn't exist for windows*/ #ifdef _XBT_WIN32 - int ffs(int bits) - { - int i; - if (bits == 0) - return (0); - for (i = 1; ; i++, bits >>= 1) - { - if (bits & 1) break; - } - return (i); - } +int ffs(int bits) +{ + int i; + if (bits == 0) + return (0); + for (i = 1;; i++, bits >>= 1) { + if (bits & 1) + break; + } + return (i); +} #endif /** @@ -29,13 +29,15 @@ xbt_setset_t xbt_setset_new(unsigned int size) { xbt_setset_elm_entry_t first_elm = NULL; xbt_setset_t setset = xbt_new0(s_xbt_setset_t, 1); - setset->elm_array = xbt_dynar_new(sizeof(u_xbt_setset_elm_entry_t), NULL); + setset->elm_array = + xbt_dynar_new(sizeof(u_xbt_setset_elm_entry_t), NULL); setset->sets = xbt_fifo_new(); /* Expand the elements dynar to the size indicated by the user, */ /* then create the first element, get a pointer to it and add it to the */ /* free elements list */ - xbt_dynar_shrink(setset->elm_array, size); - first_elm = (xbt_setset_elm_entry_t)xbt_dynar_push_ptr(setset->elm_array); + xbt_dynar_shrink(setset->elm_array, size); + first_elm = + (xbt_setset_elm_entry_t) xbt_dynar_push_ptr(setset->elm_array); first_elm->free.next = 0; return setset; } @@ -49,7 +51,7 @@ void xbt_setset_destroy(xbt_setset_t setset) xbt_fifo_item_t item; xbt_setset_set_t set; xbt_dynar_free(&setset->elm_array); - xbt_fifo_foreach(setset->sets, item, set, xbt_setset_set_t){ + xbt_fifo_foreach(setset->sets, item, set, xbt_setset_set_t) { xbt_setset_destroy_set(set); } xbt_fifo_free(setset->sets); @@ -61,19 +63,23 @@ void xbt_setset_elm_add(xbt_setset_t setset, void *obj) { xbt_setset_elm_entry_t new_entry = NULL; xbt_setset_elm_entry_t first_elm = NULL; - xbt_setset_elm_t e = (xbt_setset_elm_t)obj; + xbt_setset_elm_t e = (xbt_setset_elm_t) obj; xbt_assert0(e->ID == 0, "Adding element with non NULL ID"); - first_elm = (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, 0); - + first_elm = + (xbt_setset_elm_entry_t) xbt_dynar_get_ptr(setset->elm_array, 0); + /* Before create a new elm entry check if there is one in the free elm list. */ /* If there is not free elm entries, then create a new one */ - if(first_elm->free.next != 0){ + if (first_elm->free.next != 0) { e->ID = first_elm->free.next; - new_entry = (xbt_setset_elm_entry_t)xbt_dynar_get_ptr(setset->elm_array, first_elm->free.next); + new_entry = + (xbt_setset_elm_entry_t) xbt_dynar_get_ptr(setset->elm_array, + first_elm->free.next); first_elm->free.next = new_entry->free.next; - }else{ - new_entry = (xbt_setset_elm_entry_t)xbt_dynar_push_ptr(setset->elm_array); - e->ID = xbt_dynar_length(setset->elm_array) - 1; + } else { + new_entry = + (xbt_setset_elm_entry_t) xbt_dynar_push_ptr(setset->elm_array); + e->ID = xbt_dynar_length(setset->elm_array) - 1; } new_entry->info.obj = e; @@ -83,8 +89,9 @@ void xbt_setset_elm_add(xbt_setset_t setset, void *obj) /* Remove an object from the setset */ void xbt_setset_elm_remove(xbt_setset_t setset, void *obj) { - xbt_setset_elm_t e = (xbt_setset_elm_t)obj; - xbt_setset_elm_entry_t e_entry = xbt_dynar_get_ptr(setset->elm_array, e->ID); + xbt_setset_elm_t e = (xbt_setset_elm_t) obj; + xbt_setset_elm_entry_t e_entry = + xbt_dynar_get_ptr(setset->elm_array, e->ID); xbt_setset_elm_entry_t first_free = NULL; /* Link the elm entry to the list of free ones */ @@ -97,7 +104,8 @@ void xbt_setset_elm_remove(xbt_setset_t setset, void *obj) /* WARNING: it must be a valid index! */ void *_xbt_setset_idx_to_obj(xbt_setset_t setset, unsigned long idx) { - xbt_setset_elm_entry_t e_entry = xbt_dynar_get_ptr(setset->elm_array, idx); + xbt_setset_elm_entry_t e_entry = + xbt_dynar_get_ptr(setset->elm_array, idx); return e_entry->info.obj; } @@ -125,7 +133,7 @@ void xbt_setset_destroy_set(xbt_setset_set_t set) xbt_free(set->bitmap); xbt_fifo_remove(set->setset->sets, set); xbt_free(set); - + return; } @@ -134,22 +142,24 @@ void xbt_setset_destroy_set(xbt_setset_set_t set) * \param set The set where the element is going to be added * \param obj The element to add */ -void xbt_setset_set_insert(xbt_setset_set_t set, void* obj) +void xbt_setset_set_insert(xbt_setset_set_t set, void *obj) { - xbt_setset_elm_t e = (xbt_setset_elm_t)obj; + xbt_setset_elm_t e = (xbt_setset_elm_t) obj; - if(e->ID == 0) + if (e->ID == 0) xbt_setset_elm_add(set->setset, e); - + /* Check if we need to expand the bitmap */ - if(set->size * BITS_INT - 1 < e->ID){ - set->bitmap = xbt_realloc(set->bitmap, (e->ID / BITS_INT + 1) * sizeof(int)); - memset(&set->bitmap[set->size], 0, ((e->ID / BITS_INT + 1) - set->size) * sizeof(int)); + if (set->size * BITS_INT - 1 < e->ID) { + set->bitmap = + xbt_realloc(set->bitmap, (e->ID / BITS_INT + 1) * sizeof(int)); + memset(&set->bitmap[set->size], 0, + ((e->ID / BITS_INT + 1) - set->size) * sizeof(int)); set->size = (e->ID / BITS_INT + 1); } _set_bit(e->ID, set->bitmap); - + return; } @@ -158,12 +168,12 @@ void xbt_setset_set_insert(xbt_setset_set_t set, void* obj) * \param set The set from which the element is going to be removed * \param obj The element to remove */ -void xbt_setset_set_remove(xbt_setset_set_t set, void* obj) +void xbt_setset_set_remove(xbt_setset_set_t set, void *obj) { - xbt_setset_elm_t e = (xbt_setset_elm_t)obj; + xbt_setset_elm_t e = (xbt_setset_elm_t) obj; /* If the index of the object is between the bitmap then unset it, otherwise do not do anything, because we already know it is not in the set */ - if(e->ID != 0 && e->ID <= set->size * BITS_INT) + if (e->ID != 0 && e->ID <= set->size * BITS_INT) _unset_bit(e->ID, set->bitmap); return; @@ -187,10 +197,11 @@ void *xbt_setset_set_choose(xbt_setset_set_t set) { int i; /* Traverse the set and return the first element */ - for(i = 0; i < set->size; i++) - if(set->bitmap[i] != 0) - return _xbt_setset_idx_to_obj(set->setset, - i * BITS_INT + ffs(set->bitmap[i]) - 1); + for (i = 0; i < set->size; i++) + if (set->bitmap[i] != 0) + return _xbt_setset_idx_to_obj(set->setset, + i * BITS_INT + ffs(set->bitmap[i]) - + 1); return NULL; } @@ -202,7 +213,7 @@ void *xbt_setset_set_choose(xbt_setset_set_t set) void *xbt_setset_set_extract(xbt_setset_set_t set) { void *obj = xbt_setset_set_choose(set); - if(obj){ + if (obj) { xbt_setset_set_remove(set, obj); } return obj; @@ -215,10 +226,10 @@ void *xbt_setset_set_extract(xbt_setset_set_t set) * \param obj The element * \return TRUE if the element \a obj belongs to set \a set */ -int xbt_setset_set_belongs(xbt_setset_set_t set, void* obj) +int xbt_setset_set_belongs(xbt_setset_set_t set, void *obj) { - xbt_setset_elm_t e = (xbt_setset_elm_t)obj; - if(e->ID != 0 && e->ID <= set->size * BITS_INT){ + xbt_setset_elm_t e = (xbt_setset_elm_t) obj; + if (e->ID != 0 && e->ID <= set->size * BITS_INT) { return _is_bit_set(e->ID % BITS_INT, set->bitmap[e->ID / BITS_INT]); } return FALSE; @@ -227,10 +238,10 @@ int xbt_setset_set_belongs(xbt_setset_set_t set, void* obj) int xbt_setset_set_size(xbt_setset_set_t set) { int i, count = 0; - - for(i=0; i < set->size; i++) + + for (i = 0; i < set->size; i++) count += bitcount(set->bitmap[i]); - + return count; } @@ -246,13 +257,13 @@ void xbt_setset_add(xbt_setset_set_t set1, xbt_setset_set_t set2) int i; /* Increase the size of set1 if necessary */ - if(set1->size < set2->size){ + if (set1->size < set2->size) { xbt_realloc(set1->bitmap, set2->size * sizeof(unsigned int)); set1->size = set2->size; } - for(i=0; i < set1->size; i++) - if(set2->bitmap[i] != 0) + for (i = 0; i < set1->size; i++) + if (set2->bitmap[i] != 0) set1->bitmap[i] |= set2->bitmap[i]; return; @@ -268,8 +279,8 @@ void xbt_setset_substract(xbt_setset_set_t set1, xbt_setset_set_t set2) { int i; - for(i=0; i < MIN(set1->size, set2->size); i++) - if(set2->bitmap[i] != 0) + for (i = 0; i < MIN(set1->size, set2->size); i++) + if (set2->bitmap[i] != 0) set1->bitmap[i] ^= set2->bitmap[i]; return; @@ -285,24 +296,25 @@ void xbt_setset_intersect(xbt_setset_set_t set1, xbt_setset_set_t set2) { int i; - for(i=0; i < MIN(set1->size, set2->size); i++) - if(set1->bitmap[i] && set2->bitmap[i]) + for (i = 0; i < MIN(set1->size, set2->size); i++) + if (set1->bitmap[i] && set2->bitmap[i]) set1->bitmap[i] &= set2->bitmap[i]; return; } /* Get a cursor pointing to the first element of the set */ -void xbt_setset_cursor_first(xbt_setset_set_t set, xbt_setset_cursor_t *cursor) +void xbt_setset_cursor_first(xbt_setset_set_t set, + xbt_setset_cursor_t * cursor) { int i; (*cursor) = xbt_new0(s_xbt_setset_cursor_t, 1); (*cursor)->set = set; - - for(i = 0; i < set->size; i++){ - if(set->bitmap[i] != 0){ + + for (i = 0; i < set->size; i++) { + if (set->bitmap[i] != 0) { (*cursor)->idx = i * BITS_INT + ffs(set->bitmap[i]) - 1; - break; + break; } } } @@ -310,11 +322,11 @@ void xbt_setset_cursor_first(xbt_setset_set_t set, xbt_setset_cursor_t *cursor) /* Get the data pointed by a cursor */ int xbt_setset_cursor_get_data(xbt_setset_cursor_t cursor, void **data) { - if(cursor->idx == 0){ + if (cursor->idx == 0) { xbt_free(cursor); *data = NULL; return FALSE; - }else{ + } else { *data = _xbt_setset_idx_to_obj(cursor->set->setset, cursor->idx); return TRUE; } @@ -326,22 +338,22 @@ void xbt_setset_cursor_next(xbt_setset_cursor_t cursor) unsigned int mask; unsigned int data; cursor->idx++; - while(cursor->idx < cursor->set->size * BITS_INT){ - if((data = cursor->set->bitmap[cursor->idx / BITS_INT])){ + while (cursor->idx < cursor->set->size * BITS_INT) { + if ((data = cursor->set->bitmap[cursor->idx / BITS_INT])) { mask = 1 << cursor->idx % BITS_INT; - while(mask){ /* FIXME: mask will never be 0! */ - if(data & mask){ + while (mask) { /* FIXME: mask will never be 0! */ + if (data & mask) { return; - }else{ + } else { cursor->idx++; mask <<= 1; } } - }else{ + } else { cursor->idx += BITS_INT; } } - cursor->idx = 0; + cursor->idx = 0; } /* Check if the nth bit of an integer is set or not*/ @@ -369,7 +381,7 @@ void _unset_bit(unsigned int bit, unsigned int *bitmap) */ int bitcount(int v) { - v = v - ((v >> 1) & 0x55555555); // reuse input as temporary - v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp - return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count + v = v - ((v >> 1) & 0x55555555); // reuse input as temporary + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp + return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count } diff --git a/src/xbt/setset_private.h b/src/xbt/setset_private.h index 8a4d4364e5..6e12ee469c 100644 --- a/src/xbt/setset_private.h +++ b/src/xbt/setset_private.h @@ -21,19 +21,19 @@ typedef union u_xbt_setset_elm_entry { } u_xbt_setset_elm_entry_t, *xbt_setset_elm_entry_t; typedef struct s_xbt_setset_set { - xbt_setset_t setset; /* setset that contains this set */ - unsigned int size; /* in integers */ - unsigned int *bitmap; /* the bit array */ + xbt_setset_t setset; /* setset that contains this set */ + unsigned int size; /* in integers */ + unsigned int *bitmap; /* the bit array */ } s_xbt_setset_set_t; typedef struct s_xbt_setset { - xbt_dynar_t elm_array; /* of s_xbt_setset_elm_entry_t, to find elements by index */ - xbt_fifo_t sets; /* of s_xbt_setset_set_t, memberships in actual sets of setset */ + xbt_dynar_t elm_array; /* of s_xbt_setset_elm_entry_t, to find elements by index */ + xbt_fifo_t sets; /* of s_xbt_setset_set_t, memberships in actual sets of setset */ } s_xbt_setset_t; typedef struct s_xbt_setset_cursor { - int idx; /* Actual postition of the cursor (bit number) */ - xbt_setset_set_t set; /* The set associated to the cursor */ + int idx; /* Actual postition of the cursor (bit number) */ + xbt_setset_set_t set; /* The set associated to the cursor */ } s_xbt_setset_cursor_t; /* Some internal functions */ @@ -51,10 +51,3 @@ void _set_bit(unsigned int bit, unsigned int *bitmap); /* Unset the nth bit of an array of integers */ void _unset_bit(unsigned int bit, unsigned int *bitmap); - - - - - - - diff --git a/src/xbt/snprintf.c b/src/xbt/snprintf.c index a7acabcf14..d946499c01 100644 --- a/src/xbt/snprintf.c +++ b/src/xbt/snprintf.c @@ -357,8 +357,8 @@ #endif /* some other values of possible interest: */ - /* #define breakeven_point 8 *//* VAX 4000 - vaxc */ - /* #define breakeven_point 19 *//* VAX 4000 - gcc 2.7.0 */ + /* #define breakeven_point 8 *//* VAX 4000 - vaxc */ + /* #define breakeven_point 19 *//* VAX 4000 - gcc 2.7.0 */ #ifndef breakeven_point # define breakeven_point 6 /* some reasonable one-size-fits-all value */ @@ -417,7 +417,8 @@ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap); int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...); #if !defined(NEED_SNPRINTF_ONLY) -int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap); +int portable_vsnprintf(char *str, size_t str_m, const char *fmt, + va_list ap); #endif #endif @@ -557,7 +558,8 @@ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap) #if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF) #if !defined(NEED_SNPRINTF_ONLY) -int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) +int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ + ...) { va_list ap; int str_l; @@ -570,10 +572,12 @@ int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) #endif #if defined(NEED_SNPRINTF_ONLY) -int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) +int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ + ...) { #else -int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) +int portable_vsnprintf(char *str, size_t str_m, const char *fmt, + va_list ap) { #endif @@ -937,7 +941,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) /* Actually it uses 0x prefix even for a zero value. */ && arg_sign != 0 #endif - ) { + ) { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = 'x'; } @@ -953,7 +957,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) * converting a zero value with a precision of zero is a null string. * Actually HP returns all zeroes, and Linux returns "(nil)". */ #endif - ) { + ) { /* converted to null string */ /* When zero value is formatted with an explicit precision 0, the resulting formatted string is empty (d, i, u, o, x, X, p). */ @@ -1027,7 +1031,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) && !(zero_padding_insertion_ind < str_arg_l && tmp[zero_padding_insertion_ind] == '0') #endif - ) { /* assure leading zero for alternate-form octal numbers */ + ) { /* assure leading zero for alternate-form octal numbers */ if (!precision_specified || precision < num_of_digits + 1) { /* precision is increased to force the first character to be zero, except if a zero value is formatted with an explicit precision diff --git a/src/xbt/swag.c b/src/xbt/swag.c index 9d69e43ec5..f6e7107455 100644 --- a/src/xbt/swag.c +++ b/src/xbt/swag.c @@ -78,7 +78,8 @@ XBT_INLINE void xbt_swag_insert(void *obj, xbt_swag_t swag) } xbt_swag_getPrev(obj, swag->offset) = swag->tail; - xbt_swag_getNext(xbt_swag_getPrev(obj, swag->offset), swag->offset) = obj; + xbt_swag_getNext(xbt_swag_getPrev(obj, swag->offset), swag->offset) = + obj; swag->tail = obj; } @@ -105,7 +106,8 @@ XBT_INLINE void xbt_swag_insert_at_head(void *obj, xbt_swag_t swag) } xbt_swag_getNext(obj, swag->offset) = swag->head; - xbt_swag_getPrev(xbt_swag_getNext(obj, swag->offset), swag->offset) = obj; + xbt_swag_getPrev(xbt_swag_getNext(obj, swag->offset), swag->offset) = + obj; swag->head = obj; } @@ -132,7 +134,8 @@ XBT_INLINE void xbt_swag_insert_at_tail(void *obj, xbt_swag_t swag) } xbt_swag_getPrev(obj, swag->offset) = swag->tail; - xbt_swag_getNext(xbt_swag_getPrev(obj, swag->offset), swag->offset) = obj; + xbt_swag_getNext(xbt_swag_getPrev(obj, swag->offset), swag->offset) = + obj; swag->tail = obj; } @@ -169,8 +172,10 @@ XBT_INLINE void *xbt_swag_remove(void *obj, xbt_swag_t swag) xbt_swag_getNext(swag->tail, offset) = NULL; xbt_swag_getPrev(obj, offset) = NULL; } else { /* It's in the middle */ - xbt_swag_getNext(xbt_swag_getPrev(obj, offset), offset) = xbt_swag_getNext(obj, offset); - xbt_swag_getPrev(xbt_swag_getNext(obj, offset), offset) = xbt_swag_getPrev(obj, offset); + xbt_swag_getNext(xbt_swag_getPrev(obj, offset), offset) = + xbt_swag_getNext(obj, offset); + xbt_swag_getPrev(xbt_swag_getNext(obj, offset), offset) = + xbt_swag_getPrev(obj, offset); xbt_swag_getPrev(obj, offset) = xbt_swag_getNext(obj, offset) = NULL; } (swag->count)--; @@ -275,4 +280,4 @@ XBT_TEST_UNIT("basic", test_swag_basic, "Basic usage") xbt_swag_free(setB); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/win32_ucontext.c b/src/xbt/win32_ucontext.c index 1d7d453e1b..cbbe8eb40a 100644 --- a/src/xbt/win32_ucontext.c +++ b/src/xbt/win32_ucontext.c @@ -18,79 +18,76 @@ * License along with QueueUserAPCEx in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - + */ + #include "win32_ucontext.h" - -int getcontext(ucontext_t *ucp) -{ - int ret; - - /* Retrieve the full machine context */ - ucp->uc_mcontext.ContextFlags = CONTEXT_FULL; - ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); - - return (ret == 0) ? -1: 0; -} - -int setcontext(const ucontext_t *ucp) -{ - int ret; - - /* Restore the full machine context (already set) */ - ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); - - return (ret == 0) ? -1: 0; -} - -int makecontext(ucontext_t *ucp, void (*func)(), int argc, ...) -{ - int i; - va_list ap; - char *sp; - - /* Stack grows down */ - sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; - - /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ - sp -= argc*8; - - if ( sp < (char *)ucp->uc_stack.ss_sp) { - /* errno = ENOMEM;*/ - return -1; - } - - /* Set the instruction and the stack pointer */ - ucp->uc_mcontext.Eip = (unsigned long) func; - ucp->uc_mcontext.Esp = (unsigned long) sp - 4; - - /* Save/Restore the full machine context */ - ucp->uc_mcontext.ContextFlags = CONTEXT_FULL; - - /* Copy the arguments */ - va_start (ap, argc); - for (i=0; iuc_mcontext.ContextFlags = CONTEXT_FULL; + ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); + return (ret == 0) ? -1 : 0; + } + + int setcontext(const ucontext_t * ucp) +{ + int ret; + + /* Restore the full machine context (already set) */ + ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); + return (ret == 0) ? -1 : 0; + } + + int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) +{ + int i; + va_list ap; + char *sp; + + /* Stack grows down */ + sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; + + /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ + sp -= argc * 8; + if (sp < (char *) ucp->uc_stack.ss_sp) { + + /* errno = ENOMEM; */ + return -1; + } + + /* Set the instruction and the stack pointer */ + ucp->uc_mcontext.Eip = (unsigned long) func; + ucp->uc_mcontext.Esp = (unsigned long) sp - 4; + + /* Save/Restore the full machine context */ + ucp->uc_mcontext.ContextFlags = CONTEXT_FULL; + + /* Copy the arguments */ + va_start(ap, argc); + for (i = 0; i < argc; i++) { + memcpy(sp, ap, 8); + ap += 8; + sp += 8; + } + va_end(ap); + return 0; + } + + int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) +{ + int ret; + if ((oucp == NULL) || (ucp == NULL)) { + + /*errno = EINVAL; */ + return -1; + } + ret = getcontext(oucp); + if (ret == 0) { + ret = setcontext(ucp); + } + return ret; + } + + diff --git a/src/xbt/xbt_log_layout_format.c b/src/xbt/xbt_log_layout_format.c index 0baafcb3a9..22a7cca70e 100644 --- a/src/xbt/xbt_log_layout_format.c +++ b/src/xbt/xbt_log_layout_format.c @@ -218,31 +218,27 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - ev->cat->name); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + ev->cat->name); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), ev->cat->name); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), ev->cat->name); check_overflow; precision = -1; } break; case 'p': /* priority name; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - xbt_log_priority_names[ev->priority]); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + xbt_log_priority_names[ev->priority]); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), - xbt_log_priority_names[ev->priority]); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), + xbt_log_priority_names[ev->priority]); check_overflow; precision = -1; } @@ -250,60 +246,52 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, case 'h': /* host name; SimGrid extension */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - gras_os_myname()); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + gras_os_myname()); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), gras_os_myname()); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), gras_os_myname()); check_overflow; precision = -1; } break; case 't': /* thread name; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - xbt_thread_self_name()); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + xbt_thread_self_name()); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), xbt_thread_self_name()); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), xbt_thread_self_name()); check_overflow; precision = -1; } break; case 'P': /* process name; SimGrid extension */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - xbt_procname()); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + xbt_procname()); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), xbt_procname()); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), xbt_procname()); check_overflow; precision = -1; } break; case 'i': /* process PID name; SimGrid extension */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%d", - (*xbt_getpid) ()); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%d", + (*xbt_getpid) ()); check_overflow; } else { - p += - sprintf(p, "%.*d", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), (*xbt_getpid) ()); + p += sprintf(p, "%.*d", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), (*xbt_getpid) ()); check_overflow; precision = -1; } @@ -311,61 +299,53 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, case 'F': /* file name; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - ev->fileName); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + ev->fileName); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), ev->fileName); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), ev->fileName); check_overflow; precision = -1; } break; case 'l': /* location; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d", - ev->fileName, ev->lineNum); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d", + ev->fileName, ev->lineNum); check_overflow; } else { - p += - snprintf(p, - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), "%s:%d", ev->fileName, - ev->lineNum); + p += snprintf(p, + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), "%s:%d", ev->fileName, + ev->lineNum); check_overflow; precision = -1; } break; case 'L': /* line number; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%d", - ev->lineNum); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%d", + ev->lineNum); check_overflow; } else { - p += - sprintf(p, "%.*d", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), ev->lineNum); + p += sprintf(p, "%.*d", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), ev->lineNum); check_overflow; precision = -1; } break; case 'M': /* method (ie, function) name; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - ev->functionName); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + ev->functionName); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), ev->functionName); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), ev->functionName); check_overflow; precision = -1; } @@ -384,30 +364,27 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_backtrace_current(&e); if (*q == 'B') { if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", - e.bt_strings[2] + 8); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s", + e.bt_strings[2] + 8); check_overflow; } else { - p += - sprintf(p, "%.*s", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), e.bt_strings[2] + 8); + p += sprintf(p, "%.*s", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), e.bt_strings[2] + 8); check_overflow; precision = -1; } } else { for (i = 2; i < e.used; i++) if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s\n", - e.bt_strings[i] + 8); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), + "%s\n", e.bt_strings[i] + 8); check_overflow; } else { - p += - sprintf(p, "%.*s\n", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), e.bt_strings[i] + 8); + p += sprintf(p, "%.*s\n", + (int) MIN(XBT_LOG_BUFF_SIZE - + (p - ev->buffer), precision), + e.bt_strings[i] + 8); check_overflow; precision = -1; } @@ -416,39 +393,35 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_ex_free(e); } #else - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), - "(no backtrace on this arch)"); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), + "(no backtrace on this arch)"); check_overflow; #endif break; case 'd': /* date; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f", - gras_os_time()); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f", + gras_os_time()); check_overflow; } else { - p += - sprintf(p, "%.*f", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), gras_os_time()); + p += sprintf(p, "%.*f", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), gras_os_time()); check_overflow; precision = -1; } break; case 'r': /* application age; LOG4J compliant */ if (precision == -1) { - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f", - gras_os_time() - format_begin_of_time); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f", + gras_os_time() - format_begin_of_time); check_overflow; } else { - p += - sprintf(p, "%.*f", - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), gras_os_time() - format_begin_of_time); + p += sprintf(p, "%.*f", + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), + gras_os_time() - format_begin_of_time); check_overflow; precision = -1; } @@ -456,15 +429,13 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l, case 'm': /* user-provided message; LOG4J compliant */ if (precision == -1) { - p += - vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), msg_fmt, - ev->ap); + p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), msg_fmt, + ev->ap); check_overflow; } else { - p += - vsnprintf(p, - (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), - precision), msg_fmt, ev->ap); + p += vsnprintf(p, + (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), + precision), msg_fmt, ev->ap); check_overflow; precision = -1; } @@ -498,6 +469,6 @@ xbt_log_layout_t xbt_log_layout_format_new(char *arg) if (format_begin_of_time < 0) format_begin_of_time = gras_os_time(); - + return res; } diff --git a/src/xbt/xbt_log_layout_simple.c b/src/xbt/xbt_log_layout_simple.c index 539469982d..030a17b55f 100644 --- a/src/xbt/xbt_log_layout_simple.c +++ b/src/xbt/xbt_log_layout_simple.c @@ -36,16 +36,13 @@ static void xbt_log_layout_simple_dynamic(xbt_log_layout_t l, if (strlen(xbt_procname())) p += snprintf(p, 256 - (p - loc_buff), "%s:%s:(%d) ", gras_os_myname(), xbt_procname(), (*xbt_getpid) ()); - p += - snprintf(p, 256 - (p - loc_buff), "%f] ", - gras_os_time() - simple_begin_of_time); - if (ev->priority != xbt_log_priority_info && xbt_log_no_loc==0) - p += - snprintf(p, 256 - (p - loc_buff), "%s:%d: ", ev->fileName, - ev->lineNum); - p += - snprintf(p, 256 - (p - loc_buff), "[%s/%s] ", ev->cat->name, - xbt_log_priority_names[ev->priority]); + p += snprintf(p, 256 - (p - loc_buff), "%f] ", + gras_os_time() - simple_begin_of_time); + if (ev->priority != xbt_log_priority_info && xbt_log_no_loc == 0) + p += snprintf(p, 256 - (p - loc_buff), "%s:%d: ", ev->fileName, + ev->lineNum); + p += snprintf(p, 256 - (p - loc_buff), "[%s/%s] ", ev->cat->name, + xbt_log_priority_names[ev->priority]); xbt_strbuff_append(buff, loc_buff); @@ -73,7 +70,7 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l, xbt_log_appender_t app) { char *p; - const char *procname=NULL; + const char *procname = NULL; xbt_assert0(ev->priority >= 0, "Negative logging priority naturally forbidden"); xbt_assert1(ev->priority < sizeof(xbt_log_priority_names), @@ -85,7 +82,7 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l, check_overflow; /* Display the proc info if available */ - procname=xbt_procname(); + procname = xbt_procname(); if (strlen(procname)) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%s:(%d) ", gras_os_myname(), procname, (*xbt_getpid) ()); @@ -93,16 +90,14 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l, } /* Display the date */ - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f] ", - gras_os_time() - simple_begin_of_time); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f] ", + gras_os_time() - simple_begin_of_time); check_overflow; /* Display file position if not INFO */ if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc) - p += - snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ", - ev->fileName, ev->lineNum); + p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ", + ev->fileName, ev->lineNum); /* Display category name */ p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[%s/%s] ", diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index 978302147a..c1aec523d9 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -7,7 +7,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/misc.h" -#include "simgrid_config.h" /*HAVE_MMAP _XBT_WIN32*/ +#include "simgrid_config.h" /*HAVE_MMAP _XBT_WIN32 */ #include "time.h" /* to seed the random generator */ #include "xbt/sysdep.h" @@ -55,7 +55,7 @@ static void xbt_preinit(void) _XBT_GNUC_CONSTRUCTOR; static void xbt_postexit(void) _XBT_GNUC_DESTRUCTOR; #ifdef _XBT_WIN32 - # undef _XBT_NEED_INIT_PRAGMA +# undef _XBT_NEED_INIT_PRAGMA #endif #ifdef _XBT_NEED_INIT_PRAGMA @@ -67,12 +67,15 @@ static void xbt_postexit(void) _XBT_GNUC_DESTRUCTOR; #include /* Dummy prototype to make gcc happy */ -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, + LPVOID lpvReserved); /* see also http://msdn.microsoft.com/en-us/library/ms682583%28VS.85%29.aspx */ /* and http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx */ -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, + LPVOID lpvReserved) +{ if (fdwReason == DLL_PROCESS_ATTACH) { xbt_preinit(); } else if (fdwReason == DLL_PROCESS_DETACH) { @@ -84,10 +87,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { #endif -static void xbt_preinit(void) { - #ifdef HAVE_MMAP - mmalloc_preinit(); - #endif +static void xbt_preinit(void) +{ +#ifdef HAVE_MMAP + mmalloc_preinit(); +#endif xbt_log_preinit(); /* Connect our log channels: that must be done manually under windows */ @@ -121,7 +125,8 @@ static void xbt_preinit(void) { xbt_os_thread_mod_preinit(); } -static void xbt_postexit(void) { +static void xbt_postexit(void) +{ xbt_os_thread_mod_postexit(); xbt_backtrace_postexit(); @@ -142,7 +147,7 @@ void xbt_init(int *argc, char **argv) // FIXME it would be nice to assert that this function is called only once. But each gras process do call it... xbt_initialized++; - if (xbt_initialized >1) + if (xbt_initialized > 1) return; xbt_binary_name = xbt_strdup(argv[0]); @@ -153,14 +158,16 @@ void xbt_init(int *argc, char **argv) } /** @brief Finalize the xbt mechanisms. */ -void xbt_exit() { +void xbt_exit() +{ WARN0("This function is deprecated, you shouldn't use it"); } /* these two functions belong to xbt/sysdep.h, which have no corresponding .c file */ /** @brief like free, but you can be sure that it is a function */ -XBT_PUBLIC(void) xbt_free_f(void *p) { +XBT_PUBLIC(void) xbt_free_f(void *p) +{ free(p); } diff --git a/src/xbt/xbt_matrix.c b/src/xbt/xbt_matrix.c index fabd5a34ca..4bdeb432d3 100644 --- a/src/xbt/xbt_matrix.c +++ b/src/xbt/xbt_matrix.c @@ -108,10 +108,10 @@ void xbt_matrix_copy_values(xbt_matrix_t dst, xbt_matrix_t src, { unsigned int i, j; - DEBUG10("Copy a %dx%d submatrix from %dx%d(of %dx%d) to %dx%d (of %dx%d)", - lsize, rsize, - lpos_src, rpos_src, src->lines, src->rows, - lpos_dst, rpos_dst, dst->lines, dst->rows); + DEBUG10 + ("Copy a %dx%d submatrix from %dx%d(of %dx%d) to %dx%d (of %dx%d)", + lsize, rsize, lpos_src, rpos_src, src->lines, src->rows, lpos_dst, + rpos_dst, dst->lines, dst->rows); /* everybody knows that issue is between the chair and the screen (particulary in my office) */ xbt_assert(src->elmsize == dst->elmsize); @@ -128,7 +128,7 @@ void xbt_matrix_copy_values(xbt_matrix_t dst, xbt_matrix_t src, if (cpy_f) { for (j = 0; j < lsize; j++) xbt_matrix_get_as(dst, j + lpos_dst, i + rpos_dst, void *) = - (*cpy_f) (xbt_matrix_get_ptr(src, j + rpos_src, i + lpos_src)); + (*cpy_f) (xbt_matrix_get_ptr(src, j + rpos_src, i + lpos_src)); } else { memcpy(xbt_matrix_get_ptr(dst, lpos_dst, i + rpos_dst), xbt_matrix_get_ptr(src, lpos_src, i + rpos_src), @@ -181,12 +181,14 @@ xbt_matrix_t xbt_matrix_double_new_seq(int lines, int rows) return res; } + /** \brief Checks whether the matrix contains the sequence of numbers */ -int xbt_matrix_double_is_seq(xbt_matrix_t mat) { +int xbt_matrix_double_is_seq(xbt_matrix_t mat) +{ int i; for (i = 0; i < mat->lines * mat->rows; i++) { - double val = xbt_matrix_get_as(mat,i,0,double); + double val = xbt_matrix_get_as(mat, i, 0, double); if (val != i) return 0; } @@ -217,6 +219,6 @@ void xbt_matrix_double_addmult(xbt_matrix_t A, xbt_matrix_t B, for (j = 0; j < C->rows; j++) for (k = 0; k < B->lines; k++) xbt_matrix_get_as(C, i, j, double) += - xbt_matrix_get_as(A, i, k, double) * xbt_matrix_get_as(B, k, j, - double); + xbt_matrix_get_as(A, i, k, double) * xbt_matrix_get_as(B, k, j, + double); } diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index d1365a316d..2b8326e0fb 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -101,7 +101,8 @@ void xbt_os_thread_mod_preinit(void) } -void xbt_os_thread_mod_postexit(void) { +void xbt_os_thread_mod_postexit(void) +{ /* FIXME: don't try to free our key on shutdown. Valgrind detects no leak if we don't, and whine if we try to */ // int errcode; @@ -262,8 +263,9 @@ void xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex, double delay) case ETIMEDOUT: THROW1(timeout_error, 0, "mutex %p not ready", mutex); default: - THROW2(system_error, errcode, "xbt_mutex_timedacquire(%p) failed: %s", - mutex, strerror(errcode)); + THROW2(system_error, errcode, + "xbt_mutex_timedacquire(%p) failed: %s", mutex, + strerror(errcode)); } @@ -279,7 +281,7 @@ void xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex, double delay) errcode = pthread_mutex_timedlock(&(mutex->m), &ts_end); -#else /* Well, let's reimplement it since those lazy libc dudes didn't */ +#else /* Well, let's reimplement it since those lazy libc dudes didn't */ double start = xbt_os_time(); do { errcode = pthread_mutex_trylock(&(mutex->m)); @@ -290,7 +292,7 @@ void xbt_os_mutex_timedacquire(xbt_os_mutex_t mutex, double delay) if (errcode == EBUSY) errcode = ETIMEDOUT; -#endif /* HAVE_MUTEX_TIMEDLOCK */ +#endif /* HAVE_MUTEX_TIMEDLOCK */ switch (errcode) { case 0: @@ -446,7 +448,7 @@ xbt_os_sem_t xbt_os_sem_init(unsigned int value) THROW1(system_error, errno, "sem_init() failed: %s", strerror(errno)); res->ps = &(res->s); -#else /* damn, no sem_init(). Reimplement it */ +#else /* damn, no sem_init(). Reimplement it */ xbt_os_mutex_acquire(next_sem_ID_lock); res->name = bprintf("/%d.%d", (*xbt_getpid) (), ++next_sem_ID); @@ -463,7 +465,8 @@ xbt_os_sem_t xbt_os_sem_init(unsigned int value) /* Remove the name from the semaphore namespace: we never join on it */ if (sem_unlink(res->name) < 0) - THROW1(system_error, errno, "sem_unlink() failed: %s", strerror(errno)); + THROW1(system_error, errno, "sem_unlink() failed: %s", + strerror(errno)); #endif @@ -496,8 +499,9 @@ void xbt_os_sem_timedacquire(xbt_os_sem_t sem, double delay) case ETIMEDOUT: THROW1(timeout_error, 0, "semaphore %p not ready", sem); default: - THROW2(system_error, errcode, "xbt_os_sem_timedacquire(%p) failed: %s", - sem, strerror(errcode)); + THROW2(system_error, errcode, + "xbt_os_sem_timedacquire(%p) failed: %s", sem, + strerror(errcode)); } } else { @@ -510,7 +514,7 @@ void xbt_os_sem_timedacquire(xbt_os_sem_t sem, double delay) DEBUG2("sem_timedwait(%p,%p)", sem->ps, &ts_end); errcode = sem_timedwait(sem->s, &ts_end); -#else /* Okay, reimplement this function then */ +#else /* Okay, reimplement this function then */ double start = xbt_os_time(); do { errcode = sem_trywait(sem->ps); @@ -528,7 +532,8 @@ void xbt_os_sem_timedacquire(xbt_os_sem_t sem, double delay) case ETIMEDOUT: THROW2(timeout_error, delay, - "semaphore %p wasn't signaled before timeout (%f)", sem, delay); + "semaphore %p wasn't signaled before timeout (%f)", sem, + delay); default: THROW3(system_error, errcode, "sem_timedwait(%p,%f) failed: %s", sem, @@ -552,9 +557,9 @@ void xbt_os_sem_destroy(xbt_os_sem_t sem) THROW0(arg_error, EINVAL, "Cannot destroy the NULL sempahore"); #ifdef HAVE_SEM_INIT - if (sem_destroy(sem->ps)<0) - THROW1(system_error, errno, "sem_destroy() failed: %s", - strerror(errno)); + if (sem_destroy(sem->ps) < 0) + THROW1(system_error, errno, "sem_destroy() failed: %s", + strerror(errno)); #else if (sem_close(sem->ps) < 0) THROW1(system_error, errno, "sem_close() failed: %s", strerror(errno)); @@ -567,10 +572,12 @@ void xbt_os_sem_destroy(xbt_os_sem_t sem) void xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue) { if (!sem) - THROW0(arg_error, EINVAL, "Cannot get the value of the NULL semaphore"); + THROW0(arg_error, EINVAL, + "Cannot get the value of the NULL semaphore"); if (sem_getvalue(&(sem->s), svalue) < 0) - THROW1(system_error, errno, "sem_getvalue() failed: %s", strerror(errno)); + THROW1(system_error, errno, "sem_getvalue() failed: %s", + strerror(errno)); } /* ********************************* WINDOWS IMPLEMENTATION ************************************ */ @@ -665,12 +672,14 @@ void xbt_os_thread_join(xbt_os_thread_t thread, void **thread_return) { if (WAIT_OBJECT_0 != WaitForSingleObject(thread->handle, INFINITE)) - THROW0(system_error, (int) GetLastError(), "WaitForSingleObject failed"); + THROW0(system_error, (int) GetLastError(), + "WaitForSingleObject failed"); if (thread_return) { if (!GetExitCodeThread(thread->handle, (DWORD *) (*thread_return))) - THROW0(system_error, (int) GetLastError(), "GetExitCodeThread failed"); + THROW0(system_error, (int) GetLastError(), + "GetExitCodeThread failed"); } CloseHandle(thread->handle); @@ -860,8 +869,8 @@ void xbt_os_cond_timedwait(xbt_os_cond_t cond, xbt_os_mutex_t mutex, if (delay < 0) { xbt_os_cond_wait(cond, mutex); } else { - DEBUG3("xbt_cond_timedwait(%p,%p,%lu)", &(cond->events), &(mutex->lock), - end); + DEBUG3("xbt_cond_timedwait(%p,%p,%lu)", &(cond->events), + &(mutex->lock), end); /* lock the threads counter and increment it */ EnterCriticalSection(&cond->waiters_count_lock); @@ -997,8 +1006,8 @@ void xbt_os_sem_acquire(xbt_os_sem_t sem) /* wait failure */ if (WAIT_OBJECT_0 != WaitForSingleObject(sem->h, INFINITE)) - THROW1(system_error, GetLastError(), "WaitForSingleObject() failed: %s", - strerror(GetLastError())); + THROW1(system_error, GetLastError(), + "WaitForSingleObject() failed: %s", strerror(GetLastError())); EnterCriticalSection(&(sem->value_lock)); sem->value--; LeaveCriticalSection(&(sem->value_lock)); @@ -1074,7 +1083,8 @@ void xbt_os_sem_destroy(xbt_os_sem_t sem) void xbt_os_sem_get_value(xbt_os_sem_t sem, int *svalue) { if (!sem) - THROW0(arg_error, EINVAL, "Cannot get the value of the NULL semaphore"); + THROW0(arg_error, EINVAL, + "Cannot get the value of the NULL semaphore"); EnterCriticalSection(&(sem->value_lock)); *svalue = sem->value; diff --git a/src/xbt/xbt_os_time.c b/src/xbt/xbt_os_time.c index 19624a5905..f7e90b2471 100644 --- a/src/xbt/xbt_os_time.c +++ b/src/xbt/xbt_os_time.c @@ -44,11 +44,11 @@ double xbt_os_time(void) tv.tv_sec = (long) (tm / 1000000L); tv.tv_usec = (long) (tm % 1000000L); -# endif /* windows version checker */ +# endif /* windows version checker */ -#else /* not windows, no gettimeofday => poor resolution */ +#else /* not windows, no gettimeofday => poor resolution */ return (double) (time(NULL)); -#endif /* HAVE_GETTIMEOFDAY? */ +#endif /* HAVE_GETTIMEOFDAY? */ return (double) (tv.tv_sec + tv.tv_usec / 1000000.0); } @@ -62,7 +62,7 @@ void xbt_os_sleep(double sec) #elif _XBT_WIN32 Sleep((floor(sec) * 1000) + ((sec - floor(sec)) * 1000)); -#else /* don't have usleep. Use select to sleep less than one second */ +#else /* don't have usleep. Use select to sleep less than one second */ struct timeval timeout; @@ -93,17 +93,20 @@ struct s_xbt_os_timer { #endif }; -xbt_os_timer_t xbt_os_timer_new(void) { +xbt_os_timer_t xbt_os_timer_new(void) +{ return xbt_new0(struct s_xbt_os_timer, 1); } -void xbt_os_timer_free(xbt_os_timer_t timer) { +void xbt_os_timer_free(xbt_os_timer_t timer) +{ free(timer); } -void xbt_os_timer_start(xbt_os_timer_t timer) { +void xbt_os_timer_start(xbt_os_timer_t timer) +{ #ifdef HAVE_POSIX_GETTIME - clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->start)); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); #elif defined(HAVE_GETTIMEOFDAY) gettimeofday(&(timer->start), NULL); #else @@ -111,9 +114,10 @@ void xbt_os_timer_start(xbt_os_timer_t timer) { #endif } -void xbt_os_timer_stop(xbt_os_timer_t timer) { +void xbt_os_timer_stop(xbt_os_timer_t timer) +{ #ifdef HAVE_POSIX_GETTIME - clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&(timer->stop)); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->stop)); #elif defined(HAVE_GETTIMEOFDAY) gettimeofday(&(timer->stop), NULL); #else @@ -129,8 +133,8 @@ double xbt_os_timer_elapsed(xbt_os_timer_t timer) ((double) timer->start.tv_nsec)) / 1e9); #elif defined(HAVE_GETTIMEOFDAY) return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) + - ((((double) timer->stop.tv_usec) - - ((double) timer->start.tv_usec)) / 1000000.0); + ((((double) timer->stop.tv_usec) - + ((double) timer->start.tv_usec)) / 1000000.0); #else return (double) timer->stop - (double) timer->start; #endif diff --git a/src/xbt/xbt_queue.c b/src/xbt/xbt_queue.c index 74b19d9aed..b3829bd59f 100644 --- a/src/xbt/xbt_queue.c +++ b/src/xbt/xbt_queue.c @@ -15,7 +15,8 @@ #include "xbt/synchro.h" #include "xbt/queue.h" /* this module */ #include "gras/virtu.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_queue, xbt, "Message exchanging queue"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_queue, xbt, + "Message exchanging queue"); typedef struct s_xbt_queue_ { int capacity; @@ -78,7 +79,8 @@ void xbt_queue_push(xbt_queue_t queue, const void *src) xbt_mutex_acquire(queue->mutex); while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) { - DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity); + DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, + queue->capacity); xbt_cond_wait(queue->not_full, queue->mutex); } xbt_dynar_push(queue->data, src); @@ -117,7 +119,8 @@ void xbt_queue_unshift(xbt_queue_t queue, const void *src) xbt_mutex_acquire(queue->mutex); while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) { - DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity); + DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, + queue->capacity); xbt_cond_wait(queue->not_full, queue->mutex); } xbt_dynar_unshift(queue->data, src); @@ -164,15 +167,17 @@ void xbt_queue_push_timed(xbt_queue_t queue, const void *src, double delay) queue->capacity == xbt_dynar_length(queue->data)) { xbt_mutex_release(queue->mutex); - THROW2(timeout_error, 0, "Capacity of %p exceded (=%d), and delay = 0", - queue, queue->capacity); + THROW2(timeout_error, 0, + "Capacity of %p exceded (=%d), and delay = 0", queue, + queue->capacity); } } else { while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data) && (delay < 0 || (xbt_time() - begin) <= delay)) { - DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity); + DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, + queue->capacity); TRY { xbt_cond_timedwait(queue->not_full, queue->mutex, delay < 0 ? -1 : delay - (xbt_time() - begin)); @@ -231,7 +236,8 @@ void xbt_queue_pop_timed(xbt_queue_t queue, void *const dst, double delay) * * @see #xbt_queue_unshift */ -void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay) +void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, + double delay) { double begin = xbt_time(); xbt_ex_t e; @@ -243,15 +249,17 @@ void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay) queue->capacity == xbt_dynar_length(queue->data)) { xbt_mutex_release(queue->mutex); - THROW2(timeout_error, 0, "Capacity of %p exceded (=%d), and delay = 0", - queue, queue->capacity); + THROW2(timeout_error, 0, + "Capacity of %p exceded (=%d), and delay = 0", queue, + queue->capacity); } } else { while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data) && (delay < 0 || (xbt_time() - begin) <= delay)) { - DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity); + DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, + queue->capacity); TRY { xbt_cond_timedwait(queue->not_full, queue->mutex, delay < 0 ? -1 : delay - (xbt_time() - begin)); @@ -274,7 +282,8 @@ void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay) * @see #xbt_queue_shift * */ -void xbt_queue_shift_timed(xbt_queue_t queue, void *const dst, double delay) +void xbt_queue_shift_timed(xbt_queue_t queue, void *const dst, + double delay) { double begin = xbt_time(); xbt_ex_t e; diff --git a/src/xbt/xbt_rl_synchro.c b/src/xbt/xbt_rl_synchro.c index aee53fbdaa..12143a775d 100644 --- a/src/xbt/xbt_rl_synchro.c +++ b/src/xbt/xbt_rl_synchro.c @@ -44,7 +44,8 @@ xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code, res->userparam = param; res->code = code; DEBUG1("Create thread %p", res); - res->os_thread = xbt_os_thread_create(name, xbt_thread_create_wrapper, res); + res->os_thread = + xbt_os_thread_create(name, xbt_thread_create_wrapper, res); return res; } @@ -166,7 +167,8 @@ void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex) void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay) { DEBUG3("Wait cond %p, mutex %p for %f sec", cond, mutex, delay); - xbt_os_cond_timedwait((xbt_os_cond_t) cond, (xbt_os_mutex_t) mutex, delay); + xbt_os_cond_timedwait((xbt_os_cond_t) cond, (xbt_os_mutex_t) mutex, + delay); DEBUG3("Done waiting cond %p, mutex %p for %f sec", cond, mutex, delay); } diff --git a/src/xbt/xbt_sg_stubs.c b/src/xbt/xbt_sg_stubs.c index 56a9bbe117..e06f5320aa 100644 --- a/src/xbt/xbt_sg_stubs.c +++ b/src/xbt/xbt_sg_stubs.c @@ -45,101 +45,101 @@ xbt_os_thread_t xbt_os_thread_create(const char *name, { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_thread_create)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_thread_create)"); } void xbt_os_thread_exit(int *retcode) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_thread_exit)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_thread_exit)"); } xbt_os_thread_t xbt_os_thread_self(void) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_thread_self)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_thread_self)"); } void xbt_os_thread_yield(void) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_thread_yield)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_thread_yield)"); } xbt_os_mutex_t xbt_os_mutex_init(void) { - /* - xbt_backtrace_display_current(); - xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_init)"); - */ - return NULL; + /* + xbt_backtrace_display_current(); + xbt_die + ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_init)"); + */ + return NULL; } void xbt_os_mutex_acquire(xbt_os_mutex_t mutex) { - /* - xbt_backtrace_display_current(); - xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_acquire)"); - */ + /* + xbt_backtrace_display_current(); + xbt_die + ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_acquire)"); + */ } void xbt_os_mutex_release(xbt_os_mutex_t mutex) { - /* - xbt_backtrace_display_current(); - xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_release)"); - */ + /* + xbt_backtrace_display_current(); + xbt_die + ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_release)"); + */ } void xbt_os_mutex_destroy(xbt_os_mutex_t mutex) { - /* - xbt_backtrace_display_current(); - xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_destroy)"); - */ + /* + xbt_backtrace_display_current(); + xbt_die + ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_destroy)"); + */ } xbt_os_cond_t xbt_os_cond_init(void) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_cond_init)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_cond_init)"); } void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_cond_wait)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_cond_wait)"); } void xbt_os_cond_signal(xbt_os_cond_t cond) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_cond_signal)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_cond_signal)"); } void xbt_os_cond_broadcast(xbt_os_cond_t cond) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_cond_broadcast)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_cond_broadcast)"); } void xbt_os_cond_destroy(xbt_os_cond_t cond) { xbt_backtrace_display_current(); xbt_die - ("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)"); + ("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)"); } #endif #endif diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index 3d148a8128..8816696a6b 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -28,7 +28,7 @@ typedef struct s_xbt_thread_ { void *userparam; void *father_data; /* stuff to allow other people to wait on me with xbt_thread_join */ - int joinable:1,done:1; + int joinable:1, done:1; xbt_cond_t cond; xbt_mutex_t mutex; } s_xbt_thread_t; @@ -36,11 +36,11 @@ typedef struct s_xbt_thread_ { static int xbt_thread_create_wrapper(int argc, char *argv[]) { xbt_thread_t t = - (xbt_thread_t) SIMIX_process_get_data(SIMIX_process_self()); + (xbt_thread_t) SIMIX_process_get_data(SIMIX_process_self()); SIMIX_process_set_data(SIMIX_process_self(), t->father_data); (*t->code) (t->userparam); if (t->joinable) { - t->done=1; + t->done = 1; xbt_mutex_acquire(t->mutex); xbt_cond_broadcast(t->cond); xbt_mutex_release(t->mutex); @@ -54,7 +54,7 @@ static int xbt_thread_create_wrapper(int argc, char *argv[]) } xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code, - void *param,int joinable) + void *param, int joinable) { xbt_thread_t res = xbt_new0(s_xbt_thread_t, 1); res->name = xbt_strdup(name); @@ -90,9 +90,10 @@ const char *xbt_thread_self_name(void) void xbt_thread_join(xbt_thread_t thread) { xbt_mutex_acquire(thread->mutex); - xbt_assert1(thread->joinable,"Cannot join on %p: wasn't created joinable",thread); + xbt_assert1(thread->joinable, + "Cannot join on %p: wasn't created joinable", thread); if (!thread->done) { - xbt_cond_wait(thread->cond,thread->mutex); + xbt_cond_wait(thread->cond, thread->mutex); xbt_mutex_release(thread->mutex); } @@ -121,7 +122,8 @@ xbt_thread_t xbt_thread_self(void) return p ? SIMIX_process_get_data(p) : NULL; } -void xbt_thread_yield(void) { +void xbt_thread_yield(void) +{ SIMIX_process_yield(); } @@ -152,7 +154,7 @@ void xbt_mutex_destroy(xbt_mutex_t mutex) /***** condition related functions *****/ struct s_xbt_cond_ { - s_smx_cond_t cond; + s_smx_cond_t cond; }; xbt_cond_t xbt_cond_init(void) diff --git a/src/xbt/xbt_sha.c b/src/xbt/xbt_sha.c index 7fe54419c0..29016d9f2d 100644 --- a/src/xbt/xbt_sha.c +++ b/src/xbt/xbt_sha.c @@ -150,8 +150,8 @@ static void sha_calculate(xbt_sha_t sha) for (i = 16; i < 80; i++) sha->buf[i] = - SRL(sha->buf[i - 3] ^ sha->buf[i - 8] ^ sha-> - buf[i - 14] ^ sha->buf[i - 16], 1); + SRL(sha->buf[i - 3] ^ sha->buf[i - 8] ^ sha-> + buf[i - 14] ^ sha->buf[i - 16], 1); A = sha->hash[0]; B = sha->hash[1]; @@ -219,4 +219,4 @@ XBT_TEST_UNIT("sha", test_crypto_sha, "Test of the sha algorithm") "373ba8be29d4d95708bf7cd43038f4e409dcb439"); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 52911c5334..94e38e6f56 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -414,7 +414,7 @@ xbt_dynar_t xbt_str_split_quoted(const char *s) } } free(str_to_free); - xbt_dynar_shrink(res,0); + xbt_dynar_shrink(res, 0); return res; } @@ -432,14 +432,15 @@ xbt_dynar_t xbt_str_split_quoted(const char *s) xbt_dynar_free(&d); XBT_TEST_SUITE("xbt_str", "String Handling"); -XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted,"test the function xbt_str_split_quoted") +XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted") { xbt_dynar_t d; char *s; mytest("Empty", "", ""); mytest("Basic test", "toto tutu", "totoXXXtutu"); - mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", "totoXXXtutu"); + mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", + "totoXXXtutu"); mytest("Protected space", "toto\\ tutu", "toto tutu"); mytest("Several spaces", "toto tutu", "totoXXXtutu"); mytest("LTriming", " toto tatu", "totoXXXtatu"); @@ -464,7 +465,7 @@ XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted,"test the function xbt_s free(s); \ xbt_dynar_free(&d); -XBT_TEST_UNIT("xbt_str_split_str", test_split_str,"test the function xbt_str_split_str") +XBT_TEST_UNIT("xbt_str_split_str", test_split_str, "test the function xbt_str_split_str") { xbt_dynar_t d; char *s; @@ -475,7 +476,7 @@ XBT_TEST_UNIT("xbt_str_split_str", test_split_str,"test the function xbt_str_spl mytest_str("String with no separator in it", "toto", "##", "toto"); mytest_str("Basic test", "toto##tutu", "##", "totoXXXtutu"); } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ /** @brief Join a set of strings as a single string */ @@ -558,15 +559,16 @@ long getline(char **buf, size_t * n, FILE * stream) return (ssize_t) i; } -#endif /* HAVE_GETLINE */ +#endif /* HAVE_GETLINE */ /* * Diff related functions */ static xbt_matrix_t diff_build_LCS(xbt_dynar_t da, xbt_dynar_t db) { - xbt_matrix_t C = xbt_matrix_new(xbt_dynar_length(da), xbt_dynar_length(db), - sizeof(int), NULL); + xbt_matrix_t C = + xbt_matrix_new(xbt_dynar_length(da), xbt_dynar_length(db), + sizeof(int), NULL); unsigned long i, j; /* Compute the LCS */ @@ -596,13 +598,14 @@ static xbt_matrix_t diff_build_LCS(xbt_dynar_t da, xbt_dynar_t db) for (j = 1; j < xbt_dynar_length(db); j++) { if (!strcmp - (xbt_dynar_get_as(da, i, char *), xbt_dynar_get_as(db, j, char *))) - *((int *) xbt_matrix_get_ptr(C, i, j)) = - xbt_matrix_get_as(C, i - 1, j - 1, int) + 1; + (xbt_dynar_get_as(da, i, char *), + xbt_dynar_get_as(db, j, char *))) + *((int *) xbt_matrix_get_ptr(C, i, j)) = + xbt_matrix_get_as(C, i - 1, j - 1, int) + 1; else *((int *) xbt_matrix_get_ptr(C, i, j)) = - max(xbt_matrix_get_as(C, i, j - 1, int), - xbt_matrix_get_as(C, i - 1, j, int)); + max(xbt_matrix_get_as(C, i, j - 1, int), + xbt_matrix_get_as(C, i - 1, j, int)); } return C; } @@ -633,20 +636,19 @@ static void diff_build_diff(xbt_dynar_t res, xbt_dynar_push(res, &topush); } else if (j >= 0 && (i <= 0 || j == 0 - || xbt_matrix_get_as(C, i, j - 1, int) >= xbt_matrix_get_as(C, - i - - 1, - j, - int))) - { + || xbt_matrix_get_as(C, i, j - 1, + int) >= xbt_matrix_get_as(C, i - 1, j, + int))) { diff_build_diff(res, C, da, db, i, j - 1); topush = bprintf("+ %s", xbt_dynar_get_as(db, j, char *)); xbt_dynar_push(res, &topush); } else if (i >= 0 && (j <= 0 || xbt_matrix_get_as(C, i, j - 1, int) < xbt_matrix_get_as(C, - i - - 1, j, + i + - + 1, + j, int))) { diff_build_diff(res, C, da, db, i - 1, j); @@ -697,16 +699,17 @@ char *xbt_str_diff(char *a, char *b) /** @brief creates a new string containing what can be read on a fd * */ -char* xbt_str_from_file(FILE *file) { +char *xbt_str_from_file(FILE * file) +{ xbt_strbuff_t buff = xbt_strbuff_new(); char *res; char bread[1024]; - memset(bread,0,1024); + memset(bread, 0, 1024); while (!feof(file)) { int got = fread(bread, 1, 1023, file); bread[got] = '\0'; - xbt_strbuff_append(buff,bread); + xbt_strbuff_append(buff, bread); } res = buff->data; diff --git a/src/xbt/xbt_strbuff.c b/src/xbt/xbt_strbuff.c index 49b1400fd9..098827bc61 100644 --- a/src/xbt/xbt_strbuff.c +++ b/src/xbt/xbt_strbuff.c @@ -80,7 +80,7 @@ void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd) if (needed_space > b->size) { b->data = - realloc(b->data, MAX(minimal_increment + b->used, needed_space)); + realloc(b->data, MAX(minimal_increment + b->used, needed_space)); b->size = MAX(minimal_increment + b->used, needed_space); } strcpy(b->data + b->used, toadd); @@ -215,7 +215,7 @@ void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns) /* ok, we now have the variable name. Search the dictionary for the substituted value */ value = - xbt_dict_get_or_null_ext(patterns, beg_var, end_var - beg_var); + xbt_dict_get_or_null_ext(patterns, beg_var, end_var - beg_var); /* DEBUG1("Deal with '%s'",b->data); DEBUG4("Search for %.*s, found %s (default value = %s)\n", end_var-beg_var,beg_var, @@ -252,14 +252,15 @@ void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns) } else { /* we have to extend the data area */ int tooshort = - val_len - (end_subst - beg_subst) + 1 /*don't forget \0 */ ; + val_len - (end_subst - beg_subst) + 1 /*don't forget \0 */ ; int newused = b->used + tooshort; end += tooshort; /* update the pointer of the overall loop */ // DEBUG2("Too short (by %d chars; %d chars left in area)",val_len- (end_subst-beg_subst), b->size - b->used); if (newused > b->size) { /* We have to realloc the data area before (because b->size is too small). We have to update our pointers, too */ - char *newdata = - realloc(b->data, b->used + MAX(minimal_increment, tooshort)); + char *newdata = realloc(b->data, + b->used + MAX(minimal_increment, + tooshort)); int offset = newdata - b->data; b->data = newdata; b->size = b->used + MAX(minimal_increment, tooshort); @@ -277,7 +278,7 @@ void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns) if (default_value) free(default_value); - end--; /* compensate the next end++*/ + end--; /* compensate the next end++ */ } break; @@ -335,7 +336,7 @@ static void mytest(const char *input, const char *patterns, } XBT_TEST_SUITE("xbt_strbuff", "String Buffers"); -XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the function xbt_strbuff_substitute") +XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute, "test the function xbt_strbuff_substitute") { xbt_test_add0("Empty"); mytest("", "", ""); @@ -404,7 +405,8 @@ XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the functi xbt_test_add0("Value much longer, no braces, data before and after"); mytest("toto $t tata", "t=" force_resize, "toto " force_resize " tata"); xbt_test_add0("Value much longer, braces, data before and after"); - mytest("toto ${t} tata", "t=" force_resize, "toto " force_resize " tata"); + mytest("toto ${t} tata", "t=" force_resize, + "toto " force_resize " tata"); xbt_test_add0("Escaped $"); mytest("\\$tutu", "tutu=t", "\\$tutu"); @@ -425,4 +427,4 @@ XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the functi } -#endif /* SIMGRID_TEST */ +#endif /* SIMGRID_TEST */ diff --git a/src/xbt/xbt_synchro.c b/src/xbt/xbt_synchro.c index d10885d74a..9cb027926c 100644 --- a/src/xbt/xbt_synchro.c +++ b/src/xbt/xbt_synchro.c @@ -17,38 +17,45 @@ typedef struct { int rank; void_f_int_pvoid_t function; xbt_thread_t worker; -} s_worker_data_t,*worker_data_t; +} s_worker_data_t, *worker_data_t; -static void worker_wait_n_free(void*w) { - worker_data_t worker=*(worker_data_t*)w; +static void worker_wait_n_free(void *w) +{ + worker_data_t worker = *(worker_data_t *) w; xbt_thread_join(worker->worker); xbt_free(worker); } -static void worker_wrapper(void *w) { - worker_data_t me=(worker_data_t)w; - (*me->function)(me->rank,xbt_dynar_get_ptr(me->data,me->rank)); + +static void worker_wrapper(void *w) +{ + worker_data_t me = (worker_data_t) w; + (*me->function) (me->rank, xbt_dynar_get_ptr(me->data, me->rank)); } -void xbt_dynar_dopar(xbt_dynar_t datas, void_f_int_pvoid_t function) { - xbt_dynar_t workers = xbt_dynar_new(sizeof(worker_data_t),worker_wait_n_free); +void xbt_dynar_dopar(xbt_dynar_t datas, void_f_int_pvoid_t function) +{ + xbt_dynar_t workers = + xbt_dynar_new(sizeof(worker_data_t), worker_wait_n_free); unsigned int cursor; void *data; - if (xbt_dynar_length(datas)==0) - return; /* nothing to do */ - if (xbt_dynar_length(datas)==1) { + if (xbt_dynar_length(datas) == 0) + return; /* nothing to do */ + if (xbt_dynar_length(datas) == 1) { /* don't start any new thread, do it directly */ - (*function)(0,xbt_dynar_get_ptr(datas,0)); + (*function) (0, xbt_dynar_get_ptr(datas, 0)); return; } /* Start all workers */ - INFO1("Dopar for %ld elements",xbt_dynar_length(datas)); - xbt_dynar_foreach(datas,cursor,data){ - worker_data_t w = xbt_new0(s_worker_data_t,1); + INFO1("Dopar for %ld elements", xbt_dynar_length(datas)); + xbt_dynar_foreach(datas, cursor, data) { + worker_data_t w = xbt_new0(s_worker_data_t, 1); w->data = datas; w->function = function; - w->rank=cursor; - xbt_dynar_push(workers,&w); - w->worker = xbt_thread_create("dopar worker",worker_wrapper,w,1/*joinable*/); + w->rank = cursor; + xbt_dynar_push(workers, &w); + w->worker = + xbt_thread_create("dopar worker", worker_wrapper, w, + 1 /*joinable */ ); } /* wait them all */ xbt_dynar_free(&workers); @@ -62,9 +69,10 @@ XBT_TEST_SUITE("synchro", "Advanced synchronization mecanisms"); XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn); XBT_LOG_DEFAULT_CATEGORY(xbt_dyn); -static void add100(int rank,void *data) { +static void add100(int rank, void *data) +{ //INFO2("Thread%d: Add 100 to %d",rank,*(int*)data); - *(int*)data +=100; + *(int *) data += 100; } XBT_TEST_UNIT("dopar", test_dynar_dopar, "do parallel on dynars of integers") @@ -73,13 +81,15 @@ XBT_TEST_UNIT("dopar", test_dynar_dopar, "do parallel on dynars of integers") int i, cpt; unsigned int cursor; - xbt_test_add1("==== Push %d int, add 100 to each of them in parallel and check the results", NB_ELEM); + xbt_test_add1 + ("==== Push %d int, add 100 to each of them in parallel and check the results", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) { xbt_dynar_push_as(d, int, cpt); /* This is faster (and possible only with scalars) */ xbt_test_log2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_dopar(d,add100); + xbt_dynar_dopar(d, add100); cpt = 100; xbt_dynar_foreach(d, cursor, i) { xbt_test_assert2(i == cpt, @@ -90,6 +100,4 @@ XBT_TEST_UNIT("dopar", test_dynar_dopar, "do parallel on dynars of integers") xbt_dynar_free(&d); } -#endif /* SIMGRID_TEST */ - - +#endif /* SIMGRID_TEST */ diff --git a/src/xbt_modinter.h b/src/xbt_modinter.h index ad4100a7a9..491c1db3bd 100644 --- a/src/xbt_modinter.h +++ b/src/xbt_modinter.h @@ -30,4 +30,4 @@ void mmalloc_preinit(void); void mmalloc_postexit(void); -#endif /* XBT_MODINTER_H */ +#endif /* XBT_MODINTER_H */ diff --git a/src/xbt_str_unit.c b/src/xbt_str_unit.c index da6ade9746..13e1082646 100644 --- a/src/xbt_str_unit.c +++ b/src/xbt_str_unit.c @@ -21,14 +21,15 @@ free(s); \ xbt_dynar_free(&d); -XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted,"test the function xbt_str_split_quoted") +XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted") { xbt_dynar_t d; char *s; mytest("Empty", "", ""); mytest("Basic test", "toto tutu", "totoXXXtutu"); - mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", "totoXXXtutu"); + mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", + "totoXXXtutu"); mytest("Protected space", "toto\\ tutu", "toto tutu"); mytest("Several spaces", "toto tutu", "totoXXXtutu"); mytest("LTriming", " toto tatu", "totoXXXtatu"); @@ -53,7 +54,7 @@ XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted,"test the function xbt_s free(s); \ xbt_dynar_free(&d); -XBT_TEST_UNIT("xbt_str_split_str", test_split_str,"test the function xbt_str_split_str") +XBT_TEST_UNIT("xbt_str_split_str", test_split_str, "test the function xbt_str_split_str") { xbt_dynar_t d; char *s; diff --git a/src/xbt_strbuff_unit.c b/src/xbt_strbuff_unit.c index 2981357574..a67a2c464f 100644 --- a/src/xbt_strbuff_unit.c +++ b/src/xbt_strbuff_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 293 "xbt/xbt_strbuff.c" +#line 294 "xbt/xbt_strbuff.c" #include "xbt/strbuff.h" /* buffstr have 512 chars by default. Adding 1000 chars like this will force a resize, allowing us to test that b->used and b->size are consistent */ @@ -54,7 +54,7 @@ static void mytest(const char *input, const char *patterns, xbt_strbuff_free(sb); } -XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the function xbt_strbuff_substitute") +XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute, "test the function xbt_strbuff_substitute") { xbt_test_add0("Empty"); mytest("", "", ""); @@ -123,7 +123,8 @@ XBT_TEST_UNIT("xbt_strbuff_substitute", test_strbuff_substitute,"test the functi xbt_test_add0("Value much longer, no braces, data before and after"); mytest("toto $t tata", "t=" force_resize, "toto " force_resize " tata"); xbt_test_add0("Value much longer, braces, data before and after"); - mytest("toto ${t} tata", "t=" force_resize, "toto " force_resize " tata"); + mytest("toto ${t} tata", "t=" force_resize, + "toto " force_resize " tata"); xbt_test_add0("Escaped $"); mytest("\\$tutu", "tutu=t", "\\$tutu"); diff --git a/src/xbt_synchro_unit.c b/src/xbt_synchro_unit.c index 9c05f0f06f..95e8ff8c76 100644 --- a/src/xbt_synchro_unit.c +++ b/src/xbt_synchro_unit.c @@ -8,16 +8,17 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 59 "xbt/xbt_synchro.c" +#line 66 "xbt/xbt_synchro.c" #define NB_ELEM 50 #include "xbt/synchro.h" XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn); XBT_LOG_DEFAULT_CATEGORY(xbt_dyn); -static void add100(int rank,void *data) { +static void add100(int rank, void *data) +{ //INFO2("Thread%d: Add 100 to %d",rank,*(int*)data); - *(int*)data +=100; + *(int *) data += 100; } XBT_TEST_UNIT("dopar", test_dynar_dopar, "do parallel on dynars of integers") @@ -26,13 +27,15 @@ XBT_TEST_UNIT("dopar", test_dynar_dopar, "do parallel on dynars of integers") int i, cpt; unsigned int cursor; - xbt_test_add1("==== Push %d int, add 100 to each of them in parallel and check the results", NB_ELEM); + xbt_test_add1 + ("==== Push %d int, add 100 to each of them in parallel and check the results", + NB_ELEM); d = xbt_dynar_new(sizeof(int), NULL); for (cpt = 0; cpt < NB_ELEM; cpt++) { xbt_dynar_push_as(d, int, cpt); /* This is faster (and possible only with scalars) */ xbt_test_log2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); } - xbt_dynar_dopar(d,add100); + xbt_dynar_dopar(d, add100); cpt = 100; xbt_dynar_foreach(d, cursor, i) { xbt_test_assert2(i == cpt, -- 2.20.1