PyMCT and PyCPL: Refactoring CCSM Using Python
Michael Tobis(1), Michael Steder(1), Robert L. Jacob(2,3), Raymond T. Pierrehumbert(1), Everest T. Ong(4), & J. Walter Larson(2,3,5,6) Affiliations: (1) Department of Geosciences, University of Chicago; (2) Mathematics and Computer Science Division, Argonne National Laboratory (3) Computation Institute, University of Chicago (4) Department of Atmospheric and Oceanic Sciences, University of Wisconsin (5) ANU Supercomputer Facility, The Australian National University (6) Australian Partnership for Advanced Computing (APAC) Presented at the Python Workshop at the Biennial Computational Techniques and Applications (CTAC ‘06) Townsville, Queensland, Australia 6 July 2006 1PyMCT and PyCPL: Refactoring CCSM Using Python Michael Tobis (1) , - - PowerPoint PPT Presentation
PyMCT and PyCPL: Refactoring CCSM Using Python Michael Tobis (1) , - - PowerPoint PPT Presentation
PyMCT and PyCPL: Refactoring CCSM Using Python Michael Tobis (1) , Michael Steder (1) , Robert L. Jacob (2,3) , Raymond T. Pierrehumbert (1) , Everest T. Ong (4) , & J. Walter Larson (2,3,5,6) Affiliations: (1) Department of Geosciences,
CTAC ’06 Python Workshop
Overview
- Climate Models and the Parallel Coupling
- More specifically, CCSM, MCT, and CPL6
- Enter Python
- More than you probably want to know
- Python Bindings for MCT, a.k.a. pyMCT
- Re-implementation of CPL6, a.k.a. pyCPL
- Conclusions + Future Work
CTAC ’06 Python Workshop
ACT I: Parallel Coupled Models and CCSM
3CTAC ’06 Python Workshop
Schematic (Directed Graph) for the Climate System
ATM OCN LAND SEA- ICE
Nodes represent subsystem models Arcs represent data to be delivered from source to target (states and fluxes) 4CTAC ’06 Python Workshop
Complexity Barriers
The traditional approach was: Model the individual subsystems (atmosphere, ocean, sea-ice, and land) in isolation- Idealize interactions with outside world through prescription (e.g.,
- Why? Three complexity barriers to overcome:
- Knowledge, a consequence of specialization
- overcome through interdisciplinary teams
- Computational, i.e., getting all the math done
- overcome by faster processors, better algorithms, and parallel
- Software: build system, language barriers, interactions between
CTAC ’06 Python Workshop
One of Life’s Little Ironies...
- The solution to one problem can create a new
problem
- In this case, parallel computing in the form of
message-passing parallelism (let’s face it--MPI is pretty much the standard) helps surmount the computational complexity barrier
- Distributed-memory parallelism complicates
intercourse between coupled models due to the traffic in distributed data
- This is the Parallel Coupling Problem
CTAC ’06 Python Workshop
Parallel Coupling Problem
Given: N mutually interacting models (C1,C2,...CN), each of which may employ message-passing parallelism Goal: Build an efficient parallel coupled model Aspects of the problem:- Architecture
- Parallel data processing
- Environment
- Language barriers
- Build issues
CTAC ’06 Python Workshop
Architectural Aspects
Two sources that shape parallel coupled models:
- Science of the system under study:
- Connectivity--who talks to whom?
- Coupling event scheduling (e.g., periodic?)
- Domain overlap--lower-dimensional vs. colocation
- Timescale separation/interaction & domain overlap
- Tightness
- Implementation choices:
- Resource allocation
- Scheduling of model execution
- Number of executable images
- Mechanism
CTAC ’06 Python Workshop
Parallel Data Processing
- Description of data to be exchanged during coupling
- Physical fields/variables
- Mesh or representation associated with the data
- Domain decomposition
- Transfer of data--a.k.a. the MxN problem
- Transformation of data
- Intermesh interpolation/transformation between
- Time transformation
- Diagnostic/variable transformations
- Merging of data from multiple sources
CTAC ’06 Python Workshop
CCSM
- CCSM := Community Climate System
- Four physical components:
- One coupler component
- Together, they comprise a hub and
- As implemented, CCSM is an
CTAC ’06 Python Workshop
CCSM’s Coupler CPL6
Model Substitution Modification of fields under exchange via “Configurable Plugs”
CPL6 enables one to do--with aplomb-- some neat things to CCSM. 11CTAC ’06 Python Workshop
This is Great...But...
- Alteration of CCSM’s architecture is more difficult,
and one must re-code the coupler MAIN in terms of the bits and pieces from the CPL6 toolkit+library--in Fortran :-(
- Number of components
- Changes in scientific details of the couplings beyond
the most simple alterations
- e.g., currently take-it-or-leave-it temporal advance
coupling, not anything nearly as sophisticated as predictor/corrector But this is exactly what many scientists want to do!
12CTAC ’06 Python Workshop
CCSM’s Fortran Software Stack
13CTAC ’06 Python Workshop
Attempted Object- Oriented Programming in Fortran...or, Don’t Try This at Home...
14CTAC ’06 Python Workshop
OO Programming in Fortran-- Where’s the Swindle?
- The introduction of Derived Types and Explicit Interfaces in the
- Encapsulation and Information Hiding
- Inheritance
- Polymorphism
- But, one must implement them--they are not available as part and
- The 2003 Fortran Standard introduces the notion of a Class, but
CTAC ’06 Python Workshop
MCT is a Collection of Fortran Datatypes...
...and a comprehensive set of support routines (a.k.a methods)
Data Transformation Data Description Data TransferKEY
AttrVect GlobalSegMap GeneralGrid Accumulator SparseMatrix SparseMatrixPlus MCTWorld Router Rearranger 16CTAC ’06 Python Workshop
Seven the Hard Way
- MCT has seven classes that are linked via a class
hierarchy
- MCT is an attempt to follow OO discipline as best as
possible in a Fortran context; i.e., provide a comprehensive set of support methods for each class
- Inheritance was implemented the hard way through
hard-coding of these relationships (i.e., delegation)
- This is the primary reason that MCT is such a small set
- f classes, and why the datatypes we will encounter in
CPL6 are not in MCT
17CTAC ’06 Python Workshop
CPL6 Fortran Datatypes
Looks Like a Job for Python!
18CTAC ’06 Python Workshop
The Case for Python
- Python offers true OO programming, thus CPL6 class
implementations are far easier to implement
- Most of the complexity of the coupler is at initialization
time: scripting penalty is irrelevant
- Most of the coupler loop is idle; calculations can be
farmed out to a compiled language ('Numeric' or 'numpy' modules)
- Coupler itself is approximately 2kLOC of Fortran, re-
implementation in Python should be doable
- Realization of long-term goal of roll-your-own/disposable
couplers
19CTAC ’06 Python Workshop
PyCCSM/PyCPL/PyMCT Parts List
- Python bindings for MCT, a.k.a. pyMCT
- Python-based reimplementation of Multi-Process
Handshaking utilities (MPH)
- Implementation of CPL6 datatypes in Python (as
true classes), a.k.a. pyCPL
- Python implementation of a specific coupler +
legacy component models = pyCCSM
20CTAC ’06 Python Workshop
ACT II: MCT
21CTAC ’06 Python Workshop
- Q. Why go into so much detail about
MCT?
- A. Because PyMCT is the clear non-
climate spin-off product from this project
22CTAC ’06 Python Workshop
MCT’s Universe of Discourse
- Support coupling of MPI-based MPP models
- Data transfer using a peer commmunication model
- Description of physical meshes and associated field data
- Data transfer and transformation are viewed as multi-field,
- We leave numerous, high-level operations to the user’s
CTAC ’06 Python Workshop
Coupling as Peer Communication
- MCT’s organizing principle is the component model,
- r component (not same as CORBA, CCA, ESMF,
JavaBeans)
- An MCT component is merely a model that is part
- f the larger system and participates in coupling
- In MCT, components interact directly as peers
- The user codes these connections into the model
source
24CTAC ’06 Python Workshop
Linearization of Multi- Dimensional Space
- Linearization (first used in MxN schemes by UMD’s
METACHAOS) is the mapping from an n-tuple index space to a single global location index
- This approach allows for a single representation of
grids/arrays of aribtrary dimension
25CTAC ’06 Python Workshop
Index Space
- Definition: An M-dimensional index space is
subset of ZM , each element of which can be uniquely identified by an M-tuple of integers (i1, i2,...,ik,..., iM)
- This is what we normally use to describe
Cartesian meshes and associated field data stored in multidimensional arrays
26CTAC ’06 Python Workshop
Example: 2-D Cartesian
y-index j 1 2 3 1 2 3 4 x-index i
27CTAC ’06 Python Workshop
Index Space: Ordered Pairs
x y 1 2 3 1 2 3 4 (0,1) (1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2) (3,3) (4,3) (4,2) (4,1) (0,0) (0,2) (0,3) (1,0) (2,0) (3,0) (4,0)
28CTAC ’06 Python Workshop
Virtual Linearization of Multidimensional Index
Definition: A virtual linearization f of an index space A is a mapping f : A —›B
- where A is a subset of ZM
- B is a subset of N the set of natural numbers
- f is one-to-one and onto
- That is, f maps an M-tuple of integers to a unique
natural number
29CTAC ’06 Python Workshop
Simple Example Virtual Linearizations
Valid for i = {0,1,2,3} j = {0, 1, 2, 3, 4}
30CTAC ’06 Python Workshop
f(i,j) = i + 5j + 1
x y 1 2 3 1 2 3 4 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
31CTAC ’06 Python Workshop
f(i,j) = 4i + j + 1
x y 1 2 3 1 2 3 4 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
32CTAC ’06 Python Workshop
Pointwise Operations
- FACT: Most coupling between components
involves multivariate exchanges (e.g., ~10-12 fields between atmosphere and ocean in a climate model)
- Consolidating operations on data to be
exchanged can result in performance boosts due to better cache re-use and lowered MPI latency charges
- In MCT, implementation choices (primarily
storage order) have been made to exploit this situation
33CTAC ’06 Python Workshop
Automating (Most of) the Tough Stuff
- We leave coupled model architecture decisions to the user
- We aim to be minimally invasive--user still owns main(), still calls
- The user decides how and when to couple
- The user must describe application grids and decompositions using
- The user must pack coupling data in AttrVect form
- MCT’s library routines do the heavy lifting
CTAC ’06 Python Workshop
Data Description: Domain Decomposition
- Embodied in the GlobalSegMap class
- Linearization creates a single unique index for each
- Capable of supporting arbitrary decompositions and haloed
- Support for global-to-local and local-to-global index
CTAC ’06 Python Workshop
Data Description: Physical Meshes
- Embodied in the GeneralGrid class
- Linearization implies this class stores real and integer
- Coordinates, length, cross-sectional area, and volume
- Able to describe meshes of arbitrary dimensionality and
- Method support for sorting points in lexicographic order
CTAC ’06 Python Workshop
Data Description: Field Data
- Embodied in MCT AttrVect class, which is similar to Trilinos
- Allows storage of both integer and real attributes
- In implementation, major index is field index, keeping in line with
- Attributes are accessed via use of string tokens
- Lists of attributes are set at initialization, which allows run-time
- Numerous query and manipulation methods including importing and
CTAC ’06 Python Workshop
Data Transfer: Registration
- Singleton class MCTWorld holds a lightweight
component registry
- Components are registered with a component ID
- MCTWorld contains a rank translation table that
allows a component to message another remote component by using information from its local domain decomposition descriptor (i.e., we do not construct nor use intercommunicators)
38CTAC ’06 Python Workshop
Data Transfer: Communications Scheduling
- Scheduling for one-way parallel data
transfers are handled by the Router class
- Scheduling for two-way parallel data
transfers and parallel data redistributions are handled by the Rearranger class, which comprises two Routers
39CTAC ’06 Python Workshop
Data Transfer: Execution
- MxN Communications between components are carried out by library
- Overall blocking--Prevents concurrently scheduled components from
- utrunning each other
- Overall nonblocking--allows for same communications approach to be
- N.B.: non-blocking MPI operations are used for the individual point-to-
- MxM redistributions are handled by the MCT library routine Rearrange()
- Contains logic to prevent self-messaging (does a copy instead)
CTAC ’06 Python Workshop
Data Transformation: Intermesh Interpolation
- MCT’s linearization-based worldview casts interpolation as a linear transform and thus
- In practice, these interpolation matrices are quite sparse
- MCT’s SparseMatrix class provides storage for nonzero matrix elements in COO
- Method support includes query methods, computation of sparsity, sorting methods to aid
- Library function performs multiplication y = Mx, where x and y are of AttrVect type, and
- Main implementation targets commodity cache-based processor platforms, and MCT’s
- Modifications for vector platforms also included
CTAC ’06 Python Workshop
MCT’s Parallel Linear Transformation
- MCT provides the SparseMatrixPlus class, which
- This class includes Rearrangers to schedule communications
- Library routine to compute y = Mx in parallel, again where x
- Support for both commodity and vector processors
CTAC ’06 Python Workshop
Data Transformation: Time Accumulation
target t = tc source target t = tc source target t = tc source target t = tc source target (e) c source (a) (b) (c) (d) t = t- Time evolution of multi-component systems can
- For instantaneous exchanges, use of one or more
- For integrated data exchanges, MCT offers
- The Accumulator provides registers for time
- The accumulate() library routine works with
CTAC ’06 Python Workshop
Other Services--Spatial Integration and Averaging
- MCT provides routines for computing spatial integrals and
- These routines are included to diagnose (and if wished, even
- Library routines operate on AttrVect objects
- Spatial weight elements and masks can be provided either in
- Paired integral/average routines to compute integrals
CTAC ’06 Python Workshop
Other Services--Merging of Data from Multiple Sources
- Often one must combine outputs from multiple components
- cean, land, and sea-ice for use by atmosphere)
- MCT provides a Merge facility, which is a set of routines to
- Real and Integer masks for the merge can be supplied either in
- Automatic token-based attribute matching
CTAC ’06 Python Workshop
MCT’s Fortran Programming Model
Based on Fortran90, but applicable to
- ther languages (including Python).
- Use modules for access to MCT
classes and methods
- Declare variables of MCT datatypes
- Invoke MCT library routines to
accomplish parallel coupling operations
46CTAC ’06 Python Workshop
ACT III: pyMCT, pyCPL, and pyCCSM
47CTAC ’06 Python Workshop
OK...So Where’s the Python?
- Note so far that there hasn’t been a single line of
- Don’t worry, we’ll get there; please be patient:-)
- MCT of course is Fortran90
- Interfacing Fortran 90/95 to Python is much harder
- This is entirely the fault of the ANSI Fortran J3 and
- If this makes you angry, go to
- So, let’s first discuss this problem...
- Johnny Rotten
CTAC ’06 Python Workshop
Fortran “Dope Vectors”
- The Fortran90 Standard introduced the notion of
allocatable arrays and pointers
- The standard was utterly silent on how compiler
developers should implement array descriptors
- Furthermore, the standard failed to offer a
standardized API to query them
- This creates a BIG PROBLEM for language
interoperability
- The Fortran2003 standard promises to solve this with
its BINDC feature
49CTAC ’06 Python Workshop
Enter Babel
- You can wait until the Fortran 2003 standard is implemented and use
- The lag between the standard specification and its widespread
- There is a solution available today: Babel
- Babel is a general language interoperability tool that automates
- Babel accomplishes this by processing user-authored interface
CTAC ’06 Python Workshop
The Babel Recipe
To accomplish calling from language A to code written in language B,- ne must:
- 1. Write a SIDL interface description for the code implemented in
- 2. Run babel to create
- Skeletons in Language A (also called .IMPL files)
- The Internal Object Representation (IOR), which is implemented
- 3. Paste into the skeletons either calls to the package in Language A, or
- 4. Run babel again to create call-in stubs in Language B
- 5. Use and enjoy the Language B stubs from your source code written
CTAC ’06 Python Workshop
But...Beware!
- Babel builds are complex, and associated
language binding builds are confusing
- We found the best environment for
confronting these problems was a cluster
- ver which we had administrative control!
- MCT’s restricted SIDL API had bugs
- Fortran’s 1-based indexing vs. Python’s 0-
based indexing required modification to MCT
52CTAC ’06 Python Workshop
Python and MPI Issues
- There exist numerous Python MPI binding
implementations (pyMPI, MPI-B, ANU’s pyPar...)
- But, we have specific needs in messaging between
Python and non-Python codes, as well as the need to support multiple executable images
- Required a custom re-wrapping of MPI to confront
language interoperability+MPI issues
- called MMPI (http://www.penzilla.net/mmpi)
- Also required an upgrade to MPI-2 (specifically, we
used mpich2)
53CTAC ’06 Python Workshop
(Finally!) Some Python in the form of a pyMCT Example
54CTAC ’06 Python Workshop
What It Is
- Python implementation of a simple MCT example coupling
- In this case, component scheduling is concurrent
- Parts List:
- 1. Driver (master.py)
- 2. Generic Model (model.py)
- 3. Coupler (coupler.py)
- 4. Downloadable from MCT Web site:
http://www.mcs.anl.gov/mct
55CTAC ’06 Python Workshop
master.py (part 1)
# Check all necessary modules are available # Exits and prints an error if components aren't available import modulecheck # import standard modules import sys, traceback import Numeric # Courtesy of pyMPI import mpi # MCT from MCT import World,GlobalSegMap,AttrVect,Router # Example Codes import model import coupler 56CTAC ’06 Python Workshop
master.py -- main()
def main(): rank = mpi.rank size = mpi.size # Split MPI_COMM_WORLD into a communicator for each model if (rank == 0): print "Running PyMCT Example on %d Processors"%(size) ncomps = size color = (rank % ncomps) + 1 splitcomm = mpi.comm_create([mpi.WORLD[rank]]) # More complex test # Start up the models cpl = coupler.Coupler() pop = model.Model() csm = model.Model() csim = model.Model() clm = model.Model() if( color == 1 ): print "COUPLER COMPONENT STARTING ON PROCESSOR %d"%(rank) cpl.start(splitcomm, ncomps, color) elif( color == 2 ): print "COUPLER COMPONENT STARTING ON PROCESSOR %d"%(rank) pop.start(splitcomm, ncomps, color) elif( color == 3 ): print "COUPLER COMPONENT STARTING ON PROCESSOR %d"%(rank) csm.start(splitcomm, ncomps, color) elif( color == 4 ): print "COUPLER COMPONENT STARTING ON PROCESSOR %d"%(rank) csim.start(splitcomm, ncomps,color) elif( color == 5 ): print "COUPLER COMPONENT STARTING ON PROCESSOR %d"%(rank) clm.start(splitcomm, ncomps, color) else: print "! COLOR(%d) ERROR ON PROCESSOR %d"%(color,rank) """ """ while(1): atmdata = atmos.step() if (timestep % 5 == 0): if( mpi.rank == 0): # Im the coupler coupler.couple() if( mpi.rank == 6): atmos.couple() """ return if __name__=="__main__": main()Delegates execution to appropriate model
57CTAC ’06 Python Workshop
model.py
""" model.py This model requires a square processor decomposition i.e., a 2x2, 3x3, 4x4 grid. """ # This checks that all modules are available # and prints errors about components. #import modulecheck # Actual imports import traceback import mpi from MCT import World,GlobalSegMap,AttrVect,Router import NumericModule Imports
58CTAC ’06 Python Workshop
model.py, Cont’d...
class Model: def __init__(self): return def start(self, comm, ncomps, compid): """ start( Communicator comm, int ncomps, int compid ) This method is called to start the model instance. """ mctWorld = World.World() mctGlobalSegMap = GlobalSegMap.GlobalSegMap() mctAttrVect = AttrVect.AttrVect() router = Router.Router() myrank, mysize = comm.comm_rank(),comm.comm_size() # Register self with MCT.World print "PROCESSOR:%d INITIALIZING AS COMPONENT %d of %d"%(mpi.WORLD.comm_rank(),compid,mpi.WORLD.comm_size()) mctWorld.initd0(ncomps, mpi.WORLD, comm, compid) print "COMPID %d INITIALIZED!"%(compid) # Initialize the global segmap print "COMPID:", compid, "INITIALIZING GLOBALSEGMAP" nx = 128 ny = 64 localsize = (nx*ny)/mysize 59CTAC ’06 Python Workshop
model.py, Cont’d...
# Create arrays for start and length # MCT expects Fortran arrays starting at 1 start = Numeric.zeros(2,Numeric.Int32) start[1] = ((myrank*localsize)+1) length = Numeric.zeros(2,Numeric.Int32) length[1] = (localsize) # Describe Decomposition with MCT GSMAP TYPE print "COMPID:",compid,"INITIALIZING GLOBALSEGMAP" mctGlobalSegMap.initd0(start, length, 0, comm, compid) # Initialize an ATTRIBUTE VECTOR print "COMPID:",compid,"INITIALIZNNG ATTRVECT" len = mctGlobalSegMap.lsize(comm) mctAttrVect.init("field1:field2","field1:field2",len) print "COMPID:",compid,"INITIALIZED ATTRVECT (SIZE=",len,")" # Fill AV with DATA using the import function # MCT expects fortran arrays starting at 1 print "COMPID",compid,"IMPORTING ATTRIBUTES" field1 = Numeric.zeros(len) field2 = Numeric.zeros(len) for i in xrange(len): field1[i] = 1.0 / len field2[i] = 0.5 mctAttrVect.importRAttr("field1",field1) mctAttrVect.importRAttr("field2",field2) 60CTAC ’06 Python Workshop
model.py, Cont’d...
# Initialize a ROUTER print "COMPID:",compid,"INITIALIZING ROUTER" router.init(1,mctGlobalSegMap,comm) # Send data over the router print "COMPID:",compid,"SENDING ATTRVECT TO COMP 1" tag = 888+compid print "COMPID:",compid,"TAG:",tag mctAttrVect.send(router, tag) # Deallocate and clean up: mctAttrVect.clean() mctGlobalSegMap.clean() router.clean() mctWorld.clean() # DONE print "COMPID:",compid,"FINISHED" return 61CTAC ’06 Python Workshop
coupler.py
""" Mike Steder 10/20/04 """ #First make sure all the necessary modules are available #import modulecheck # Now handle actual imports import sys, traceback,math import Numeric import mpi from MCT import World,GlobalSegMap,AttrVect,Router,SparseMatrix,SparseMatrixPlus 62CTAC ’06 Python Workshop
coupler.py, Cont’d...
class Coupler: def __init__(self): return def start(self,comm, ncomps, compid): # Get local rank and size myrank,mysize = comm.comm_rank(),comm.comm_size() # Initialize MCTWORLD print "PROCESSOR:%d INITIALIZING AS COMPONENT %d of %d"%(mpi.WORLD.comm_rank(), compid,mpi.WORLD.comm_size()) mctworld = World.World() mctworld.initd0(ncomps, mpi.WORLD, comm, compid) print "COMPID:%d WORLD INITIALIZED!"%(compid) # Set up latitude decomposition nx, ny = 128,64 localsize = (nx*ny)/mysize # Create start and length arrays start = Numeric.zeros(2,Numeric.Int32) start[1] = (myrank*localsize)+1 length = Numeric.zeros(2,Numeric.Int32) length[1] = localsize 63CTAC ’06 Python Workshop
coupler.py, Cont’d...
# Describe decomposition with MCT Global Seg Map print "COMPID",compid,"INITIALIZING ATMOSPHERE GLOBALSEGMAP" AtmGSMap = GlobalSegMap.GlobalSegMap() AtmGSMap.initd0(start,length, 0,comm, compid) print "COMPID",compid,"INITIALIZED ATMOS GLOBALSEGMAP" # Initialize a globalsegmap for the ocean # By setting up a checkboard grid decomposition nx,ny = 320,384 nxprocs = math.sqrt(mysize) nyprocs = math.sqrt(mysize) if(mysize==2): # Special Case Layout nxprocs=nyprocs=1 # Number of lat/lon's in *my* grid lonsize = nx / nxprocs latsize = ny / nyprocs rowindex = myrank/nxprocs colindex = myrank/nxprocs # Lower left vertex of grid box boxvertex = (colindex*lonsize+1) + (latsize*rowindex*nx) # Create more start/length arrays start = Numeric.zeros(latsize+1,Numeric.Int32) length = Numeric.zeros(latsize+1,Numeric.Int32) for i in range(0,int(latsize)): # Was (i-1) in C++, but the indexing is different here. start[i] = boxvertex+(i)*nx length[i] = lonsize print "COMPID",compid,"INITIALIZING OCEAN GLOBALSEGMAP" OcnGSMap = GlobalSegMap.GlobalSegMap() OcnGSMap.initd0(start, length, 0, comm, compid) 64CTAC ’06 Python Workshop
coupler.py, Cont’d...
# Initializng an attribute vector for the atmosphere # grid and ocean grid print "COMPID",compid,"INITIALIZING ATTRVECT" AtmAV = AttrVect.AttrVect() AtmAV.init("field1:field2","field1:field2",AtmGSMap.lsize(comm)) print "COMPID",compid,"INITIALIZED ATTRVECT (SIZE=",AtmAV.lsize(),")" # Setup a SPARSEMATRIX with some test data #print "COMPID",compid,"CREATING SPARSEMATRIX..." nRows = 320 * 384 nCols = 128 * 64 num_elements = 145548 rows = Numeric.zeros(num_elements,Numeric.Int32) columns = Numeric.zeros(num_elements, Numeric.Int32) weights = Numeric.zeros(num_elements, Numeric.Float32) 65CTAC ’06 Python Workshop
coupler.py, Cont’d...
print "COMPID",compid,"ENTERING RECV LOOP ..." for i in range( 0, ncomps-1 ): # Adjust from 0 index to component index i = i + 2 Rout = Router.Router() Rout.init(i, AtmGSMap, comm ) print "COMPID",compid,"RECEIVING ATTRVECT FROM COMP",i tag = 888 + i sum = False print "COMPID",compid,"TAG:",tag AtmAV.recv(Rout, tag, sum) # Remove for now due to buggy ness # Interpolate with a Parallel Sparsematrix Multiply #print "COMPID",compid,"INTERPOLATING DATA FROM COMPID",i #OcnAV.sMatAvMult_sMPlus( AtmAV, A2OMatPlus ) Rout.clean() print "COMPID",compid,"PRINTING FIELD2" field2 = AtmAV.exportRAttr("field2") #print field2 #sum = 0 #for i in range(AtmGSMap.lsize()): # if (field2.get(i) != 0.5): # print "CORRUPT DATA IN ATMAV =", field2.get(i) print "COMPID",compid,"FINISHED" return 66CTAC ’06 Python Workshop
About pyCCSM
- The whole CPL6 toolkit and library layer was re-
implemented using Python
- After that, the CPL6 main was re-written in Python,
and the legacy models (atmosphere, ocean, sea-ice, and land-surface) were left as-is
- This all now works for CCSM’s “dead” and “data”
models
- Live models now “close to working”
- So far, the performance penalty is negligible
CTAC ’06 Python Workshop
What We Have Learned
- Control level of a big multiphysics application like CCSM should be
- MCT provides an excellent basis for a scalable and logically
- Fortran 90/95 arrays still provide an considerable language
- CCSM’s initiative to go towards from a multiple to a single
CTAC ’06 Python Workshop
Where This is Going
- The US NSF ITR grant that funded this work
will end later this year
- We still hope to get a working version of
pyCCSM by the project’s end
- This project has produced two useful spin-
- ff software products--pyMCT and MMPI
- We hope these packages will see public
release
69CTAC ’06 Python Workshop