Changeset 986


Ignore:
Timestamp:
10/24/19 18:27:01 (5 years ago)
Author:
dubos
Message:

devel/Python : update reorder.py and fix C syntax of partition.h

Location:
codes/icosagcm/devel/Python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/dynamico/partition.h

    r977 r986  
    1111  idx_t options[]={0}, wgtflag=0, numflag=0, ncon=1; 
    1212  real_t tpwgts[2*nparts], ubvec[]={1.05}; 
    13  
     13  int i; 
    1414  /* int ParMETIS V3 PartKway ( 
    1515     idx t *vtxdist, idx t *xadj, idx t *adjncy, idx t *vwgt, idx t *adjwgt,  
     
    2222  printf("partition_graph : %d %d %d\n", mpi_rank, mpi_size, nparts);  
    2323  printf("vtxdist : \n");  
    24   for(int i=0; i<mpi_size+1; i++) printf("%d %d %d\n", mpi_rank, i, vtxdist[i]); */ 
     24  for(i=0; i<mpi_size+1; i++) printf("%d %d %d\n", mpi_rank, i, vtxdist[i]); */ 
    2525       
    26   for(int i=0; i<2*nparts; i++) tpwgts[i] = 1./nparts; 
     26  for(i=0; i<2*nparts; i++) tpwgts[i] = 1./nparts; 
    2727  ParMETIS_V3_PartKway(vtxdist, xadj_loc, adjncy_loc, NULL, NULL,  
    2828                       &wgtflag, &numflag, &ncon, &nparts,  
     
    5151static inline void dynamico_morton_encode(int n, const int *x, const int *y, const int *z, uint64_t *m) 
    5252{ 
    53   for(int i=0; i<n; i++) 
     53  int i; 
     54  for(i=0; i<n; i++) 
    5455    m[i]=mortonEncode_magicbits(x[i],y[i],z[i]); 
    5556} 
  • codes/icosagcm/devel/Python/dynamico/partition.pyx

    r977 r986  
    1  
    21from ctypes import c_void_p, c_int, c_double, c_float, c_bool 
    32from numpy cimport ndarray 
     
    65 
    76ctypedef int idx_t 
     7ctypedef unsigned long uint64_t 
    88 
    99cdef extern from "partition.h": 
     
    1111                     idx_t vtxdist[], idx_t xadj_loc[], idx_t adjncy_loc[], 
    1212                     idx_t nparts, idx_t part[]) 
     13    void dynamico_morton_encode(int n, const int *x, const int *y, const int *z, long *m) 
    1314 
    1415 
     
    5152    dynamico_partition_graph(mpi_rank, mpi_size, &vtxdist[0], &xadj_loc[0], &adjncy_loc[0], nparts, &owner[0]) 
    5253    return owner 
     54 
     55#-------------------------------- Space-filling (Morton) ordering ------------------------# 
     56 
     57def toint(x): return np.int32((x+1.)*65536) 
     58 
     59def morton_index(x,y,z): 
     60    cdef int nn 
     61    cdef int[::1] xx,yy,zz 
     62    cdef long[::1] idx_ 
     63    nn, xx, yy, zz = x.size, toint(x), toint(y), toint(z) 
     64    idx=np.zeros(nn, dtype=np.int64) 
     65    idx_=idx 
     66    dynamico_morton_encode(nn, &xx[0],&yy[0],&zz[0], &idx_[0]) 
     67    return idx 
  • codes/icosagcm/devel/Python/test/py/reorder.py

    r779 r986  
     1#------------ Read command-line arguments ----------# 
     2from dynamico import getargs 
     3getargs.add("--grid", type=int, default=2562, 
     4                    help="number of primal cells in MPAS mesh") 
     5args = getargs.parse() 
     6grid = args.grid 
     7 
     8#------------- Start --------------# 
    19print 'Loading DYNAMICO modules ...' 
    2 from dynamico.meshes import morton_index, key_to_perm, reorder_indices, reorder_values, MPAS_Format, Unstructured_Mesh 
     10from dynamico.meshes import key_to_perm, reorder_indices, reorder_values, MPAS_Format, Unstructured_Mesh 
     11from dynamico.partition import morton_index 
    312print '...Done' 
    413import numpy as np 
     
    716import time 
    817 
    9 #------------ Read command-line arguments ----------# 
    10  
    11 import argparse 
    12 parser = argparse.ArgumentParser() 
    13 parser.add_argument("-n", type=int, default=2562, 
    14                     help="number of primal cells in MPAS mesh") 
    15 args = parser.parse_args() 
    16 grid = args.n 
    1718 
    1819#-------------- read MPAS mesh ----------------# 
Note: See TracChangeset for help on using the changeset viewer.