From ab545316726524bd56e598d6ed2b836f9e0a8d20 Mon Sep 17 00:00:00 2001 From: schnetter Date: Tue, 22 Oct 2002 22:37:44 +0000 Subject: Removed C99-isms. *sigh* -- here goes quite a bit of readability. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/Slab/trunk@5 2e825fa2-fb71-486d-8b7f-a5ff3f0f6cb8 --- src/slab.c | 353 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 208 insertions(+), 145 deletions(-) diff --git a/src/slab.c b/src/slab.c index a7280e3..826c2f2 100644 --- a/src/slab.c +++ b/src/slab.c @@ -102,11 +102,12 @@ MPI_Allgather (void * sendbuf, int sendcnt, int sendtype, void * recvbuf, int recvcnt, int recvtype, MPI_Comm comm) { + int recvsize; assert (sendbuf); assert (recvbuf); assert (sendcnt == recvcnt); assert (sendtype == recvtype); - int const recvsize = CCTK_VarTypeSize (recvtype); + recvsize = CCTK_VarTypeSize (recvtype); assert (size > 0); memcpy (recvbuf, sendbuf, recvcnt * recvsize); return 0; @@ -117,11 +118,12 @@ MPI_Alltoall (void * sendbuf, int sendcnt, int sendtype, void * recvbuf, int recvcnt, int recvtype, MPI_Comm comm) { + int recvsize; assert (sendbuf); assert (recvbuf); assert (sendcnt == recvcnt); assert (sendtype == recvtype); - int const recvsize = CCTK_VarTypeSize (recvtype); + recvsize = CCTK_VarTypeSize (recvtype); assert (size > 0); memcpy (recvbuf, sendbuf, recvcnt * recvsize); return 0; @@ -132,6 +134,7 @@ MPI_Alltoallv (void * sendbuf, int * sendcnt, int * sendoff, int sendtype, void * recvbuf, int * recvcnt, int * recvoff, int recvtype, MPI_Comm comm) { + int recvsize; assert (sendbuf); assert (recvbuf); assert (sendcnt); @@ -142,7 +145,7 @@ MPI_Alltoallv (void * sendbuf, int * sendcnt, int * sendoff, int sendtype, assert (*sendoff == 0); assert (*recvoff == 0); assert (sendtype == recvtype); - int const recvsize = CCTK_VarTypeSize (recvtype); + recvsize = CCTK_VarTypeSize (recvtype); assert (size > 0); memcpy (recvbuf, sendbuf, *recvcnt * recvsize); return 0; @@ -232,6 +235,8 @@ static void active2bbox (struct slabinfo const * restrict const slab, struct bbox * restrict const bbox, int const useghosts) { + int nlghostzones; + int nughostzones; assert (slab); assert (bbox); assert (useghosts == 0 || useghosts == 1); @@ -241,8 +246,8 @@ static void active2bbox (struct slabinfo const * restrict const slab, assert (slab->lbbox == 0 || slab->lbbox == 1); assert (slab->ubbox == 0 || slab->ubbox == 1); assert (slab->nghostzones >= 0); - int const nlghostzones = slab->lbbox || useghosts ? 0 : slab->nghostzones; - int const nughostzones = slab->ubbox || useghosts ? 0 : slab->nghostzones; + nlghostzones = slab->lbbox || useghosts ? 0 : slab->nghostzones; + nughostzones = slab->ubbox || useghosts ? 0 : slab->nghostzones; bbox->off = slab->lbnd + nlghostzones; bbox->len = slab->lsh - nlghostzones - nughostzones; bbox->str = 1; @@ -263,20 +268,24 @@ static void slab2bbox (struct slabinfo const * restrict const slab, static int bbox_iscontained (struct bbox const * restrict const inner, struct bbox const * restrict const outer) { + int inner_last; + int outer_last; bbox_check (inner); bbox_check (outer); - int const inner_last = inner->off + (inner->len - 1) * inner->str; - int const outer_last = outer->off + (outer->len - 1) * outer->str; + inner_last = inner->off + (inner->len - 1) * inner->str; + outer_last = outer->off + (outer->len - 1) * outer->str; return inner->off >= outer->off && inner_last <= outer_last; } static void bbox_clip (struct bbox * restrict const inner, struct bbox const * restrict const outer) { + int inner_last; + int outer_last; bbox_check (inner); bbox_check (outer); - int inner_last = inner->off + (inner->len - 1) * inner->str; - int const outer_last = outer->off + (outer->len - 1) * outer->str; + inner_last = inner->off + (inner->len - 1) * inner->str; + outer_last = outer->off + (outer->len - 1) * outer->str; if (inner->off < outer->off) { inner->off += roundup (outer->off - inner->off, inner->str); } @@ -298,17 +307,20 @@ static void bbox_xform (struct bbox * restrict const ydst, struct bbox const * restrict const xsrc, int const flip) { + int xsrc_last; + int xdst_last; + int ysrc_last; + int ydst_last; assert (ydst); bbox_check (ysrc); bbox_check (xdst); bbox_check (xsrc); assert (ysrc->str == xsrc->str); - int const xsrc_last = xsrc->off + (xsrc->len - 1) * xsrc->str; - int const xdst_last = xdst->off + (xdst->len - 1) * xdst->str; - int const ysrc_last = ysrc->off + (ysrc->len - 1) * ysrc->str; + xsrc_last = xsrc->off + (xsrc->len - 1) * xsrc->str; + xdst_last = xdst->off + (xdst->len - 1) * xdst->str; + ysrc_last = ysrc->off + (ysrc->len - 1) * ysrc->str; ydst->str = xdst->str; assert ((ysrc->off - xsrc->off) % ysrc->str == 0); - int ydst_last; ydst->off = xdst->off + (ysrc->off - xsrc->off) / ysrc->str * ydst->str; ydst_last = xdst->off + (ysrc_last - xsrc->off) / ysrc->str * ydst->str; if (flip) { @@ -333,6 +345,29 @@ int Slab_Transfer (cGH * const cctkGH, int const dsttype, void * const dstptr) { + struct info * restrict info; + size_t srclentot, dstlentot; + + struct info * restrict allinfo; + struct bbox * restrict srcdetail; + struct bbox * restrict dstdetail; + + int * restrict srccount; + int * restrict srcoffset; + int * restrict dstcount; + int * restrict dstoffset; + + void * restrict srcdata; + void * restrict dstdata; + + MPI_Comm comm; + int size, rank; + MPI_Datatype srcdatatype, dstdatatype; + + int i, j, k; + int n; + int d; + /* Check arguments */ assert (cctkGH); assert (dim >= 0); @@ -342,8 +377,9 @@ int Slab_Transfer (cGH * const cctkGH, assert (dsttype == CCTK_VARIABLE_REAL); assert (dstptr); - struct info info[dim]; - for (int d=0; d= info[c].src.local.off && srcipos[c] < info[c].src.local.off + info[c].src.local.len); - if (! (srcipos[c] >= allinfo[n][c].src.slab.off - && srcipos[c] <= allinfo[n][c].src.slab.off + (allinfo[n][c].src.slab.len - 1) * allinfo[n][c].src.slab.str)) { - printf ("ssc n=%d ipos=[%d,%d,%d] d=%d srcipos=%d slab.off=%d slab.len=%d\n", n, i, j, k, d, srcipos[c], allinfo[n][c].src.slab.off, allinfo[n][c].src.slab.len); + if (! (srcipos[c] >= allinfo[n*dim+c].src.slab.off + && srcipos[c] <= allinfo[n*dim+c].src.slab.off + (allinfo[n*dim+c].src.slab.len - 1) * allinfo[n*dim+c].src.slab.str)) { + printf ("ssc n=%d ipos=[%d,%d,%d] d=%d srcipos=%d slab.off=%d slab.len=%d\n", n, i, j, k, d, srcipos[c], allinfo[n*dim+c].src.slab.off, allinfo[n*dim+c].src.slab.len); } - assert (srcipos[c] >= allinfo[n][c].src.slab.off - && srcipos[c] <= allinfo[n][c].src.slab.off + (allinfo[n][c].src.slab.len - 1) * allinfo[n][c].src.slab.str); - assert ((srcipos[c] - allinfo[n][c].src.slab.off) % allinfo[n][c].src.slab.str == 0); + assert (srcipos[c] >= allinfo[n*dim+c].src.slab.off + && srcipos[c] <= allinfo[n*dim+c].src.slab.off + (allinfo[n*dim+c].src.slab.len - 1) * allinfo[n*dim+c].src.slab.str); + assert ((srcipos[c] - allinfo[n*dim+c].src.slab.off) % allinfo[n*dim+c].src.slab.str == 0); bufipos[d] = ipos[d]; - assert (bufipos[d] >= 0 && bufipos[d] < srcdetail[n][c].len); + assert (bufipos[d] >= 0 && bufipos[d] < srcdetail[n*dim+c].len); } - size_t srcind = 0; - size_t bufind = 0; - for (int d=dim-1; d>=0; --d) { + srcind = 0; + bufind = 0; + for (d=dim-1; d>=0; --d) { int const c = info[d].xpose; srcind = srcind * info[d].src.local.len + srcipos[d] - info[d].src.local.off; - bufind = bufind * srcdetail[n][c].len + bufipos[d]; + bufind = bufind * srcdetail[n*dim+c].len + bufipos[d]; } assert (srcind < srclentot); assert (bufind < srccount[n]); @@ -623,10 +674,10 @@ int Slab_Transfer (cGH * const cctkGH, } ifcheck { + const CCTK_REAL * restrict const srcptr = srcdata; CCTK_REAL marker; memset (&marker, -1, sizeof marker); - const CCTK_REAL * restrict const srcptr = srcdata; - for (size_t i = 0; i < srcoffset[size]; ++i) { + for (i = 0; i < srcoffset[size]; ++i) { assert (memcmp(&srcptr[i], &marker, sizeof marker) != 0); } } @@ -637,43 +688,45 @@ int Slab_Transfer (cGH * const cctkGH, dstdata, dstcount, dstoffset, dstdatatype, comm); ifcheck { + const CCTK_REAL * restrict const dstptr = dstdata; CCTK_REAL marker; memset (&marker, -1, sizeof marker); - const CCTK_REAL * restrict const dstptr = dstdata; - for (size_t i = 0; i < dstoffset[size]; ++i) { + for (i = 0; i < dstoffset[size]; ++i) { assert (memcmp(&dstptr[i], &marker, sizeof marker) != 0); } } - for (int n = 0; n < size; ++n) { + for (n = 0; n < size; ++n) { assert (dim == 3); - for (int k = 0; k < dstdetail[n][2].len; ++k) { - for (int j = 0; j < dstdetail[n][1].len; ++j) { - for (int i = 0; i < dstdetail[n][0].len; ++i) { - int ipos[dim]; + for (k = 0; k < dstdetail[n*dim+2].len; ++k) { + for (j = 0; j < dstdetail[n*dim+1].len; ++j) { + for (i = 0; i < dstdetail[n*dim+0].len; ++i) { + int ipos[3]; + int bufipos[3]; + int dstipos[3]; + size_t bufind; + size_t dstind; ipos[0] = i; ipos[1] = j; ipos[2] = k; - int bufipos[dim]; - int dstipos[dim]; - for (int d=0; d= 0 && bufipos[d] < dstdetail[n][d].len); - dstipos[d] = dstdetail[n][d].off + ipos[d] * info[d].dst.slab.str; + assert (bufipos[d] >= 0 && bufipos[d] < dstdetail[n*dim+d].len); + dstipos[d] = dstdetail[n*dim+d].off + ipos[d] * info[d].dst.slab.str; assert (dstipos[d] >= info[d].dst.local.off && dstipos[d] < info[d].dst.local.off + info[d].dst.local.len); assert (dstipos[d] >= info[d].dst.slab.off && dstipos[d] <= info[d].dst.slab.off + (info[d].dst.slab.len - 1) * info[d].dst.slab.str); assert ((dstipos[d] - info[d].dst.slab.off) % info[d].dst.slab.str == 0); } - size_t bufind = 0; - size_t dstind = 0; - for (int d=dim-1; d>=0; --d) { - bufind = bufind * dstdetail[n][d].len + bufipos[d]; + bufind = 0; + dstind = 0; + for (d=dim-1; d>=0; --d) { + bufind = bufind * dstdetail[n*dim+d].len + bufipos[d]; dstind = dstind * info[d].dst.local.len + dstipos[d] - info[d].dst.local.off; } assert (bufind < dstcount[n]); @@ -687,8 +740,18 @@ int Slab_Transfer (cGH * const cctkGH, - free (srcdata); free (dstdata); + free (dstcount); + free (dstoffset); + free (dstdetail); + + free (srcdata); + free (srccount); + free (srcoffset); + free (srcdetail); + + free (allinfo); + free (info); -- cgit v1.2.3