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_cartesian.py

    r759 r760  
    33from dynamico import unstructured as unst 
    44from dynamico import meshes 
    5 ker=unst.ker 
    6  
    7 from mpi4py import MPI 
    8 comm = MPI.COMM_WORLD 
    9 mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size() 
    10 print '%d/%d starting'%(mpi_rank,mpi_size) 
    11  
    125import numpy as np 
    136 
    14 nqdyn,nqtot,llm = 1,1,4 
     7# client.__exit__() and context.__exit__() are called at the end of the 'with' blocks 
     8# even if an exception is raised in the body of the block 
    159 
    16 if False: 
    17     nx,ny,llm = 64,64 
    18     Lx,Ly,f = 1.,1.,1. 
    19     mesh = meshes.Cartesian_Mesh(nx,ny,llm,nqdyn,Lx,Ly,f) 
    20 else: 
    21     filename, g, f, radius = 'cart_128_128.nc', 1., 1., None 
    22     filename = 'cart_004_004.nc' 
    23     unst.setvar('g',g) 
    24     print 'Reading Cartesian mesh ...' 
    25     def coriolis(lon,lat): 
    26         return f+0.*lon 
    27     meshfile = meshes.DYNAMICO_Format(filename) 
    28     nx,ny=meshfile.nx,meshfile.ny 
     10with xios.Client() as client: 
     11    comm = client.comm 
     12    mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size() 
     13    print '%d/%d starting'%(mpi_rank,mpi_size) 
    2914 
    30     pmesh = meshes.Unstructured_PMesh(comm,meshfile) 
    31     mesh = meshes.Local_Mesh(pmesh, llm, nqdyn, radius, coriolis) 
     15    nqdyn,nqtot,llm = 1,1,4 
     16 
     17    if False: 
     18        nx,ny,llm = 64,64 
     19        Lx,Ly,f = 1.,1.,1. 
     20        mesh = meshes.Cartesian_Mesh(nx,ny,llm,nqdyn,Lx,Ly,f) 
     21    else: 
     22        filename, g, f, radius = 'cart_128_128.nc', 1., 1., None 
     23    #    filename = 'cart_008_008.nc' 
     24        unst.setvar('g',g) 
     25        print 'Reading Cartesian mesh ...' 
     26        def coriolis(lon,lat): 
     27            return f+0.*lon 
     28        meshfile = meshes.DYNAMICO_Format(filename) 
     29        nx,ny=meshfile.nx,meshfile.ny 
     30 
     31        pmesh = meshes.Unstructured_PMesh(comm,meshfile) 
     32    #    pmesh.partition_metis() 
     33        pmesh.partition_curvilinear(2,2) 
     34        mesh = meshes.Local_Mesh(pmesh, llm, nqdyn, radius, coriolis) 
    3235 
    3336#--------------------------------- write some data ---------------------------------------- 
    3437 
    35 context=xios.XIOS_Context_Curvilinear(mesh,nqtot, 3600) 
    36 #lon_i,lat_i = mesh.xx[:,:,0].flatten(), mesh.yy[:,:,0].flatten() 
    37 lon_i,lat_i = mesh.lon_i, mesh.lat_i 
    38 lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='ij') 
     38    with xios.Context_Curvilinear(mesh,nqtot, 3600) as context: 
     39        lon_i,lat_i = mesh.lon_i, mesh.lat_i 
     40        lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='ij') 
     41        lon_ik, junk  = np.meshgrid(lon_i, np.arange(llm), indexing='ij') 
    3942 
    40 no_error=True 
    41 try: 
    42     for i in range(3): 
    43         context.update_calendar(i) 
    44         print 'send_field', i, lat_ik.shape 
    45         context.send_field_primal('ps', lat_i) 
    46         context.send_field_primal('theta', lat_ik) 
    47 except: 
    48     print 'An error has occured, trying to close XIOS properly' 
    49     no_error=False 
    50  
    51 print 'xios.context_finalize()' 
    52 context.finalize() 
    53 print 'xios.finalize()' 
    54 xios.finalize() 
    55 print 'Done' 
    56  
    57 if not no_error : raise 
     43        for i in range(48): 
     44            context.update_calendar(i) 
     45#            print 'send_field', i, lat_ik.shape 
     46            context.send_field_primal('ps', lat_i+lon_i) 
     47            context.send_field_primal('theta', lat_ik+lon_ik) 
Note: See TracChangeset for help on using the changeset viewer.