[620] | 1 | #include <mpi.h> |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <parmetis.h> |
---|
| 4 | |
---|
| 5 | void dynamico_partition_graph(int mpi_rank, int mpi_size, |
---|
| 6 | idx_t vtxdist[], idx_t xadj_loc[], idx_t adjncy_loc[], |
---|
| 7 | idx_t nparts, idx_t part[]) |
---|
| 8 | { |
---|
| 9 | MPI_Comm comm = MPI_COMM_WORLD; /* avoid passing a communicator as argument due to Fortran/C issues */ |
---|
| 10 | idx_t edgecut; |
---|
| 11 | idx_t options[]={0}, wgtflag=0, numflag=0, ncon=1; |
---|
| 12 | real_t tpwgts[2*nparts], ubvec[]={1.05}; |
---|
| 13 | |
---|
| 14 | /* int ParMETIS V3 PartKway ( |
---|
| 15 | idx t *vtxdist, idx t *xadj, idx t *adjncy, idx t *vwgt, idx t *adjwgt, |
---|
| 16 | idx t *wgtflag, idx t *numflag, idx t *ncon, idx t *nparts, |
---|
| 17 | real t *tpwgts, real t *ubvec, idx t *options, idx t *edgecut, idx t *part, |
---|
| 18 | MPI Comm *comm ) |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | /* printf("sizeof : %d %d \n", sizeof(int), sizeof(idx_t)); |
---|
| 22 | printf("partition_graph : %d %d %d\n", mpi_rank, mpi_size, nparts); |
---|
| 23 | printf("vtxdist : \n"); |
---|
| 24 | for(int i=0; i<mpi_size+1; i++) printf("%d %d %d\n", mpi_rank, i, vtxdist[i]); */ |
---|
| 25 | |
---|
| 26 | for(int i=0; i<2*nparts; i++) tpwgts[i] = 1./nparts; |
---|
| 27 | ParMETIS_V3_PartKway(vtxdist, xadj_loc, adjncy_loc, NULL, NULL, |
---|
| 28 | &wgtflag, &numflag, &ncon, &nparts, |
---|
| 29 | tpwgts, ubvec, options, &edgecut, part, &comm); |
---|
| 30 | } |
---|
[674] | 31 | |
---|
| 32 | |
---|
| 33 | // http://www.forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/ |
---|
| 34 | // method to seperate bits from a given integer 3 positions apart |
---|
| 35 | static inline uint64_t splitBy3(unsigned int a){ |
---|
| 36 | uint64_t x = a & 0x1fffff; // we only look at the first 21 bits |
---|
| 37 | x = (x | x << 32) & 0x1f00000000ffff; // shift left 32 bits, OR with self, and 00011111000000000000000000000000000000001111111111111111 |
---|
| 38 | x = (x | x << 16) & 0x1f0000ff0000ff; // shift left 32 bits, OR with self, and 00011111000000000000000011111111000000000000000011111111 |
---|
| 39 | x = (x | x << 8) & 0x100f00f00f00f00f; // shift left 32 bits, OR with self, and 0001000000001111000000001111000000001111000000001111000000000000 |
---|
| 40 | x = (x | x << 4) & 0x10c30c30c30c30c3; // shift left 32 bits, OR with self, and 0001000011000011000011000011000011000011000011000011000100000000 |
---|
| 41 | x = (x | x << 2) & 0x1249249249249249; |
---|
| 42 | return x; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | static inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z){ |
---|
| 46 | uint64_t answer = 0; |
---|
| 47 | answer |= splitBy3(x) | splitBy3(y) << 1 | splitBy3(z) << 2; |
---|
| 48 | return answer; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void dynamico_morton_encode(int n, const int *x, const int *y, const int *z, uint64_t *m) |
---|
| 52 | { |
---|
| 53 | for(int i=0; i<n; i++) |
---|
| 54 | m[i]=mortonEncode_magicbits(x[i],y[i],z[i]); |
---|
| 55 | } |
---|