source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/6-apple_and_orange/python/sender-apple.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 numpy
4import pyoasis
5from pyoasis import OASIS
6from mpi4py import MPI
7
8comm = MPI.COMM_WORLD
9
10component_name = "sender-apple"
11
12comp = pyoasis.Component(component_name, True, comm)
13print(comp)
14
15local_comm_rank = comp.localcomm.rank
16local_comm_size = comp.localcomm.size
17
18icpl = 1
19if local_comm_size > 3:
20    if local_comm_rank >= local_comm_size - 2:
21        icpl = 0
22
23couplcomm = comp.localcomm.Split(icpl, local_comm_rank)
24if icpl == 0:
25    couplcomm = MPI.COMM_NULL
26
27comp.set_couplcomm(couplcomm)
28
29if icpl == 1:
30
31    n_points = 16
32
33    comm_rank = comp.couplcomm.rank
34    comm_size = comp.couplcomm.size
35
36    local_size = int(n_points/comm_size)
37    offset = comm_rank*local_size
38    if comm_rank == comm_size - 1:
39        local_size = n_points - offset
40
41    partition = pyoasis.ApplePartition(offset, local_size)
42    print(partition)
43
44    variable = pyoasis.Var("FSENDOCN", partition, OASIS.OUT)
45    print(variable)
46
47comp.enddef()
48
49if icpl == 1:
50
51    date = int(0)
52
53    field = pyoasis.asarray(numpy.zeros(local_size))
54
55    for i in range(local_size):
56        field[i] = offset + i
57
58    print("Sent data: "+str(field))
59
60    variable.put(date, field)
61
62del comp
Note: See TracBrowser for help on using the repository browser.