-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
919 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <sort.h> | ||
#include <float.h> | ||
#include <parRSB.h> | ||
|
||
void get_axis_len(double *length,struct array *a,struct comm *c,int ndim) | ||
{ | ||
double min[MAXDIM],max[MAXDIM]; | ||
sint i; | ||
for(i=0;i<ndim;i++) min[i]=DBL_MAX,max[i]=-DBL_MAX; | ||
|
||
sint nel=a->n; | ||
elm_rcb* elems=a->ptr; | ||
for(i=0;i<nel;i++){ | ||
if(elems[i].coord[0]<min[0]) min[0]=elems[i].coord[0]; | ||
if(elems[i].coord[1]<min[1]) min[1]=elems[i].coord[1]; | ||
if(ndim==3) | ||
if(elems[i].coord[2]<min[2]) min[2]=elems[i].coord[2]; | ||
|
||
if(elems[i].coord[0]>max[0]) max[0]=elems[i].coord[0]; | ||
if(elems[i].coord[1]>max[1]) max[1]=elems[i].coord[1]; | ||
if(ndim==3) | ||
if(elems[i].coord[2]>max[2]) max[2]=elems[i].coord[2]; | ||
} | ||
|
||
double buf[MAXDIM]; | ||
comm_allreduce(c,gs_double,gs_min,min,MAXDIM,buf); | ||
comm_allreduce(c,gs_double,gs_max,max,MAXDIM,buf); | ||
|
||
for(i=0;i<ndim;i++) | ||
length[i]=max[i]-min[i]; | ||
} | ||
|
||
int parRCB(struct comm *ci,struct array *a,int ndim){ | ||
struct comm c; comm_dup(&c,ci); | ||
|
||
uint offsets[3]={offsetof(elm_rcb,coord[0]), | ||
offsetof(elm_rcb,coord[1]),offsetof(elm_rcb,coord[2])}; | ||
|
||
double length[MAXDIM]; | ||
|
||
sint rank=c.id; | ||
sint size=c.np; | ||
|
||
if(rank == 0) | ||
printf("running RCB "), fflush(stdout); | ||
|
||
while(size>1){ | ||
get_axis_len(length,a,&c,ndim); | ||
|
||
int axis1=0,d; | ||
for(d=1;d<ndim;d++) | ||
if(length[d]>length[axis1]) axis1=d; | ||
int axis2=(axis1+1)%2; | ||
for(d=0;d<ndim;d++) | ||
if(length[d]>length[axis2] && d!=axis1) axis2=d; | ||
|
||
uint off=offsets[axis1]; | ||
parallel_sort(elm_rcb,a,off,gs_double,&c); | ||
|
||
int p=(size+1)/2; | ||
int bin=(rank>=p); | ||
|
||
comm_ext old=c.c; | ||
#ifdef MPI | ||
MPI_Comm new; MPI_Comm_split(old,bin,rank,&new); | ||
comm_free(&c); comm_init(&c,new); | ||
MPI_Comm_free(&new); | ||
#endif | ||
rank=c.id; | ||
size=c.np; | ||
} | ||
|
||
comm_free(&c); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
#include <sort.h> | ||
#include <parRSB.h> | ||
|
||
void fparRCB_partMesh(int *part,double *vtx,int *nel,int *nv, | ||
int *options,int *comm,int *err) | ||
{ | ||
*err = 1; | ||
|
||
comm_ext c; c = MPI_Comm_f2c(*comm); | ||
*err=parRCB_partMesh(part,vtx,*nel,*nv,options,c); | ||
} | ||
|
||
int parRCB_partMesh(int *part,double *vtx,int nel,int nv, | ||
int *options,MPI_Comm comm) | ||
{ | ||
struct comm c; comm_init(&c,comm); | ||
int rank=c.id,size=c.np; | ||
|
||
/* load balance input data */ | ||
slong out[2][1],buf[2][1]; | ||
slong nell=nel; | ||
comm_scan(out,&c,gs_long,gs_add,&nell,1,&buf); | ||
slong nelg_start=out[0][0]; | ||
slong nelg =out[1][0]; | ||
|
||
struct array a; array_init(elm_rcb,&a,nel); | ||
elm_rcb *data=a.ptr; | ||
|
||
int ndim=(nv==8)?3:2; | ||
|
||
int e, n; | ||
for(e=0;e<nel;++e){ | ||
data[e].id=nelg_start+(e+1); | ||
data[e].orig=rank; | ||
for(int n=0;n<ndim;n++) | ||
data[e].coord[n]=vtx[e*ndim+n]; | ||
} | ||
a.n=nel; | ||
|
||
//TODO: load balance | ||
|
||
struct comm rcb; | ||
comm_ext old=c.c; | ||
#ifdef MPI | ||
MPI_Comm new; MPI_Comm_split(old,nel>0,rank,&new); | ||
comm_init(&rcb,new); MPI_Comm_free(&new); | ||
#else | ||
comm_init(&rcb,1); | ||
#endif | ||
|
||
if(nel>0){ | ||
comm_barrier(&rcb); | ||
double time=comm_time(); | ||
|
||
parRCB(&rcb,&a,ndim); | ||
|
||
comm_barrier(&rcb); | ||
time=comm_time()-time; | ||
|
||
if(c.id==0) | ||
printf(" finished in %lfs\n",time); | ||
fflush(stdout); | ||
} | ||
comm_free(&rcb); | ||
|
||
/* restore original input */ | ||
struct crystal cr; crystal_init(&cr,&c); | ||
sarray_transfer(elm_rcb,&a,orig,1,&cr); | ||
crystal_free(&cr); | ||
|
||
comm_free(&c); | ||
|
||
assert(a.n==nel); | ||
|
||
buffer b; buffer_init(&b,1024); | ||
sarray_sort(elm_rcb,a.ptr,a.n,id,1,&b); | ||
buffer_free(&b); | ||
|
||
data=a.ptr; | ||
for(int e=0;e<nel;e++) part[e]=data[e].orig; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.