18 const double A[16] = { 2, -1, -1, 0,
22 const uint Ai[16] = { 0, 0, 0, 0,
26 Aj[16] = { 0, 1, 2, 3,
31 double x[4]={1,1,1,1}, b[4], bmean;
32 uint i, w, gn, px, py;
38 w = ceil(sqrt(comm->
np)); gn = (w+1)*(w+1);
40 if(comm->
id==0) printf(
"arranging procs in a %u x %u square\n", w, w);
42 px = comm->
id%w, py = comm->
id/w;
43 b[0] = xid[0] = (w+1)*py +px+1;
44 b[1] = xid[1] = (w+1)*py +px+2;
45 b[2] = xid[2] = (w+1)*(py+1)+px+1;
46 b[3] = xid[3] = (w+1)*(py+1)+px+2;
48 gn = comm_reduce_slong(comm, gs_max, (
const slong*)&xid[3],1);
49 bmean = comm_reduce_double(comm, gs_add, b,4)/gn;
52 gs(x,gs_double,gs_add,0,gsh,0);
53 gs(b,gs_double,gs_add,0,gsh,0);
54 for(i=0;i<4;++
i) b[i]=xid[i]-bmean/x[i];
55 gs(b,gs_double,gs_add,0,gsh,0);
59 for(i=0;i<4;++
i) uid[i]=comm->
id;
62 for(i=0;i<4;++
i) uid[i] = (uid[i]==comm->
id?(
slong)xid[i]:-(
slong)xid[i]);
67 for(i=0;i<gn;++
i) xgid[i] = -(
slong)(i+1);
68 for(i=0;i<4;++
i) xgid[xid[i]-1] = uid[i];
73 if(comm->
id==0)
for(i=0;i<4;++
i) xg[xid[i]-1]=b[i];
74 gs(comm->
id?b:xg,gs_double,gs_add, 0, gsh, 0);
75 if(comm->
id==0)
for(i=0;i<gn;++
i) printf(
"b[%u] = %g\n",i,xg[i]);
76 for(i=0;i<4;++
i) b[i]=xid[i]-bmean/x[i];
86 if(comm->
id==0)
for(i=0;i<4;++
i) xg[xid[i]-1]=x[i];
87 gs(comm->
id?x:xg,gs_double,gs_add, 0, gsh, 0);
88 if(comm->
id==0)
for(i=0;i<gn;++
i) printf(
"x[%u] = %g\n",i,xg[i]);
91 if(comm->
id==0) free(xg), free(xgid);
94 int main(
int narg,
char* arg[])
100 world = MPI_COMM_WORLD;
101 MPI_Comm_size(world,&np);
#define tmalloc(type, count)
void test(const struct comm *const comm)
static void comm_free(struct comm *c)
int main(int narg, char *arg[])
Gather/Scatter Library interface.
establishes some macros to establish naming conventions
static void comm_init(struct comm *c, comm_ext ce)