Ignore:
Timestamp:
10/15/18 01:04:44 (6 years ago)
Author:
dubos
Message:

devel/Python : block-wise partitioning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/test/py/test_xios.py

    r759 r760  
    1 import dynamico.unstructured as unst 
    2 import dynamico.xios as xios 
     1from dynamico import unstructured as unst 
     2from dynamico import xios 
    33from dynamico.meshes import radian, MPAS_Format, Unstructured_PMesh as PMesh, Local_Mesh as Mesh 
     4import numpy as np 
    45 
    5 from mpi4py import MPI 
    6 comm = MPI.COMM_WORLD 
    7 mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size() 
    8 print '%d/%d starting'%(mpi_rank,mpi_size) 
    9  
    10 import numpy as np 
    11 import cProfile 
    12 import re 
     6with xios.Client() as client:     
     7    comm = client.comm 
     8    mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size() 
     9    print '%d/%d starting'%(mpi_rank,mpi_size) 
    1310 
    1411#----------------------------- read MPAS mesh -------------------------------- 
    1512 
    16 grid, llm, nqdyn, nqtot = 2562, 4,1,1 # 2562, 10242, 40962   
    17 Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4 
    18 N, T, courant = 40, 10800., 1.2 # simulation length = N*T 
    19 print 'Omega, planetary PV', Omega, 2*Omega/gh0 
     13    grid, llm, nqdyn, nqtot = 2562, 4,1,1 # 2562, 10242, 40962   
     14    Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4 
     15    N, T, courant = 40, 10800., 1.2 # simulation length = N*T 
     16    print 'Omega, planetary PV', Omega, 2*Omega/gh0 
    2017 
    21 def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter                                                                                                                 
    22 print 'Reading MPAS mesh ...' 
    23 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 
    24 pmesh = PMesh(comm,meshfile) 
    25 mesh = Mesh(pmesh, llm, nqdyn, radius, f) 
    26 print '...Done' 
     18    def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter                                                                                                                 
     19    print 'Reading MPAS mesh ...' 
     20    meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 
     21    pmesh = PMesh(comm,meshfile) 
     22    pmesh.partition_metis() 
     23    mesh = Mesh(pmesh, llm, nqdyn, radius, f) 
     24    print '...Done' 
    2725 
    2826#--------------------------------- write some data ---------------------------------------- 
    2927 
    30 context=xios.XIOS_Context_Unstructured(pmesh,mesh,nqtot, 3600) 
     28    with xios.Context_Unstructured(pmesh,mesh,nqtot, 3600) as context: 
     29        lat_i = radian*mesh.lat_i 
     30        lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='ij') 
    3131 
    32 lat_i = radian*mesh.lat_i 
    33 lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='ij') 
    34  
    35 no_error=True 
    36 try: 
    37     for i in range(100): 
    38         context.update_calendar(i) 
    39         print 'send_field', i, lat_ik.shape 
    40         context.send_field_primal('ps', lat_i) 
    41         context.send_field_primal('theta', lat_ik) 
    42 except: 
    43     print 'An error has occured, trying to close XIOS properly' 
    44     no_error=False 
    45  
    46 print 'xios.context_finalize()' 
    47 context.finalize() 
    48 print 'xios.finalize()' 
    49 xios.finalize() 
    50 print 'Done' 
    51  
    52 if not no_error : raise 
     32        for i in range(100): 
     33            context.update_calendar(i) 
     34            print 'send_field', i, lat_ik.shape 
     35            context.send_field_primal('ps', lat_i) 
     36            context.send_field_primal('theta', lat_ik) 
Note: See TracChangeset for help on using the changeset viewer.