doc/msg-tuto-src/masterworker2
doc/msg-tuto-src/masterworker3
doc/msg-tuto-src/masterworker4
-examples/msg/app-chainsend/chainsend
examples/msg/cloud-capping/cloud-capping
examples/msg/cloud-masterworker/cloud-masterworker
examples/msg/cloud-migration/cloud-migration
-examples/msg/cloud-simple/cloud-simple
-examples/msg/cloud-two-tasks/cloud-two-tasks
-examples/msg/dht-chord/dht-chord
examples/msg/dht-kademlia/dht-kademlia
examples/msg/dht-pastry/dht-pastry
examples/msg/energy-onoff/energy-onoff
examples/msg/energy-vm/energy-vm
examples/msg/platform-failures/platform-failures
-examples/msg/plugin-hostload/plugin-hostload
examples/msg/process-create/process-create
examples/msg/app-masterworker/app-masterworker
examples/msg/mc/bugged1
examples/msg/mc/test/snapshot_comparison5
examples/msg/ms.trace
examples/msg/network-ns3/network-ns3
-examples/msg/task-priority/task-priority
examples/msg/procmig.trace
examples/msg/synchro-semaphore/synchro-semaphore
examples/msg/maestro-set/maestro-set
examples/msg/simulation.trace
-examples/msg/app-token-ring/app-token-ring
examples/msg/trace-categories/trace-categories
examples/msg/trace-route-user-variables/trace-route-user-variables
examples/msg/trace-link-user-variables/trace-link-user-variables
examples/s4u/actor-suspend/s4u-actor-suspend
examples/s4u/actor-yield/s4u-actor-yield
examples/s4u/app-bittorrent/s4u-bittorrent
+examples/s4u/app-chainsend/s4u-app-chainsend
examples/s4u/app-masterworker/s4u-app-masterworker
examples/s4u/app-pingpong/s4u-app-pingpong
examples/s4u/app-token-ring/s4u-app-token-ring
examples/s4u/async-waitany/s4u-async-waitany
examples/s4u/cloud-simple/s4u-cloud-simple
examples/s4u/dht-chord/s4u-dht-chord
+examples/s4u/energy-exec/s4u-energy-exec
examples/s4u/energy-link/s4u-energy-link
-examples/s4u/energy-ptask/s4u-energy-ptask
examples/s4u/energy-vm/s4u-energy-vm
examples/s4u/exec-async/s4u-exec-async
examples/s4u/exec-basic/s4u-exec-basic
examples/s4u/exec-dvfs/s4u-exec-dvfs
examples/s4u/exec-monitor/s4u-exec-monitor
+examples/s4u/exec-ptask/s4u-exec-ptask
examples/s4u/exec-remote/s4u-exec-remote
examples/s4u/io-file-system/s4u-io-file-system
examples/s4u/io-file-remote/s4u-io-file-remote
teshsuite/mc/mutex-handling/without-mutex-handling
teshsuite/msg/actions-comm/actions-comm
teshsuite/msg/actions-storage/actions-storage
+teshsuite/msg/app-chainsend/chainsend
teshsuite/msg/app-bittorrent/bittorrent
teshsuite/msg/app-pingpong/app-pingpong
+teshsuite/msg/app-token-ring/app-token-ring
teshsuite/msg/async-wait/async-wait
teshsuite/msg/async-waitall/async-waitall
teshsuite/msg/async-waitany/async-waitany
teshsuite/msg/cloud-sharing/cloud-sharing
+teshsuite/msg/cloud-simple/cloud-simple
+teshsuite/msg/cloud-two-tasks/cloud-two-tasks
teshsuite/msg/concurrent_rw/concurrent_rw
+teshsuite/msg/dht-chord/dht-chord
teshsuite/msg/energy-consumption/energy-consumption
teshsuite/msg/energy-pstate/energy-pstate
teshsuite/msg/energy-ptask/energy-ptask
teshsuite/msg/io-raw-storage/io-raw-storage
teshsuite/msg/pid/pid
teshsuite/msg/platform-properties/platform-properties
+teshsuite/msg/plugin-hostload/plugin-hostload
teshsuite/msg/process/process
teshsuite/msg/process-daemon/process-daemon
teshsuite/msg/process-kill/process-kill
# C examples
-foreach(x app-masterworker app-token-ring
+foreach(x app-masterworker
cloud-capping cloud-masterworker cloud-migration
dht-pastry energy-onoff energy-vm platform-failures
- plugin-hostload
process-create
synchro-semaphore trace-categories
trace-route-user-variables trace-link-user-variables trace-masterworker
set_target_properties(network-ns3 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/network-ns3)
endif()
-add_executable (chainsend app-chainsend/chainsend.c app-chainsend/iterator.c app-chainsend/common.c app-chainsend/messages.c app-chainsend/broadcaster.c app-chainsend/peer.c)
-target_link_libraries(chainsend simgrid)
-set_target_properties(chainsend PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/app-chainsend)
-foreach (file common iterator messages broadcaster peer)
- set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/${file}.h)
-endforeach()
-
add_executable (dht-kademlia dht-kademlia/dht-kademlia.c dht-kademlia/node.c dht-kademlia/routing_table.c dht-kademlia/task.c dht-kademlia/answer.c)
target_link_libraries(dht-kademlia simgrid)
set_target_properties(dht-kademlia PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dht-kademlia)
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.h)
endforeach()
-foreach (file app-chainsend app-masterworker dht-kademlia dht-pastry)
+foreach (file app-masterworker dht-kademlia dht-pastry)
set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/${file}/${file}_d.xml)
endforeach()
set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/README.doc PARENT_SCOPE)
set(bin_files ${bin_files} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/generate.py
${CMAKE_CURRENT_SOURCE_DIR}/dht-pastry/generate.py PARENT_SCOPE)
-set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/chainsend.c
- ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/common.h
+set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/common.h
${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/network-ns3.c PARENT_SCOPE)
-set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/app-chainsend.tesh
- ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia.tesh
+set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia.tesh
${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-multicore.tesh
${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-vivaldi.tesh
${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/network-ns3.tesh PARENT_SCOPE)
${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/one_cluster_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/two_clusters_d.xml PARENT_SCOPE)
-foreach(x app-chainsend app-masterworker app-token-ring
+foreach(x app-masterworker
cloud-capping cloud-masterworker cloud-migration
dht-pastry dht-kademlia platform-failures
energy-onoff energy-vm
- plugin-hostload
process-create
synchro-semaphore)
ADD_TESH_FACTORIES(msg-${x} "thread;ucontext;raw;boost"
@section msg_ex_basics Basic examples and features
- - <b>Token Ring</b>.
- @ref examples/msg/app-token-ring/app-token-ring.c\n
- Classical communication pattern, where a token is exchanged
- along a ring to reach every participant.
- The tesh file laying in the directory shows how to run the same
- example on different virtual platforms.
-
- <b>Master Workers</b>.
@ref examples/msg/app-masterworker/app-masterworker.c\n
Another good old example, where one Master process has a bunch of
/**
-@example examples/msg/app-token-ring/app-token-ring.c
@example examples/msg/app-masterworker/app-masterworker.c
@example examples/msg/process-create/process-create.c
#! ./tesh
-$ ${bindir:=.}/s4u-energy-ptask$EXEEXT ${platfdir}/energy_platform.xml --energy --cfg=host/model:ptask_L07 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/s4u-exec-ptask$EXEEXT ${platfdir}/energy_platform.xml --energy --cfg=host/model:ptask_L07 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07'
> [ 0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks.
> [ 0.000000] (1:test@MyHost1) First, build a classical parallel task, with 1 Gflop to execute on each node, and 10MB to exchange between each pair
# C examples
foreach(x actions-comm actions-storage
- app-pingpong
+ app-pingpong app-token-ring
async-wait async-waitall async-waitany
cloud-sharing cloud-two-tasks cloud-simple
get_sender host_on_off host_on_off_recv host_on_off_processes
energy-consumption energy-ptask energy-pstate platform-properties
io-file io-raw-storage io-file-remote
task-priority
+ plugin-hostload
trace_integration)
add_executable (${x} ${x}/${x}.c)
target_link_libraries(${x} simgrid)
set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/${file}.h)
endforeach()
-
+add_executable (chainsend app-chainsend/chainsend.c app-chainsend/iterator.c app-chainsend/common.c app-chainsend/messages.c app-chainsend/broadcaster.c app-chainsend/peer.c)
+target_link_libraries(chainsend simgrid)
+set_target_properties(chainsend PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/app-chainsend)
+foreach (file common iterator messages broadcaster peer)
+ set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/${file}.h)
+endforeach()
+set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/chainsend.c)
+
set(teshsuite_src ${teshsuite_src} PARENT_SCOPE)
-set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/app-bittorrent.tesh PARENT_SCOPE)
+set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/app-bittorrent.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/app-chainsend.tesh
+ PARENT_SCOPE)
set(bin_files ${bin_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/generate.py PARENT_SCOPE)
set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/actions-comm.txt
${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/actions-comm_split_p0.txt
${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/actions-comm_split_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/actions-storage_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/app-bittorrent_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/app-chainsend/app-chainsend_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/app-pingpong/app-pingpong_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-wait/async-wait_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-wait/async-wait2_d.xml
foreach(x
actions-comm actions-storage
async-wait async-waitall async-waitany
- app-bittorrent app-pingpong
+ app-bittorrent app-chainsend app-pingpong app-token-ring
cloud-two-tasks cloud-simple
energy-pstate
host_on_off host_on_off_processes host_on_off_recv
energy-consumption energy-ptask
io-file io-raw-storage io-file-remote
platform-properties
+ plugin-hostload
trace_integration)
ADD_TESH_FACTORIES(tesh-msg-${x} "thread;ucontext;raw;boost"
--setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
! timeout 60
! output sort 19
-$ $SG_TEST_EXENV ${bindir:=.}/chainsend ${platfdir}/cluster.xml ${srcdir}/app-chainsend_d.xml "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
+$ $SG_TEST_EXENV ${bindir:=.}/chainsend ${platfdir}/cluster.xml app-chainsend_d.xml "--log=root.fmt:[%12.6r]%e(%i:%P@%h)%e%m%n"
> [ 2.214423] (2:peer@node-1.acme.org) ### 2.214423 16777216 bytes (Avg 7.225359 MB/s); copy finished (simulated).
> [ 2.222796] (3:peer@node-2.acme.org) ### 2.222796 16777216 bytes (Avg 7.198141 MB/s); copy finished (simulated).
> [ 2.231170] (4:peer@node-3.acme.org) ### 2.231170 16777216 bytes (Avg 7.171126 MB/s); copy finished (simulated).
{
xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), xbt_free_ref);
for (int i = 1; i <= hostcount; i++) {
- char *hostname = bprintf("host%d", i);
+ char* hostname = bprintf("host%d", i);
XBT_DEBUG("%s", hostname);
xbt_dynar_push(host_list, &hostname);
}
int broadcaster_build_chain(broadcaster_t bc)
{
- msg_task_t task = NULL;
+ msg_task_t task = NULL;
char** cur = (char**)xbt_dynar_iterator_next(bc->it);
const char* me = MSG_host_get_name(MSG_host_self());
const char* current_host = NULL;
/* Build the chain if there's at least one peer */
if (cur != NULL) {
/* init: prev=NULL, host=current cur, next=next cur */
- next = *cur;
+ next = *cur;
bc->first = next;
/* 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);
- prev = last;
+ cur = (char**)xbt_dynar_iterator_next(bc->it);
+ prev = last;
current_host = next;
if (cur != NULL)
next = *cur;
broadcaster_t bc = xbt_new(s_broadcaster_t, 1);
bc->first = NULL;
- bc->piece_count = piece_count;
- bc->current_piece = 0;
- bc->host_list = host_list;
- bc->it = xbt_dynar_iterator_new(bc->host_list, forward_indices_list);
+ bc->piece_count = piece_count;
+ bc->current_piece = 0;
+ bc->host_list = host_list;
+ bc->it = xbt_dynar_iterator_new(bc->host_list, forward_indices_list);
bc->max_pending_sends = MAX_PENDING_SENDS;
- bc->pending_sends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
+ bc->pending_sends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
status = broadcaster_build_chain(bc);
xbt_assert(status == MSG_OK, "Chain initialization failed");
}
/** Emitter function */
-int broadcaster(int argc, char *argv[])
+int broadcaster(int argc, char* argv[])
{
unsigned int piece_count = PIECE_COUNT;
#ifndef BROADCASTER_H
#define BROADCASTER_H
-#include "xbt/dynar.h"
-#include "messages.h"
-#include "iterator.h"
#include "common.h"
+#include "iterator.h"
+#include "messages.h"
+#include "xbt/dynar.h"
/* Connection parameters */
#define MAX_PENDING_SENDS 10
/* Broadcaster struct */
typedef struct s_broadcaster {
- const char *first;
+ const char* first;
int piece_count;
int current_piece;
xbt_dynar_t host_list;
xbt_dynar_t pending_sends;
} s_broadcaster_t;
-typedef s_broadcaster_t *broadcaster_t;
+typedef s_broadcaster_t* broadcaster_t;
xbt_dynar_t build_hostlist_from_hostcount(int hostcount);
int broadcaster_send_file(broadcaster_t bc);
/* Tasks */
-int broadcaster(int argc, char *argv[]);
+int broadcaster(int argc, char* argv[]);
#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 "simgrid/msg.h"
+#include "broadcaster.h"
#include "iterator.h"
#include "messages.h"
-#include "broadcaster.h"
#include "peer.h"
+#include "simgrid/msg.h"
/** @addtogroup MSG_examples
*
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chainsend, "Messages specific for chainsend");
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
MSG_init(&argc, argv);
int empty = 0;
msg_comm_t comm;
- xbt_dynar_foreach(q, iter, comm) {
+ xbt_dynar_foreach (q, iter, comm) {
empty = 1;
if (MSG_comm_test(comm)) {
status = MSG_comm_get_status(comm);
{
xbt_dynar_iterator_t it = xbt_new(xbt_dynar_iterator_s, 1);
- it->list = list;
- it->length = xbt_dynar_length(list);
+ it->list = list;
+ it->length = xbt_dynar_length(list);
it->indices_list = criteria_fn(it->length); // Creates and fills a dynar of int
- it->criteria_fn = criteria_fn;
- it->current = 0;
+ it->criteria_fn = criteria_fn;
+ it->current = 0;
return it;
}
/* Returns the next element iterated by iterator it, NULL if there are no more elements */
-void *xbt_dynar_iterator_next(xbt_dynar_iterator_t it)
+void* xbt_dynar_iterator_next(xbt_dynar_iterator_t it)
{
if (it->current >= it->length) {
return NULL;
int current;
unsigned long length;
xbt_dynar_t (*criteria_fn)(int size);
-} *xbt_dynar_iterator_t;
+} * xbt_dynar_iterator_t;
typedef struct xbt_dynar_iterator_struct xbt_dynar_iterator_s;
/* Iterator methods */
xbt_dynar_iterator_t xbt_dynar_iterator_new(xbt_dynar_t list, xbt_dynar_t (*criteria_fn)(int));
void xbt_dynar_iterator_reset(xbt_dynar_iterator_t it);
void xbt_dynar_iterator_seek(xbt_dynar_iterator_t it, int pos);
-void *xbt_dynar_iterator_next(xbt_dynar_iterator_t it);
+void* xbt_dynar_iterator_next(xbt_dynar_iterator_t it);
void xbt_dynar_iterator_delete(xbt_dynar_iterator_t it);
/* Iterator generators */
msg_task_t task_message_new(e_message_type type, unsigned int len)
{
- message_t msg = xbt_new(s_message_t, 1);
- msg->type = type;
+ message_t msg = xbt_new(s_message_t, 1);
+ msg->type = type;
msg->prev_hostname = NULL;
msg->next_hostname = NULL;
- msg_task_t task = MSG_task_create(NULL, 0, len, msg);
+ msg_task_t task = MSG_task_create(NULL, 0, len, msg);
return task;
}
-msg_task_t task_message_chain_new(const char* prev, const char *next, const unsigned int num_pieces)
+msg_task_t task_message_chain_new(const char* prev, const char* next, const unsigned int num_pieces)
{
- msg_task_t task = task_message_new(MESSAGE_BUILD_CHAIN, MESSAGE_BUILD_CHAIN_SIZE);
- message_t msg = MSG_task_get_data(task);
+ msg_task_t task = task_message_new(MESSAGE_BUILD_CHAIN, MESSAGE_BUILD_CHAIN_SIZE);
+ message_t msg = MSG_task_get_data(task);
msg->prev_hostname = xbt_strdup(prev);
msg->next_hostname = xbt_strdup(next);
- msg->num_pieces = num_pieces;
+ msg->num_pieces = num_pieces;
return task;
}
-msg_task_t task_message_data_new(const char *block, unsigned int len)
+msg_task_t task_message_data_new(const char* block, unsigned int len)
{
- msg_task_t task = task_message_new(MESSAGE_SEND_DATA, MESSAGE_SEND_DATA_HEADER_SIZE + len);
- message_t msg = MSG_task_get_data(task);
- msg->data_block = block;
+ msg_task_t task = task_message_new(MESSAGE_SEND_DATA, MESSAGE_SEND_DATA_HEADER_SIZE + len);
+ message_t msg = MSG_task_get_data(task);
+ msg->data_block = block;
msg->data_length = len;
return task;
}
-void task_message_delete(void *task)
+void task_message_delete(void* task)
{
message_t msg = MSG_task_get_data(task);
xbt_free(msg);
#define MESSAGE_END_DATA_SIZE 1
/* Messages enum */
-typedef enum {
- MESSAGE_BUILD_CHAIN = 0,
- MESSAGE_SEND_DATA
-} e_message_type;
+typedef enum { MESSAGE_BUILD_CHAIN = 0, MESSAGE_SEND_DATA } e_message_type;
/* Message struct */
typedef struct s_message {
e_message_type type;
- char *prev_hostname;
- char *next_hostname;
- const char *data_block;
+ char* prev_hostname;
+ char* next_hostname;
+ const char* data_block;
unsigned int data_length;
unsigned int num_pieces;
} s_message_t;
-typedef s_message_t *message_t;
+typedef s_message_t* message_t;
/* Message methods */
msg_task_t task_message_new(e_message_type type, unsigned int len);
-msg_task_t task_message_chain_new(const char* prev, const char *next, const unsigned int num_pieces);
-msg_task_t task_message_data_new(const char *block, unsigned int len);
-void task_message_delete(void *);
+msg_task_t task_message_chain_new(const char* prev, const char* next, const unsigned int num_pieces);
+msg_task_t task_message_data_new(const char* block, unsigned int len);
+void task_message_delete(void*);
#endif /* MESSAGES_H */
void peer_init_chain(peer_t peer, message_t msg)
{
- peer->prev = msg->prev_hostname;
- peer->next = msg->next_hostname;
+ peer->prev = msg->prev_hostname;
+ peer->next = msg->next_hostname;
peer->total_pieces = msg->num_pieces;
- peer->init = 1;
+ peer->init = 1;
}
static void peer_forward_msg(peer_t peer, message_t msg)
int peer_execute_task(peer_t peer, msg_task_t task)
{
- int done = 0;
+ int done = 0;
message_t msg = MSG_task_get_data(task);
XBT_DEBUG("Peer %s got message of type %u\n", peer->me, msg->type);
msg_error_t status;
msg_comm_t comm = NULL;
msg_task_t task = NULL;
- int done = 0;
+ int done = 0;
while (done == 0) {
comm = MSG_task_irecv(&task, peer->me);
queue_pending_connection(comm, peer->pending_recvs);
int idx = MSG_comm_waitany(peer->pending_recvs);
if (idx != -1) {
- comm = xbt_dynar_get_as(peer->pending_recvs, idx, msg_comm_t);
+ comm = xbt_dynar_get_as(peer->pending_recvs, idx, msg_comm_t);
status = MSG_comm_get_status(comm);
XBT_DEBUG("peer_wait_for_message: error code = %u", status);
xbt_assert(status == MSG_OK, "peer_wait_for_message() failed");
return status;
}
-void peer_init(peer_t p, int argc, char *argv[])
+void peer_init(peer_t p, int argc, char* argv[])
{
- p->init = 0;
- p->prev = NULL;
- p->next = NULL;
- p->pieces = 0;
- p->bytes = 0;
+ p->init = 0;
+ p->prev = NULL;
+ p->next = NULL;
+ p->pieces = 0;
+ p->bytes = 0;
p->pending_recvs = xbt_dynar_new(sizeof(msg_comm_t), NULL);
p->pending_sends = xbt_dynar_new(sizeof(msg_comm_t), NULL);
/* Set mailbox name: use host number from argv or hostname if no argument given */
{
unsigned int size = xbt_dynar_length(p->pending_sends);
unsigned int idx;
- msg_comm_t *comms = xbt_new(msg_comm_t, size);
+ msg_comm_t* comms = xbt_new(msg_comm_t, size);
for (idx = 0; idx < size; idx++) {
comms[idx] = xbt_dynar_get_as(p->pending_sends, idx, msg_comm_t);
void peer_print_stats(peer_t p, float elapsed_time)
{
- XBT_INFO("### %f %llu bytes (Avg %f MB/s); copy finished (simulated).", elapsed_time, p->bytes, p->bytes / 1024.0 / 1024.0 / elapsed_time);
+ XBT_INFO("### %f %llu bytes (Avg %f MB/s); copy finished (simulated).", elapsed_time, p->bytes,
+ p->bytes / 1024.0 / 1024.0 / elapsed_time);
}
/** Peer function */
-int peer(int argc, char *argv[])
+int peer(int argc, char* argv[])
{
peer_t p = xbt_new(s_peer_t, 1);
msg_error_t status;
peer_init(p, argc, argv);
float start_time = MSG_get_clock();
- status = peer_wait_for_message(p);
+ status = peer_wait_for_message(p);
peer_shutdown(p);
float end_time = MSG_get_clock();
peer_print_stats(p, end_time - start_time);
#include "simgrid/msg.h"
#include "xbt/dynar.h"
-#include "messages.h"
#include "common.h"
+#include "messages.h"
#define PEER_SHUTDOWN_DEADLINE 60000
/* Peer struct */
typedef struct s_peer {
int init;
- char *prev;
- char *next;
- char *me;
+ char* prev;
+ char* next;
+ char* me;
int pieces;
unsigned long long bytes;
xbt_dynar_t pending_recvs;
xbt_dynar_t pending_sends;
unsigned int total_pieces;
} s_peer_t;
-typedef s_peer_t *peer_t;
+typedef s_peer_t* peer_t;
/* Peer: helper functions */
msg_error_t peer_wait_for_message(peer_t peer);
void peer_init_chain(peer_t peer, message_t msg);
void peer_delete(peer_t p);
void peer_shutdown(peer_t p);
-void peer_init(peer_t p, int argc, char *argv[]);
+void peer_init(peer_t p, int argc, char* argv[]);
void peer_print_stats(peer_t p, float elapsed_time);
-int peer(int argc, char *argv[]);
+int peer(int argc, char* argv[]);
#endif /* PEER_H */
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_token_ring, "Messages specific for this msg example");
/* Main function of all processes used in this example */
-static int relay_runner(int argc, char *argv[])
+static int relay_runner(int argc, char* argv[])
{
- xbt_assert(argc==0, "The relay_runner function does not accept any parameter from the XML deployment file");
- int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Any process of this example must have a numerical name, not %s");
+ xbt_assert(argc == 0, "The relay_runner function does not accept any parameter from the XML deployment file");
+ int rank = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()),
+ "Any process of this example must have a numerical name, not %s");
char mailbox[256];
if (rank == 0) {
/* The root process (rank 0) first sends the token then waits to receive it back */
- snprintf(mailbox,255, "%d", rank+1);
+ snprintf(mailbox, 255, "%d", rank + 1);
unsigned int task_comm_size = 1000000; /* The token is 1MB long*/
- msg_task_t task = MSG_task_create("Token", 0, task_comm_size, NULL);
- XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name,mailbox);
+ msg_task_t task = MSG_task_create("Token", 0, task_comm_size, NULL);
+ XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox);
MSG_task_send(task, mailbox);
- task = NULL;
+ task = NULL;
int res = MSG_task_receive(&task, MSG_process_get_name(MSG_process_self()));
xbt_assert(res == MSG_OK, "MSG_task_get failed");
XBT_INFO("Host \"%d\" received \"%s\"", rank, MSG_task_get_name(task));
} else {
/* The others processes receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */
msg_task_t task = NULL;
- int res = MSG_task_receive(&task, MSG_process_get_name(MSG_process_self()));
+ int res = MSG_task_receive(&task, MSG_process_get_name(MSG_process_self()));
xbt_assert(res == MSG_OK, "MSG_task_get failed");
- XBT_INFO("Host \"%d\" received \"%s\"",rank, MSG_task_get_name(task));
+ XBT_INFO("Host \"%d\" received \"%s\"", rank, MSG_task_get_name(task));
- if (rank+1 == MSG_get_host_number())
+ if (rank + 1 == MSG_get_host_number())
/* But the last process, which sends the token back to rank 0 */
- snprintf(mailbox,255, "0");
+ snprintf(mailbox, 255, "0");
else
- snprintf(mailbox,255, "%d", rank+1);
- XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",rank,task->name,mailbox);
+ snprintf(mailbox, 255, "%d", rank + 1);
+ XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name, mailbox);
MSG_task_send(task, mailbox);
}
return 0;
}
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
MSG_init(&argc, argv);
- xbt_assert(argc>1, "Usage: %s platform.xml\n",argv[0]);
- MSG_create_environment(argv[1]); /* - Load the platform description */
+ xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
+ MSG_create_environment(argv[1]); /* - Load the platform description */
xbt_dynar_t hosts = MSG_hosts_as_dynar();
XBT_INFO("Number of hosts '%d'", MSG_get_host_number());
unsigned int i;
msg_host_t h;
- xbt_dynar_foreach (hosts, i, h) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */
- char* name_host = bprintf("%u",i);
+ xbt_dynar_foreach (hosts, i,
+ h) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */
+ char* name_host = bprintf("%u", i);
MSG_process_create(name_host, relay_runner, NULL, h);
free(name_host);
}
xbt_dynar_free(&hosts);
- int res = MSG_main(); /* - Run the simulation */
+ int res = MSG_main(); /* - Run the simulation */
XBT_INFO("Simulation time %g", MSG_get_clock());
return res != MSG_OK;
}