source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/9-python_fortran_C-multi_intracomm/sender-box.py @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 1.2 KB
Line 
1#!/usr/bin/env python3
2
3import pyoasis
4from pyoasis import OASIS
5from mpi4py import MPI
6import numpy as np
7
8comm = MPI.COMM_WORLD
9
10component_name = "sender-box"
11
12comp = pyoasis.Component(component_name)
13comm_rank = comp.localcomm.rank
14
15print(comp)
16print("Sender: rank = {} of {}".format(comm_rank,
17                                       comp.localcomm.size))
18
19comp.enddef()
20
21comp_list = ['receiver', component_name, 'xios']
22intra_comm, root_ranks = comp.get_multi_intracomm(comp_list)
23
24print("Sender: rank({}) intra_comm: rank = {} of {}".format(comm_rank,
25                                                            intra_comm.rank,
26                                                            intra_comm.size))
27
28if comm_rank == 0:
29    for comp in root_ranks:
30        print("Sender: component {} starts at {}".format(comp, root_ranks[comp]))
31
32    il_x = 111
33    intra_comm.Send([np.array([il_x],dtype=np.int32), MPI.INT], dest=root_ranks['xios'], tag=0)
34    print("Sender rank({}) sent il_x = {}".format(comm_rank,il_x))
35
36il_x = np.empty(1, dtype=np.int32)
37intra_comm.Bcast(il_x, root=root_ranks['xios'])
38il_x = il_x[0]
39print("Sender rank({}) got broadcasted il_x = {}".format(comm_rank,il_x))
Note: See TracBrowser for help on using the repository browser.