/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
-
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-
-#include <stdio.h>
-#include <stdlib.h>
+#include "simgrid/msg.h"
/** @addtogroup MSG_examples
*
- * - <b>properties/msg_prop.c</b> Attaching arbitrary informations to
- * host, processes and such, and retrieving them with @ref
- * MSG_host_get_properties, @ref MSG_host_get_property_value, @ref
- * MSG_process_get_properties and @ref
- * MSG_process_get_property_value. Also make sure to read the
- * platform and deployment XML files to see how to declare these
- * data.
- *
+ * - <b>properties/msg_prop.c</b> Attaching arbitrary informations to host, processes and such, and retrieving them
+ * with @ref MSG_host_get_properties, @ref MSG_host_get_property_value, @ref MSG_process_get_properties and
+ * @ref MSG_process_get_property_value. Also make sure to read the platform and deployment XML files to see how to
+ * declare these data.
*/
XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
-int alice(int argc, char *argv[]);
-int bob(int argc, char *argv[]);
-int carole(int argc, char *argv[]);
-int david(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
static void test_host(const char*hostname)
{
msg_host_t thehost = MSG_host_by_name(hostname);
XBT_INFO("== Print the properties of the host '%s'", hostname);
xbt_dict_foreach(props, cursor, key, data)
- XBT_INFO(" Host property: '%s' -> '%s'", key, data);
+ XBT_INFO(" Host property: '%s' -> '%s'", key, data);
XBT_INFO("== Try to get a host property that does not exist");
value = MSG_host_get_property_value(thehost, noexist);
XBT_INFO("== Try to get a host property that does exist");
value = MSG_host_get_property_value(thehost, exist);
- xbt_assert(value, "\tProperty %s is undefined (where it should)",
- exist);
- xbt_assert(!strcmp(value, "180"),
- "\tValue of property %s is defined to %s (where it should be 180)",
- exist, value);
+ xbt_assert(value, "\tProperty %s is undefined (where it should)", exist);
+ xbt_assert(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value);
XBT_INFO(" Property: %s old value: %s", exist, value);
XBT_INFO("== Trying to modify a host property");
/* Test if we have changed the value */
value = MSG_host_get_property_value(thehost, exist);
xbt_assert(value, "Property %s is undefined (where it should)", exist);
- xbt_assert(!strcmp(value, "250"),
- "Value of property %s is defined to %s (where it should be 250)",
- exist, value);
+ xbt_assert(!strcmp(value, "250"), "Value of property %s is defined to %s (where it should be 250)", exist, value);
XBT_INFO(" Property: %s old value: %s", exist, value);
/* Restore the value for the next test */
MSG_host_set_property_value(thehost, exist, xbt_strdup("180"), xbt_free_f);
}
-int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
+static int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
test_host("host1");
return 0;
}
-int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */
+
+static int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */
MSG_process_sleep(1); // Wait for alice to be done with its experiment
test_host("host1");
return 0;
}
-int david(int argc, char *argv[]) {/* Dump what we have on a remote host */
+
+static int david(int argc, char *argv[]) {/* Dump what we have on a remote host */
MSG_process_sleep(2); // Wait for alice and carole to be done with its experiment
test_host("node-0.acme.org");
return 0;
}
-int bob(int argc, char *argv[])
+static int bob(int argc, char *argv[])
{
/* Get the property list of current bob process */
xbt_dict_t props = MSG_process_get_properties(MSG_process_self());
XBT_INFO("== Print the properties of the process");
xbt_dict_foreach(props, cursor, key, data)
- XBT_INFO(" Process property: %s -> %s", key, data);
+ XBT_INFO(" Process property: %s -> %s", key, data);
XBT_INFO("== Try to get a process property that does not exist");
return 0;
}
-/** Test function */
-msg_error_t test_all(const char *platform_file,
- const char *application_file)
+int main(int argc, char *argv[])
{
- int host_number;
+ msg_error_t res = MSG_OK;
unsigned int i;
xbt_dynar_t hosts;
msg_host_t host;
- msg_error_t ret;
+
+ MSG_init(&argc, argv);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
MSG_function_register("alice", alice);
MSG_function_register("bob", bob);
MSG_function_register("carole", carole);
MSG_function_register("david", david);
- MSG_create_environment(platform_file);
+ MSG_create_environment(argv[1]);
- host_number = MSG_get_host_number();
- XBT_INFO("There are %d hosts in the environment", host_number);
+ XBT_INFO("There are %d hosts in the environment", MSG_get_host_number());
hosts = MSG_hosts_as_dynar();
xbt_dynar_foreach(hosts, i, host){
- XBT_INFO("Host '%s' runs at %.0f flops/s",MSG_host_get_name(host),
- MSG_get_host_speed(host));
+ XBT_INFO("Host '%s' runs at %.0f flops/s",MSG_host_get_name(host), MSG_get_host_speed(host));
}
- MSG_launch_application(application_file);
+ MSG_launch_application(argv[2]);
- ret = MSG_main();
+ res = MSG_main();
xbt_dynar_free(&hosts);
- return ret;
-} /* end_of_test_all */
-
-
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
-
- MSG_init(&argc, argv);
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s msg_platform.xml msg_deployment.xml\n",
- argv[0], argv[0]);
-
- res = test_all(argv[1], argv[2]);
-
- return res != MSG_OK;
+ return res!=MSG_OK;
}
/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
static int my_onexit(void* ignored1, void *ignored2) {
XBT_INFO("Exiting now (done sleeping or got killed).");
return 0;
}
-/** Test function */
-static msg_error_t test_all(const char *platform_file,
- const char *application_file)
+int main(int argc, char *argv[])
{
msg_error_t res = MSG_OK;
- MSG_create_environment(platform_file);
+ MSG_init(&argc, argv);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
MSG_function_register("sleeper", sleeper);
- MSG_launch_application(application_file);
+ MSG_launch_application(argv[2]);
res = MSG_main();
-
XBT_INFO("Simulation time %g", MSG_get_clock());
- return res;
-} /* end_of_test_all */
-
-
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
-
- MSG_init(&argc, argv);
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s msg_platform.xml msg_deployment.xml\n",
- argv[0], argv[0]);
-
- test_all(argv[1], argv[2]);
-
return res != MSG_OK;
}
${tesh_files}
${CMAKE_CURRENT_SOURCE_DIR}/suspend.tesh
PARENT_SCOPE)
-set(xml_files
- ${xml_files}
- ${CMAKE_CURRENT_SOURCE_DIR}/deployment_suspend.xml
- PARENT_SCOPE)
set(examples_src
${examples_src}
${CMAKE_CURRENT_SOURCE_DIR}/suspend.c
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
-<platform version="4">
- <process host="Jacquelin" function="dream_master"/>
-</platform>
/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
#define SLEEP(duration) \
if (MSG_process_sleep(duration) != MSG_OK) \
- xbt_die("What's going on??? I failed to sleep!"); \
- else \
- (void)0
+ xbt_die("What's going on??? I failed to sleep!");
/** @addtogroup MSG_examples
*
- * - <b>suspend/suspend.c</b>: Demonstrates how to suspend and resume processes using @ref MSG_process_suspend and @ref MSG_process_resume.
+ * - <b>suspend/suspend.c</b>: Demonstrates how to suspend and resume processes using
+ * @ref MSG_process_suspend and @ref MSG_process_resume.
*/
/** Lazy guy function. This process suspends itself asap. */
return 0;
} /* end_of_lazy_guy */
-/** Dream master function. This process creates a lazy_guy process and
- resumes it 10 seconds later. */
+/** Dream master function. This process creates a lazy_guy process and resumes it 10 seconds later. */
static int dream_master(int argc, char *argv[])
{
msg_process_t lazy = NULL;
XBT_INFO("OK, goodbye now.");
return 0;
-} /* end_of_dram_master */
+} /* end_of_dream_master */
-/** Test function */
-static msg_error_t test_all(const char *platform_file,
- const char *application_file)
-{
- msg_error_t res = MSG_OK;
-
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("dream_master", dream_master);
- MSG_launch_application(application_file);
- }
- res = MSG_main();
-
- XBT_INFO("Simulation time %g", MSG_get_clock());
- return res;
-} /* end_of_test_all */
-
-
-/** Main function */
int main(int argc, char *argv[])
{
msg_error_t res = MSG_OK;
MSG_init(&argc, argv);
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s msg_platform.xml msg_deployment_suspend.xml\n",
- argv[0], argv[0]);
+ xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
- test_all(argv[1], argv[2]);
+ MSG_create_environment(argv[1]);
+ MSG_function_register("dream_master", dream_master);
+ MSG_process_create("dream_master", dream_master, NULL, xbt_dynar_getfirst_as(MSG_hosts_as_dynar(), msg_host_t));
+ res = MSG_main();
+ XBT_INFO("Simulation time %g", MSG_get_clock());
return res != MSG_OK;
}
p Testing the suspend/resume feature of MSG
! output sort 19
-$ $SG_TEST_EXENV suspend/suspend ${srcdir:=.}/../platforms/platform.xml ${srcdir:=.}/suspend/deployment_suspend.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ $SG_TEST_EXENV suspend/suspend ${srcdir:=.}/../platforms/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (1:dream_master@Jacquelin) Let's create a lazy guy.
> [ 0.000000] (1:dream_master@Jacquelin) Let's wait a little bit...
> [ 0.000000] (2:Lazy@Jacquelin) Nobody's watching me ? Let's go to sleep.
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
-int host(int argc, char *argv[]);
-unsigned int task_comp_size = 50000000;
-unsigned int task_comm_size = 1000000;
-
-int nb_hosts; /* All declared hosts */
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(ring, "Messages specific for this msg example");
/** @addtogroup MSG_examples
*
* @section MSG_ex_apps Examples of full applications
*
- * - <b>token_ring/ring_call.c</b>: Classical token ring
- * communication, where a token is exchanged along a ring to reach
- * every participant.
- *
+ * - <b>token_ring/ring_call.c</b>: Classical token ring communication, where a token is exchanged along a ring to
+ * reach every participant.
*/
-int host(int argc, char *argv[])
+static int host(int argc, char *argv[])
{
- int host_number = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s");
+ unsigned int task_comp_size = 50000000;
+ unsigned int task_comm_size = 1000000;
+ int host_number =
+ xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s");
char mailbox[256];
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
xbt_assert(res == MSG_OK, "MSG_task_get failed");
XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
MSG_task_destroy(task);
- }
- else{ //slave receive then send
+ } else{ //slave receive then send
res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
xbt_assert(res == MSG_OK, "MSG_task_get failed");
XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
- if(host_number+1 == nb_hosts)
+ if(host_number+1 == MSG_get_host_number())
sprintf(mailbox, "0");
else
sprintf(mailbox, "%d", host_number+1);
int main(int argc, char **argv)
{
- int i,res;
+ unsigned int i;
MSG_init(&argc, argv);
MSG_create_environment(argv[1]);
xbt_dynar_t hosts = MSG_hosts_as_dynar();
- nb_hosts = xbt_dynar_length(hosts);
+ msg_host_t h;
MSG_function_register("host", host);
- XBT_INFO("Number of host '%d'",nb_hosts);
- for(i = 0 ; i<nb_hosts; i++)
- {
- char* name_host = bprintf("%d",i);
- MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
+ XBT_INFO("Number of host '%d'",MSG_get_host_number());
+ xbt_dynar_foreach (hosts, i, h){
+ char* name_host = bprintf("%u",i);
+ MSG_process_create(name_host, host, NULL, h);
free(name_host);
}
xbt_dynar_free(&hosts);
- res = MSG_main();
+ int res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
return res != MSG_OK;
}