* msg/icomms/peer2.c: demonstrates the MSG_comm_waitall() function
* msg/icomms/peer3.c: demonstrates the MSG_comm_waitany() function
-Tracing and vizualization features
+Tracing and visualization features
==================================
* tracing/simple.c very simple program that creates, executes and
destroy a task
/* 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" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
+#include "simgrid/msg.h"
#include "simgrid/simix.h" /* semaphores for the barrier */
#include <xbt/replay.h>
*
* @section MSG_ex_actions Trace driven simulations
*
- * The <b>actions/actions.c</b> example demonstrates how to run trace-driven simulations. It
- * is very handy when you want to test an algorithm or protocol that
- * does nothing unless it receives some events from outside. For
- * example, a P2P protocol reacts to requests from the user, but
- * does nothing if there is no such event.
+ * The <b>actions/actions.c</b> example demonstrates how to run trace-driven simulations. It is very handy when you
+ * want to test an algorithm or protocol that does nothing unless it receives some events from outside. For example,
+ * a P2P protocol reacts to requests from the user, but does nothing if there is no such event.
*
- * In such situations, SimGrid allows to write your protocol in your
- * C file, and the events to react to in a separate text file.
- * Declare a function handling each of the events that you want to
- * accept in your trace files, register them using \ref
- * xbt_replay_action_register in your main, and then use \ref
- * MSG_action_trace_run to launch the simulation. You can either
- * have one trace file containing all your events, or a file per
- * simulated process. Check the tesh files in the example directory
- * for details on how to do it.
+ * In such situations, SimGrid allows to write your protocol in your C file, and the events to react to in a separate
+ * text file. Declare a function handling each of the events that you want to accept in your trace files, register
+ * them using \ref xbt_replay_action_register in your main, and then use \ref MSG_action_trace_run to launch the
+ * simulation. You can either have one trace file containing all your events, or a file per simulated process. Check
+ * the tesh files in the example directory for details on how to do it.
*
- * This example uses this approach to replay MPI-like traces. It
- * comes with a set of event handlers reproducing MPI events. This
- * is somehow similar to SMPI, yet differently implemented. This
- * code should probably be changed to use SMPI internals instead,
- * but wasn't, so far.
- *
+ * This example uses this approach to replay MPI-like traces. It comes with a set of event handlers reproducing MPI
+ * events. This is somehow similar to SMPI, yet differently implemented. This code should probably be changed to use
+ * SMPI internals instead, but wasn't, so far.
*/
XBT_LOG_NEW_DEFAULT_CATEGORY(actions, "Messages specific for this msg example");
static void asynchronous_cleanup(void)
{
- process_globals_t globals =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
/* Destroy any isend which correspond to completed communications */
int found;
char to[250];
const char *size_str = action[3];
double size = parse_double(size_str);
- double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */
+ double clock = MSG_get_clock();
sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]);
char to[250];
const char *size = action[3];
double clock = MSG_get_clock();
- process_globals_t globals =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]);
- msg_comm_t comm =
- MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to);
+ msg_comm_t comm = MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to);
xbt_dynar_push(globals->isends, &comm);
XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self()));
asynchronous_cleanup();
}
-
static void action_recv(const char *const *action)
{
char mailbox_name[250];
msg_task_t task = NULL;
double clock = MSG_get_clock();
- sprintf(mailbox_name, "%s_%s", action[2],
- MSG_process_get_name(MSG_process_self()));
+ sprintf(mailbox_name, "%s_%s", action[2], MSG_process_get_name(MSG_process_self()));
ACT_DEBUG("Receiving: %s", NAME);
msg_error_t res = MSG_task_receive(&task, mailbox_name);
{
char mailbox[250];
double clock = MSG_get_clock();
- process_globals_t globals =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
XBT_DEBUG("Irecv on %s", MSG_process_get_name(MSG_process_self()));
- sprintf(mailbox, "%s_%s", action[2],
- MSG_process_get_name(MSG_process_self()));
+ sprintf(mailbox, "%s_%s", action[2], MSG_process_get_name(MSG_process_self()));
msg_task_t t = NULL;
xbt_dynar_push(globals->tasks, &t);
- msg_comm_t c =
- MSG_task_irecv(xbt_dynar_get_ptr
- (globals->tasks, xbt_dynar_length(globals->tasks) - 1),
- mailbox);
+ msg_comm_t c = MSG_task_irecv(xbt_dynar_get_ptr(globals->tasks, xbt_dynar_length(globals->tasks) - 1), mailbox);
xbt_dynar_push(globals->irecvs, &c);
log_action(action, MSG_get_clock() - clock);
asynchronous_cleanup();
}
-
static void action_wait(const char *const *action)
{
msg_task_t task = NULL;
msg_comm_t comm;
double clock = MSG_get_clock();
- process_globals_t globals =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
- xbt_assert(xbt_dynar_length(globals->irecvs),
- "action wait not preceded by any irecv: %s",
+ xbt_assert(xbt_dynar_length(globals->irecvs), "action wait not preceded by any irecv: %s",
xbt_str_join_array(action, " "));
ACT_DEBUG("Entering %s", NAME);
cond = simcall_cond_init();
processes_arrived_sofar = 0;
}
- ACT_DEBUG("Entering barrier: %s (%d already there)", NAME,
- processes_arrived_sofar);
+ ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar);
simcall_mutex_lock(mutex);
if (++processes_arrived_sofar == communicator_size) {
const char *process_name;
double clock = MSG_get_clock();
- process_globals_t counters =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
- xbt_assert(communicator_size, "Size of Communicator is not defined, "
- "can't use collective operations");
+ xbt_assert(communicator_size, "Size of Communicator is not defined can't use collective operations");
process_name = MSG_process_get_name(MSG_process_self());
MSG_task_execute(comp_task);
MSG_task_destroy(comp_task);
XBT_DEBUG("%s: computed", reduce_identifier);
-
} else {
XBT_DEBUG("%s: %s sends", reduce_identifier, process_name);
sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name);
XBT_DEBUG("put on %s", mailbox);
- MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL),
- mailbox);
+ MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL), mailbox);
}
log_action(action, MSG_get_clock() - clock);
const char *process_name;
double clock = MSG_get_clock();
- process_globals_t counters =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
- xbt_assert(communicator_size, "Size of Communicator is not defined, "
- "can't use collective operations");
+ xbt_assert(communicator_size, "Size of Communicator is not defined, can't use collective operations");
process_name = MSG_process_get_name(MSG_process_self());
for (i = 1; i < communicator_size; i++) {
sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i);
- comms[i - 1] =
- MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox);
+ comms[i - 1] = MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox);
}
MSG_comm_waitall(comms, communicator_size - 1, -1);
for (i = 1; i < communicator_size; i++)
MSG_comm_destroy(comms[i - 1]);
xbt_free(comms);
- XBT_DEBUG("%s: all messages sent by %s have been received",
- bcast_identifier, process_name);
-
+ XBT_DEBUG("%s: all messages sent by %s have been received", bcast_identifier, process_name);
} else {
sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name);
MSG_task_receive(&task, mailbox);
xbt_free(bcast_identifier);
}
-
static void action_sleep(const char *const *action)
{
const char *duration = action[2];
const char *process_name;
double clock = MSG_get_clock();
- process_globals_t counters =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
- xbt_assert(communicator_size, "Size of Communicator is not defined, "
- "can't use collective operations");
+ xbt_assert(communicator_size, "Size of Communicator is not defined, can't use collective operations");
process_name = MSG_process_get_name(MSG_process_self());
for (i = 1; i < communicator_size; i++) {
sprintf(mailbox, "%s_p0_p%d", allreduce_identifier, i);
- comms[i - 1] =
- MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox);
+ comms[i - 1] = MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox);
}
MSG_comm_waitall(comms, communicator_size - 1, -1);
for (i = 1; i < communicator_size; i++)
MSG_comm_destroy(comms[i - 1]);
xbt_free(comms);
- XBT_DEBUG("%s: all messages sent by %s have been received",
- allreduce_identifier, process_name);
-
+ XBT_DEBUG("%s: all messages sent by %s have been received", allreduce_identifier, process_name);
} else {
XBT_DEBUG("%s: %s sends", allreduce_identifier, process_name);
sprintf(mailbox, "%s_%s_p0", allreduce_identifier, process_name);
XBT_DEBUG("put on %s", mailbox);
- MSG_task_send(MSG_task_create(allreduce_identifier, 0, comm_size, NULL),
- mailbox);
+ MSG_task_send(MSG_task_create(allreduce_identifier, 0, comm_size, NULL), mailbox);
sprintf(mailbox, "%s_p0_%s", allreduce_identifier, process_name);
MSG_task_receive(&task, mailbox);
static void action_init(const char *const *action)
{
XBT_DEBUG("Initialize the counters");
- process_globals_t globals =
- (process_globals_t) calloc(1, sizeof(s_process_globals_t));
+ process_globals_t globals = (process_globals_t) calloc(1, sizeof(s_process_globals_t));
globals->isends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
globals->irecvs = xbt_dynar_new(sizeof(msg_comm_t), NULL);
globals->tasks = xbt_dynar_new(sizeof(msg_task_t), NULL);
MSG_process_set_data(MSG_process_self(), globals);
-
}
static void action_finalize(const char *const *action)
{
- process_globals_t globals =
- (process_globals_t) MSG_process_get_data(MSG_process_self());
+ process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
if (globals) {
asynchronous_cleanup();
xbt_dynar_free_container(&(globals->isends));
argv[0],argv[0],argv[0]);
printf("WARNING: THIS BINARY IS KINDA DEPRECATED\n"
- "This example is still relevant if you want to learn about MSG-based trace replay, "
- "but if you want to simulate MPI-like traces, you should use the newer version "
- "that is in the examples/smpi/replay directory instead.\n");
+ "This example is still relevant if you want to learn about MSG-based trace replay, but if you want to simulate "
+ "MPI-like traces, you should use the newer version that is in the examples/smpi/replay directory instead.\n");
- /* Simulation setting */
MSG_create_environment(argv[1]);
-
- /* No need to register functions as in classical MSG programs: the actions get started anyway */
MSG_launch_application(argv[2]);
/* Action registration */
xbt_replay_action_register("sleep", action_sleep);
xbt_replay_action_register("compute", action_compute);
-
/* Actually do the simulation using MSG_action_trace_run */
res = MSG_action_trace_run(argv[3]); // it's ok to pass a NULL argument here
MSG_action_exit();
return res != MSG_OK;
-} /* end_of_main */
+}
/* 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"
-#include "xbt.h" /* calloc, printf */
#include <xbt/replay.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(storage_actions, "Messages specific for this example");
static sg_size_t parse_size(const char *string){
sg_size_t size;
char *endptr;
-
+
size = strtoul(string, &endptr, 10);
if (*endptr != '\0')
THROWF(unknown_error, 0, "%s is not a long unsigned int (a.k.a. sg_size_t)", string);
return size;
}
-
static void action_open(const char *const *action) {
const char *file_name = action[2];
char full_name[1024];
msg_file_t file = NULL;
- double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */
+ double clock = MSG_get_clock();
- sprintf(full_name, "%s:%s", MSG_process_get_name(MSG_process_self()),
- file_name);
+ sprintf(full_name, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);
ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
file = MSG_file_open(file_name, NULL);
-
+
xbt_dict_set(opened_files, full_name, file, NULL);
-
+
log_action(action, MSG_get_clock() - clock);
}
const char *size_str = action[3];
msg_file_t file = NULL;
sg_size_t size = parse_size(size_str);
-
- double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */
+
+ double clock = MSG_get_clock();
file = get_file_descriptor(file_name);
-
+
ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size);
MSG_file_read(file, size);
static void action_close(const char *const *action) {
const char *file_name = action[2];
msg_file_t file;
- double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */
+ double clock = MSG_get_clock();
file = get_file_descriptor(file_name);
int main(int argc, char *argv[]) {
msg_error_t res = MSG_OK;
- /* Check the given arguments */
MSG_init(&argc, argv);
/* Explicit initialization of the action module is required now*/
MSG_action_init();
- if (argc < 3) {
- printf("Usage: %s platform_file deployment_file [action_files]\n", argv[0]);
- printf
- ("example: %s msg_platform.xml msg_deployment.xml actions # if all actions are in the same file\n",
- argv[0]);
- printf
- ("example: %s msg_platform.xml msg_deployment.xml # if actions are in separate files, specified in deployment\n",
- argv[0]);
- exit(1);
- }
+ xbt_assert(argc > 3,"Usage: %s platform_file deployment_file [action_files]\n"
+ "\texample: %s platform.xml deployment.xml actions # if all actions are in the same file\n"
+ "\texample: %s platform.xml deployment.xml # if actions are in separate files, specified in deployment\n",
+ argv[0], argv[0], argv[0]);
- /* Simulation setting */
MSG_create_environment(argv[1]);
-
- /* No need to register functions as in classical MSG programs: the actions get started anyway */
MSG_launch_application(argv[2]);
/* Action registration */
xbt_replay_action_register("open", action_open);
xbt_replay_action_register("read", action_read);
xbt_replay_action_register("close", action_close);
-
+
if (!opened_files)
opened_files = xbt_dict_new_homogeneous(NULL);
/* Actually do the simulation using MSG_action_trace_run */
/* Explicit finalization of the action module is required now*/
MSG_action_exit();
- return !!res;
-} /* end_of_main */
+ return res!=MSG_OK;
+}
xbt_free(co->bitfield);
xbt_free(co->mailbox);
xbt_free(co);
-
}
${CMAKE_CURRENT_SOURCE_DIR}/peer.c
${CMAKE_CURRENT_SOURCE_DIR}/chainsend.c
PARENT_SCOPE)
-set(bin_files
- ${bin_files}
- PARENT_SCOPE)
-set(txt_files
- ${txt_files}
- ${CMAKE_CURRENT_SOURCE_DIR}/README
- PARENT_SCOPE)
+++ /dev/null
-This directory contains a MSG implementation of a file broadcasting
-system, similar to Kastafior (from the Kadeploy).
#include "broadcaster.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_broadcaster,
- "Messages specific for the broadcaster");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_broadcaster, "Messages specific for the broadcaster");
xbt_dynar_t build_hostlist_from_hostcount(int hostcount)
{
next = *cur;
bc->first = next;
- /* This iterator iterates one step ahead: cur is current iterated element,
- but it's actually the next one in the chain */
+ /* This iterator iterates one step ahead: cur is current iterated element, but is actually next in the chain */
do {
/* following steps: prev=last, host=next, next=cur */
cur = (char**)xbt_dynar_iterator_next(bc->it);
next = *cur;
else
next = NULL;
- XBT_DEBUG("Building chain -- broadcaster:\"%s\" dest:\"%s\" prev:\"%s\" next:\"%s\"", me, current_host, prev, next);
-
+ XBT_DEBUG("Building chain--broadcaster:\"%s\" dest:\"%s\" prev:\"%s\" next:\"%s\"", me, current_host, prev, next);
+
/* Send message to current peer */
task = task_message_chain_new(prev, next, bc->piece_count);
MSG_task_send(task, current_host);
/* 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 KADEPLOY_BROADCASTER_H
-#define KADEPLOY_BROADCASTER_H
-
-#include "simgrid/msg.h"
-#include "xbt/sysdep.h"
-
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
+#ifndef BROADCASTER_H
+#define BROADCASTER_H
+#include "xbt/dynar.h"
#include "messages.h"
#include "iterator.h"
#include "common.h"
/* Tasks */
int broadcaster(int argc, char *argv[]);
-#endif /* KADEPLOY_BROADCASTER_H */
+#endif /* BROADCASTER_H */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc */
-
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-
+#include "simgrid/msg.h"
#include "iterator.h"
#include "messages.h"
#include "broadcaster.h"
/** @addtogroup MSG_examples
*
- * - <b>chainsend/chainsend.c: Chainsend implementation</b>.
+ * - <b>chainsend: MSG implementation of a file broadcasting system, similar to Kastafior (from Kadeploy).</b>.
*/
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chainsend, "Messages specific for chainsend");
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chainsend,
- "Messages specific for chainsend");
-
-/*
- Data structures
- */
-
-/* Initialization stuff */
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
-
-/** Test function */
-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;
- XBT_DEBUG("test_all");
+ MSG_init(&argc, argv);
- /* Simulation setting */
- MSG_create_environment(platform_file);
+ MSG_create_environment(argv[1]);
/* Trace categories */
TRACE_category_with_color("host0", "0 0 1");
MSG_function_register("broadcaster", broadcaster);
MSG_function_register("peer", peer);
- MSG_launch_application(application_file);
+ MSG_launch_application(argv[2]);
res = MSG_main();
- return res;
-} /* end_of_test_all */
-
-
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
-
-#ifdef _MSC_VER
- unsigned int prev_exponent_format =
- _set_output_format(_TWO_DIGIT_EXPONENT);
-#endif
-
- MSG_init(&argc, argv);
-
- res = test_all(argv[1], argv[2]);
-
XBT_INFO("Total simulation time: %e", MSG_get_clock());
-#ifdef _MSC_VER
- _set_output_format(prev_exponent_format);
-#endif
-
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. */
-#ifndef KADEPLOY_COMMON_H
-#define KADEPLOY_COMMON_H
+#ifndef COMMON_H
+#define COMMON_H
#include "simgrid/msg.h"
#include "xbt/sysdep.h"
int process_pending_connections(xbt_dynar_t q);
-#endif /* KADEPLOY_COMMON_H */
+#endif /* COMMON_H */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#ifndef KADEPLOY_ITERATOR_H
-#define KADEPLOY_ITERATOR_H
-
-#include <stdlib.h>
+#ifndef ITERATOR_H
+#define ITERATOR_H
#include "xbt/dynar.h"
#include "xbt/sysdep.h"
xbt_dynar_get_as(indices_list, (unsigned int)i, type)); \
xbt_dynar_set_as(indices_list, (unsigned int)i, type, tmp);
-#endif /* KADEPLOY_ITERATOR_H */
+#endif /* ITERATOR_H */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#ifndef KADEPLOY_MESSAGES_H
-#define KADEPLOY_MESSAGES_H
+#ifndef MESSAGES_H
+#define MESSAGES_H
#include "simgrid/msg.h"
-#include "xbt/sysdep.h"
#define MESSAGE_BUILD_CHAIN_SIZE 40
#define MESSAGE_SEND_DATA_HEADER_SIZE 1
msg_task_t task_message_data_new(const char *block, unsigned int len);
void task_message_delete(void *);
-#endif /* KADEPLOY_MESSAGES_H */
+#endif /* MESSAGES_H */
#include "peer.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peer,
- "Messages specific for the peer");
-
-/*******************************************************
- * Peer *
- *******************************************************/
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_peer, "Messages specific for the peer");
void peer_init_chain(peer_t peer, message_t msg)
{
peer_delete(p);
return status;
-} /* end_of_receiver */
+}
/* 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 KADEPLOY_PEER_H
-#define KADEPLOY_PEER_H
+#ifndef PEER_H
+#define PEER_H
#include "simgrid/msg.h"
-#include "xbt/sysdep.h"
+#include "xbt/dynar.h"
#include "messages.h"
#include "common.h"
int peer(int argc, char *argv[]);
-#endif /* KADEPLOY_PEER_H */
+#endif /* PEER_H */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <stdio.h>
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
#include "simgrid/modelchecker.h"
#include <xbt/RngStream.h>
#include "src/mc/mc_replay.h" // FIXME: this is an internal header
/** @addtogroup MSG_examples
*
* - <b>chord/chord.c: Classical Chord P2P protocol</b>
- * This example implements the well known Chord P2P protocol. Its
- * main advantage is that it constitute a fully working non-trivial
- * example. In addition, its implementation is rather efficient, as
- * demonstrated in http://hal.inria.fr/inria-00602216/
+ * This example implements the well known Chord P2P protocol. Its main advantage is that it constitute a fully
+ * working non-trivial example. In addition, its implementation is rather efficient, as demonstrated in
+ * http://hal.inria.fr/inria-00602216/
*/
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord, "Messages specific for this msg example");
#define COMM_SIZE 10
#define COMP_SIZE 0
extern long int smx_total_comms;
-/*
- * Finger element.
- */
+/* Finger element. */
typedef struct s_finger {
int id;
char mailbox[MAILBOX_NAME_SIZE]; // string representation of the id
} s_finger_t, *finger_t;
-/*
- * Node data.
- */
+/* Node data. */
typedef struct s_node {
int id; // my id
char mailbox[MAILBOX_NAME_SIZE]; // my mailbox name (string representation of the id)
RngStream stream; //RngStream for
} s_node_t, *node_t;
-/**
- * Types of tasks exchanged between nodes.
- */
+/* Types of tasks exchanged between nodes. */
typedef enum {
TASK_FIND_SUCCESSOR,
TASK_FIND_SUCCESSOR_ANSWER,
TASK_PREDECESSOR_ALIVE_ANSWER
} e_task_type_t;
-/*
- * Data attached with the tasks sent and received
- */
+/* Data attached with the tasks sent and received */
typedef struct s_task_data {
e_task_type_t type; // type of task
int request_id; // id paramater (used by some types of tasks)
static xbt_dynar_t host_list;
// utility functions
-static void chord_initialize(void);
static void chord_exit(void);
static int normalize(int id);
static int is_in_interval(int id, int start, int end);
static void random_lookup(node_t);
static void quit_notify(node_t node);
-/**
- * \brief Global initialization of the Chord simulation.
- */
+/* \brief Global initialization of the Chord simulation. */
static void chord_initialize(void)
{
// compute the powers of 2 once for all
node->comm_receive = NULL;
handle_task(node, task_received);
}else{
- XBT_DEBUG("Received the answer to my 'Predecessor Alive' request (task %p) : my predecessor %d is alive", task_received, node->pred_id);
+ XBT_DEBUG("Received the answer to my 'Predecessor Alive' request (task %p) : my predecessor %d is alive",
+ task_received, node->pred_id);
stop = 1;
MSG_comm_destroy(node->comm_receive);
node->comm_receive = NULL;
}
-/**
- * \brief Main function.
- */
int main(int argc, char *argv[])
{
MSG_init(&argc, argv);
xbt_assert(argc > 2,
"Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n"
- "\tExample: %s ../msg_platform.xml chord.xml\n",
- argv[0], argv[0]);
+ "\tExample: %s ../msg_platform.xml chord.xml\n", argv[0], argv[0]);
char **options = &argv[1];
while (!strncmp(options[0], "-", 1)) {
/* 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 "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"
-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 MAXMBOXLEN 64
const double task_comp_size = 10000000;
const double task_comm_size = 10000000;
-
-int master_fun(int argc, char *argv[]);
-int worker_fun(int argc, char *argv[]);
-
-
static void send_tasks(int nb_workers)
{
- int i;
- for (i = 0; i < nb_workers; i++) {
+ for (int i = 0; i < nb_workers; i++) {
char *tname = bprintf("Task%02d", i);
char *mbox = bprintf("MBOX:WRK%02d", i);
}
}
-int master_fun(int argc, char *argv[])
+static int worker_fun(int argc, char *argv[])
+{
+ const char *pr_name = MSG_process_get_name(MSG_process_self());
+ char mbox[MAXMBOXLEN];
+ snprintf(mbox, MAXMBOXLEN, "MBOX:%s", pr_name);
+
+ XBT_INFO("%s is listening on mailbox(%s)", pr_name, mbox);
+
+ for (;;) {
+ msg_task_t task = NULL;
+
+ msg_error_t res = MSG_task_receive(&task, mbox);
+ if (res != MSG_OK) {
+ XBT_CRITICAL("MSG_task_get failed");
+ DIE_IMPOSSIBLE;
+ }
+
+ XBT_INFO("%s received task(%s) from mailbox(%s)", pr_name, MSG_task_get_name(task), mbox);
+
+ if (!strcmp(MSG_task_get_name(task), "finalize")) {
+ MSG_task_destroy(task);
+ break;
+ }
+
+ MSG_task_execute(task);
+ XBT_INFO("%s executed task(%s)", pr_name, MSG_task_get_name(task));
+ MSG_task_destroy(task);
+ }
+ return 0;
+}
+
+static int master_fun(int argc, char *argv[])
{
msg_vm_t vm;
unsigned int i;
xbt_dynar_t vms = xbt_dynar_new(sizeof(msg_vm_t), NULL);
-
/* Launch VMs and worker processes. One VM per PM, and one worker process per VM. */
-
XBT_INFO("# Launch %d VMs", nb_workers);
- for (i = 0; i< nb_workers; i++) {
+ for (int i = 0; i< nb_workers; i++) {
char *vm_name = bprintf("VM%02d", i);
char *pr_name = bprintf("WRK%02d", i);
xbt_free(pr_name);
}
-
/* Send a bunch of work to every one */
XBT_INFO("# Send a task to %d worker process", nb_workers);
send_tasks(nb_workers);
MSG_vm_resume(vm);
}
-
XBT_INFO("# Sleep long enough for everyone to be done with previous batch of work");
MSG_process_sleep(1000 - MSG_get_clock());
MSG_vm_migrate(vm, worker_pm1);
}
-
XBT_INFO("# Shutdown the half of worker processes gracefuly. The remaining half will be forcibly killed.");
for (i = 0; i < nb_workers; i++) {
char mbox[MAXMBOXLEN];
XBT_INFO("# Wait a while before effective shutdown.");
MSG_process_sleep(2);
-
XBT_INFO("# Shutdown and destroy all the VMs. The remaining worker processes will be forcibly killed.");
xbt_dynar_foreach(vms, i, vm) {
XBT_INFO("shutdown %s", MSG_host_get_name(vm));
XBT_INFO("# Goodbye now!");
xbt_dynar_free(&vms);
-
return 0;
}
/** Receiver function */
-int worker_fun(int argc, char *argv[])
-{
- const char *pr_name = MSG_process_get_name(MSG_process_self());
- char mbox[MAXMBOXLEN];
- snprintf(mbox, MAXMBOXLEN, "MBOX:%s", pr_name);
-
- XBT_INFO("%s is listenning on mailbox(%s)", pr_name, mbox);
-
- for (;;) {
- msg_task_t task = NULL;
-
- msg_error_t res = MSG_task_receive(&task, mbox);
- if (res != MSG_OK) {
- XBT_CRITICAL("MSG_task_get failed");
- DIE_IMPOSSIBLE;
- }
-
- XBT_INFO("%s received task(%s) from mailbox(%s)",
- pr_name, MSG_task_get_name(task), mbox);
-
- if (!strcmp(MSG_task_get_name(task), "finalize")) {
- MSG_task_destroy(task);
- break;
- }
-
- MSG_task_execute(task);
- XBT_INFO("%s executed task(%s)", pr_name, MSG_task_get_name(task));
- MSG_task_destroy(task);
- }
-
- return 0;
-}
-
-
-
-
int main(int argc, char *argv[])
{
const int nb_workers = 2;
MSG_init(&argc, argv);
- if (argc != 2) {
- printf("Usage: %s example/msg/msg_platform.xml\n", argv[0]);
- return 1;
- }
+ xbt_assert(argc >1,"Usage: %s example/msg/msg_platform.xml\n", argv[0]);
/* Load the platform file */
MSG_create_environment(argv[1]);
xbt_dynar_t pms = MSG_hosts_as_dynar();
/* we need a master node and worker nodes */
- if (xbt_dynar_length(pms) < nb_workers + 1) {
- XBT_CRITICAL("need %d hosts", nb_workers + 1);
- return 1;
- }
+ xbt_assert(xbt_dynar_length(pms) > nb_workers,"need %d hosts", nb_workers + 1);
/* the first pm is the master, the others are workers */
msg_host_t master_pm = xbt_dynar_get_as(pms, 0, msg_host_t);
xbt_dynar_t worker_pms = xbt_dynar_new(sizeof(msg_host_t), NULL);
- int i;
- for (i = 1; i < nb_workers + 1; i++) {
+ for (int i = 1; i < nb_workers + 1; i++) {
msg_host_t pm = xbt_dynar_get_as(pms, i, msg_host_t);
xbt_dynar_push(worker_pms, &pm);
}
-
/* Start the master process on the master pm. */
MSG_process_create("master", master_fun, worker_pms, master_pm);
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] create VM00 on PM(Intel)
> [0.000000] [surf_vm/INFO] Create VM(VM00)@PM(Intel) with 0 mounted disks
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] put a process (WRK00) on VM00
-> [VM00:WRK00:(2) 0.000000] [msg_test/INFO] WRK00 is listenning on mailbox(MBOX:WRK00)
+> [VM00:WRK00:(2) 0.000000] [msg_test/INFO] WRK00 is listening on mailbox(MBOX:WRK00)
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] create VM01 on PM(Provost)
> [0.000000] [surf_vm/INFO] Create VM(VM01)@PM(Provost) with 0 mounted disks
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] put a process (WRK01) on VM01
-> [VM01:WRK01:(3) 0.000000] [msg_test/INFO] WRK01 is listenning on mailbox(MBOX:WRK01)
+> [VM01:WRK01:(3) 0.000000] [msg_test/INFO] WRK01 is listening on mailbox(MBOX:WRK01)
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] # Send a task to 2 worker process
> [Jacquelin:master:(1) 0.000000] [msg_test/INFO] Send task(Task00) to mailbox(MBOX:WRK00)
> [VM00:WRK00:(2) 23.846402] [msg_test/INFO] WRK00 received task(Task00) from mailbox(MBOX:WRK00)
> [VM01:WRK01:(3) 50.726576] [msg_test/INFO] WRK01 executed task(Task01)
> [Jacquelin:master:(1) 1000.000000] [msg_test/INFO] # Add one more process on each VM
> [Jacquelin:master:(1) 1000.000000] [msg_test/INFO] put a process (WRK02) on VM00
-> [VM00:WRK02:(4) 1000.000000] [msg_test/INFO] WRK02 is listenning on mailbox(MBOX:WRK02)
+> [VM00:WRK02:(4) 1000.000000] [msg_test/INFO] WRK02 is listening on mailbox(MBOX:WRK02)
> [Jacquelin:master:(1) 1000.000000] [msg_test/INFO] put a process (WRK03) on VM01
-> [VM01:WRK03:(5) 1000.000000] [msg_test/INFO] WRK03 is listenning on mailbox(MBOX:WRK03)
+> [VM01:WRK03:(5) 1000.000000] [msg_test/INFO] WRK03 is listening on mailbox(MBOX:WRK03)
> [Jacquelin:master:(1) 1000.000000] [msg_test/INFO] # Send a task to 4 worker process
> [Jacquelin:master:(1) 1000.000000] [msg_test/INFO] Send task(Task00) to mailbox(MBOX:WRK00)
> [VM00:WRK00:(2) 1023.846402] [msg_test/INFO] WRK00 received task(Task00) from mailbox(MBOX:WRK00)
/* 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 "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"
-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 void vm_migrate(msg_vm_t vm, msg_host_t dst_pm)
{
s_vm_params_t params;
memset(¶ms, 0, sizeof(params));
-
-
vm0 = MSG_vm_create_core(pm0, "VM0");
params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
MSG_host_set_params(vm0, ¶ms);
MSG_vm_destroy(vm0);
-
-
vm0 = MSG_vm_create_core(pm0, "VM0");
params.ramsize = 1L * 1000 * 1000 * 100; // 100Mbytes
MSG_host_set_params(vm0, ¶ms);
MSG_vm_destroy(vm0);
-
-
vm0 = MSG_vm_create_core(pm0, "VM0");
vm1 = MSG_vm_create_core(pm0, "VM1");
MSG_vm_destroy(vm0);
MSG_vm_destroy(vm1);
-
-
vm0 = MSG_vm_create_core(pm0, "VM0");
vm1 = MSG_vm_create_core(pm0, "VM1");
MSG_vm_destroy(vm0);
MSG_vm_destroy(vm1);
-
return 0;
}
MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
}
-
int main(int argc, char *argv[])
{
/* Get the arguments */
int res = MSG_main();
XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
-
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 <stdio.h>
#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"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-
-
-
static int worker_main(int argc, char *argv[])
{
msg_task_t task = MSG_process_get_data(MSG_process_self());
return 0;
}
-
struct task_data {
msg_task_t task;
double prev_computation_amount;
double prev_clock;
};
-
static void task_data_init_clock(struct task_data *t)
{
t->prev_computation_amount = MSG_task_get_flops_amount(t->task);
t->prev_clock = MSG_get_clock();
}
-
static void task_data_get_clock(struct task_data *t)
{
double now_computation_amount = MSG_task_get_flops_amount(t->task);
t->prev_clock = now_clock;
}
-
static void test_pm_pin(void)
{
xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
-
struct task_data t1;
struct task_data t2;
struct task_data t3;
MSG_process_create("worker3", worker_main, t3.task, pm1);
MSG_process_create("worker4", worker_main, t4.task, pm1);
-
XBT_INFO("## 1. start 4 tasks on PM1 (2 cores)");
task_data_init_clock(&t1);
task_data_init_clock(&t2);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
XBT_INFO("## 2. pin all tasks to CPU0");
MSG_task_set_affinity(t1.task, pm1, 0x01);
MSG_task_set_affinity(t2.task, pm1, 0x01);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
XBT_INFO("## 3. clear the affinity of task4");
MSG_task_set_affinity(t4.task, pm1, 0);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
XBT_INFO("## 4. clear the affinity of task3");
MSG_task_set_affinity(t3.task, pm1, 0);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
XBT_INFO("## 5. clear the affinity of task2");
MSG_task_set_affinity(t2.task, pm1, 0);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
XBT_INFO("## 6. pin all tasks to CPU0 of another PM (no effect now)");
MSG_task_set_affinity(t1.task, pm0, 0);
MSG_task_set_affinity(t2.task, pm0, 0);
task_data_get_clock(&t3);
task_data_get_clock(&t4);
-
-
MSG_task_cancel(t1.task);
MSG_task_cancel(t2.task);
MSG_task_cancel(t3.task);
MSG_task_destroy(t4.task);
}
-
static void test_vm_pin(void)
{
xbt_dynar_t hosts_dynar = MSG_hosts_as_dynar();
msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t); // 2 cores
msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t); // 4 cores
-
/* set up VMs on PM2 (4 cores) */
msg_vm_t vm0 = MSG_vm_create_core(pm2, "VM0");
msg_vm_t vm1 = MSG_vm_create_core(pm2, "VM1");
MSG_vm_start(vm2);
MSG_vm_start(vm3);
-
/* set up tasks and processes */
struct task_data t0;
struct task_data t1;
MSG_process_create("worker2", worker_main, t2.task, vm2);
MSG_process_create("worker3", worker_main, t3.task, vm3);
-
/* start experiments */
XBT_INFO("## 1. start 4 VMs on PM2 (4 cores)");
task_data_init_clock(&t0);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
XBT_INFO("## 2. pin all VMs to CPU0 of PM2");
MSG_vm_set_affinity(vm0, pm2, 0x01);
MSG_vm_set_affinity(vm1, pm2, 0x01);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
XBT_INFO("## 3. pin all VMs to CPU0 of PM1 (no effect at now)");
/* Because VMs are on PM2, the below operations do not effect computation now. */
MSG_vm_set_affinity(vm0, pm1, 0x01);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
XBT_INFO("## 4. unpin VM0, and pin VM2 and VM3 to CPU1 of PM2");
MSG_vm_set_affinity(vm0, pm2, 0x00);
MSG_vm_set_affinity(vm2, pm2, 0x02);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
XBT_INFO("## 5. migrate all VMs to PM0 (only 1 CPU core)");
MSG_vm_migrate(vm0, pm0);
MSG_vm_migrate(vm1, pm0);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
XBT_INFO("## 6. migrate all VMs to PM1 (2 CPU cores, with affinity settings)");
MSG_vm_migrate(vm0, pm1);
MSG_vm_migrate(vm1, pm1);
task_data_get_clock(&t2);
task_data_get_clock(&t3);
-
/* clean up everything */
MSG_task_cancel(t0.task);
MSG_task_cancel(t1.task);
MSG_vm_destroy(vm3);
}
-
static int master_main(int argc, char *argv[])
{
XBT_INFO("=== Test PM (set affinity) ===");
return 0;
}
-
int main(int argc, char *argv[])
{
/* Get the arguments */
msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
-
- XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm0), MSG_host_get_core_number(pm0), MSG_get_host_speed(pm0));
- XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm1), MSG_host_get_core_number(pm1), MSG_get_host_speed(pm1));
- XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm2), MSG_host_get_core_number(pm2), MSG_get_host_speed(pm2));
-
-
+ XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm0), MSG_host_get_core_number(pm0),
+ MSG_get_host_speed(pm0));
+ XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm1), MSG_host_get_core_number(pm1),
+ MSG_get_host_speed(pm1));
+ XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm2), MSG_host_get_core_number(pm2),
+ MSG_get_host_speed(pm2));
MSG_process_create("master", master_main, NULL, pm0);
-
-
-
int res = MSG_main();
XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
-
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 <stdio.h>
#include <sys/time.h>
#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"
-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");
/*
* Usage:
static double time_precise(void) {
struct timeval tv;
int ret = gettimeofday(&tv, NULL);
- if (ret < 0)
- xbt_die("gettimeofday");
-
- double now = (double) tv.tv_sec + tv.tv_usec * 0.001 * 0.001;
-
- return now;
+ xbt_assert(ret >= 0, "gettimeofday");
+ return (double) tv.tv_sec + tv.tv_usec * 0.001 * 0.001;
}
static int computation_fun(int argc, char *argv[]) {
// XBT_INFO("%f", clock_end - clock_sta);
}
-
-
return 0;
}
xbt_free(vm_name);
}
-
XBT_INFO("## Test (start)");
for (i = 0; i < 10; i++) {
XBT_INFO("duration %f", clock_end - clock_sta);
}
-
for (i = 0; i < nvm; i++) {
MSG_vm_destroy(vm[i]);
}
XBT_INFO("## Test (ended)");
-
return 0;
}
int res = MSG_main();
XBT_INFO("Bye (simulation time %g)", MSG_get_clock());
-
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 <stdio.h>
#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"
-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 computation_fun(int argc, char *argv[])
{
struct task_priv *priv = MSG_task_get_data(task);
double clock_end = MSG_get_clock();
- XBT_INFO("%s:%s to %s:%s => %g sec",
- MSG_host_get_name(priv->tx_host),
- MSG_process_get_name(priv->tx_proc),
+ XBT_INFO("%s:%s to %s:%s => %g sec", MSG_host_get_name(priv->tx_host), MSG_process_get_name(priv->tx_proc),
host_name, pr_name, clock_end - priv->clock_sta);
xbt_free(priv);
static void launch_communication_worker(msg_host_t tx_host, msg_host_t rx_host)
{
- char *mbox = bprintf("MBOX:%s-%s",
- MSG_host_get_name(tx_host),
- MSG_host_get_name(rx_host));
+ char *mbox = bprintf("MBOX:%s-%s", MSG_host_get_name(tx_host), MSG_host_get_name(rx_host));
char **argv = NULL;
const char *pr_name_tx = "comm_tx";
XBT_INFO("## Test 1 (ended)");
-
XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
XBT_INFO("### Put a VM on a PM, and put a task to the VM");
XBT_INFO("## Test 2 (ended)");
-
XBT_INFO("## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
XBT_INFO("### Put a VM on a PM, and put a task to the PM");
XBT_INFO("## Test 3 (ended)");
-
- XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
+ XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
+ " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
vm0 = MSG_vm_create_core(pm0, "VM0");
MSG_vm_destroy(vm1);
XBT_INFO("## Test 4 (ended)");
-
XBT_INFO("## Test 5 (started): Analyse network impact");
XBT_INFO("### Make a connection between PM0 and PM1");
launch_communication_worker(pm0, pm1);
XBT_INFO("## Test 5 (ended)");
-
- XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the network one");
+ XBT_INFO("## Test 6 (started): Check migration impact (not yet implemented neither on the CPU resource nor on the"
+ " network one");
XBT_INFO("### Relocate VM0 between PM0 and PM1");
vm0 = MSG_vm_create_core(pm0, "VM0");
{
MSG_process_sleep(5);
MSG_vm_destroy(vm0);
XBT_INFO("## Test 6 (ended)");
-
+
xbt_dynar_free(&hosts_dynar);
return 0;
}
MSG_process_create_with_arguments(pr_name, master_main, NULL, host, 1, argv);
}
-
int main(int argc, char *argv[])
{
/* Get the arguments */
/* 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 "simgrid/msg.h"
-#include "xbt/sysdep.h"
-#include "xbt/log.h"
-#include "xbt/asserts.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");
msg_task_t atask = NULL;
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 <stdio.h>
#include "simgrid/msg.h"
-#include "xbt/sysdep.h" /* calloc */
#include "simgrid/plugins/energy.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
-
-int dvfs(int argc, char *argv[]);
-
-
-int dvfs(int argc, char *argv[])
+static int dvfs(int argc, char *argv[])
{
- msg_host_t host = NULL;
- msg_task_t task1 = NULL;
- host = MSG_host_by_name("MyHost1");
+ msg_host_t host = MSG_host_by_name("MyHost1");
-
- XBT_INFO("Energetic profile: %s",
- MSG_host_get_property_value(host,"watt_per_state"));
- XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
- MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
+ XBT_INFO("Energetic profile: %s",MSG_host_get_property_value(host,"watt_per_state"));
+ XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_current_power_peak(host),
+ sg_host_get_consumed_energy(host));
double start = MSG_get_clock();
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
- XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
- MSG_get_clock()-start,
+ XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", MSG_get_clock()-start,
MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
// Run a task
start = MSG_get_clock();
- task1 = MSG_task_create ("t1", 100E6, 0, NULL);
+ msg_task_t task1 = MSG_task_create ("t1", 100E6, 0, NULL);
XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1));
MSG_task_execute (task1);
MSG_task_destroy(task1);
- XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW depending on load; Energy dissipated=%.0f J",
- MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), sg_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
- sg_host_get_wattmax_at(host,MSG_host_get_pstate(host)),
- sg_host_get_consumed_energy(host));
+ XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
+ " depending on load; Energy dissipated=%.0f J", MSG_get_clock()-start,
+ MSG_host_get_current_power_peak(host), sg_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
+ sg_host_get_wattmax_at(host,MSG_host_get_pstate(host)), sg_host_get_consumed_energy(host));
// ========= Change power peak =========
int pstate=2;
MSG_host_set_pstate(host, pstate);
XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)",
- pstate,
- MSG_host_get_power_peak_at(host, pstate),
- MSG_host_get_current_power_peak(host));
+ pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_current_power_peak(host));
// Run a second task
start = MSG_get_clock();
MSG_task_execute (task1);
MSG_task_destroy(task1);
XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
+ MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
start = MSG_get_clock();
XBT_INFO("Sleep for 4 seconds");
MSG_process_sleep(4);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
+ MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
// =========== Turn the other host off ==========
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
start = MSG_get_clock();
MSG_process_sleep(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
+ MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
return 0;
}
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]);
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
- /* Application deployment */
+ MSG_create_environment(argv[1]);
MSG_function_register("dvfs_test", dvfs);
MSG_launch_application(argv[2]);
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 <stdio.h>
#include "simgrid/msg.h"
-#include "xbt/sysdep.h" /* calloc */
#include "simgrid/plugins/energy.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
static void simulate_bootup(msg_host_t host) {
-
int previous_pstate = MSG_host_get_pstate(host);
XBT_INFO("Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example");
}
static void simulate_shutdown(msg_host_t host) {
-
int previous_pstate = MSG_host_get_pstate(host);
XBT_INFO("Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example");
static int onoff(int argc, char *argv[]) {
msg_host_t host1 = MSG_host_by_name("MyHost1");
- XBT_INFO("Energetic profile: %s",
- MSG_host_get_property_value(host1,"watt_per_state"));
+ XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host1,"watt_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
-
return 0;
}
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]);
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
MSG_create_environment(argv[1]);
- /* Application deployment */
MSG_function_register("onoff_test", onoff);
-
MSG_launch_application(argv[2]);
res = MSG_main();
return res != MSG_OK;
}
-
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
-#include "xbt/sysdep.h" /* calloc */
-
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-
/** @addtogroup MSG_examples
*
- * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined
- * for a host and how the current pstate can be accessed/changed
- * with @ref MSG_get_host_current_power_peak and @ref
- * MSG_set_host_pstate.
- * Make sure to read the platform XML file for details on how
- * to declare the CPU capacity for each pstate.
- *
+ * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined for a host and how the current pstate can be
+ * accessed/changed with @ref MSG_get_host_current_power_peak and @ref MSG_set_host_pstate.
+ * Make sure to read the platform XML file for details on how to declare the CPU capacity for each pstate.
*/
-XBT_LOG_NEW_DEFAULT_CATEGORY(test,
- "Pstate properties test");
-
-int dvfs(int argc, char *argv[]);
-
+XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
-int dvfs(int argc, char *argv[])
+static int dvfs(int argc, char *argv[])
{
- msg_host_t host = NULL;
- msg_task_t task1 = NULL;
- double task_time = 0;
double workload = 100E6;
int new_peak_index=2;
- host = MSG_host_self();; //MSG_get_host_by_name("MyHost1");
+ msg_host_t host = MSG_host_self();; //MSG_get_host_by_name("MyHost1");
int nb = MSG_host_get_nb_pstates(host);
XBT_INFO("Count of Processor states=%d", nb);
XBT_INFO("Current power peak=%f", current_peak);
// Run a task
- task1 = MSG_task_create ("t1", workload, 0, NULL);
+ msg_task_t task1 = MSG_task_create ("t1", workload, 0, NULL);
MSG_task_execute (task1);
MSG_task_destroy(task1);
- task_time = MSG_get_clock();
+ double task_time = MSG_get_clock();
XBT_INFO("Task1 simulation time: %e", task_time);
// Change power peak
- if ((new_peak_index >= nb) || (new_peak_index < 0))
- {
+ if ((new_peak_index >= nb) || (new_peak_index < 0)){
XBT_INFO("Cannot set pstate %d, host supports only %d pstates", new_peak_index, nb);
return 0;
- }
+ }
double peak_at = MSG_host_get_power_peak_at(host, new_peak_index);
XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_peak_index);
task_time = MSG_get_clock() - task_time;
XBT_INFO("Task2 simulation time: %e", task_time);
-
// Verify the default pstate is set to 0
host = MSG_host_by_name("MyHost2");
int nb2 = MSG_host_get_nb_pstates(host);
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]);
-
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
+
MSG_create_environment(argv[1]);
- /* Application deployment */
MSG_function_register("dvfs_test", dvfs);
-
MSG_launch_application(argv[2]);
res = MSG_main();
return res != MSG_OK;
}
-
${tesh_files}
${CMAKE_CURRENT_SOURCE_DIR}/energy_vm.tesh
PARENT_SCOPE)
-set(xml_files
- ${xml_files}
- ${CMAKE_CURRENT_SOURCE_DIR}/deployment_consumption.xml
- PARENT_SCOPE)
set(examples_src
${examples_src}
${CMAKE_CURRENT_SOURCE_DIR}/energy_vm.c
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
-<platform version="4">
- <process host="MyHost1" function="dvfs_test" />
-</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 <stdio.h>
#include "simgrid/msg.h"
-#include "xbt/sysdep.h" /* calloc */
#include "simgrid/plugins/energy.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-
XBT_LOG_NEW_DEFAULT_CATEGORY(energy_vm, "Messages of this example");
-
static int worker_func() {
msg_task_t task1 = MSG_task_create("t1", 300E6, 0, NULL);
MSG_task_execute (task1);
MSG_process_create("p31", worker_func, NULL, vm_host3);
MSG_process_create("p32", worker_func, NULL, vm_host3);
- XBT_INFO("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, so they run for 6 seconds)");
+ XBT_INFO("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, "
+ "so they run for 6 seconds)");
MSG_process_sleep(5);
XBT_INFO("Wait another 5 seconds. The tasks stop at some point in between");
MSG_process_sleep(5);
sg_energy_plugin_init();
MSG_init(&argc, argv);
- xbt_assert(argc > 1, "Usage: %s platform_file\n"
- "\tExample: %s msg_platform.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]);
MSG_create_environment(argv[1]);
- /* Application deployment */
MSG_process_create("dvfs",dvfs,NULL,MSG_host_by_name("MyHost1"));
res = MSG_main();
/* 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 "xbt/log.h"
#include "simgrid/msg.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test_exception,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test_exception, "Messages specific for this msg example");
/** @addtogroup MSG_examples
*
/** Victim. This process gets a lot of remote exceptions */
static int victim(int argc, char *argv[]) {
-
xbt_ex_t e;
msg_error_t res = MSG_OK;
xbt_ex_free(e);
}
-
XBT_INFO("Let's get suspended.");
int gotit = 0;
TRY {
if(!gotit) {
xbt_die("I was expecting an exception during my suspension!");
}
-
+
XBT_INFO("Let's sleep for 10 seconds.");
TRY {
res = MSG_process_sleep(10);
MSG_process_sleep(10);
XBT_INFO("That's enough now. I quit.");
-
return 0;
}
XBT_INFO("Send a first exception (host failure)");
SIMIX_process_throw(victim_process, host_error, 0, "First Trick: Let's pretend that the host failed");
-
XBT_INFO("Sweet, let's prepare a second trick!");
XBT_INFO("Going to sleep for 2 seconds");
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]);
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
MSG_function_register("terrorist", terrorist);
MSG_create_environment(argv[1]);
MSG_launch_application(argv[2]);
-
// Launch the simulation
res = MSG_main();
* - <b>gpu/test_MSG_gpu_task_create.c</b> Example of use of the very experimental (for now) GPU resource.
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for GPU msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for GPU msg example");
-
-/** Main function */
int main(int argc, char *argv[])
{
msg_error_t 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 <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.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");
/** @addtogroup MSG_examples
*
* - <b>gtnets</b> Simple ping-pong using GTNeTs instead of the SimGrid network models.
*/
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
int timer_start = 1;
//keep a pointer to all surf running tasks.
int gl_task_array_id = 0;
int count_finished = 0;
-/** master */
-int master(int argc, char *argv[])
+static int master(int argc, char *argv[])
{
char *slavename = NULL;
double task_comm_size = 0;
//unique id to control statistics
int id = -1;
- xbt_assert(argc == 4, "Strange number of arguments expected 3 got %d",
- argc - 1);
+ xbt_assert(argc == 4, "Strange number of arguments expected 3 got %d", argc - 1);
/* data size */
int read;
MSG_task_send(todo, id_alias);
end_time = MSG_get_clock();
-
return 0;
-} /* end_of_master */
+}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
-
msg_task_t task = NULL;
- int a;
- int id = 0;
#ifdef HAVE_LATENCY_BOUND_TRACKING
int limited_latency = 0;
#endif
double remaining = 0;
char id_alias[10];
- xbt_assert(argc == 2, "Strange number of arguments expected 1 got %d",
- argc - 1);
+ xbt_assert(argc == 2, "Strange number of arguments expected 1 got %d", argc - 1);
- id = atoi(argv[1]);
+ int id = atoi(argv[1]);
sprintf(id_alias, "%d", id);
int trace_id = id;
- a = MSG_task_receive(&(task), id_alias);
+ int a = MSG_task_receive(&(task), id_alias);
count_finished--;
if(count_finished == 0){
timer_start = 0;
}
- xbt_assert(a == MSG_OK,"Hey?! What's up? Unexpected behavior");
+ xbt_assert(a == MSG_OK,"Hey?! What's up? Unexpected behavior");
elapsed_time = MSG_get_clock() - start_time;
XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
}
#endif
- XBT_INFO
- ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
- id, gl_data_size[id] / elapsed_time, masternames[id],
- slavenames[id], 0.0);
+ XBT_INFO ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
+ id, gl_data_size[id] / elapsed_time, masternames[id], slavenames[id], 0.0);
MSG_task_destroy(gl_task_array[id]);
gl_task_array[id]=NULL;
} else {
- remaining =
- MSG_task_get_remaining_communication(gl_task_array[id]);
+ remaining = MSG_task_get_remaining_communication(gl_task_array[id]);
#ifdef HAVE_LATENCY_BOUND_TRACKING
limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
}
#endif
- XBT_INFO
- ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
- id, (gl_data_size[id] - remaining) / elapsed_time,
- masternames[id], slavenames[id], remaining);
+ XBT_INFO ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
+ id, (gl_data_size[id] - remaining) / elapsed_time, masternames[id], slavenames[id], remaining);
if(remaining==0) {
MSG_task_destroy(gl_task_array[id]);
gl_task_array[id]=NULL;
if(bool_printed==2 && gl_task_array[trace_id]) MSG_task_destroy(gl_task_array[trace_id]);
return 0;
-} /* end_of_slave */
+}
-/** Test function */
-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;
+ bool_printed = 0;
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
+ MSG_init(&argc, argv);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
TRACE_declare_mark("endmark");
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ MSG_launch_application(argv[2]);
- MSG_launch_application(application_file);
- }
res = MSG_main();
- return res;
-} /* end_of_test_all */
-
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
- bool_printed = 0;
-
- MSG_init(&argc, argv);
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s platform.xml deployment.xml\n",
- argv[0], argv[0]);
-
- res = test_all(argv[1], argv[2]);
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 <stdio.h>
#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"
-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");
/** @addtogroup MSG_examples
*
*
* - <b>msg/icomms/peer.c</b>: basic example of async functions (@ref MSG_task_isend, @ref MSG_task_irecv, @ref MSG_comm_wait)
*/
-int sender(int argc, char *argv[]);
-int receiver(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
-/** Sender function */
-int sender(int argc, char *argv[])
+static int sender(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid compute size: %s");
double sleep_start_time = xbt_str_parse_double(argv[5], "Invalid sleep start time: %s");
double sleep_test_time = xbt_str_parse_double(argv[6], "Invalid test time: %s");
- XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
- sleep_test_time);
+ XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
msg_comm_t comm = NULL;
int i;
sprintf(mailbox, "receiver-%ld", i % receivers_count);
sprintf(sprintf_buffer, "Task_%d", i);
- task =
- MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
- NULL);
+ task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
};
}
MSG_comm_destroy(comm);
-
}
for (i = 0; i < receivers_count; i++) {
};
}
MSG_comm_destroy(comm);
-
}
XBT_INFO("Goodbye now!");
return 0;
-} /* end_of_sender */
+}
-/** Receiver function */
-int receiver(int argc, char *argv[])
+static int receiver(int argc, char *argv[])
{
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED msg_error_t res;
msg_comm_t res_irecv;
double sleep_start_time = xbt_str_parse_double(argv[2], "Invalid sleep start parameter: %s");
double sleep_test_time = xbt_str_parse_double(argv[3], "Invalid sleep test parameter: %s");
- XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
- sleep_test_time);
+ XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
XBT_ATTRIB_UNUSED int read;
read = sscanf(argv[1], "%d", &id);
- xbt_assert(read,
- "Invalid argument %s\n", argv[1]);
+ xbt_assert(read, "Invalid argument %s\n", argv[1]);
MSG_process_sleep(sleep_start_time);
}
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_receiver */
-
-/** Test function */
-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("sender", sender);
- MSG_function_register("receiver", receiver);
- 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.xml\n",
- argv[0], argv[0]);
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
- res = test_all(argv[1], argv[2]);
+ MSG_create_environment(argv[1]);
+
+ MSG_function_register("sender", sender);
+ MSG_function_register("receiver", receiver);
+ MSG_launch_application(argv[2]);
+
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
/** @addtogroup MSG_examples
*
* - <b>msg/icomms/peer2.c</b>: demonstrates the @ref MSG_comm_waitall function
*/
-int sender(int argc, char *argv[]);
-int receiver(int argc, char *argv[]);
-
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
-/** Sender function */
-int sender(int argc, char *argv[])
+static int sender(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
XBT_INFO("Goodbye now!");
xbt_free(comm);
return 0;
-} /* end_of_sender */
+}
-/** Receiver function */
-int receiver(int argc, char *argv[])
+static int receiver(int argc, char *argv[])
{
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED msg_error_t res;
}
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_receiver */
-
-/** Test function */
-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("sender", sender);
- MSG_function_register("receiver", receiver);
- 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.xml\n",
- argv[0], argv[0]);
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
- res = test_all(argv[1], argv[2]);
+ MSG_create_environment(argv[1]);
+ MSG_function_register("sender", sender);
+ MSG_function_register("receiver", receiver);
+ MSG_launch_application(argv[2]);
+
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
-#include <math.h>
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+#include "simgrid/msg.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
/** @addtogroup MSG_examples
*
* - <b>msg/icomms/peer3.c</b>: demonstrates the @ref MSG_comm_waitany function
*/
-int sender(int argc, char *argv[]);
-int receiver(int argc, char *argv[]);
-
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
-/** Sender function */
-int sender(int argc, char *argv[])
+static int sender(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
task_comm_size / coef, NULL);
comm = MSG_task_isend(task, mailbox);
xbt_dynar_push_as(d, msg_comm_t, comm);
- XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count,
- sprintf_buffer, task_comm_size / coef);
+ XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, sprintf_buffer, task_comm_size / coef);
}
/* Here we are waiting for the completion of all communications */
XBT_INFO("Goodbye now!");
return 0;
-} /* end_of_sender */
+}
-/** Receiver function */
-int receiver(int argc, char *argv[])
+static int receiver(int argc, char *argv[])
{
int id = -1;
- int i;
char mailbox[80];
xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
int tasks = xbt_str_parse_int(argv[2], "Invalid amount of tasks: %s");
sprintf(mailbox, "receiver-%d", id);
MSG_process_sleep(10);
msg_comm_t res_irecv;
- for (i = 0; i < tasks; i++) {
+ for (int i = 0; i < tasks; i++) {
XBT_INFO("Wait to receive task %d", i);
task[i] = NULL;
res_irecv = MSG_task_irecv(&task[i], mailbox);
MSG_comm_destroy(res_irecv);
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_receiver */
+}
-/** Test function */
-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;
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("sender", sender);
- MSG_function_register("receiver", receiver);
- MSG_launch_application(application_file);
- }
- res = MSG_main();
+ 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]);
- XBT_INFO("Simulation time %g", MSG_get_clock());
- return res;
-} /* end_of_test_all */
+ MSG_create_environment(argv[1]);
+ MSG_function_register("sender", sender);
+ MSG_function_register("receiver", receiver);
+ MSG_launch_application(argv[2]);
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
- 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;
}
#define FILENAME3 "/home/doc/simgrid/examples/platforms/g5k_cabinets.xml"
#define FILENAME4 "/home/doc/simgrid/examples/platforms/nancy.xml"
-#include <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
-int host(int argc, char *argv[]);
+XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example");
-XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
- "Messages specific for this io example");
-
-int host(int argc, char *argv[])
+static int host(int argc, char *argv[])
{
msg_file_t file = NULL;
sg_size_t read,write;
/* Write 100KB in file from the current position, i.e, end of file or 10MB */
write = MSG_file_write(file, 100000);
- XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu",write,filename,
- MSG_file_get_size(file));
+ XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu",write,filename, MSG_file_get_size(file));
XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
/* rewind to the beginning of the file */
- XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
- filename);
+ XBT_INFO("\tComing back to the beginning of the stream for file '%s'", filename);
MSG_file_seek(file, 0, SEEK_SET);
/* Try to read 110KB */
read = MSG_file_read(file, 110000);
- XBT_INFO("\tHave read %llu from '%s' (of size %llu)",read,filename,
- MSG_file_get_size(file));
+ XBT_INFO("\tHave read %llu from '%s' (of size %llu)",read,filename, MSG_file_get_size(file));
/* rewind once again to the beginning of the file */
- XBT_INFO("\tComing back to the beginning of the stream for file '%s'",
- filename);
+ XBT_INFO("\tComing back to the beginning of the stream for file '%s'", filename);
MSG_file_seek(file, 0, SEEK_SET);
/* Write 110KB in file from the current position, i.e, end of file or 10MB */
write = MSG_file_write(file, 110000);
- XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu", write,filename,
- MSG_file_get_size(file));
+ XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu", write,filename, MSG_file_get_size(file));
XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu",
filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st));
XBT_INFO("\tClose file '%s'",filename);
MSG_file_close(file);
-
return 0;
}
int main(int argc, char **argv)
{
- int i,res;
MSG_init(&argc, argv);
MSG_create_environment(argv[1]);
xbt_dynar_t hosts = MSG_hosts_as_dynar();
MSG_function_register("host", host);
unsigned long nb_hosts = xbt_dynar_length(hosts);
XBT_INFO("Number of host '%lu'",nb_hosts);
- for(i = 0 ; i<nb_hosts; i++)
- {
+ for(int 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) );
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;
}
#define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
-#include <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
-int host(int argc, char *argv[]);
+XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example");
-XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
- "Messages specific for this io example");
-
-int host(int argc, char *argv[])
+static int host(int argc, char *argv[])
{
- msg_file_t file = NULL;
- sg_size_t write;
-
// First open
XBT_INFO("\tOpen file '%s'",FILENAME1);
- file = MSG_file_open(FILENAME1, NULL);
+ msg_file_t file = MSG_file_open(FILENAME1, NULL);
// Unlink the file
XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
file = MSG_file_open(FILENAME1, NULL);
// Write into the new file
- write = MSG_file_write(file,100000); // Write for 100Ko
+ sg_size_t write = MSG_file_write(file,100000); // Write for 100Ko
XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
// Write into the new file
int main(int argc, char **argv)
{
- int res;
MSG_init(&argc, argv);
MSG_create_environment(argv[1]);
xbt_dynar_t hosts = MSG_hosts_as_dynar();
xbt_dynar_free(&hosts);
- res = MSG_main();
+ int res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
return res != MSG_OK;
}
* - <b>io/remote.c</b> Example of delegated I/O operations
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "simgrid/msg.h"
#define INMEGA (1024*1024)
-int host(int argc, char *argv[]);
+XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example");
-XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io,
- "Messages specific for this io example");
-
-
-int host(int argc, char *argv[]){
- msg_file_t file = NULL;
- const char* filename;
- sg_size_t read, write;
-
- file = MSG_file_open(argv[1], NULL);
- filename = MSG_file_get_name(file);
+static int host(int argc, char *argv[]){
+ msg_file_t file = MSG_file_open(argv[1], NULL);
+ char *filename = MSG_file_get_name(file);
XBT_INFO("Opened file '%s'",filename);
MSG_file_dump(file);
XBT_INFO("Try to read %llu from '%s'",MSG_file_get_size(file),filename);
- read = MSG_file_read(file, MSG_file_get_size(file));
- XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename,
- MSG_file_tell(file));
+ sg_size_t read = MSG_file_read(file, MSG_file_get_size(file));
+ XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu",read,filename, MSG_file_tell(file));
XBT_INFO("Seek back to the begining of the stream...");
MSG_file_seek(file, 0, SEEK_SET);
XBT_INFO("Offset is now at: %llu", MSG_file_tell(file));
file = MSG_file_open(argv[2], NULL);
filename = MSG_file_get_name(file);
XBT_INFO("Opened file '%s'",filename);
- XBT_INFO("Try to write %llu MiB to '%s'",
- MSG_file_get_size(file)/1024,
- filename);
- write = MSG_file_write(file, MSG_file_get_size(file)*1024);
+ XBT_INFO("Try to write %llu MiB to '%s'", MSG_file_get_size(file)/1024, filename);
+ sg_size_t write = MSG_file_write(file, MSG_file_get_size(file)*1024);
XBT_INFO("Have written %llu bytes to '%s'.",write,filename);
msg_host_t src, dest;
src= MSG_host_self();
dest = MSG_host_by_name(argv[3]);
if (xbt_str_parse_int(argv[5], "Argument 5 (move or copy) must be an int, not '%s'")) {
- XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,
- MSG_file_get_size(file), MSG_host_get_name(src),
- argv[3]);
+ XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename,MSG_file_get_size(file), MSG_host_get_name(src),
+ argv[3]);
MSG_file_rmove(file, dest, argv[4]);
} else {
- XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename,
- MSG_file_get_size(file), MSG_host_get_name(src),
- argv[3]);
+ XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, MSG_file_get_size(file), MSG_host_get_name(src),
+ argv[3]);
MSG_file_rcopy(file, dest, argv[4]);
MSG_file_close(file);
}
return 0;
}
-
-
int main(int argc, char **argv)
{
- int res;
unsigned int cur;
- xbt_dynar_t storages;
msg_storage_t st;
MSG_init(&argc, argv);
MSG_function_register("host", host);
MSG_launch_application(argv[2]);
- storages = MSG_storages_as_dynar();
+ xbt_dynar_t storages = MSG_storages_as_dynar();
xbt_dynar_foreach(storages, cur, st){
- XBT_INFO("Init: %llu MiB used on '%s'",
- MSG_storage_get_used_size(st)/INMEGA,
- MSG_storage_get_name(st));
+ XBT_INFO("Init: %llu MiB used on '%s'", MSG_storage_get_used_size(st)/INMEGA, MSG_storage_get_name(st));
}
- res = MSG_main();
+ int res = MSG_main();
xbt_dynar_foreach(storages, cur, st){
- XBT_INFO("Init: %llu MiB used on '%s'",
- MSG_storage_get_used_size(st)/INMEGA,
- MSG_storage_get_name(st));
+ XBT_INFO("Init: %llu MiB used on '%s'", MSG_storage_get_used_size(st)/INMEGA, MSG_storage_get_name(st));
}
xbt_dynar_free_container(&storages);
******************************************************************************/
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/dict.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
}
xbt_dict_free(&storage_list);
-
// Create a 200,000 bytes file named './tmp/data.txt' on /sd1
char* file_name = xbt_strdup("/home/tmp/data.txt");
msg_file_t file = NULL;
XBT_INFO("Free size: %llu bytes", MSG_storage_get_free_size(storage));
XBT_INFO("Used size: %llu bytes", MSG_storage_get_used_size(storage));
-
// Now retrieve the size of created file and read it completely
file_size = MSG_file_get_size(file);
MSG_file_seek(file, 0, SEEK_SET);
xbt_free(data);
xbt_free(storage_name);
-
// Dump disks contents
XBT_INFO("*** Dump content of %s ***",MSG_host_get_name(MSG_host_self()));
xbt_dict_t contents = NULL;
return 1;
}
-
int main(int argc, char *argv[])
{
-
MSG_init(&argc, argv);
MSG_create_environment(argv[1]);
MSG_function_register("host", host);
#include "task.h"
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
/** @addtogroup MSG_examples
* <b>kademlia/kademlia.c: Kademlia protocol</b>
* Implements the Kademlia protocol, using 32 bits identifiers.
#include "node.h"
#include "routing_table.h"
-
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
+
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_node, "Messages specific for this msg example");
/** @brief Initialization of a node
#include "routing_table.h"
#include "node.h"
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
+
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table, "Messages specific for this msg example");
/** @brief Initialization of a node routing table. */
/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
#define task_comp_size 50000000
#define task_comm_size 1000000
return n * (rand() / ((double)RAND_MAX + 1));
}
-/** Emitter function */
static int master(int argc, char *argv[])
{
int i;
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
sprintf(sprintf_buffer, "Task_%d", i);
task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
- XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
- number_of_jobs, mailbox);
+ XBT_DEBUG("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_jobs, mailbox);
MSG_task_send(task, mailbox);
}
XBT_DEBUG("Goodbye now!");
return 0;
-} /* end_of_master */
+}
-/** Receiver function */
static int slave(int argc, char *argv[])
{
msg_task_t task = NULL;
task = NULL;
}
return 0;
-} /* end_of_slave */ /* 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 > 3, "Usage: %s platform_file number_of_jobs number_of_slaves\n"
- "\tExample: %s msg_platform.xml 10 5\n",
- argv[0], argv[0]);
+ "\tExample: %s msg_platform.xml 10 5\n", argv[0], argv[0]);
MSG_function_register("master", master);
MSG_function_register("slave", slave);
msg_host_t *host_table = xbt_dynar_to_array(host_dynar);
- MSG_process_create( "master", master,
- NULL,
- host_table[my_random(number_max)]
- );
+ MSG_process_create("master", master, NULL, host_table[my_random(number_max)]);
for(i = 0 ; i<number_of_slaves; i++) {
char* name_host = bprintf("slave-%ld",i);
- MSG_process_create( name_host, slave,
- NULL,
- host_table[my_random(number_max)]
- );
+ MSG_process_create( name_host, slave, NULL, host_table[my_random(number_max)]);
free(name_host);
}
xbt_free(host_table);
/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
-
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
-/** Emitter function */
-int master(int argc, char *argv[])
+static int master(int argc, char *argv[])
{
int slaves_count = 0;
msg_host_t *slaves = NULL;
XBT_INFO("Got %d task to process :", number_of_tasks);
for (i = 0; i < number_of_tasks; i++) {
- msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size,
- xbt_new0(double, 1));
- msg_error_t a;
+ msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, xbt_new0(double, 1));
*((double *) task->data) = MSG_get_clock();
- a = MSG_task_send_with_timeout(task,MSG_host_get_name(slaves[i % slaves_count]),10.0);
+ msg_error_t a = MSG_task_send_with_timeout(task,MSG_host_get_name(slaves[i % slaves_count]),10.0);
if (a == MSG_OK) {
XBT_INFO("Send completed");
} else if (a == MSG_HOST_FAILURE) {
- XBT_INFO
- ("Gloups. The cpu on which I'm running just turned off!. See you!");
+ XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
free(task->data);
MSG_task_destroy(task);
free(slaves);
return 0;
} else if (a == MSG_TRANSFER_FAILURE) {
- XBT_INFO
- ("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!",
- MSG_host_get_name(slaves[i % slaves_count]));
+ XBT_INFO("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!",
+ 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!",
+ XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!",
MSG_host_get_name(slaves[i % slaves_count]));
free(task->data);
MSG_task_destroy(task);
}
}
- XBT_INFO
- ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < slaves_count; i++) {
msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
int a = MSG_task_send_with_timeout(task,MSG_host_get_name(slaves[i]),1.0);
if (a == MSG_OK)
continue;
if (a == MSG_HOST_FAILURE) {
- XBT_INFO
- ("Gloups. The cpu on which I'm running just turned off!. See you!");
+ XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
MSG_task_destroy(task);
free(slaves);
return 0;
} else if (a == MSG_TRANSFER_FAILURE) {
- XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!",
- MSG_host_get_name(slaves[i]));
+ XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", 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!",
- MSG_host_get_name(slaves[i % slaves_count]));
+ XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!",
+ MSG_host_get_name(slaves[i % slaves_count]));
MSG_task_destroy(task);
} else {
XBT_INFO("Hey ?! What's up ? ");
XBT_INFO("Goodbye now!");
free(slaves);
return 0;
-} /* end_of_master */
+}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
while (1) {
msg_task_t task = NULL;
free(task->data);
MSG_task_destroy(task);
} else if (a == MSG_HOST_FAILURE) {
- XBT_INFO
- ("Gloups. The cpu on which I'm running just turned off!. See you!");
+ XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
free(task->data);
MSG_task_destroy(task);
return 0;
xbt_die("Unexpected behavior");
}
} else if (a == MSG_HOST_FAILURE) {
- XBT_INFO
- ("Gloups. The cpu on which I'm running just turned off!. See you!");
+ XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
return 0;
} else if (a == MSG_TRANSFER_FAILURE) {
XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!");
}
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_slave */
+}
-/** Test function */
-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;
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- MSG_launch_application(application_file);
- }
- res = MSG_main();
+ 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]);
- XBT_INFO("Simulation time %g", MSG_get_clock());
- return res;
-} /* end_of_test_all */
+ MSG_create_environment(argv[1]);
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ MSG_launch_application(argv[2]);
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
+ res = MSG_main();
- 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]);
+ XBT_INFO("Simulation time %g", MSG_get_clock());
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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
/** @addtogroup MSG_examples
*
- * - <b>masterslave/masterslave_forwarder.c: Master/slaves
- * example</b>. This good old example is also very simple. Its basic
- * version is fully commented on this page: \ref MSG_ex_master_slave,
- * but several variants can be found in the same directory.
+ * - <b>masterslave/masterslave_forwarder.c: Master/slaves example</b>. This good old example is also very simple. Its
+ * basic version is fully commented on this page: \ref MSG_ex_master_slave, but several variants can be found in the
+ * same directory.
*/
-
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-int forwarder(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
/** Emitter function */
-int master(int argc, char *argv[])
+static int master(int argc, char *argv[])
{
int slaves_count = 0;
msg_host_t *slaves = NULL;
for (i = 0; i < number_of_tasks; i++) {
sprintf(sprintf_buffer, "Task_%d", i);
- todo[i] =
- MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
- NULL);
+ todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
}
}
for (i = 4; i < argc; i++) {
slaves[i - 4] = MSG_host_by_name(argv[i]);
- xbt_assert(slaves[i - 4] != NULL, "Unknown host %s. Stopping Now! ",
- argv[i]);
+ xbt_assert(slaves[i - 4] != NULL, "Unknown host %s. Stopping Now! ", argv[i]);
}
}
- XBT_INFO("Got %d slaves and %d tasks to process", slaves_count,
- number_of_tasks);
+ 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", MSG_host_get_name(slaves[i]));
for (i = 0; i < number_of_tasks; i++) {
- XBT_INFO("Sending \"%s\" to \"%s\"",
- todo[i]->name, MSG_host_get_name(slaves[i % slaves_count]));
+ XBT_INFO("Sending \"%s\" to \"%s\"", 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 ! :)");
}
XBT_INFO("Sent");
}
- XBT_INFO
- ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < slaves_count; i++) {
msg_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE);
MSG_task_send(finalize, MSG_host_get_name(slaves[i]));
free(slaves);
free(todo);
return 0;
-} /* end_of_master */
+}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
}
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_slave */
+}
-/** Forwarder function */
-int forwarder(int argc, char *argv[])
+static int forwarder(int argc, char *argv[])
{
int i;
int slaves_count;
if (a == MSG_OK) {
XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
if (MSG_task_get_data(task) == FINALIZE) {
- XBT_INFO
- ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < slaves_count; i++)
- MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE),
- MSG_host_get_name(slaves[i]));
+ MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE), MSG_host_get_name(slaves[i]));
MSG_task_destroy(task);
break;
}
- XBT_INFO("Sending \"%s\" to \"%s\"",
- MSG_task_get_name(task), MSG_host_get_name(slaves[i % slaves_count]));
+ XBT_INFO("Sending \"%s\" to \"%s\"", 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 {
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_forwarder */
+}
-/** Test function */
-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;
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- MSG_function_register("forwarder", forwarder);
- MSG_launch_application(application_file);
- }
- res = MSG_main();
+ 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]);
- XBT_INFO("Simulation time %g", MSG_get_clock());
- return res;
-} /* end_of_test_all */
+ MSG_create_environment(argv[1]);
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ MSG_function_register("forwarder", forwarder);
+ MSG_launch_application(argv[2]);
-/** Main function */
-int main(int argc, char *argv[])
-{
- msg_error_t res = MSG_OK;
+ res = MSG_main();
- 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]);
+ XBT_INFO("Simulation time %g", MSG_get_clock());
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");
/** Lazy guy function. This process suspends itself asap. */
static int slave(int argc, char *argv[])
MSG_task_execute(MSG_task_create("toto", 1e9, 0, NULL));
XBT_INFO("Bye!");
return 0;
-} /* end_of_lazy_guy */
+}
static int master(int argc, char *argv[])
{
XBT_INFO("OK, goodbye now.");
return 0;
-} /* end_of_dram_master */
+}
-/** 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_suspend.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
+
MSG_function_register("master", master);
MSG_function_register("slave", slave);
- 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_suspend.xml\n",
- argv[0], argv[0]);
-
- test_all(argv[1], argv[2]);
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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h"
+#include "simgrid/msg.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-
-/** Sender function */
-int master(int argc, char *argv[])
+static int master(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
sprintf(mailbox, "slave-%ld", i % slaves_count);
sprintf(sprintf_buffer, "Task_%d", i);
- task =
- MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
- NULL);
+ task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
if (number_of_tasks < 10000 || i % 10000 == 0)
- XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
- number_of_tasks, mailbox);
+ XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
MSG_task_send(task, mailbox);
}
- XBT_INFO
- ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < slaves_count; i++) {
char mailbox[80];
MSG_task_send(finalize, mailbox);
}
-// XBT_INFO("Goodbye now!");
return 0;
-} /* end_of_master */
+}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
}
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_slave */
+}
-/** Main function */
int main(int argc, char *argv[])
{
- msg_error_t res;
- const char *platform_file;
- const char *application_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]);
-
- platform_file = argv[1];
- application_file = argv[2];
-
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- MSG_launch_application(application_file);
- }
- res = MSG_main();
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
+
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ MSG_launch_application(argv[2]);
+
+ msg_error_t res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
/* 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" /* core library */
-#include "xbt/sysdep.h" /* calloc */
-#include "xbt/synchro_core.h"
+#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");
/** @addtogroup MSG_examples
*
- * - <b>migration/migration.c</b> Demonstrates how to use the @ref
- * MSG_process_migrate function to let processes change the host they
- * run on after their start.
+ * - <b>migration/migration.c</b> Demonstrates how to use the @ref MSG_process_migrate function to let processes
+ * change the host they run on after their start.
*/
xbt_mutex_t mutex = NULL;
static int emigrant(int argc, char *argv[])
{
msg_task_t task;
- XBT_INFO
- ("I'll look for a new job on another machine where the grass is greener.");
+ XBT_INFO("I'll look for a new job on another machine where the grass is greener.");
MSG_process_migrate(MSG_process_self(), MSG_host_by_name("Boivin"));
-
+
XBT_INFO("Yeah, found something to do");
task = MSG_task_create("job", 98095000, 0, NULL);
MSG_task_execute(task);
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 */
-
+}
/* This function move the emigrant on Jacquelin */
static int policeman(int argc, char *argv[])
{
-
xbt_mutex_acquire(mutex);
XBT_INFO("Wait a bit before migrating the emigrant.");
while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex);
xbt_mutex_release(mutex);
return 0;
-} /* end_of_policeman */
-
+}
-/** Main function */
int main(int argc, char *argv[])
{
msg_error_t res = MSG_OK;
- /* Argument checking */
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]);
+ "\tExample: %s msg_platform.xml msg_deployment_suspend.xml\n", argv[0], argv[0]);
- /* Simulation setting */
MSG_create_environment(argv[1]);
- /* Application deployment */
MSG_function_register("emigrant", emigrant);
MSG_function_register("policeman", policeman);
MSG_launch_application(argv[2]);
- /* Run the simulation */
mutex = xbt_mutex_init();
cond = xbt_cond_init();
res = MSG_main();
/* 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"
-#include "xbt/log.h"
-#include "xbt/asserts.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");
/** @addtogroup MSG_examples
*
* @subsection MSG_ex_PLS Packet level simulators
*
- * These examples demonstrate how to use the bindings to classical
- * Packet-Level Simulators (PLS), as explained in \ref pls. The most
- * interesting is probably not the C files since they are unchanged
- * from the other simulations, but the associated files, such as the
- * platform files to see how to declare a platform to be used with
- * the PLS bindings of SimGrid and the tesh files to see how to
- * actually start a simulation in these settings.
+ * These examples demonstrate how to use the bindings to classicalPacket-Level Simulators (PLS), as explained in
+ * \ref pls. The most interesting is probably not the C files since they are unchanged from the other simulations,
+ * but the associated files, such as the platform files to see how to declare a platform to be used with the PLS
+ * bindings of SimGrid and the tesh files to see how to actually start a simulation in these settings.
*
* - <b>ns3</b>: Simple ping-pong using ns3 instead of the SimGrid network models.
- *
*/
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-int timer(int argc, char *argv[]);
-msg_error_t test_all(const char *platform_file,
- const char *application_file);
-
int timer_start; //set as 1 in the master process
//keep a pointer to all surf running tasks.
#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
-/** master */
-int master(int argc, char *argv[])
+static int master(int argc, char *argv[])
{
msg_task_t todo;
gl_data_size[id] = task_comm_size;
}
- { /* Process organization */
- MSG_host_by_name(slavename);
- }
+ MSG_host_by_name(slavename);
count_finished++;
timer_start = 1 ;
XBT_DEBUG ("Finished");
xbt_free(id_alias);
return 0;
-} /* end_of_master */
-
+}
-/** Timer function */
int timer(int argc, char *argv[])
{
double sleep_time;
do {
XBT_DEBUG ("Get sleep");
- MSG_process_sleep(sleep_time);
+ MSG_process_sleep(sleep_time);
} while(timer_start);
XBT_DEBUG ("Finished");
return 0;
}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
-
msg_task_t task = NULL;
- int a = MSG_OK;
- int id = 0;
char id_alias[10];
xbt_assert(argc==2,"Strange number of arguments expected 1 got %d", argc - 1);
XBT_DEBUG ("Slave started");
- id = xbt_str_parse_int(argv[1], "Invalid id: %s");
+ int id = xbt_str_parse_int(argv[1], "Invalid id: %s");
sprintf(id_alias, "%d", id);
- a = MSG_task_receive(&(task), id_alias);
+ msg_error_t a = MSG_task_receive(&(task), id_alias);
count_finished--;
if(count_finished == 0){
timer_start = 0;
}
-
-
if (a != MSG_OK) {
XBT_INFO("Hey?! What's up?");
xbt_die("Unexpected behavior.");
}
elapsed_time = MSG_get_clock() - start_time;
-
- XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s",
- id,
- MSG_task_get_bytes_amount(task),
- masternames[id],
- slavenames[id]);
+
+ XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, MSG_task_get_bytes_amount(task), masternames[id],
+ slavenames[id]);
// MSG_task_execute(task);
MSG_task_destroy(task);
XBT_DEBUG ("Finished");
return 0;
-} /* end_of_slave */
-
-/** Test function */
-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);
- }
-
- TRACE_declare_mark("endmark");
-
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- MSG_function_register("timer", timer);
-
- MSG_launch_application(application_file);
- }
- res = MSG_main();
- 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 platform.xml deployment.xml\n",
- argv[0], argv[0]);
-
+ "\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
+ TRACE_declare_mark("endmark");
- res = test_all(argv[1], argv[2]);
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ MSG_function_register("timer", timer);
+
+ MSG_launch_application(argv[2]);
+
+ res = MSG_main();
return res != MSG_OK;
}
* interfaces, but it's not possible ATM).
*/
-
static int runner(int argc, char *argv[])
{
/* Retrieve the list of all hosts as an array of hosts */
int slaves_count = xbt_dynar_length(slaves_dynar);
msg_host_t *slaves = xbt_dynar_to_array(slaves_dynar);
- XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, and 10MB to exchange between each pair");
+ XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, "
+ "and 10MB to exchange between each pair");
double *computation_amounts = xbt_new0(double, slaves_count);
double *communication_amounts = xbt_new0(double, slaves_count * slaves_count);
/* 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 <math.h>
#include "simgrid/msg.h"
-#include "xbt/log.h"
-#include "xbt/asserts.h"
- XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pastry,
- "Messages specific for this msg example");
+ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pastry, "Messages specific for this msg example");
/***************************************
* PASTRY *
extern long int smx_total_comms;
-
typedef struct s_node {
int id; //128bits generated random(2^128 -1)
int known_id;
int routing_table[LEVELS_COUNT][LEVEL_SIZE];
} s_state_t, *state_t;
-/**
- * Types of tasks exchanged between nodes.
- */
+/** Types of tasks exchanged between nodes. */
typedef enum {
TASK_JOIN,
TASK_JOIN_REPLY,
static void create(node_t node);
static int join(node_t node);
-
/**
* \brief Gets the mailbox name of a host given its chord id.
* \param node_id id of a node
#include "simgrid/msg.h"
#include "xbt/matrix.h"
-#include "xbt/log.h"
#include "xbt/xbt_os_time.h"
/** @addtogroup MSG_examples
/* 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 <stdlib.h>
#include "simgrid/msg.h"
-#include "xbt/log.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, "Messages specific for this msg example");
{
XBT_INFO("Hello! I go to sleep.");
MSG_process_on_exit(my_onexit, NULL);
-
+
MSG_process_sleep(xbt_str_parse_int(argv[1], "sleeper process expects an integer parameter but got %s"));
XBT_INFO("Done sleeping.");
return 0;