File: mc-failing-assert.py

package info (click to toggle)
simgrid 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,192 kB
  • sloc: cpp: 124,913; ansic: 66,744; python: 8,560; java: 6,773; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,194; perl: 1,436; makefile: 111; lisp: 49; javascript: 7; sed: 6
file content (48 lines) | stat: -rw-r--r-- 1,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) 2010-2025. 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.

# ******************* Non-deterministic message ordering  ******************
# Server assumes a fixed order in the reception of messages from its clients
# which is incorrect because the message ordering is non-deterministic      
# **************************************************************************

import sys
from simgrid import Actor, Engine, Host, Semaphore, NetZone, Mailbox, this_actor, MC_assert

def server(worker_amount: int):
  value_got = -1
  mb = Mailbox.by_name("server")
  for _ in range(worker_amount):
    value_got = mb.get()

  # We assert here that the last message we got (which overwrite any previously received message) is the one from the
  # last worker This will obviously fail when the messages are received out of order.
  MC_assert(value_got == 2)

  this_actor.info("OK")
  return 0

def client(rank: int):
  # I just send my rank onto the mailbox. It must be passed as a stable memory block (thus the new) so that that
  # memory survives even after the end of the client */

  mailbox = Mailbox.by_name("server")
  mailbox.put(rank, 1) # communication cost (second parameter) is not really relevant in MC mode

  this_actor.info("Sent!")

if __name__ == '__main__':
    e = Engine(sys.argv)

    e.load_platform(sys.argv[1])             # Load the platform description

    hosts = e.all_hosts
    assert len(hosts) >= 3, "This example requires at least 3 hosts"

    hosts[0].add_actor("server", server, 2)
    hosts[1].add_actor("client1", client, 1)
    hosts[2].add_actor("client2", client, 2)

    e.run()