History

merge

ericvh committed 16 years ago

Commit f68939a2 parents 6083349 da88d0b5 files · +67 −34Browse files

Unified · Split

5 files
  1. sys/src/cmd/rompi/mkfile +1 −0
  2. sys/src/cmd/rompi/reduce.c +17 −5
  3. sys/src/cmd/rompi/rompi.c +18 −17
  4. sys/src/cmd/rompi/stupidreduce.c +29 −10
  5. sys/src/cmd/rompi/torus.c +2 −2
sys/src/cmd/rompi/mkfile+1−0
@@ -13,6 +13,7 @@ DIRS=\ · 12 unmodified lines
13OTHEROFILES=\13OTHEROFILES=\
14 torus.$O\14 torus.$O\
15 rompi.$O\15 rompi.$O\
16 support.$O\
16 17
17HFILES=mpi.h18HFILES=mpi.h
18 19
sys/src/cmd/rompi/reduce.c+17−5
@@ -5,6 +5,7 @@ · 4 unmodified lines
5#include "mpi.h"5#include "mpi.h"
6 6
7/* tested may 17 2010 and works */7/* tested may 17 2010 and works */
8u64int tbget(void);
8extern int torusdebug, rompidebug;9extern int torusdebug, rompidebug;
9extern int x, y, z, xsize, ysize, zsize; 10extern int x, y, z, xsize, ysize, zsize;
10int xyztorank(int x, int y, int z);11int xyztorank(int x, int y, int z);
@@ -16,20 +17,31 @@ main(int argc, char **argv) · 5 unmodified lines
16{17{
17 int node, nproc;18 int node, nproc;
18 unsigned int sum[1], nsum[1];19 unsigned int sum[1], nsum[1];
20 int i;
21 vlong startnsec, stopnsec;
22 int iter = 100;
19 23
20 MPI_Init(&argc,&argv);24 MPI_Init(&argc,&argv);
21 MPI_Comm_rank(MPI_COMM_WORLD, &node);25 MPI_Comm_rank(MPI_COMM_WORLD, &node);
22 MPI_Comm_size(MPI_COMM_WORLD, &nproc);26 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
23 27
24 print("%lld Hello World from Node %d of %d\n", nsec(),node, nproc);28 print("%lld Hello World from Node %d of %d\n", tbget(),node, nproc);
25
26 sum[0] = node;
27 29
28 if (0 && node) 30 if (0 && node)
29 rompidebug |= 4;31 rompidebug |= 4;
30 MPI_Reduce (sum, nsum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);32 for (i = 0; i < iter; i++){
33 if (i == 1)
34 startnsec = tbget();
35 sum[0] = node;
36 MPI_Reduce (sum, nsum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
37// if (! node)
38// print("%d\n", i);
39 }
40 stopnsec = tbget();
31 41
32 print("%lld Node %d (%d, %d, %d) computes sum as %d and MPI says sum is %d\n", nsec(), node, x, y, z, ((nproc-1)*nproc)/2, nsum[0]);42 print("%lld Node %d (%d, %d, %d) computes sum as %d and MPI says sum is %d\n", tbget(), node, x, y, z, ((nproc-1)*nproc)/2, nsum[0]);
43 if (! node)
44 print("%lld nsec for %d iterations\n", stopnsec-startnsec, iter);
33 print("%lld %d: Finalize\n", nsec(), node);45 print("%lld %d: Finalize\n", nsec(), node);
34 MPI_Finalize();46 MPI_Finalize();
35}47}
sys/src/cmd/rompi/rompi.c+18−17
@@ -40,6 +40,7 @@ void torusinit(int *pmyproc, const int pnprocs); · 39 unmodified lines
40void ranktoxyz(int rank, int *x, int *y, int *z);40void ranktoxyz(int rank, int *x, int *y, int *z);
41int xyztorank(int x, int y, int z);41int xyztorank(int x, int y, int z);
42extern int x, y, z, xsize, ysize, zsize;42extern int x, y, z, xsize, ysize, zsize;
43u64int tbget(void);
43 44
44void45void
45buf_add(struct bufpacket *new)46buf_add(struct bufpacket *new)
@@ -282,7 +283,7 @@ int reduce_end ( void *buf, int num, MPI_Datatype datatype, int /*root*/, · 236 unmodified lines
282 torustag[TAGtag] = reducetag;283 torustag[TAGtag] = reducetag;
283 torustag[TAGsource] = myproc;284 torustag[TAGsource] = myproc;
284 285
285 if(rompidebug&4) print("%lld reduce_end: %d(%d, %d, %d)\n", nsec(), myproc, x, y, z);286 if(rompidebug&4) print("%lld reduce_end: %d(%d, %d, %d)\n", tbget(), myproc, x, y, z);
286 if (myproc) {287 if (myproc) {
287 /* who we get it from depends on who we are. */288 /* who we get it from depends on who we are. */
288 /* this shows some bad design. We compute x,y,z, turn it into rank, 289 /* this shows some bad design. We compute x,y,z, turn it into rank,
@@ -298,9 +299,9 @@ int reduce_end ( void *buf, int num, MPI_Datatype datatype, int /*root*/, · 9 unmodified lines
298 else if (x)299 else if (x)
299 fromz = fromy = fromx = 0;300 fromz = fromy = fromx = 0;
300 fromrank = xyztorank(fromx, fromy, fromz);301 fromrank = xyztorank(fromx, fromy, fromz);
301 if(rompidebug&4) print("%lld reduce_end: %d(%d,%d,%d): wait from (%d, %d, %d)\n", nsec(), myproc, x, y, z, fromx, fromy, fromz);302 if(rompidebug&4) print("%lld reduce_end: %d(%d,%d,%d): wait from (%d, %d, %d)\n", tbget(), myproc, x, y, z, fromx, fromy, fromz);
302 MPI_Recv(buf, 1, MPI_INT, fromrank, reducetag, MPI_COMM_WORLD, status);303 MPI_Recv(buf, 1, MPI_INT, fromrank, reducetag, MPI_COMM_WORLD, status);
303 if(rompidebug&4) print("%lld reduce_end: %d: Got from %d\n", nsec(), myproc, fromrank);304 if(rompidebug&4) print("%lld reduce_end: %d: Got from %d\n", tbget(), myproc, fromrank);
304 }305 }
305 306
306 /* OK, we got it, we just need to do one send to our "axis" (of evil?) */307 /* OK, we got it, we just need to do one send to our "axis" (of evil?) */
@@ -311,24 +312,24 @@ int reduce_end ( void *buf, int num, MPI_Datatype datatype, int /*root*/, · 4 unmodified lines
311 */312 */
312 if (z) {313 if (z) {
313 } else if (y) {314 } else if (y) {
314 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, x, y, zsize-1);315 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, x, y, zsize-1);
315 torustag[TAGsource] = myproc;316 torustag[TAGsource] = myproc;
316 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));317 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));
317 }318 }
318 else if (x) {319 else if (x) {
319 /* send down BOTH our y and z axis */320 /* send down BOTH our y and z axis */
320 torustag[TAGsource] = myproc;321 torustag[TAGsource] = myproc;
321 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, x, ysize-1, 0);322 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, x, ysize-1, 0);
322 torussend(buf, count, x, ysize-1, 0, 1, torustag, sizeof(torustag));323 torussend(buf, count, x, ysize-1, 0, 1, torustag, sizeof(torustag));
323 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, x, y, zsize-1);324 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, x, y, zsize-1);
324 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));325 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));
325 } else {326 } else {
326 /* send down x, y, z */327 /* send down x, y, z */
327 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, xsize-1, 0, 0);328 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, xsize-1, 0, 0);
328 torussend(buf, count, xsize-1, 0, 0, 1, torustag, sizeof(torustag));329 torussend(buf, count, xsize-1, 0, 0, 1, torustag, sizeof(torustag));
329 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, x, ysize-1, 0);330 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, x, ysize-1, 0);
330 torussend(buf, count, x, ysize-1, 0, 1, torustag, sizeof(torustag));331 torussend(buf, count, x, ysize-1, 0, 1, torustag, sizeof(torustag));
331 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", nsec(), myproc, x, y, z, x, y, zsize-1);332 if(rompidebug&4) print("%lld reduce_end %d(%d, %d, %d): send to (%d, %d, %d)\n", tbget(), myproc, x, y, z, x, y, zsize-1);
332 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));333 torussend(buf, count, x, y, zsize-1, 1, torustag, sizeof(torustag));
333 }334 }
334 335
@@ -344,7 +345,7 @@ opsum(void *dst, void *src, int) · 9 unmodified lines
344 int *is = src;345 int *is = src;
345 int *id = dst;346 int *id = dst;
346 int tmp = *is;347 int tmp = *is;
347 if (rompidebug & 4) print("%lld %d(%d,%d,%d): SUM %d+%d=%d\n", nsec(), myproc, x,y,z,*id, *is, *id+tmp);348 if (rompidebug & 4) print("%lld %d(%d,%d,%d): SUM %d+%d=%d\n", tbget(), myproc, x,y,z,*id, *is, *id+tmp);
348 *id += tmp;349 *id += tmp;
349 return *id;350 return *id;
350}351}
@@ -397,7 +398,7 @@ int MPI_Reduce ( void *sendbuf, void *recvbuf, int count, · 46 unmodified lines
397 if (z) {398 if (z) {
398 torank = xyztorank(x,y,0);399 torank = xyztorank(x,y,0);
399 if (rompidebug&4)400 if (rompidebug&4)
400 print("%lld %d:(%d,%d,%d) sends %d to %d\n", nsec(), myproc, x, y, z, myproc, torank);401 print("%lld %d:(%d,%d,%d) sends %d to %d\n", tbget(), myproc, x, y, z, myproc, torank);
401 MPI_Send(tmp, 1, datatype, torank, 1, comm);402 MPI_Send(tmp, 1, datatype, torank, 1, comm);
402 } else {403 } else {
403 /* gather up all our z >0 data */404 /* gather up all our z >0 data */
@@ -407,14 +408,14 @@ int MPI_Reduce ( void *sendbuf, void *recvbuf, int count, · 3 unmodified lines
407 op(tmp, recvbuf, count);408 op(tmp, recvbuf, count);
408 }409 }
409 if (rompidebug&4)410 if (rompidebug&4)
410 print("%lld AFTER Z: %d(%d, %d, %d): %d\n", nsec(), myproc, x, y, z, sum[0]);411 print("%lld AFTER Z: %d(%d, %d, %d): %d\n", tbget(), myproc, x, y, z, sum[0]);
411 412
412 /* y? y o y? */413 /* y? y o y? */
413 if (y) {414 if (y) {
414 torank = xyztorank(x,0,0);415 torank = xyztorank(x,0,0);
415 /* send to our parent */416 /* send to our parent */
416 if (rompidebug&4)417 if (rompidebug&4)
417 print("%lld %d:(%d,%d,%d) sends %d to %d\n", nsec(), myproc, x, y, z, sum[0], torank);418 print("%lld %d:(%d,%d,%d) sends %d to %d\n", tbget(), myproc, x, y, z, sum[0], torank);
418 MPI_Send(tmp, 1, datatype, torank, 1, comm);419 MPI_Send(tmp, 1, datatype, torank, 1, comm);
419 } else {420 } else {
420 /* This is the vector along the X axis. All myprocs, including (0,0,0), gather up along 421 /* This is the vector along the X axis. All myprocs, including (0,0,0), gather up along
@@ -429,11 +430,11 @@ int MPI_Reduce ( void *sendbuf, void *recvbuf, int count, · 8 unmodified lines
429 op(tmp, recvbuf, count);430 op(tmp, recvbuf, count);
430 }431 }
431 if (rompidebug&4)432 if (rompidebug&4)
432 print("%lld %d:(%d,%d,%d) gets %d accum %d\n", nsec(), myproc, x, y, z, nsum[0], sum[0]);433 print("%lld %d:(%d,%d,%d) gets %d accum %d\n", tbget(), myproc, x, y, z, nsum[0], sum[0]);
433 if (x) {434 if (x) {
434 /* send to our parent */435 /* send to our parent */
435 if (rompidebug&4)436 if (rompidebug&4)
436 print("%lld %d:(%d,%d,%d) sends %d to %d\n", nsec(), myproc, x, y, z, sum[0], torank);437 print("%lld %d:(%d,%d,%d) sends %d to %d\n", tbget(), myproc, x, y, z, sum[0], torank);
437 MPI_Send(tmp, 1, datatype, torank, 1, comm);438 MPI_Send(tmp, 1, datatype, torank, 1, comm);
438 } else {439 } else {
439 /* sum contains the sum from our y axis above */440 /* sum contains the sum from our y axis above */
@@ -441,7 +442,7 @@ int MPI_Reduce ( void *sendbuf, void *recvbuf, int count, · 1 unmodified line
441 MPI_Recv(recvbuf, 1, datatype, i, 1, comm, &status);442 MPI_Recv(recvbuf, 1, datatype, i, 1, comm, &status);
442 op(tmp, recvbuf, count);443 op(tmp, recvbuf, count);
443 if (rompidebug&4)444 if (rompidebug&4)
444 print("%lld %d:(%d,%d,%d) recv %d to %d\n", nsec(), myproc, x, y, z, sum[0], i);445 print("%lld %d:(%d,%d,%d) recv %d to %d\n", tbget(), myproc, x, y, z, sum[0], i);
445 }446 }
446 }447 }
447 }448 }
@@ -450,7 +451,7 @@ int MPI_Reduce ( void *sendbuf, void *recvbuf, int count, · 2 unmodified lines
450 if (! myproc){451 if (! myproc){
451 memmove(recvbuf, tmp, nbytes);452 memmove(recvbuf, tmp, nbytes);
452 if (rompidebug&4)453 if (rompidebug&4)
453 print("%lld reduce: %d(%d,%d,%d): gather done, send SUM %d\n", nsec(), myproc, x, y, z, sum[0]);454 print("%lld reduce: %d(%d,%d,%d): gather done, send SUM %d\n", tbget(), myproc, x, y, z, sum[0]);
454 }455 }
455 456
456 return reduce_end (recvbuf, count, datatype, root, comm, &status);457 return reduce_end (recvbuf, count, datatype, root, comm, &status);
sys/src/cmd/rompi/stupidreduce.c+29−10
@@ -6,21 +6,14 @@ · 5 unmodified lines
6 6
7/* tested may 17 2010 and works */7/* tested may 17 2010 and works */
8extern int torusdebug;8extern int torusdebug;
9u64int tbget(void);
10int node, nproc;
9 11
10void12void
11main(int argc, char **argv)13stupidreduce(unsigned int *sum)
12{14{
13 int node, nproc;
14 unsigned int sum[1];
15 MPI_Status status;15 MPI_Status status;
16 int i;16 int i;
17
18 MPI_Init(&argc,&argv);
19 MPI_Comm_rank(MPI_COMM_WORLD, &node);
20 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
21
22 print("Hello World from Node %d of %d\n",node, nproc);
23
24 if (node) {17 if (node) {
25 sum[0] = node;18 sum[0] = node;
26 MPI_Send(sum, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);19 MPI_Send(sum, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
@@ -36,7 +29,33 @@ main(int argc, char **argv) · 9 unmodified lines
36 MPI_Send(sum, 1, MPI_INT, i, 1, MPI_COMM_WORLD);29 MPI_Send(sum, 1, MPI_INT, i, 1, MPI_COMM_WORLD);
37 }30 }
38 }31 }
32}
33
34void
35main(int argc, char **argv)
36{
37 unsigned int sum[1];
38 int i;
39 vlong startnsec, stopnsec;
40 int iter = 100;
41
42 MPI_Init(&argc,&argv);
43 MPI_Comm_rank(MPI_COMM_WORLD, &node);
44 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
45
46 print("Hello World from Node %d of %d\n",node, nproc);
47
48 for(i = 0; i < iter; i++){
49 if (i == 1)
50 startnsec = tbget();
51 sum[0] = node;
52 stupidreduce(sum);
53 }
54 stopnsec = tbget();
55
39 print("%d: Finalize\n", node);56 print("%d: Finalize\n", node);
57 if (! node)
58 print("%lld nsec for %d iterations\n", stopnsec-startnsec, iter-1);
40 MPI_Finalize();59 MPI_Finalize();
41 print("Node %d computes sum as %d and MPI says sum is %d\n", node, ((nproc-1)*nproc)/2, sum[0]);60 print("Node %d computes sum as %d and MPI says sum is %d\n", node, ((nproc-1)*nproc)/2, sum[0]);
42}61}
sys/src/cmd/rompi/torus.c+2−2
@@ -205,11 +205,11 @@ void torusinit(int *pmyproc, const int numprocs) · 204 unmodified lines
205 z = d[Z];205 z = d[Z];
206 206
207 *pmyproc = (z << (lx + ly)) + (y << lx) + x;207 *pmyproc = (z << (lx + ly)) + (y << lx) + x;
208 /*208
209 print( "%d/%d %d/%d %d/%d\n", x, xsize, y, ysize, z, zsize);209 print( "%d/%d %d/%d %d/%d\n", x, xsize, y, ysize, z, zsize);
210 print( "numprocs %d \n", numprocs);210 print( "numprocs %d \n", numprocs);
211 print("%d/%d %d/%d %d/%d\n", lx, xbits, ly, ybits, lz, zbits);211 print("%d/%d %d/%d %d/%d\n", lx, xbits, ly, ybits, lz, zbits);
212 */212
213 /* make some tables. Mapping is done as it is to maximally distributed broadcast traffic */213 /* make some tables. Mapping is done as it is to maximally distributed broadcast traffic */
214 xyz = calloc(numprocs, sizeof(*xyz));214 xyz = calloc(numprocs, sizeof(*xyz));
215 if (!xyz)215 if (!xyz)