File: threads.py

package info (click to toggle)
mpi4py 4.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,540 kB
  • sloc: python: 34,465; ansic: 16,475; makefile: 614; sh: 325; cpp: 193; f90: 178
file content (37 lines) | stat: -rw-r--r-- 733 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

if False:
    import mpi4py

    name = "name"  # lib{name}.so
    path = []
    mpi4py.profile(name, path=path)

import threading
from array import array

from mpi4py import MPI

send_msg = array("i", [7] * 1000)
send_msg *= 1000
recv_msg = array("i", [0] * 1000)
recv_msg *= 1000


def self_send(comm, rank):
    comm.Send([send_msg, MPI.INT], dest=rank, tag=0)


def self_recv(comm, rank):
    comm.Recv([recv_msg, MPI.INT], source=rank, tag=0)


comm = MPI.COMM_WORLD
rank = comm.Get_rank()
send_thread = threading.Thread(target=self_send, args=(comm, rank))
recv_thread = threading.Thread(target=self_recv, args=(comm, rank))

send_thread.start()
recv_thread.start()
recv_thread.join()
send_thread.join()