From: Jean-Edouard BOULANGER Date: Mon, 14 Mar 2022 18:01:12 +0000 (+0100) Subject: Make synchro-mutex.py in line with s4u-synchro-mutex.cpp X-Git-Tag: v3.31~106^2~1 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/92fe1e32f2111e4720e80429af53d976b31bf80b Make synchro-mutex.py in line with s4u-synchro-mutex.cpp --- diff --git a/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp b/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp index 52e2595aa2..648024aa78 100644 --- a/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp +++ b/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp @@ -49,6 +49,7 @@ static void master() /* Create the requested amount of actors pairs. Each pair has a specific mutex and cell in `result`. */ int result[cfg_actor_count.get()]; + sg4::MutexPtr mutex = sg4::Mutex::create(); for (int i = 0; i < cfg_actor_count; i++) { result[i] = 0; sg4::MutexPtr mutex = sg4::Mutex::create(); diff --git a/examples/python/synchro-mutex/synchro-mutex.py b/examples/python/synchro-mutex/synchro-mutex.py index 4e4a88621f..ec0d8da419 100644 --- a/examples/python/synchro-mutex/synchro-mutex.py +++ b/examples/python/synchro-mutex/synchro-mutex.py @@ -14,10 +14,10 @@ def create_parser() -> ArgumentParser: help='path to the platform description' ) parser.add_argument( - '--workers', + '--actors', type=int, default=6, - help='number of workers to start' + help='how many pairs of actors should be started?' ) return parser @@ -63,18 +63,9 @@ def master(settings): """ result = ResultHolder(value=0) mutex = Mutex() - actors = [] - for i in range(settings.workers): - use_worker_context_manager = i % 2 == 0 - actors.append( - Actor.create( - f"worker-{i}(mgr)" if use_worker_context_manager else f"worker-{i}", - Host.by_name("Jupiter" if use_worker_context_manager else "Tremblay"), - worker_context_manager if use_worker_context_manager else worker, - mutex, - result - ) - ) + for i in range(settings.actors): + Actor.create(f"worker-{i}(mgr)", Host.by_name("Jupiter"), worker_context_manager, mutex, result) + Actor.create(f"worker-{i}", Host.by_name("Tremblay"), worker, mutex, result) this_actor.sleep_for(10) this_actor.info(f"The final result is: {result.value}") diff --git a/examples/python/synchro-mutex/synchro-mutex.tesh b/examples/python/synchro-mutex/synchro-mutex.tesh index 169c876d23..9537cff5bb 100644 --- a/examples/python/synchro-mutex/synchro-mutex.tesh +++ b/examples/python/synchro-mutex/synchro-mutex.tesh @@ -2,41 +2,71 @@ p Testing Mutex -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --workers 0 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --actors 0 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" >[ 10.000000] (1:master@Tremblay) The final result is: 0 -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --workers 1 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --actors 1 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" >[ 0.000000] (2:worker-0(mgr)@Jupiter) I just started >[ 0.000000] (2:worker-0(mgr)@Jupiter) acquired the mutex with context manager >[ 0.000000] (2:worker-0(mgr)@Jupiter) updated shared result, which is now 1 +>[ 0.000000] (3:worker-0@Tremblay) I just started >[ 0.000000] (2:worker-0(mgr)@Jupiter) released the mutex after leaving the context manager >[ 0.000000] (2:worker-0(mgr)@Jupiter) Bye now! ->[ 10.000000] (1:master@Tremblay) The final result is: 1 +>[ 0.000000] (3:worker-0@Tremblay) acquired the mutex manually +>[ 0.000000] (3:worker-0@Tremblay) updated shared result, which is now 2 +>[ 0.000000] (3:worker-0@Tremblay) released the mutex manually +>[ 0.000000] (3:worker-0@Tremblay) Bye now! +>[ 10.000000] (1:master@Tremblay) The final result is: 2 -$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --workers 5 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/synchro-mutex.py --platform ${platfdir}/two_hosts.xml --actors 5 "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" >[ 0.000000] (2:worker-0(mgr)@Jupiter) I just started >[ 0.000000] (2:worker-0(mgr)@Jupiter) acquired the mutex with context manager >[ 0.000000] (2:worker-0(mgr)@Jupiter) updated shared result, which is now 1 ->[ 0.000000] (3:worker-1@Tremblay) I just started +>[ 0.000000] (3:worker-0@Tremblay) I just started >[ 0.000000] (2:worker-0(mgr)@Jupiter) released the mutex after leaving the context manager >[ 0.000000] (2:worker-0(mgr)@Jupiter) Bye now! ->[ 0.000000] (3:worker-1@Tremblay) acquired the mutex manually ->[ 0.000000] (3:worker-1@Tremblay) updated shared result, which is now 2 ->[ 0.000000] (4:worker-2(mgr)@Jupiter) I just started ->[ 0.000000] (3:worker-1@Tremblay) released the mutex manually ->[ 0.000000] (3:worker-1@Tremblay) Bye now! ->[ 0.000000] (4:worker-2(mgr)@Jupiter) acquired the mutex with context manager ->[ 0.000000] (4:worker-2(mgr)@Jupiter) updated shared result, which is now 3 ->[ 0.000000] (5:worker-3@Tremblay) I just started ->[ 0.000000] (4:worker-2(mgr)@Jupiter) released the mutex after leaving the context manager ->[ 0.000000] (4:worker-2(mgr)@Jupiter) Bye now! ->[ 0.000000] (5:worker-3@Tremblay) acquired the mutex manually ->[ 0.000000] (5:worker-3@Tremblay) updated shared result, which is now 4 ->[ 0.000000] (6:worker-4(mgr)@Jupiter) I just started ->[ 0.000000] (5:worker-3@Tremblay) released the mutex manually ->[ 0.000000] (5:worker-3@Tremblay) Bye now! ->[ 0.000000] (6:worker-4(mgr)@Jupiter) acquired the mutex with context manager ->[ 0.000000] (6:worker-4(mgr)@Jupiter) updated shared result, which is now 5 ->[ 0.000000] (6:worker-4(mgr)@Jupiter) released the mutex after leaving the context manager ->[ 0.000000] (6:worker-4(mgr)@Jupiter) Bye now! ->[ 10.000000] (1:master@Tremblay) The final result is: 5 +>[ 0.000000] (3:worker-0@Tremblay) acquired the mutex manually +>[ 0.000000] (3:worker-0@Tremblay) updated shared result, which is now 2 +>[ 0.000000] (4:worker-1(mgr)@Jupiter) I just started +>[ 0.000000] (3:worker-0@Tremblay) released the mutex manually +>[ 0.000000] (3:worker-0@Tremblay) Bye now! +>[ 0.000000] (4:worker-1(mgr)@Jupiter) acquired the mutex with context manager +>[ 0.000000] (4:worker-1(mgr)@Jupiter) updated shared result, which is now 3 +>[ 0.000000] (5:worker-1@Tremblay) I just started +>[ 0.000000] (4:worker-1(mgr)@Jupiter) released the mutex after leaving the context manager +>[ 0.000000] (4:worker-1(mgr)@Jupiter) Bye now! +>[ 0.000000] (5:worker-1@Tremblay) acquired the mutex manually +>[ 0.000000] (5:worker-1@Tremblay) updated shared result, which is now 4 +>[ 0.000000] (6:worker-2(mgr)@Jupiter) I just started +>[ 0.000000] (5:worker-1@Tremblay) released the mutex manually +>[ 0.000000] (5:worker-1@Tremblay) Bye now! +>[ 0.000000] (6:worker-2(mgr)@Jupiter) acquired the mutex with context manager +>[ 0.000000] (6:worker-2(mgr)@Jupiter) updated shared result, which is now 5 +>[ 0.000000] (7:worker-2@Tremblay) I just started +>[ 0.000000] (6:worker-2(mgr)@Jupiter) released the mutex after leaving the context manager +>[ 0.000000] (6:worker-2(mgr)@Jupiter) Bye now! +>[ 0.000000] (7:worker-2@Tremblay) acquired the mutex manually +>[ 0.000000] (7:worker-2@Tremblay) updated shared result, which is now 6 +>[ 0.000000] (8:worker-3(mgr)@Jupiter) I just started +>[ 0.000000] (7:worker-2@Tremblay) released the mutex manually +>[ 0.000000] (7:worker-2@Tremblay) Bye now! +>[ 0.000000] (8:worker-3(mgr)@Jupiter) acquired the mutex with context manager +>[ 0.000000] (8:worker-3(mgr)@Jupiter) updated shared result, which is now 7 +>[ 0.000000] (9:worker-3@Tremblay) I just started +>[ 0.000000] (8:worker-3(mgr)@Jupiter) released the mutex after leaving the context manager +>[ 0.000000] (8:worker-3(mgr)@Jupiter) Bye now! +>[ 0.000000] (9:worker-3@Tremblay) acquired the mutex manually +>[ 0.000000] (9:worker-3@Tremblay) updated shared result, which is now 8 +>[ 0.000000] (10:worker-4(mgr)@Jupiter) I just started +>[ 0.000000] (9:worker-3@Tremblay) released the mutex manually +>[ 0.000000] (9:worker-3@Tremblay) Bye now! +>[ 0.000000] (10:worker-4(mgr)@Jupiter) acquired the mutex with context manager +>[ 0.000000] (10:worker-4(mgr)@Jupiter) updated shared result, which is now 9 +>[ 0.000000] (11:worker-4@Tremblay) I just started +>[ 0.000000] (10:worker-4(mgr)@Jupiter) released the mutex after leaving the context manager +>[ 0.000000] (10:worker-4(mgr)@Jupiter) Bye now! +>[ 0.000000] (11:worker-4@Tremblay) acquired the mutex manually +>[ 0.000000] (11:worker-4@Tremblay) updated shared result, which is now 10 +>[ 0.000000] (11:worker-4@Tremblay) released the mutex manually +>[ 0.000000] (11:worker-4@Tremblay) Bye now! +>[ 10.000000] (1:master@Tremblay) The final result is: 10