-/* Copyright (c) 2010. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#define DO_VA_COPY(d,s) memcpy((void *)(d), (void *)(s)), sizeof(*(s))
-void test(char *str, ...)
-{
- va_list ap, ap2;
- int i;
- va_start(ap, str);
- DO_VA_COPY(ap2, ap);
- for (i = 1; i <= 9; i++) {
- int k = (int)va_arg(ap, int);
- if (k != i)
- abort();
- }
- DO_VA_COPY(ap, ap2);
- for (i = 1; i <= 9; i++) {
- int k = (int)va_arg(ap, int);
- if (k != i)
- abort();
- }
- va_end(ap);
-}
-int main(int argc, char *argv[])
-{
- test(test, 1, 2, 3, 4, 5, 6, 7, 8, 9);
- exit(0);
-}
+ #include <stdarg.h>
+ #include <string.h>
+ #define DO_VA_COPY(d,s) memcpy((void *)(d), (void *)(s)), sizeof(*(s))
+ void test(char *str, ...)
+ {
+ va_list ap, ap2;
+ int i;
+ va_start(ap, str);
+ DO_VA_COPY(ap2, ap);
+ for (i = 1; i <= 9; i++) {
+ int k = (int)va_arg(ap, int);
+ if (k != i)
+ abort();
+ }
+ DO_VA_COPY(ap, ap2);
+ for (i = 1; i <= 9; i++) {
+ int k = (int)va_arg(ap, int);
+ if (k != i)
+ abort();
+ }
+ va_end(ap);
+ }
+ int main(int argc, char *argv[])
+ {
+ test(test, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ exit(0);
+ }
add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/masterslave)
add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/trace)
add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/tracing)
+add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/mc)
if(HAVE_GTNETS)
add_definitions("-lgtnets -L${gtnets_path}/lib -I${gtnets_path}/include/gtnets")
add_subdirectory(${PROJECT_DIRECTORY}/examples/msg/gtnets)
priority/priority \
properties/msg_prop \
actions/actions \
- trace/test_trace_integration
+ trace/test_trace_integration \
+ mc/centralized \
+ mc/bugged1 \
+ mc/bugged2
if HAVE_GTNETS
noinst_PROGRAMS += gtnets/gtnets
trace_test_trace_integration_SOURCES = trace/test_trace_integration.c
trace_test_trace_integration_LDADD = $(top_builddir)/src/libsimgrid.la
+# Model-checking examples
+mc_centralized_SOURCES = mc/centralized_mutex.c
+mc_centralized_LDADD = $(top_builddir)/src/libsimgrid.la
+
+# bugged example 1
+mc_bugged1_SOURCES = mc/bugged1.c
+mc_bugged1_LDADD = $(top_builddir)/src/libsimgrid.la
+
+# bugged example 2
+mc_bugged2_SOURCES = mc/bugged2.c
+mc_bugged2_LDADD = $(top_builddir)/src/libsimgrid.la
+
+
# verify if the GTNETS feature is working
if HAVE_GTNETS
gtnets_gtnets_SOURCES = gtnets/gtnets.c
--- /dev/null
+cmake_minimum_required(VERSION 2.6)
+
+set(EXECUTABLE_OUTPUT_PATH "${PROJECT_DIRECTORY}/examples/msg/actions/")
+
+add_executable(centralized centralized_mutex.c)
+add_executable(bugged1 bugged1.c)
+add_executable(bugged2 bugged2.c)
+
+target_link_libraries(centralized simgrid m -fprofile-arcs)
+target_link_libraries(bugged1 simgrid m -fprofile-arcs)
+target_link_libraries(bugged2 simgrid m -fprofile-arcs)
--- /dev/null
+#include <msg/msg.h>
+#include <mc/modelchecker.h>
+#define N 3
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(example,"this example");
+
+int server(int argc,char *argv[]);
+int client(int argc,char *argv[]);
+
+int server(int argc,char *argv[]) {
+ m_task_t task = NULL;
+ int count = 0;
+ while(count < N){
+ if(task){
+ MSG_task_destroy(task);
+ task = NULL;
+ }
+ MSG_task_receive(&task,"mymailbox");
+ count++;
+ }
+ MC_assert(atoi(MSG_task_get_name(task)) == 3);
+
+ INFO0("OK");
+ return 0;
+}
+
+int client(int argc,char *argv[]) {
+
+ m_task_t task = MSG_task_create(argv[1], 0/*comp cost*/, 10000/*comm size*/, NULL /*arbitrary data*/);
+
+ MSG_task_send(task,"mymailbox");
+
+ INFO0("Sent!");
+ return 0;
+}
+
+int main(int argc,char*argv[]) {
+
+ MSG_global_init(&argc,argv);
+
+ MSG_create_environment("platform.xml");
+
+ MSG_function_register("server", server);
+
+ MSG_function_register("client", client);
+
+ MSG_launch_application("deploy.xml");
+
+ MSG_main();
+
+ return 0;
+
+}
+
+
--- /dev/null
+#include <msg/msg.h>
+#include <mc/modelchecker.h>
+#define N 3
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(example,"this example");
+
+int server(int argc,char *argv[]);
+int client(int argc,char *argv[]);
+
+int server(int argc,char *argv[])
+{
+ m_task_t task1, task2;
+ long val1, val2;
+
+ MSG_task_receive(&task1,"mymailbox");
+ val1 = (long)MSG_task_get_data(task1);
+ INFO1("Received %lu", val1);
+
+ MSG_task_receive(&task2,"mymailbox");
+ val2 = (long)MSG_task_get_data(task2);
+ INFO1("Received %lu", val2);
+
+ MC_assert( min(val1, val2) == 1 );
+
+ INFO0("OK");
+ return 0;
+}
+
+int client(int argc,char *argv[])
+{
+ m_task_t task1 = MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
+ m_task_t task2 = MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
+
+ INFO1("Send %d!", atoi(argv[1]));
+ MSG_task_send(task1,"mymailbox");
+
+ INFO1("Send %d!", atoi(argv[1]));
+ MSG_task_send(task2,"mymailbox");
+
+ return 0;
+}
+
+int main(int argc,char*argv[])
+{
+ MSG_global_init(&argc,argv);
+
+ MSG_create_environment("platform.xml");
+
+ MSG_function_register("server", server);
+
+ MSG_function_register("client", client);
+
+ MSG_launch_application("deploy.xml");
+
+ MSG_main();
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/* Centralized Mutual Exclusion Algorithm
+ *
+ * This constitutes the answer to the exercice 2 of the practical
+ * lab on implementing mutual exclusion algorithms with SimGrid.
+ *
+ * YOU SHOULD TRY IMPLEMENTING IT YOURSELF BEFORE READING THE SOLUTION.
+ */
+
+#include "msg/msg.h"
+
+#define AMOUNT_OF_CLIENTS 5
+#define CS_PER_PROCESS 2
+XBT_LOG_NEW_DEFAULT_CATEGORY(centralized, "my log messages");
+
+int coordinator(int argc, char** argv);
+int client(int argc, char** argv);
+
+int coordinator(int argc, char*argv[]) {
+ xbt_dynar_t requests=xbt_dynar_new(sizeof(char*),NULL); // dynamic vector storing requests (which are char*)
+ int CS_used=0; // initially the CS is idle
+ int todo= AMOUNT_OF_CLIENTS*CS_PER_PROCESS; // amount of releases we are expecting
+ while(todo>0) {
+ m_task_t task=NULL;
+ MSG_task_receive(&task,"coordinator");
+ const char *kind = MSG_task_get_name(task); //is it a request or a release?
+ if (!strcmp(kind,"request")) { // that's a request
+ char *req = MSG_task_get_data(task);
+ if (CS_used) { // need to push the request in the vector
+ INFO0("CS already used. Queue the request");
+ xbt_dynar_push(requests, &req);
+ } else { // can serve it immediatly
+ INFO0("CS idle. Grant immediatly");
+ m_task_t answer = MSG_task_create("grant",0,1000,NULL);
+ MSG_task_send(answer,req);
+ CS_used = 1;
+ }
+ } else { // that's a release. Check if someone was waiting for the lock
+ if (xbt_dynar_length(requests)>0) {
+ INFO1("CS release. Grant to queued requests (queue size: %lu)",xbt_dynar_length(requests));
+ char *req;
+ xbt_dynar_pop(requests,&req);
+ MSG_task_send(MSG_task_create("grant",0,1000,NULL),req);
+ todo--;
+ } else { // nobody wants it
+ INFO0("CS release. resource now idle");
+ CS_used=0;
+ todo--;
+ }
+ }
+ //MSG_task_destoy(task);
+ }
+ INFO0("Received all releases, quit now");
+ return 0;
+}
+
+int client(int argc, char *argv[]) {
+ int my_pid=MSG_process_get_PID(MSG_process_self());
+ // use my pid as name of mailbox to contact me
+ char *my_mailbox=bprintf("%d",my_pid);
+ // request the CS 3 times, sleeping a bit in between
+ int i;
+ for (i=0; i<CS_PER_PROCESS;i++) {
+ INFO0("Ask the request");
+ MSG_task_send(MSG_task_create("request",0,1000,my_mailbox),"coordinator");
+ // wait the answer
+ m_task_t grant = NULL;
+ MSG_task_receive(&grant,my_mailbox);
+ //MSG_task_destoy(grant);
+ INFO0("got the answer. Sleep a bit and release it");
+ MSG_process_sleep(1);
+ MSG_task_send(MSG_task_create("release",0,1000,NULL),"coordinator");
+ MSG_process_sleep(my_pid);
+ }
+ INFO0("Got all the CS I wanted, quit now");
+ return 0;
+}
+
+int main(int argc, char*argv[]) {
+ MSG_global_init(&argc,argv);
+ MSG_create_environment("../msg_platform.xml");
+ MSG_function_register("coordinator", coordinator);
+ MSG_function_register("client", client);
+ MSG_launch_application("deploy.xml");
+ MSG_main();
+ return 0;
+}
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+ <process host="HostA" function="server">
+ <argument value="0"/>
+ </process>
+ <process host="HostB" function="client">
+ <argument value="1"/>
+ </process>
+ <process host="HostC" function="client">
+ <argument value="2"/>
+ </process>
+ <process host="HostD" function="client">
+ <argument value="3"/>
+ </process>
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+ <process host="HostA" function="server">
+ <argument value="0"/>
+ </process>
+ <process host="HostB" function="client">
+ <argument value="1"/>
+ </process>
+ <process host="HostC" function="client">
+ <argument value="2"/>
+ </process>
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+
+<platform version="2">
+
+ <process host="Tremblay" function="coordinator" />
+
+ <process host="Fafard" function="client" />
+
+ <process host="Boivin" function="client" />
+
+ <process host="TeX" function="client" />
+
+ <process host="Geoff" function="client" />
+
+ <process host="Disney" function="client" />
+
+<!-- <process host="iRMX" function="client" />
+
+ <process host="McGee" function="client" />
+
+ <process host="Gatien" function="client" />
+
+ <process host="Laroche" function="client" />
+
+ <process host="Tanguay" function="client" />
+
+ <process host="Morin" function="client" />
+
+ <process host="Ethernet" function="client" />
+
+ <process host="Bellemarre" function="client" />
+
+ <process host="Kuenning" function="client" />
+
+ <process host="Gaston" function="client" /> -->
+
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+ <host id="HostA" power="137333000"/>
+ <host id="HostB" power="98095000"/>
+ <host id="HostC" power="98095000"/>
+ <host id="HostD" power="98095000"/>
+ <link id="1" bandwidth="3430125" latency="0.000536941"/>
+ <link id="2" bandwidth="3430125" latency="0.000536941"/>
+ <link id="3" bandwidth="3430125" latency="0.000536941"/>
+ <route src="HostA" dst="HostB"><link:ctn id="1"/></route>
+ <route src="HostB" dst="HostA"><link:ctn id="1"/></route>
+ <route src="HostA" dst="HostC"><link:ctn id="2"/></route>
+ <route src="HostC" dst="HostA"><link:ctn id="2"/></route>
+ <route src="HostA" dst="HostD"><link:ctn id="3"/></route>
+ <route src="HostD" dst="HostA"><link:ctn id="3"/></route>
+</platform>
+
--- /dev/null
+#include "xbt.h"
+
+XBT_PUBLIC(void) MC_assert(int);
\ No newline at end of file