source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/2-apple/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: 933 bytes
Line 
1#!/usr/bin/env python3
2
3import numpy
4import pyoasis
5from pyoasis import OASIS
6from mpi4py import MPI
7
8component_name = "sender-apple"
9
10commworld = MPI.COMM_WORLD.Split(1)
11comp = pyoasis.Component(component_name, communicator = commworld)
12print(comp)
13
14comm_rank = comp.localcomm.rank
15comm_size = comp.localcomm.size
16
17n_points = 1600
18
19local_size = int(n_points / comm_size)
20offset = comm_rank * local_size
21if comm_rank == comm_size - 1:
22    local_size = n_points - offset
23
24partition = pyoasis.ApplePartition(offset, local_size)
25print(partition)
26
27variable = pyoasis.Var("FSENDOCN", partition, OASIS.OUT)
28print(variable)
29
30comp.enddef()
31
32date = int(0)
33
34field = pyoasis.asarray(numpy.arange(start=offset, stop=offset + local_size,
35                        dtype=numpy.float64))
36
37print("Sent data: from {} to {}".format(int(field[0]), int(field[-1])))
38
39variable.put(date, field)
40
41print("Terminating component {}".format(comp.name))
42del comp
Note: See TracBrowser for help on using the repository browser.