From: Marion Guthmuller Date: Thu, 3 May 2012 08:54:19 +0000 (+0200) Subject: Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid X-Git-Tag: v3_7~30^2~4 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cb91af44a1bd7e5f331686df25d5fe80ff571a43?hp=836c888a9f8c7be6a2ec571a2f838c76a7df1a40 Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid --- diff --git a/ChangeLog b/ChangeLog index 5583490eaa..095ef382ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,10 +43,11 @@ SimGrid (3.7) NOT RELEASED; urgency=low Switch to MSG_task_{send,recv} instead, or compile Simgrid command line 'cmake -Dcustom_flags="-DMSG_USE_DEPRECATED" .' if you really need to use these (crappy) functions in your code. - These functions will be removed at some point. Stop using them now. + These functions will be removed soon. Stop using them now. * Deprecate MSG_get_host_{table,number} Implement MSG_hosts_as_dynar() instead. * Implement MSG_processes_as_dynar() (Closes gforge #13642) + * Remove the public field msg_host_t->name. Use MSG_host_get_name() Simix: * Stabilize the parallel execution mode of user contexts diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 45da8465ab..bf28e63461 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -437,6 +437,7 @@ set(headers_to_install include/xbt/file_stat.h include/simgrid/platf.h include/simgrid/modelchecker.h + include/simgrid/simix.h include/msg/msg.h include/msg/datatypes.h include/simdag/simdag.h @@ -460,9 +461,6 @@ set(headers_to_install include/instr/instr.h include/gras.h include/xbt.h - include/simix/simix.h - include/simix/datatypes.h - include/simix/context.h ) set(source_of_generated_headers include/simgrid_config.h.in diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index d2c306c0f9..e45e988dde 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -7,7 +7,7 @@ #include #include #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "simix/simix.h" /* semaphores for the barrier */ +#include "simgrid/simix.h" /* semaphores for the barrier */ #include "xbt.h" /* calloc, printf */ #include "instr/instr_private.h" diff --git a/examples/msg/masterslave/masterslave_bypass.c b/examples/msg/masterslave/masterslave_bypass.c index 4c6f2a8cea..343c92fcaa 100644 --- a/examples/msg/masterslave/masterslave_bypass.c +++ b/examples/msg/masterslave/masterslave_bypass.c @@ -199,7 +199,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("\t %s", slaves[i]->name); + XBT_INFO("\t %s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -208,7 +208,7 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } diff --git a/examples/msg/masterslave/masterslave_cluster.c b/examples/msg/masterslave/masterslave_cluster.c index 6f871fdec6..1e54f5e73b 100644 --- a/examples/msg/masterslave/masterslave_cluster.c +++ b/examples/msg/masterslave/masterslave_cluster.c @@ -69,7 +69,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("\t %s", slaves[i]->name); + XBT_INFO("\t %s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -78,7 +78,7 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } diff --git a/examples/msg/masterslave/masterslave_failure.c b/examples/msg/masterslave/masterslave_failure.c index c882244eea..39e7d7e077 100644 --- a/examples/msg/masterslave/masterslave_failure.c +++ b/examples/msg/masterslave/masterslave_failure.c @@ -55,7 +55,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("%s", slaves[i]->name); + XBT_INFO("%s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -79,13 +79,13 @@ int master(int argc, char *argv[]) } else if (a == MSG_TRANSFER_FAILURE) { XBT_INFO ("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); free(task->data); MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); free(task->data); MSG_task_destroy(task); } else { @@ -109,16 +109,16 @@ int master(int argc, char *argv[]) return 0; } else if (a == MSG_TRANSFER_FAILURE) { XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", - slaves[i]->name); + MSG_host_get_name(slaves[i])); MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); MSG_task_destroy(task); } else { XBT_INFO("Hey ?! What's up ? "); - xbt_die("Unexpected behavior with '%s': %d", slaves[i]->name, a); + xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a); } } diff --git a/examples/msg/masterslave/masterslave_forwarder.c b/examples/msg/masterslave/masterslave_forwarder.c index 1e0d779dcb..4ebb580d8d 100644 --- a/examples/msg/masterslave/masterslave_forwarder.c +++ b/examples/msg/masterslave/masterslave_forwarder.c @@ -77,11 +77,11 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slaves and %d tasks to process", slaves_count, number_of_tasks); for (i = 0; i < slaves_count; i++) - XBT_DEBUG("%s", slaves[i]->name); + XBT_DEBUG("%s", MSG_host_get_name(slaves[i])); for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } @@ -165,7 +165,7 @@ int forwarder(int argc, char *argv[]) break; } XBT_INFO("Sending \"%s\" to \"%s\"", - MSG_task_get_name(task), slaves[i % slaves_count]->name); + MSG_task_get_name(task), MSG_host_get_name(slaves[i % slaves_count])); MSG_task_send(task, MSG_host_get_name(slaves[i % slaves_count])); i++; } else { diff --git a/examples/msg/migration/migration.c b/examples/msg/migration/migration.c index f0ec59694f..898ac256e8 100644 --- a/examples/msg/migration/migration.c +++ b/examples/msg/migration/migration.c @@ -46,7 +46,7 @@ static int emigrant(int argc, char *argv[]) xbt_mutex_release(mutex); MSG_process_suspend(MSG_process_self()); m_host_t h = MSG_process_get_host(MSG_process_self()); - XBT_INFO("I've been moved on this new host: %s", h->name); + XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h)); XBT_INFO("Uh, nothing to do here. Stopping now"); return 0; } /* end_of_emigrant */ diff --git a/examples/msg/tracing/ms.c b/examples/msg/tracing/ms.c index 95b3a28dc3..575612e315 100644 --- a/examples/msg/tracing/ms.c +++ b/examples/msg/tracing/ms.c @@ -41,7 +41,7 @@ int master(int argc, char *argv[]) long slaves_count = atol(argv[4]); //setting the variable "is_master" (previously declared) to value 1 - TRACE_host_variable_set(MSG_host_self()->name, "is_master", 1); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_master", 1); TRACE_mark("msmark", "start_send_tasks"); int i; @@ -50,7 +50,7 @@ int master(int argc, char *argv[]) task = MSG_task_create("task", task_comp_size, task_comm_size, NULL); //setting the variable "task_creation" to value i - TRACE_host_variable_set(MSG_host_self()->name, "task_creation", i); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "task_creation", i); //setting the category of task to "compute" //the category of a task must be defined before it is sent or executed @@ -73,7 +73,10 @@ int slave(int argc, char *argv[]) { m_task_t task = NULL; - TRACE_host_variable_set(MSG_host_self()->name, "is_slave", 1); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_slave", 1); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), + "task_computation", + 0); while (1) { MSG_task_receive(&(task), "master_mailbox"); @@ -83,7 +86,7 @@ int slave(int argc, char *argv[]) } //adding the value returned by MSG_task_get_compute_duration(task) //to the variable "task_computation" - TRACE_host_variable_add(MSG_host_self()->name, + TRACE_host_variable_add(MSG_host_get_name(MSG_host_self()), "task_computation", MSG_task_get_compute_duration(task)); MSG_task_execute(task); diff --git a/examples/msg/tracing/user_variables.c b/examples/msg/tracing/user_variables.c index ea2b959bed..6c63b9d20f 100644 --- a/examples/msg/tracing/user_variables.c +++ b/examples/msg/tracing/user_variables.c @@ -27,7 +27,7 @@ int master(int argc, char *argv[]); int master(int argc, char *argv[]) { - char *hostname = MSG_host_self()->name; + const char *hostname = MSG_host_get_name(MSG_host_self()); int i; //the hostname has an empty HDD with a capacity of 100000 (bytes) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index 08a6b2626d..79fc90ae62 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -8,18 +8,33 @@ #define MSG_DATATYPE_H #include "xbt/misc.h" #include "xbt/file_stat.h" +#include "simgrid/simix.h" #include "simgrid_config.h" // for HAVE_TRACING SG_BEGIN_DECL() -/* ******************************** Host ************************************ */ +/* ******************************** Mailbox ************************************ */ + +/** @brief Mailbox datatype + * @ingroup msg_task_usage + * + * Object representing a communication rendez-vous point, on which + * the sender finds the receiver it wants to communicate with. As a + * MSG user, you will only rarely manipulate any of these objects + * directly, since most of the public interface (such as + * #MSG_task_send and friends) hide this object behind a string + * alias. That mean that you don't provide the mailbox on which you + * want to send your task, but only the name of this mailbox. */ +typedef struct s_smx_rvpoint *msg_mailbox_t; -typedef struct simdata_host *simdata_host_t; + +/* ******************************** Host ************************************ */ typedef struct m_host { - char *name; /**< @brief host name if any */ - simdata_host_t simdata; /**< @brief simulator data */ - void *data; /**< @brief user data */ + smx_host_t smx_host; /**< SIMIX representation of this host */ +#ifdef MSG_USE_DEPRECATED + msg_mailbox_t *mailboxes; /**< the channels */ +#endif } s_m_host_t; /** @brief Host datatype @@ -130,19 +145,6 @@ typedef struct s_smx_process *m_process_t; typedef int m_channel_t; #endif -/* ******************************** Mailbox ************************************ */ - -/** @brief Mailbox datatype - * @ingroup msg_task_usage - * - * Object representing a communication rendez-vous point, on which - * the sender finds the receiver it wants to communicate with. As a - * MSG user, you will only rarely manipulate any of these objects - * directly, since most of the public interface (such as - * #MSG_task_send and friends) hide this object behind a string - * alias. That mean that you don't provide the mailbox on which you - * want to send your task, but only the name of this mailbox. */ -typedef struct s_smx_rvpoint *msg_mailbox_t; SG_END_DECL() diff --git a/include/msg/msg.h b/include/msg/msg.h index 4d3bc10a5a..d28939b70e 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -12,6 +12,8 @@ #include "msg/datatypes.h" #include "xbt/automaton.h" +#include "simgrid/simix.h" + SG_BEGIN_DECL() /** @brief Return code of most MSG functions @@ -192,7 +194,7 @@ XBT_PUBLIC(MSG_error_t) XBT_PUBLIC(msg_comm_t) MSG_task_isend(m_task_t task, const char *alias); XBT_PUBLIC(msg_comm_t) MSG_task_isend_with_matching(m_task_t task, const char *alias, - int (*match_fun)(void*,void*), + int (*match_fun)(void*,void*, smx_action_t), void *match_data); XBT_PUBLIC(void) MSG_task_dsend(m_task_t task, const char *alias, void_f_pvoid_t cleanup); @@ -286,7 +288,6 @@ XBT_PUBLIC(int) MSG_get_channel_number(void); #include "instr/instr.h" /* Used only by the bindings */ -#include "simix/simix.h" XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(m_process_t process); SG_END_DECL() diff --git a/include/simix/simix.h b/include/simgrid/simix.h similarity index 65% rename from include/simix/simix.h rename to include/simgrid/simix.h index 59522ffd25..dec17ece07 100644 --- a/include/simix/simix.h +++ b/include/simgrid/simix.h @@ -12,11 +12,191 @@ #include "xbt/dict.h" #include "xbt/file_stat.h" #include "xbt/function_types.h" -#include "simix/datatypes.h" -#include "simix/context.h" +#include "xbt/parmap.h" +#include "xbt/swag.h" SG_BEGIN_DECL() + +/* ******************************** Host ************************************ */ +/** @defgroup m_datatypes_management_details Details on SIMIX datatypes */ +/** @brief Host datatype + @ingroup m_datatypes_management + + A location (or host) is any possible place where + a process may run. Thus it is represented as a physical + resource with computing capabilities, some mailboxes + to enable running process to communicate with remote ones, and + some private data that can be only accessed by local + process. + + \see m_host_management + @{ */ +typedef struct s_smx_host *smx_host_t; +typedef enum { + SIMIX_WAITING, + SIMIX_READY, + SIMIX_RUNNING, + SIMIX_DONE, + SIMIX_CANCELED, + SIMIX_FAILED, + SIMIX_SRC_HOST_FAILURE, + SIMIX_DST_HOST_FAILURE, + SIMIX_SRC_TIMEOUT, + SIMIX_DST_TIMEOUT, + SIMIX_LINK_FAILURE +} e_smx_state_t; +/** @} */ + + +typedef struct s_smx_timer* smx_timer_t; + +/* ******************************** Synchro ************************************ */ +typedef struct s_smx_mutex *smx_mutex_t; +typedef struct s_smx_cond *smx_cond_t; +typedef struct s_smx_sem *smx_sem_t; + +/********************************** File *************************************/ +typedef struct s_smx_file *smx_file_t; +typedef struct s_smx_stat *smx_stat_t; + +/********************************** Action *************************************/ +typedef struct s_smx_action *smx_action_t; /* FIXME: replace by specialized action handlers */ + + + +/* ****************************** Process *********************************** */ +/** @brief Process datatype + @ingroup m_datatypes_management + + A processt may be defined as a code, with some private + data, executing in a location. + \see m_process_management + @{ */ +typedef struct s_smx_process *smx_process_t; +/** @} */ + + +/* + * Type of function that creates a process. + * The function must accept the following parameters: + * void* process: the process created will be stored there + * const char *name: a name for the object. It is for user-level information and can be NULL + * xbt_main_func_t code: is a function describing the behavior of the process + * void *data: data a pointer to any data one may want to attach to the new object. + * smx_host_t host: the location where the new process is executed + * int argc, char **argv: parameters passed to code + * xbt_dict_t pros: properties + */ +typedef void (*smx_creation_func_t) ( /* process */ smx_process_t*, + /* name */ const char*, + /* code */ xbt_main_func_t, + /* userdata */ void*, + /* hostname */ const char*, + /* kill_time */ double, + /* argc */ int, + /* argv */ char**, + /* props */ xbt_dict_t); + + +/******************************* Networking ***********************************/ +typedef struct s_smx_rvpoint *smx_rdv_t; + +/******************************** Context *************************************/ +typedef struct s_smx_context *smx_context_t; +typedef struct s_smx_context_factory *smx_context_factory_t; + +/* Process creation/destruction callbacks */ +typedef void (*void_pfn_smxprocess_t) (smx_process_t); + + +/* 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_pfn_smxprocess_t, void* data); +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); +typedef void (*smx_pfn_context_suspend_t) (smx_context_t context); +typedef void (*smx_pfn_context_runall_t) (void); +typedef smx_context_t (*smx_pfn_context_self_t) (void); +typedef void* (*smx_pfn_context_get_data_t) (smx_context_t context); + +/* interface of the context factories */ +typedef struct s_smx_context_factory { + const char *name; + smx_pfn_context_factory_create_context_t create_context; + smx_pfn_context_factory_finalize_t finalize; + smx_pfn_context_free_t free; + smx_pfn_context_stop_t stop; + smx_pfn_context_suspend_t suspend; + smx_pfn_context_runall_t runall; + smx_pfn_context_self_t self; + smx_pfn_context_get_data_t get_data; +} s_smx_context_factory_t; + +/* Hack: let msg load directly the right factory */ +typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*); +XBT_PUBLIC(smx_ctx_factory_initializer_t) smx_factory_initializer_to_use; +extern char* smx_context_factory_name; +extern int smx_context_stack_size; + +#ifdef HAVE_THREAD_LOCAL_STORAGE +extern __thread smx_context_t smx_current_context; +#else +extern smx_context_t smx_current_context; +#endif + +/* *********************** */ +/* Context type definition */ +/* *********************** */ +/* 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 beginning -- OOP in C :/ */ +typedef struct s_smx_context { + s_xbt_swag_hookup_t hookup; + xbt_main_func_t code; + void_pfn_smxprocess_t cleanup_func; + void *data; /* Here SIMIX stores the smx_process_t containing the context */ + char **argv; + int argc; + int iwannadie:1; +} s_smx_ctx_base_t; + +/* methods of this class */ +XBT_PUBLIC(void) smx_ctx_base_factory_init(smx_context_factory_t *factory); +XBT_PUBLIC(int) smx_ctx_base_factory_finalize(smx_context_factory_t *factory); + +XBT_PUBLIC(smx_context_t) +smx_ctx_base_factory_create_context_sized(size_t size, + xbt_main_func_t code, int argc, + char **argv, + void_pfn_smxprocess_t cleanup, + void* data); +XBT_PUBLIC(void) smx_ctx_base_free(smx_context_t context); +XBT_PUBLIC(void) smx_ctx_base_stop(smx_context_t context); +XBT_PUBLIC(smx_context_t) smx_ctx_base_self(void); +XBT_PUBLIC(void) *smx_ctx_base_get_data(smx_context_t context); + +XBT_PUBLIC(xbt_dynar_t) SIMIX_process_get_runnable(void); +XBT_PUBLIC(smx_process_t) SIMIX_process_from_PID(int PID); +XBT_PUBLIC(xbt_dynar_t) SIMIX_processes_as_dynar(void); + +/* parallelism */ +XBT_PUBLIC(int) SIMIX_context_is_parallel(void); +XBT_PUBLIC(int) SIMIX_context_get_nthreads(void); +XBT_PUBLIC(void) SIMIX_context_set_nthreads(int nb_threads); +XBT_PUBLIC(int) SIMIX_context_get_parallel_threshold(void); +XBT_PUBLIC(void) SIMIX_context_set_parallel_threshold(int threshold); +XBT_PUBLIC(e_xbt_parmap_mode_t) SIMIX_context_get_parallel_mode(void); +XBT_PUBLIC(void) SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode); + + + /********************************** Global ************************************/ /* Initialization and exit */ XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv); @@ -170,24 +350,24 @@ XBT_PUBLIC(xbt_dict_t) SIMIX_get_rdv_points(void); XBT_PUBLIC(void) simcall_comm_send(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout); XBT_PUBLIC(smx_action_t) simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void (*clean_fun)(void *), void *data, int detached); XBT_PUBLIC(void) simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout); XBT_PUBLIC(smx_action_t) simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void *data); XBT_PUBLIC(void) simcall_comm_destroy(smx_action_t comm); diff --git a/include/simix/context.h b/include/simix/context.h deleted file mode 100644 index 9408c19125..0000000000 --- a/include/simix/context.h +++ /dev/null @@ -1,113 +0,0 @@ -/* a fast and simple context switching library */ - -/* Copyright (c) 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef _SIMIX_CONTEXT_H -#define _SIMIX_CONTEXT_H - -#include "xbt/swag.h" -#include "xbt/parmap.h" -#include "simix/datatypes.h" -#include "simgrid_config.h" - -SG_BEGIN_DECL() -/******************************** Context *************************************/ -typedef struct s_smx_context *smx_context_t; -typedef struct s_smx_context_factory *smx_context_factory_t; - -/* Process creation/destruction callbacks */ -typedef void (*void_pfn_smxprocess_t) (smx_process_t); - - -/* 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_pfn_smxprocess_t, void* data); -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); -typedef void (*smx_pfn_context_suspend_t) (smx_context_t context); -typedef void (*smx_pfn_context_runall_t) (void); -typedef smx_context_t (*smx_pfn_context_self_t) (void); -typedef void* (*smx_pfn_context_get_data_t) (smx_context_t context); - -/* interface of the context factories */ -typedef struct s_smx_context_factory { - const char *name; - smx_pfn_context_factory_create_context_t create_context; - smx_pfn_context_factory_finalize_t finalize; - smx_pfn_context_free_t free; - smx_pfn_context_stop_t stop; - smx_pfn_context_suspend_t suspend; - smx_pfn_context_runall_t runall; - smx_pfn_context_self_t self; - smx_pfn_context_get_data_t get_data; -} s_smx_context_factory_t; - -/* Hack: let msg load directly the right factory */ -typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*); -XBT_PUBLIC(smx_ctx_factory_initializer_t) smx_factory_initializer_to_use; -extern char* smx_context_factory_name; -extern int smx_context_stack_size; - -#ifdef HAVE_THREAD_LOCAL_STORAGE -extern __thread smx_context_t smx_current_context; -#else -extern smx_context_t smx_current_context; -#endif - -/* *********************** */ -/* Context type definition */ -/* *********************** */ -/* 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 beginning -- OOP in C :/ */ -typedef struct s_smx_context { - s_xbt_swag_hookup_t hookup; - xbt_main_func_t code; - void_pfn_smxprocess_t cleanup_func; - void *data; /* Here SIMIX stores the smx_process_t containing the context */ - char **argv; - int argc; - int iwannadie:1; -} s_smx_ctx_base_t; - -/* methods of this class */ -XBT_PUBLIC(void) smx_ctx_base_factory_init(smx_context_factory_t *factory); -XBT_PUBLIC(int) smx_ctx_base_factory_finalize(smx_context_factory_t *factory); - -XBT_PUBLIC(smx_context_t) -smx_ctx_base_factory_create_context_sized(size_t size, - xbt_main_func_t code, int argc, - char **argv, - void_pfn_smxprocess_t cleanup, - void* data); -XBT_PUBLIC(void) smx_ctx_base_free(smx_context_t context); -XBT_PUBLIC(void) smx_ctx_base_stop(smx_context_t context); -XBT_PUBLIC(smx_context_t) smx_ctx_base_self(void); -XBT_PUBLIC(void) *smx_ctx_base_get_data(smx_context_t context); - -XBT_PUBLIC(xbt_dynar_t) SIMIX_process_get_runnable(void); -XBT_PUBLIC(smx_process_t) SIMIX_process_from_PID(int PID); -XBT_PUBLIC(xbt_dynar_t) SIMIX_processes_as_dynar(void); - -/* parallelism */ -XBT_PUBLIC(int) SIMIX_context_is_parallel(void); -XBT_PUBLIC(int) SIMIX_context_get_nthreads(void); -XBT_PUBLIC(void) SIMIX_context_set_nthreads(int nb_threads); -XBT_PUBLIC(int) SIMIX_context_get_parallel_threshold(void); -XBT_PUBLIC(void) SIMIX_context_set_parallel_threshold(int threshold); -XBT_PUBLIC(e_xbt_parmap_mode_t) SIMIX_context_get_parallel_mode(void); -XBT_PUBLIC(void) SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode); - -SG_END_DECL() - -#endif /* !_XBT_CONTEXT_H */ diff --git a/include/simix/datatypes.h b/include/simix/datatypes.h deleted file mode 100644 index 97e8af5ad8..0000000000 --- a/include/simix/datatypes.h +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (c) 2007, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef _SIMIX_DATATYPES_H -#define _SIMIX_DATATYPES_H -#include "xbt/misc.h" -#include "xbt/swag.h" -#include "xbt/fifo.h" -#include "xbt/dict.h" - -SG_BEGIN_DECL() - -/* ******************************** Host ************************************ */ -/** @defgroup m_datatypes_management_details Details on SIMIX datatypes */ -/** @brief Host datatype - @ingroup m_datatypes_management - - A location (or host) is any possible place where - a process may run. Thus it is represented as a physical - resource with computing capabilities, some mailboxes - to enable running process to communicate with remote ones, and - some private data that can be only accessed by local - process. - - \see m_host_management - @{ */ -typedef struct s_smx_host *smx_host_t; -typedef enum { - SIMIX_WAITING, - SIMIX_READY, - SIMIX_RUNNING, - SIMIX_DONE, - SIMIX_CANCELED, - SIMIX_FAILED, - SIMIX_SRC_HOST_FAILURE, - SIMIX_DST_HOST_FAILURE, - SIMIX_SRC_TIMEOUT, - SIMIX_DST_TIMEOUT, - SIMIX_LINK_FAILURE -} e_smx_state_t; -/** @} */ - - -typedef struct s_smx_timer* smx_timer_t; - -/* ******************************** Synchro ************************************ */ -typedef struct s_smx_mutex *smx_mutex_t; -typedef struct s_smx_cond *smx_cond_t; -typedef struct s_smx_sem *smx_sem_t; - -/********************************** File *************************************/ -typedef struct s_smx_file *smx_file_t; -typedef struct s_smx_stat *smx_stat_t; - -/********************************** Action *************************************/ -typedef struct s_smx_action *smx_action_t; /* FIXME: replace by specialized action handlers */ - - - -/* ****************************** Process *********************************** */ -/** @brief Process datatype - @ingroup m_datatypes_management - - A processt may be defined as a code, with some private - data, executing in a location. - \see m_process_management - @{ */ -typedef struct s_smx_process *smx_process_t; -/** @} */ - - -/* - * Type of function that creates a process. - * The function must accept the following parameters: - * void* process: the process created will be stored there - * const char *name: a name for the object. It is for user-level information and can be NULL - * xbt_main_func_t code: is a function describing the behavior of the process - * void *data: data a pointer to any data one may want to attach to the new object. - * smx_host_t host: the location where the new process is executed - * int argc, char **argv: parameters passed to code - * xbt_dict_t pros: properties - */ -typedef void (*smx_creation_func_t) ( /* process */ smx_process_t*, - /* name */ const char*, - /* code */ xbt_main_func_t, - /* userdata */ void*, - /* hostname */ const char*, - /* kill_time */ double, - /* argc */ int, - /* argv */ char**, - /* props */ xbt_dict_t); - - -/******************************* Networking ***********************************/ -typedef struct s_smx_rvpoint *smx_rdv_t; - - -SG_END_DECL() -#endif diff --git a/src/gras/Msg/sg_msg.c b/src/gras/Msg/sg_msg.c index 0471d13b68..3816885af6 100644 --- a/src/gras/Msg/sg_msg.c +++ b/src/gras/Msg/sg_msg.c @@ -18,7 +18,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg); typedef void *gras_trp_bufdata_; -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "simix/smx_private.h" /* Yeah, the following is awfull, breaking the encapsulation of at least 3 modules diff --git a/src/gras/Transport/transport_interface.h b/src/gras/Transport/transport_interface.h index abbda60904..c0bb894dbe 100644 --- a/src/gras/Transport/transport_interface.h +++ b/src/gras/Transport/transport_interface.h @@ -12,7 +12,7 @@ #define GRAS_TRP_INTERFACE_H #include "portable.h" /* sometimes needed for fd_set */ -#include "simix/simix.h" +#include "simgrid/simix.h" #include "xbt/queue.h" /* Data of this module specific to each process diff --git a/src/gras/Transport/transport_plugin_sg.c b/src/gras/Transport/transport_plugin_sg.c index ebdc3d9255..6dbffd0228 100644 --- a/src/gras/Transport/transport_plugin_sg.c +++ b/src/gras/Transport/transport_plugin_sg.c @@ -12,7 +12,7 @@ #include "xbt/ex.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "gras/Msg/msg_private.h" #include "gras/Transport/transport_private.h" #include "gras/Virtu/virtu_sg.h" diff --git a/src/gras/Virtu/virtu_private.h b/src/gras/Virtu/virtu_private.h index 315214c046..529ce8384c 100644 --- a/src/gras/Virtu/virtu_private.h +++ b/src/gras/Virtu/virtu_private.h @@ -14,7 +14,7 @@ #include "xbt/dynar.h" #include "gras/Virtu/virtu_interface.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "gras/Msg/msg_private.h" /** @brief Data for each process */ diff --git a/src/gras/Virtu/virtu_sg.h b/src/gras/Virtu/virtu_sg.h index 93e1cce9ce..f4e7bab1fd 100644 --- a/src/gras/Virtu/virtu_sg.h +++ b/src/gras/Virtu/virtu_sg.h @@ -11,7 +11,7 @@ #include "gras/Virtu/virtu_private.h" #include "xbt/dynar.h" -#include "simix/simix.h" /* SimGrid header */ +#include "simgrid/simix.h" /* SimGrid header */ #include "gras/Transport/transport_private.h" typedef struct { diff --git a/src/gras/rl_stubs.c b/src/gras/rl_stubs.c index 2a75a5f243..a9d5ddf790 100644 --- a/src/gras/rl_stubs.c +++ b/src/gras/rl_stubs.c @@ -8,7 +8,7 @@ #include "xbt_modinter.h" #include "xbt/sysdep.h" -#include "simix/simix.h" +#include "simgrid/simix.h" void SIMIX_display_process_status(void) { diff --git a/src/include/mc/mc.h b/src/include/mc/mc.h index 1bd8148ff6..1fe6b57339 100644 --- a/src/include/mc/mc.h +++ b/src/include/mc/mc.h @@ -11,7 +11,7 @@ #include "xbt/dict.h" #include "xbt/function_types.h" #include "mc/datatypes.h" -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "simgrid/modelchecker.h" /* our public interface (and definition of HAVE_MC) */ #include "xbt/automaton.h" diff --git a/src/include/simix/context.h b/src/include/simix/context.h index 072ab5dfc2..eaa0bfcf0a 100644 --- a/src/include/simix/context.h +++ b/src/include/simix/context.h @@ -10,7 +10,7 @@ #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 */ -#include "simix/simix.h" +#include "simgrid/simix.h" SG_BEGIN_DECL() diff --git a/src/instr/instr_msg_process.c b/src/instr/instr_msg_process.c index fc96c0cd86..c1a8154f46 100644 --- a/src/instr/instr_msg_process.c +++ b/src/instr/instr_msg_process.c @@ -45,7 +45,7 @@ void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_hos PJ_container_free(existing_container); //create new container on the new_host location - msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(new_host->name)); + msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(SIMIX_host_get_name(new_host->smx_host))); //end link msg = PJ_container_get(instr_process_id(process, str, len)); @@ -60,7 +60,7 @@ void TRACE_msg_process_create (const char *process_name, int process_pid, m_host int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; - container_t host_container = PJ_container_get (host->name); + container_t host_container = PJ_container_get (SIMIX_host_get_name(host->smx_host)); PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container); } } diff --git a/src/mc/mc_private.h b/src/mc/mc_private.h index 9481343e5f..09e8932ec1 100644 --- a/src/mc/mc_private.h +++ b/src/mc/mc_private.h @@ -19,7 +19,6 @@ #include "xbt/hash.h" #include "msg/msg.h" #include "msg/datatypes.h" -#include "simix/datatypes.h" /****************************** Snapshots ***********************************/ diff --git a/src/msg/msg_config.c b/src/msg/msg_config.c index 733d2bf359..c993773be6 100644 --- a/src/msg/msg_config.c +++ b/src/msg/msg_config.c @@ -7,7 +7,7 @@ #include "msg_private.h" #include "xbt/sysdep.h" #include "xbt/log.h" -#include "simix/simix.h" +#include "simgrid/simix.h" /** \brief set a configuration variable * diff --git a/src/msg/msg_environment.c b/src/msg/msg_environment.c index c263080a62..5814f78189 100644 --- a/src/msg/msg_environment.c +++ b/src/msg/msg_environment.c @@ -43,7 +43,7 @@ void MSG_create_environment(const char *file) /* Initialize MSG hosts */ xbt_lib_foreach(host_lib, cursor, name, data) { if(data[SIMIX_HOST_LEVEL]) - __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL], NULL); + __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL]); } } diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 8e6d1d1f0f..5081378556 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -53,7 +53,7 @@ MSG_error_t MSG_task_execute(m_task_t task) p_simdata = SIMIX_process_self_get_data(self); simdata->isused=1; simdata->compute = - simcall_host_execute(task->name, p_simdata->m_host->simdata->smx_host, + simcall_host_execute(task->name, p_simdata->m_host->smx_host, simdata->computation_amount, simdata->priority); #ifdef HAVE_TRACING @@ -146,7 +146,7 @@ MSG_parallel_task_create(const char *name, int host_nb, simdata->comm_amount = communication_amount; for (i = 0; i < host_nb; i++) - simdata->host_list[i] = host_list[i]->simdata->smx_host; + simdata->host_list[i] = host_list[i]->smx_host; return task; } @@ -175,7 +175,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) xbt_assert(simdata->host_nb, "This is not a parallel task. Go to hell."); - XBT_DEBUG("Parallel computing on %s", p_simdata->m_host->name); + XBT_DEBUG("Parallel computing on %s", SIMIX_host_get_name(p_simdata->m_host->smx_host)); simdata->isused=1; @@ -383,12 +383,15 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias) * * \param task a #m_task_t to send on another location. * \param alias name of the mailbox to sent the task to - * \param match_fun boolean function taking the match_data provided by sender (here), and the one of the receiver (if any) and returning whether they match + * \param match_fun boolean function which parameters are: + * - match_data_provided_here + * - match_data_provided_by_other_side_if_any + * - the_smx_action_describing_the_other_side * \param match_data user provided data passed to match_fun * \return the msg_comm_t communication created */ XBT_INLINE msg_comm_t MSG_task_isend_with_matching(m_task_t task, const char *alias, - int (*match_fun)(void*,void*), + int (*match_fun)(void*,void*, smx_action_t), void *match_data) { simdata_task_t t_simdata = NULL; diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index ce32fdf887..a683d423bb 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -23,37 +23,29 @@ */ /********************************* Host **************************************/ -m_host_t __MSG_host_create(smx_host_t workstation, void *data) +m_host_t __MSG_host_create(smx_host_t workstation) { - const char *name; - simdata_host_t simdata = xbt_new0(s_simdata_host_t, 1); + const char *name = SIMIX_host_get_name(workstation); m_host_t host = xbt_new0(s_m_host_t, 1); - name = SIMIX_host_get_name(workstation); - /* Host structure */ - host->name = xbt_strdup(name); - host->simdata = simdata; - host->data = data; - - simdata->smx_host = workstation; + host->smx_host = workstation; #ifdef MSG_USE_DEPRECATED int i; char alias[MAX_ALIAS_NAME + 1] = { 0 }; /* buffer used to build the key of the mailbox */ if (msg_global->max_channel > 0) - simdata->mailboxes = xbt_new0(msg_mailbox_t, msg_global->max_channel); + host->mailboxes = xbt_new0(msg_mailbox_t, msg_global->max_channel); for (i = 0; i < msg_global->max_channel; i++) { sprintf(alias, "%s:%d", name, i); /* the key of the mailbox (in this case) is build from the name of the host and the channel number */ - simdata->mailboxes[i] = MSG_mailbox_new(alias); + host->mailboxes[i] = MSG_mailbox_new(alias); memset(alias, 0, MAX_ALIAS_NAME + 1); } #endif - simcall_host_set_data(workstation, host); xbt_lib_set(host_lib,name,MSG_HOST_LEVEL,host); return host; @@ -68,16 +60,9 @@ m_host_t __MSG_host_create(smx_host_t workstation, void *data) */ m_host_t MSG_get_host_by_name(const char *name) { - smx_host_t simix_h = NULL; - simix_h = simcall_host_get_by_name(name); - - if (simix_h == NULL) - return NULL; - - return (m_host_t) simcall_host_get_data(simix_h); + return (m_host_t) xbt_lib_get_or_null(host_lib,name,MSG_HOST_LEVEL); } - /** \ingroup m_host_management * * \brief Set the user data of a #m_host_t. @@ -87,11 +72,7 @@ m_host_t MSG_get_host_by_name(const char *name) */ MSG_error_t MSG_host_set_data(m_host_t host, void *data) { - xbt_assert((host != NULL), "Invalid parameters"); - xbt_assert((host->data == NULL), "Data already set"); - - /* Assign data */ - host->data = data; + SIMIX_host_set_data(host->smx_host,data); return MSG_OK; } @@ -105,11 +86,7 @@ MSG_error_t MSG_host_set_data(m_host_t host, void *data) */ void *MSG_host_get_data(m_host_t host) { - - xbt_assert((host != NULL), "Invalid parameters"); - - /* Return data */ - return (host->data); + return SIMIX_host_get_data(host->smx_host); } /** \ingroup m_host_management @@ -119,14 +96,8 @@ void *MSG_host_get_data(m_host_t host) * This functions checks whether \a host is a valid pointer or not and return its name. */ -const char *MSG_host_get_name(m_host_t host) -{ - - xbt_assert((host != NULL) - && (host->simdata != NULL), "Invalid parameters"); - - /* Return data */ - return (host->name); +const char *MSG_host_get_name(m_host_t host) { + return SIMIX_host_get_name(host->smx_host); } /** \ingroup m_host_management @@ -140,26 +111,15 @@ m_host_t MSG_host_self(void) /** \ingroup m_host_management * - * \brief Destroys a host + * \brief Destroys a host (internal call only) */ -void __MSG_host_destroy(m_host_t host) -{ - simdata_host_t simdata = NULL; - - xbt_assert((host != NULL), "Invalid parameters"); - - /* Clean simulator data */ - simdata = (host)->simdata; +void __MSG_host_destroy(m_host_t host) { #ifdef MSG_USE_DEPRECATED if (msg_global->max_channel > 0) - free(simdata->mailboxes); + free(host->mailboxes); #endif - free(simdata); - - /* Clean host structure */ - free(host->name); free(host); } @@ -227,7 +187,7 @@ double MSG_get_host_speed(m_host_t h) { xbt_assert((h != NULL), "Invalid parameters"); - return (simcall_host_get_speed(h->simdata->smx_host)); + return (simcall_host_get_speed(h->smx_host)); } /** \ingroup m_host_management @@ -252,7 +212,7 @@ xbt_dict_t MSG_host_get_properties(m_host_t host) { xbt_assert((host != NULL), "Invalid parameters (host is NULL)"); - return (simcall_host_get_properties(host->simdata->smx_host)); + return (simcall_host_get_properties(host->smx_host)); } @@ -265,5 +225,5 @@ xbt_dict_t MSG_host_get_properties(m_host_t host) int MSG_host_is_avail(m_host_t host) { xbt_assert((host != NULL), "Invalid parameters (host is NULL)"); - return (simcall_host_get_state(host->simdata->smx_host)); + return (simcall_host_get_state(host->smx_host)); } diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index 7279654fc4..9b94299312 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -41,7 +41,7 @@ MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, m_host_t host) { return simcall_rdv_comm_count_by_host(mailbox, - host->simdata->smx_host); + host->smx_host); } msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias) diff --git a/src/msg/msg_mailbox.h b/src/msg/msg_mailbox.h index cdfe0e6ab0..851e77ce3a 100644 --- a/src/msg/msg_mailbox.h +++ b/src/msg/msg_mailbox.h @@ -8,7 +8,7 @@ #define MSG_MAILBOX_H #include "xbt/fifo.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "msg/datatypes.h" diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index c9663621e7..55a22d6346 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -8,7 +8,7 @@ #define METASIMGRID_PRIVATE_H #include "msg/msg.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "surf/surf.h" #include "xbt/fifo.h" #include "xbt/dynar.h" @@ -20,10 +20,6 @@ SG_BEGIN_DECL() /**************** datatypes **********************************/ -typedef struct simdata_host { - smx_host_t smx_host; /* SURF modeling */ - msg_mailbox_t *mailboxes; /* mailboxes to store msg tasks of of the host */ -} s_simdata_host_t; /********************************* Task **************************************/ @@ -125,7 +121,7 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; # define MSG_RETURN(val) return(val) #endif -m_host_t __MSG_host_create(smx_host_t workstation, void *data); +m_host_t __MSG_host_create(smx_host_t workstation); void __MSG_host_destroy(m_host_t host); void __MSG_display_process_status(void); diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index e8bf1b7202..6e9a904896 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -176,7 +176,7 @@ m_process_t MSG_process_create_with_environment(const char *name, /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ - simcall_process_create(&process, name, code, simdata, host->name, kill_time, + simcall_process_create(&process, name, code, simdata, SIMIX_host_get_name(host->smx_host), kill_time, argc, argv, properties); if (!process) { @@ -233,7 +233,7 @@ MSG_error_t MSG_process_migrate(m_process_t process, m_host_t host) m_host_t now = simdata->m_host; TRACE_msg_process_change_host(process, now, host); #endif - simcall_process_change_host(process, host->simdata->smx_host); + simcall_process_change_host(process, host->smx_host); return MSG_OK; } diff --git a/src/simix/smx_context_base.c b/src/simix/smx_context_base.c index dc1fe2d194..616f669a2b 100644 --- a/src/simix/smx_context_base.c +++ b/src/simix/smx_context_base.c @@ -8,7 +8,7 @@ #include "xbt/function_types.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "simix/context.h" #include "smx_private.h" diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 55efda3f87..66d587e5a5 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -7,7 +7,7 @@ #ifndef _SIMIX_HOST_PRIVATE_H #define _SIMIX_HOST_PRIVATE_H -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "smx_smurf_private.h" /** @brief Host datatype */ diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index f38cd9bdba..945538d5f4 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -7,7 +7,7 @@ #ifndef _SIMIX_IO_PRIVATE_H #define _SIMIX_IO_PRIVATE_H -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "smx_smurf_private.h" void SIMIX_pre_file_read(smx_simcall_t simcall); diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index db189293bd..82a372fced 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -20,7 +20,8 @@ static void SIMIX_comm_copy_data(smx_action_t comm); static smx_action_t SIMIX_comm_new(e_smx_comm_type_t type); static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm); static smx_action_t SIMIX_rdv_get_comm(smx_rdv_t rdv, e_smx_comm_type_t type, - int (*match_fun)(void *, void *), void *); + int (*match_fun)(void *, void *,smx_action_t), + void *user_data, smx_action_t my_action); static void SIMIX_rdv_free(void *data); void SIMIX_network_init(void) @@ -118,33 +119,28 @@ XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm) comm->comm.rdv = NULL; } -/** - * \brief Wrapper to SIMIX_rdv_get_comm - */ -smx_action_t SIMIX_comm_get_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) { - return SIMIX_rdv_get_comm(rdv, SIMIX_COMM_SEND, match_fun, data); -} - /** * \brief Checks if there is a communication action 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 action if found, NULL otherwise */ smx_action_t SIMIX_rdv_get_comm(smx_rdv_t rdv, e_smx_comm_type_t type, - int (*match_fun)(void *, void *), void *data) + int (*match_fun)(void *, void *,smx_action_t), + void *this_user_data, smx_action_t my_action) { - // FIXME rewrite this function by using SIMIX_rdv_has_send/recv_match smx_action_t action; xbt_fifo_item_t item; - void* comm_data = NULL; + void* other_user_data = NULL; xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t) { if (action->comm.type == SIMIX_COMM_SEND) { - comm_data = action->comm.src_data; + other_user_data = action->comm.src_data; } else if (action->comm.type == SIMIX_COMM_RECEIVE) { - comm_data = action->comm.dst_data; + other_user_data = action->comm.dst_data; } - if (action->comm.type == type && (!match_fun || match_fun(data, comm_data))) { + if (action->comm.type == type && + (!match_fun || match_fun(this_user_data, other_user_data, action)) && + (!action->comm.match_fun || action->comm.match_fun(other_user_data, this_user_data, my_action))) { XBT_DEBUG("Found a matching communication action %p", action); xbt_fifo_remove_item(rdv->comm_fifo, item); xbt_fifo_free_item(item); @@ -153,63 +149,22 @@ smx_action_t SIMIX_rdv_get_comm(smx_rdv_t rdv, e_smx_comm_type_t type, return action; } XBT_DEBUG("Sorry, communication action %p does not match our needs:" - " its type is %d but we are looking for a comm of type %d", + " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)", action, (int)action->comm.type, (int)type); } XBT_DEBUG("No matching communication action found"); return NULL; } -/** - * \brief Checks if there is a send communication action - * queued in a rendez-vous matching our needs. - * \return 1 if found, 0 otherwise - */ -int SIMIX_comm_has_send_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) { - - smx_action_t action; - xbt_fifo_item_t item; - - xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t){ - if (action->comm.type == SIMIX_COMM_SEND - && (!match_fun || match_fun(data, action->comm.src_data))) { - XBT_DEBUG("Found a matching communication action %p", action); - return 1; - } - } - XBT_DEBUG("No matching communication action found"); - return 0; -} - -/** - * \brief Checks if there is a recv communication action - * queued in a rendez-vous matching our needs. - * \return 1 if found, 0 otherwise - */ -int SIMIX_comm_has_recv_match(smx_rdv_t rdv, int (*match_fun)(void*, void*), void* data) { - - smx_action_t action; - xbt_fifo_item_t item; - - xbt_fifo_foreach(rdv->comm_fifo, item, action, smx_action_t) { - if (action->comm.type == SIMIX_COMM_RECEIVE - && (!match_fun || match_fun(data, action->comm.dst_data))) { - XBT_DEBUG("Found a matching communication action %p", action); - return 1; - } - } - XBT_DEBUG("No matching communication action found"); - return 0; -} /******************************************************************************/ -/* Comunication Actions */ +/* Communication Actions */ /******************************************************************************/ /** - * \brief Creates a new comunicate action + * \brief Creates a new communicate action * \param type The direction of communication (comm_send, comm_recv) - * \return The new comunicate action + * \return The new communicate action */ smx_action_t SIMIX_comm_new(e_smx_comm_type_t type) { @@ -303,86 +258,101 @@ void SIMIX_comm_destroy_internal_actions(smx_action_t action) smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *,smx_action_t), void (*clean_fun)(void *), // used to free the action in case of problem after a detached send void *data, int detached) { - smx_action_t action; + /* Prepare an action describing us, so that it gets passed to the user-provided filter of other side */ + smx_action_t this_action = SIMIX_comm_new(SIMIX_COMM_SEND); - /* Look for communication action matching our needs. - If it is not found then create it and push it into the rendez-vous point */ - action = SIMIX_rdv_get_comm(rdv, SIMIX_COMM_RECEIVE, match_fun, data); + /* Look for communication action matching our needs. We also provide a description of + * ourself so that the other side also gets a chance of choosing if it wants to match with us. + * + * If it is not found then push our communication into the rendez-vous point */ + smx_action_t other_action = SIMIX_rdv_get_comm(rdv, SIMIX_COMM_RECEIVE, match_fun, data, this_action); - if (!action) { - action = SIMIX_comm_new(SIMIX_COMM_SEND); - SIMIX_rdv_push(rdv, action); + if (!other_action) { + other_action = this_action; + SIMIX_rdv_push(rdv, this_action); } else { - action->state = SIMIX_READY; - action->comm.type = SIMIX_COMM_READY; + SIMIX_comm_destroy(this_action); + --smx_total_comms; // this creation was a pure waste + + other_action->state = SIMIX_READY; + other_action->comm.type = SIMIX_COMM_READY; } - xbt_fifo_push(src_proc->comms, action); + xbt_fifo_push(src_proc->comms, other_action); /* if the communication action is detached then decrease the refcount * by one, so it will be eliminated by the receiver's destroy call */ if (detached) { - action->comm.detached = 1; - action->comm.refcount--; - action->comm.clean_fun = clean_fun; + other_action->comm.detached = 1; + other_action->comm.refcount--; + other_action->comm.clean_fun = clean_fun; } else { - action->comm.clean_fun = NULL; + other_action->comm.clean_fun = NULL; } /* Setup the communication action */ - action->comm.src_proc = src_proc; - action->comm.task_size = task_size; - action->comm.rate = rate; - action->comm.src_buff = src_buff; - action->comm.src_buff_size = src_buff_size; - action->comm.src_data = data; + other_action->comm.src_proc = src_proc; + other_action->comm.task_size = task_size; + other_action->comm.rate = rate; + other_action->comm.src_buff = src_buff; + other_action->comm.src_buff_size = src_buff_size; + other_action->comm.src_data = data; + + other_action->comm.match_fun = match_fun; if (MC_IS_ENABLED) { - action->state = SIMIX_RUNNING; - return action; + other_action->state = SIMIX_RUNNING; + return other_action; } - SIMIX_comm_start(action); - return (detached ? NULL : action); + SIMIX_comm_start(other_action); + return (detached ? NULL : other_action); } smx_action_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size, - int (*match_fun)(void *, void *), void *data) + int (*match_fun)(void *, void *, smx_action_t), void *data) { - smx_action_t action; + /* Prepare an action describing us, so that it gets passed to the user-provided filter of other side */ + smx_action_t this_action = SIMIX_comm_new(SIMIX_COMM_RECEIVE); - /* Look for communication action matching our needs. - * If it is not found then create it and push it into the rendez-vous point - */ - action = SIMIX_rdv_get_comm(rdv, SIMIX_COMM_SEND, match_fun, data); + /* Look for communication action matching our needs. We also provide a description of + * ourself so that the other side also gets a chance of choosing if it wants to match with us. + * + * If it is not found then push our communication into the rendez-vous point */ + smx_action_t other_action = SIMIX_rdv_get_comm(rdv, SIMIX_COMM_SEND, match_fun, data, this_action); - if (!action) { - action = SIMIX_comm_new(SIMIX_COMM_RECEIVE); - SIMIX_rdv_push(rdv, action); + if (!other_action) { + other_action = this_action; + SIMIX_rdv_push(rdv, this_action); } else { - action->state = SIMIX_READY; - action->comm.type = SIMIX_COMM_READY; + SIMIX_comm_destroy(this_action); + --smx_total_comms; // this creation was a pure waste + + other_action->state = SIMIX_READY; + other_action->comm.type = SIMIX_COMM_READY; } - xbt_fifo_push(dst_proc->comms, action); + xbt_fifo_push(dst_proc->comms, other_action); /* Setup communication action */ - action->comm.dst_proc = dst_proc; - action->comm.dst_buff = dst_buff; - action->comm.dst_buff_size = dst_buff_size; - action->comm.dst_data = data; + other_action->comm.dst_proc = dst_proc; + other_action->comm.dst_buff = dst_buff; + other_action->comm.dst_buff_size = dst_buff_size; + other_action->comm.dst_data = data; + + other_action->comm.match_fun = match_fun; if (MC_IS_ENABLED) { - action->state = SIMIX_RUNNING; - return action; + other_action->state = SIMIX_RUNNING; + return other_action; } - SIMIX_comm_start(action); - return action; + SIMIX_comm_start(other_action); + return other_action; } void SIMIX_pre_comm_wait(smx_simcall_t simcall, smx_action_t action, double timeout, int idx) diff --git a/src/simix/smx_network_private.h b/src/simix/smx_network_private.h index d9e2fcfbdd..d14ec57ce5 100644 --- a/src/simix/smx_network_private.h +++ b/src/simix/smx_network_private.h @@ -7,7 +7,7 @@ #ifndef _SIMIX_NETWORK_PRIVATE_H #define _SIMIX_NETWORK_PRIVATE_H -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "smx_smurf_private.h" /** @brief Rendez-vous point datatype */ @@ -34,22 +34,22 @@ void SIMIX_comm_start(smx_action_t action); void SIMIX_comm_send(smx_process_t src_proc, smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*)(void *, void *), void *data, + int (*match_fun)(void *, void *,smx_action_t), void *data, double timeout); smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void (*clean_fun)(void *), // used to free the action in case of problem after a detached send void *data, int detached); void SIMIX_comm_recv(smx_process_t dst_proc, smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size, - int (*)(void *, void *), void *data, + int (*)(void *, void *,smx_action_t), void *data, double timeout); smx_action_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size, - int (*)(void *, void *), void *data); + int (*)(void *, void *, smx_action_t), void *data); void SIMIX_comm_destroy(smx_action_t action); void SIMIX_comm_destroy_internal_actions(smx_action_t action); void SIMIX_pre_comm_wait(smx_simcall_t simcall, smx_action_t action, double timeout, int idx); diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 824239f438..b19e966584 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -7,7 +7,7 @@ #ifndef _SIMIX_PRIVATE_H #define _SIMIX_PRIVATE_H -#include "simix/simix.h" +#include "simgrid/simix.h" #include "surf/surf.h" #include "xbt/fifo.h" #include "xbt/swag.h" @@ -123,6 +123,9 @@ typedef struct s_smx_action { int detached; /* If detached or not */ void (*clean_fun)(void*); /* Function to clean the detached src_buf if something goes wrong */ + int (*match_fun)(void*,void*,smx_action_t); /* Filter function used by the other side. It is used when + looking if a given communication matches my needs. For that, myself must match the + expectations of the other side, too. See */ /* Surf action data */ surf_action_t surf_comm; /* The Surf communication action encapsulated */ diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index d5295c957d..2b9359be0a 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -7,7 +7,7 @@ #ifndef _SIMIX_PROCESS_PRIVATE_H #define _SIMIX_PROCESS_PRIVATE_H -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "smx_smurf_private.h" /** @brief Process datatype */ diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index c16c605e9b..13233a778b 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -320,7 +320,7 @@ typedef struct s_smx_simcall { double rate; void *src_buff; size_t src_buff_size; - int (*match_fun)(void *, void *); + int (*match_fun)(void *, void *, smx_action_t); void *data; double timeout; } comm_send; @@ -331,7 +331,7 @@ typedef struct s_smx_simcall { double rate; void *src_buff; size_t src_buff_size; - int (*match_fun)(void *, void *); + int (*match_fun)(void *, void *, smx_action_t); void (*clean_fun)(void *); void *data; int detached; @@ -342,7 +342,7 @@ typedef struct s_smx_simcall { smx_rdv_t rdv; void *dst_buff; size_t *dst_buff_size; - int (*match_fun)(void *, void *); + int (*match_fun)(void *, void *, smx_action_t); void *data; double timeout; } comm_recv; @@ -351,8 +351,8 @@ typedef struct s_smx_simcall { smx_rdv_t rdv; void *dst_buff; size_t *dst_buff_size; - int (*match_fun)(void *, void *); - void *data; + int (*match_fun)(void *, void *, smx_action_t); + void *data; smx_action_t result; } comm_irecv; diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 2663088b9d..455b98d52a 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -700,7 +700,7 @@ smx_action_t simcall_rdv_get_head(smx_rdv_t rdv) void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), void *data, + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout) { /* checking for infinite values */ @@ -735,7 +735,7 @@ void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate, smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate, void *src_buff, size_t src_buff_size, - int (*match_fun)(void *, void *), + int (*match_fun)(void *, void *, smx_action_t), void (*clean_fun)(void *), void *data, int detached) @@ -764,7 +764,7 @@ smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate, } void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), void *data, double timeout) + int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout) { xbt_assert(isfinite(timeout), "timeout is not finite!"); xbt_assert(rdv, "No rendez-vous point defined for recv"); @@ -791,7 +791,7 @@ void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, } smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size, - int (*match_fun)(void *, void *), void *data) + int (*match_fun)(void *, void *, smx_action_t), void *data) { xbt_assert(rdv, "No rendez-vous point defined for irecv"); diff --git a/src/smpi/private.h b/src/smpi/private.h index 6105faaa10..a01ffef124 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -9,7 +9,7 @@ #include "xbt.h" #include "xbt/xbt_os_time.h" -#include "simix/simix.h" +#include "simgrid/simix.h" #include "smpi/smpi.h" #include "smpi/smpif.h" #include "smpi/smpi_cocci.h" diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index d27f40c666..d98b98af9a 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)"); -static int match_recv(void* a, void* b) { +static int match_recv(void* a, void* b, smx_action_t ignored) { MPI_Request ref = (MPI_Request)a; MPI_Request req = (MPI_Request)b; @@ -21,7 +21,7 @@ static int match_recv(void* a, void* b) { && (ref->tag == MPI_ANY_TAG || req->tag == ref->tag); } -static int match_send(void* a, void* b) { +static int match_send(void* a, void* b,smx_action_t ignored) { MPI_Request ref = (MPI_Request)a; MPI_Request req = (MPI_Request)b; diff --git a/src/xbt/xbt_sg_synchro.c b/src/xbt/xbt_sg_synchro.c index db92f6556a..d485ba37ed 100644 --- a/src/xbt/xbt_sg_synchro.c +++ b/src/xbt/xbt_sg_synchro.c @@ -13,8 +13,7 @@ #include "xbt/synchro.h" /* This module */ -#include "simix/simix.h" /* used implementation */ -#include "simix/datatypes.h" +#include "simgrid/simix.h" /* used implementation */ #include "../simix/smx_private.h" /* FIXME */ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt, diff --git a/src/xbt/xbt_sg_time.c b/src/xbt/xbt_sg_time.c index 726b0c2a9a..8a3722f3fd 100644 --- a/src/xbt/xbt_sg_time.c +++ b/src/xbt/xbt_sg_time.c @@ -7,7 +7,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "gras/Virtu/virtu_sg.h" -#include "simix/simix.h" +#include "simgrid/simix.h" /* * Time elapsed since the begining of the simulation. diff --git a/tools/gras/struct_diff.c b/tools/gras/struct_diff.c index edb9aeca97..8e25f90e94 100644 --- a/tools/gras/struct_diff.c +++ b/tools/gras/struct_diff.c @@ -18,7 +18,7 @@ #include "xbt/datadesc.h" #include "xbt/file_stat.h" #include "../../src/xbt/datadesc/datadesc_private.h" // RAAAAH! ugly relative path, but it's late, I want it to be done NOW. -#include "simix/datatypes.h" +#include "simgrid/simix.h" #include "../../src/simix/smx_smurf_private.h" // RAAAAH! ugly relative path, but it's even later and it still doesn't work static void define_types(void) {