This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

"Internal compiler error"


Dear Maintainers of GNU C++,

The compiler informs me I should submit a bug report.  I looked on the
web under "frequently reported bugs", etc, but could find no mention of
the rather mysterious "Internal compiler error".

Here's what happened:

c++ -c  -DLINUX -DWant_c_files -I. -I../include -I/d/bh3/home/shawley/bbh_grace/include  -I/usr/local/include  -DLINUX -DWant_c_files -DIO_RNPLIO  -DSTDC_HEADERS=1 -DHAVE_STRDUP=1 -DHAVE_ATEXIT=1   -DLINUX -DF77_HAS_SYSTEM -DF77_HAS_CHDIR -DHAVE_LIBVS=1 -


DHAVE_LIBSV=1 -DHAVE_LIBMPI=1 -DACE_REUSE_GDB -DDEBUG_PRINT -DACE_WRITEBOXES -DDEBUG_PRINT_GD_FILL ACEDistribution.cpp
ACEDistribution.cpp: In method `ACEDistribution::ACEDistribution(int, BBoxList &)':
ACEDistribution.cpp:30: Internal compiler error.
ACEDistribution.cpp:30: Please submit a full bug report.
ACEDistribution.cpp:30: See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> for instructions.
make: [ACEDistribution.o] Error 1 (ignored)

I'm running GNU c++ version 2.95.2 (19991024) under Mandrake Linux 6.1 (full 
installation) on one of the front end nodes of the 64-node vn cluster at 
University of British Columbia
(Each node has dual PIII 450 MHz processors and 512 MByte of RAM.)

Attached is a copy of the source file ACEDistribution.cpp
However, there are many, many include files used for this file.  I can send
a complete configurable distribution upon request, or you can download 
the distribution via anonymous FTP from  
ftp://dirac.ph.utexas.edu/pub/bbh_grace/bbh_grace.tar.gz
(then "./configure ; cd src; make" )
We have no trouble installing using the SGI compilers on IRIX 6.2 or using
the Portland Group compilers on Mandrake Linux 6.1.

For further information, please contact me or 
Matthew Choptuik:  matt@laplace.physics.ubc.ca
  (Matt would know, e.g. the operands used for "configure" when the compiler
   was installed)

Best wishes,
Scott Hawley


............................................................................
Scott H. Hawley                  Office: RLM 9.206 
Center for Relativity            Voice: (512) 471-5426, FAX: (512) 471-0890
Department of Physics            shawley@physics.utexas.edu
University of Texas at Austin    http://wwwrel.ph.utexas.edu/Members/shawley

/*
*************************************************************************
* ACEDistribution.C							*
*                                                                       *
* Author:  Manish Parashar <parashar@caip.rutgers.edu>                     *
*                                                                       *
*************************************************************************
*/

#include "ACEDistribution.h"

#ifdef DEBUG_PRINT
#include "CommServer.h"
#endif

/*************************************************************************/
/* Partitioning functions based on Paul Walker's implementation          */
/*************************************************************************/
void partition_one(const BBox& wholebbox, BBox* boxes, const int np, 
                   const int dim);
void partition_two(const BBox& wholebbox, BBox* boxes, const int np, 
                   const int dim1, const int dim2);
void partition_all(const BBox& wholebbox, BBox* boxes, const int np);
void pwalker_partition(const BBox& wholebbox, BBox* boxes, const int np);
/*************************************************************************/

ACEDistribution::ACEDistribution(const int disttype, BBoxList& bbl)
        : type(disttype), wfunc(0), boxes(0)
  {
    boxes = new BBox[bbl.number()];
    register BBox* bb = 0;
    register int cnt = 0;
    for (bb=bbl.first();bb;bb=bbl.next()) {
      boxes[cnt++] = *bb; 
    }
  }

void ACEDistribution::set_dist(const int disttype, BBoxList& bbl)
  {
    type = disttype;
    if (boxes) delete [] boxes;
    boxes = new BBox[bbl.number()];
    register BBox* bb = 0;
    register int cnt = 0;
    for (bb=bbl.first();bb;bb=bbl.next()) {
      boxes[cnt++] = *bb; 
    }
  }

unsigned long ACEDistribution::get_load(GridUnitList& ggul, 
					 const short* olap)
  {
    if (wfunc) { 
      unsigned long load = 0, n = 0;
      int levels = ggul.levels();
      for (int l=0;l<levels;l++) 
	load += (*wfunc)(&(n=ggul.numelems(l,olap)),&l);
      return load;
    } 
    else return( ggul.load(olap) );
  }

void ACEDistribution::partition(GridUnitList*& ggul,
                                 GridUnitList*& lgul,
                                 const int np, const int me, 
                                 const int minw, const short* olap)
  {
    if (type == ACECompositeDistribution) 
      partitionComposite(ggul, lgul, np, me, minw, olap);

    else if (type == ACEBlockXDistribution) 
      partitionBlockOne(ACE_X, ggul, lgul, np, me, minw, olap);
    else if (type == ACEBlockYDistribution) 
      partitionBlockOne(ACE_Y, ggul, lgul, np, me, minw, olap);
    else if (type == ACEBlockZDistribution) 
      partitionBlockOne(ACE_Z, ggul, lgul, np, me, minw, olap);

    else if (type == ACEBlockXYDistribution) 
      partitionBlockTwo(ACE_X, ACE_Y, ggul, lgul, np, me, minw, olap);
    else if (type == ACEBlockYZDistribution) 
      partitionBlockTwo(ACE_Y, ACE_Z, ggul, lgul, np, me, minw, olap);
    else if (type == ACEBlockXZDistribution) 
      partitionBlockTwo(ACE_X, ACE_Z, ggul, lgul, np, me, minw, olap);

    else if (type == ACEBlockAllDistribution) 
      partitionBlockAll(ggul, lgul, np, me, minw, olap);

    else if (type == ACEUserDefDistribution) 
      partitionUserDef(ggul, lgul, np, me, minw, olap);

    else
      assert(0);
  }

void ACEDistribution::partition(const BBox& wbbox,
				 BBox& mybbox,
                                 const int np, 
				 const int me)
  {
#ifdef DEBUG_PRINT
    assert (type != ACECompositeDistribution);
#endif

    if (type != ACEUserDefDistribution) {
      if (boxes) delete [] boxes;
      boxes = new BBox[np];

      if (type == ACEBlockXDistribution) 
	partition_one(wbbox, boxes, np, ACE_X);
      else if (type == ACEBlockYDistribution) 
	partition_one(wbbox, boxes, np, ACE_Y);
      else if (type == ACEBlockZDistribution) 
	partition_one(wbbox, boxes, np, ACE_Z);
      
      else if (type == ACEBlockXYDistribution) 
	partition_two(wbbox, boxes, np, ACE_X, ACE_Y);
      else if (type == ACEBlockYZDistribution) 
	partition_two(wbbox, boxes, np, ACE_Y, ACE_Z);
      else if (type == ACEBlockXZDistribution) 
	partition_two(wbbox, boxes, np, ACE_X, ACE_Z);

      else if (type == ACEBlockAllDistribution) 
	partition_all(wbbox, boxes, np);

      else
	assert(0);
    }
    if (me < np) mybbox = boxes[me];
    else mybbox.setempty();
  }

void ACEDistribution::partitionComposite(GridUnitList*& ggul,
                                          GridUnitList*& lgul,
                                          const int np, const int me, 
                                          const int minw, const short* olap)
  {
#ifdef DEBUG_PRINT
    /* Cannot partition an empty list */
    assert(ggul->number() > 0);
  
    /* Zero procs... ? */
    assert(np > 0);
#endif

    //if (!localspans.isempty()) localspans.empty();

    if (me < np) {
      if (lgul) lgul->empty();
      else {
	lgul = new GridUnitList;
      }
    }

    dMapIndex *lmin = 0;
    dMapIndex lmax;

    unsigned long work = get_load(*ggul,olap);

    unsigned long thresh = (unsigned) ((1.0*(work/np))+0.5);
    register unsigned long curthresh = thresh;

    int p = 0, pcnt = 0;
    unsigned tmpw = 0, w = 0;

    register GridUnit *tmpgu = ggul->first();

#ifdef DEBUG_PRINT_DIST
     ( comm_service::log() << "\n{ Composite Distribution: "
                           << np << " " << work << " " << thresh
                           << "} \n"
                           ).flush();
#endif

    for (int cnt=0;tmpgu;cnt++,tmpgu=ggul->next()) {
      w += (tmpw = tmpgu->guWork(olap));

#ifdef DEBUG_PRINT_DIST
     ( comm_service::log() << "\n{ Partitioning: "
                           << cnt << " " << p << " "
                           << curthresh << " " << w << " " << tmpw << " "
                           << tmpgu->guBaseIndex()  << " "
                           << *ggul->currec()
                           << "} \n"
                           ).flush();
#endif

      if (w <= curthresh) {

#ifdef DEBUG_PRINT_DIST
     if (p>=np)
       ( comm_service::log() << "\n************* Current Composite List *************\n"
	 << *ggul
	 << "\n************* ***************** *************\n"
	 << "\n************* Current Bucket *************\n"
	 << *((SimpleBucketVoid *) ggul)
	 << "\n************* ***************** *************\n"
	 ).flush();
#endif
#ifdef DEBUG_PRINT
        assert (p<np);
#endif
        tmpgu->guSetOwner(p); pcnt++;
        if (p == me)  lgul->add(*tmpgu);
        if (!lmin) lmin = new dMapIndex(tmpgu->guBaseIndex());
        lmax = tmpgu->guBaseIndex();
      }
      else if (w-curthresh < tmpw/4) {

#ifdef DEBUG_PRINT_DIST
     if (p>=np)
       ( comm_service::log() << "\n************* Current Composite List *************\n"
	 << *ggul
	 << "\n************* ***************** *************\n"
	 << "\n************* Current Bucket *************\n"
	 << *((SimpleBucketVoid *) ggul)
	 << "\n************* ***************** *************\n"
	 ).flush();
#endif
#ifdef DEBUG_PRINT
        assert(p<np);
#endif
        tmpgu->guSetOwner(p); pcnt++;
        if (p == me)  lgul->add(*tmpgu);
        lmax = tmpgu->guBaseIndex();
        p++; pcnt = 0;
        curthresh = w + (unsigned) ((1.0*((work-w)/(np-p)))+0.5);
      }
      else if (tmpw > thresh && tmpgu->guExtent(tmpgu->guCrsLev()) > minw) {
        w -= tmpw;
        cnt--;
        int oldwork = work;
        ggul->decompose();
        work = get_load(*ggul,olap);

#ifdef DEBUG_PRINT_DIST
     ( comm_service::log() << "\n************* After Decompose *************\n"
                           << "Cur Proc:" << p << " "
                           << tmpgu->guBaseIndex() << " "
                           << *ggul->current() << "\n"
                           << "Cur GU:" << ggul->current() << "\n"
                           << "\n************* ***************** *************\n"
                           ).flush();
#endif

        thresh = (unsigned) ((1.0*(work/np))+0.5);
        curthresh = curthresh+(unsigned)((1.0*((work-oldwork)/(np-p)))+0.5);
      }
      else if (pcnt == 0) {

#ifdef DEBUG_PRINT_DIST
     if (p>=np)
       ( comm_service::log() << "\n************* Current Composite List *************\n"
	 << *ggul
	 << "\n************* ***************** *************\n"
	 << "\n************* Current Bucket *************\n"
	 << *((SimpleBucketVoid *) ggul)
	 << "\n************* ***************** *************\n"
	 ).flush();
#endif
#ifdef DEBUG_PRINT
        assert(p<np);
#endif
        tmpgu->guSetOwner(p); pcnt++;
        if (p == me)  lgul->add(*tmpgu);
        lmax = tmpgu->guBaseIndex();
        p++; pcnt = 0;
        curthresh = w + (unsigned) ((1.0*((work-w)/(np-p)))+0.5);
      }
      else  {
        p++; pcnt = 0;

#ifdef DEBUG_PRINT_DIST
     if (p>=np)
       ( comm_service::log() << "\n************* Current Composite List *************\n"
	 << *ggul
	 << "\n************* ***************** *************\n"
	 << "\n************* Current Bucket *************\n"
	 << *((SimpleBucketVoid *) ggul)
	 << "\n************* ***************** *************\n"
	 ).flush();
#endif
#ifdef DEBUG_PRINT
        assert(p<np);
#endif
        tmpgu->guSetOwner(p);
        if (p == me) lgul->add(*tmpgu);
        if (!lmin) lmin = new dMapIndex(tmpgu->guBaseIndex());
        lmax = tmpgu->guBaseIndex();
        curthresh = (w-tmpw) + (unsigned) ((1.0*((work-(w-tmpw))/(np-p)))+0.5);
        if (w >= curthresh) {
          p++; pcnt = 0;
          if (p < np)
            curthresh = w + (unsigned) ((1.0*((work-w)/(np-p)))+0.5);
        }
      }
    }
    //localspans.add(ACESpan(*lmin,lmax));
    if(lmin) delete lmin;
  }

void ACEDistribution::partitionBlockOne(const int axis,
                                         GridUnitList*& ggul,
                                         GridUnitList*& lgul,
                                         const int np, const int me, 
                                         const int minw, const short* olap)
  {
#ifdef DEBUG_PRINT
    /* Cannot partition an empty list */
    assert(ggul->number() > 0);
  
    /* Zero procs... ? */
    assert(np > 0);
#endif

    if (boxes) delete [] boxes;
    boxes = new BBox[np];

    const int flev = (ggul->first())->guFineLev();
    BBoxList tmpbbl;
    ggul->bboxlist(tmpbbl, flev, 0, 0);
    BBox wbbox = tmpbbl.reduce();
    partition_one(wbbox, boxes, np, axis);

    GridUnitList tmpgul;
    for (register int p=0;p<np;p++) {
      ggul->intersect(boxes[p], flev, tmpgul, 0);
      GridUnitList tmpgul(*ggul);
      tmpgul *= boxes[p];
      ggul->setowner(tmpgul,p);
      if (p == me) {
        if (lgul) {
          lgul->empty();
          *lgul = tmpgul;
        }
        else {
          lgul = new GridUnitList(tmpgul);
        }
        lgul->setowner(me);
      } 
    }
  }

void ACEDistribution::partitionBlockTwo(const int axis1, const int axis2,
                                         GridUnitList*& ggul,
                                         GridUnitList*& lgul,
                                         const int np, const int me, 
                                         const int minw, const short* olap)
  {
#ifdef DEBUG_PRINT
    /* Cannot partition an empty list */
    assert(ggul->number() > 0);
  
    /* Zero procs... ? */
    assert(np > 0);
#endif

    if (boxes) delete [] boxes;
    boxes = new BBox[np];

    const int flev = (ggul->first())->guFineLev();
    BBoxList tmpbbl;
    ggul->bboxlist(tmpbbl, flev, 0, 0);
    BBox wbbox = tmpbbl.reduce();
    partition_two(wbbox, boxes, np, axis1, axis2);

    GridUnitList tmpgul;
    for (register int p=0;p<np;p++) {
      ggul->intersect(boxes[p], flev, tmpgul, 0);
      GridUnitList tmpgul(*ggul);
      tmpgul *= boxes[p];
      ggul->setowner(tmpgul,p);
      if (p == me) {
        if (lgul) {
          lgul->empty();
          *lgul = tmpgul;
        }
        else {
          lgul = new GridUnitList(tmpgul);
        }
        lgul->setowner(me);
      } 
    }
  }

void ACEDistribution::partitionBlockAll(GridUnitList*& ggul,
                                         GridUnitList*& lgul,
                                         const int np, const int me, 
                                         const int minw, const short* olap)
  {
#ifdef DEBUG_PRINT
    /* Cannot partition an empty list */
    assert(ggul->number() > 0);
  
    /* Zero procs... ? */
    assert(np > 0);
#endif

    if (boxes) delete boxes;
    boxes = new BBox[np];

    const int flev = (ggul->first())->guFineLev();
    BBoxList tmpbbl;
    ggul->bboxlist(tmpbbl, flev, 0, 0);
    BBox wbbox = tmpbbl.reduce();
    partition_all(wbbox, boxes, np);

    GridUnitList tmpgul;
    for (register int p=0;p<np;p++) {
      ggul->intersect(boxes[p], flev, tmpgul, 0);
      GridUnitList tmpgul(*ggul);
      tmpgul *= boxes[p];
      ggul->setowner(tmpgul,p);
      if (p == me) {
        if (lgul) {
          lgul->empty();
          *lgul = tmpgul;
        }
        else {
          lgul = new GridUnitList(tmpgul);
        }
        lgul->setowner(me);
      } 
    }
  }

void ACEDistribution::partitionUserDef(GridUnitList*& ggul,
                                        GridUnitList*& lgul,
                                        const int np, const int me, 
                                        const int minw, const short* olap)
  {
#ifdef DEBUG_PRINT
    /* The list boxes has to be defined */
    assert(boxes); 

    /* Cannot partition an empty list */
    assert(ggul->number() > 0);
  
    /* Zero procs... ? */
    assert(np > 0);
#endif

    const int flev = (ggul->first())->guFineLev();
    BBoxList tmpbbl;
    ggul->bboxlist(tmpbbl, flev, 0, 0);
    BBox wbbox = tmpbbl.reduce();
    partition_all(wbbox, boxes, np);

    GridUnitList tmpgul;
    for (register int p=0;p<np;p++) {
      ggul->intersect(boxes[p], flev, tmpgul, 0);
      GridUnitList tmpgul(*ggul);
      tmpgul *= boxes[p];
      ggul->setowner(tmpgul,p);
      if (p == me) {
        if (lgul) {
          lgul->empty();
          *lgul = tmpgul;
        }
        else {
          lgul = new GridUnitList(tmpgul);
        }
        lgul->setowner(me);
      } 
    }
  }

/*$int ACEDistribution::islocal(dMapIndex const &idx)
  {
    ACESpan *span = 0;

    ACEListLoop(localspans,span,ACESpan) 
	if (span->contains(idx)) return 1;
    ACEEndLoop
    
    return 0;
  }$*/

void partition_one(const BBox& wholebbox, BBox* boxes, const int np, 
                   const int dim)
  {
    const int rank = wholebbox.rank;
    const int glb = wholebbox.lower(dim);
    const int gub = wholebbox.upper(dim);
    const int step = wholebbox.stepsize(dim);
    const int extent = wholebbox.extents(dim);

#ifdef DEBUG_PRINT
    assert (extent >= np); // I should have atleast extent points. */
#endif

    const int dx = extent/np;
    const int Xtra = extent%np;

    for (register int p=0;p<np;p++) {
      const int dlower = p*dx + min(Xtra,p);
      const int dupper = (np-p-1)*dx + max((Xtra-p-1),0);
      boxes[p] = wholebbox;
      boxes[p].growlower(dim,dlower);
      boxes[p].growupper(dim,-dupper);
    }
  }

/* A modification of pwalker_partition by Paul Walker */
void partition_two(const BBox& wholebbox, BBox* boxes, const int np, 
                   const int dim1, const int dim2)
  {
    /* Great now figure out the decomposition in n1,n2 */
    int n1,n2;
    
    /* Initizialize */
    n1 = np;
    n2 = 1;
    if (n1 % 2 == 0) {
      while (n1 % 2 == 0 && n1 > n2
             && (abs(n1-n2) >= abs(n1/2-n2*2))) {
        n1 /= 2;
        n2 *= 2;
      }
    } else {
      while (n1 % 3 == 0 && n1 > n2
             && (abs(n1-n2) >= abs(n1/3-n2*3))) {
        n1 /= 3;
        n2 *= 3;
      }
    }

    const int rank = wholebbox.rank;
    const Coords& glb = wholebbox.lower();
    const Coords& gub = wholebbox.upper();
    const Coords& step = wholebbox.stepsize();
    const Coords& ext = wholebbox.extents();

    Coords tmpe(ext);
    const int ld1 = (tmpe(dim1) >= tmpe(dim2)) ? dim1 : dim2; 
    const int ld2 = (tmpe(dim1) < tmpe(dim2)) ? dim1 : dim2;
    
    Coords tmpp(rank,0);
    tmpp(dim1) = n1; tmpp(dim2) = n2;
    const int nn1 = (tmpp(dim1) >= tmpp(dim2)) ? dim1 : dim2; 
    const int nn2 = (tmpp(dim1) < tmpp(dim2)) ? dim1 : dim2;

    tmpe(ld1) = tmpp(nn1);
    tmpe(ld2) = tmpp(nn2);

    n1 = tmpe(dim1);
    n2 = tmpe(dim2);

    /* Set up deltas */
    Coords delt(rank,0); 
    delt(dim1) = (ext(dim1)/n1);
    delt(dim2) = (ext(dim2)/n2);
    /*$delt(dim1) =  (gub(dim1)-glb(dim1)+step(dim1))/n1;
    delt(dim2) =  (gub(dim2)-glb(dim2)+step(dim2))/n2;$*/

    /* Set up correction vector */
    Coords cor(rank,0);
    cor(dim1) = ext(dim1)%n1;
    cor(dim2) = ext(dim2)%n2;
    /*$cor(0) =  (gub(0)-glb(0)+step(0))%n1;
    cor(1) =  (gub(1)-glb(1)+step(1))%n2;$*/

    /* Initialize the bboxes */
    for (register int p=0;p<np;p++) boxes[p] = wholebbox;

    for (register int ii=0;ii<n1;ii++) {
      for (register int jj=0;jj<n2;jj++) {
        /* We may care about topology here later... */
        int whichp = ii + jj*n1;

	Coords c1(rank,0), c2 (rank,0);

	c1(dim1) = (cor(dim1) > ii) ? 1 : 0;
	c1(dim2) = (cor(dim2) > jj) ? 1 : 0;
        
	/*$c2(0) = n1 - (cor(0) - ii) - 1;
	c2(1) = n2 - (cor(1) - jj) - 1;$*/

	c2(dim1) = min(cor(dim1),ii);
	c2(dim2) = min(cor(dim2),jj);
	
	Coords& lb = boxes[whichp].lower();
	Coords& ub = boxes[whichp].upper();

	lb(dim1) = glb(dim1) + (ii * (delt(dim1)) + c2(dim1))*step(dim1);
	lb(dim2) = glb(dim2) + (jj * (delt(dim2)) + c2(dim2))*step(dim2);
        
	ub(dim1) = lb(dim1) + (delt(dim1) + c1(dim1) - 1)*step(dim1);
	ub(dim2) = lb(dim2) + (delt(dim2) + c1(dim2) - 1)*step(dim2);
      }
    }
  }

/* A modification of pwalker_partition by Paul Walker */
void partition_all(const BBox& wholebbox, BBox* boxes, const int np)
  {
    /* Great now figure out the decomposition in n1,n2,n3 */
    int n1,n2,n3;
    
    /* Initizialize */
    n1 = np;
    n2 = 1;
    n3 = 1;
    for (register int i=0;i<2;i++) {
      int twof = 0;
      if (n1 % 2 == 0) twof = 1;
      if (twof) {
        while (n1 % 2 == 0 && n1 > n2
               && (abs(n1-n2) >= abs(n1/2-n2*2))) {
          n1 /= 2;
          n2 *= 2;
        }
      } else {
        while (n1 % 3 == 0 && n1 > n2
               && (abs(n1-n2) >= abs(n1/3-n2*3))) {
          n1 /= 3;
          n2 *= 3;
        }
      }
      twof = 0;
      if (n2 % 2 == 0) twof = 1;
      if (twof) {
        while (n2 % 2 == 0 && n2 > n3
               && (abs(n2-n3) >= abs(n2/2-n3*2))) {
          n2 /= 2;
          n3 *= 2;
        }
      } else {
        while (n2 % 3 == 0 && n2 > n3
               && (abs(n2-n3) >= abs(n2/3-n3*3))) {
          n2 /= 3;
          n3 *= 3;
        }
      }
    }
    /* Sort based on global box (later)... */ 
    
    const int rank = wholebbox.rank;
    const Coords& glb = wholebbox.lower();
    const Coords& gub = wholebbox.upper();
    const Coords& step = wholebbox.stepsize();
    const Coords& ext = wholebbox.extents();
    
    Coords tmpe(ext);
    const int ld1 = (tmpe(0) > tmpe(1)) ? 
      ((tmpe(0) > tmpe(2)) ? 0 : 2) : 
      ((tmpe(1) > tmpe(2) ? 1 : 2));
    tmpe(ld1) = 0; 
    const int ld2 = (tmpe(0) > tmpe(1)) ? 
      ((tmpe(0) > tmpe(2)) ? 0 : 2) : 
      ((tmpe(1) > tmpe(2) ? 1 : 2));
    tmpe(ld2) = 0; 
    const int ld3 = (tmpe(0) > tmpe(1)) ? 
      ((tmpe(0) > tmpe(2)) ? 0 : 2) : 
      ((tmpe(1) > tmpe(2) ? 1 : 2));
    
    Coords tmpp(rank,0);
    tmpp(0) = n1; tmpp(1) = n2; tmpp(2) = n3;    
    const int nn1 = (tmpp(0) > tmpp(1)) ? 
      ((tmpp(0) > tmpp(2)) ? 0 : 2) : 
      ((tmpp(1) > tmpp(2) ? 1 : 2));
    tmpp(nn1) = 0; 
    const int nn2 = (tmpp(0) > tmpp(1)) ? 
      ((tmpp(0) > tmpp(2)) ? 0 : 2) : 
      ((tmpp(1) > tmpp(2) ? 1 : 2));
    tmpp(nn2) = 0; 
    const int nn3 = (tmpp(0) > tmpp(1)) ? 
      ((tmpp(0) > tmpp(2)) ? 0 : 2) : 
      ((tmpp(1) > tmpp(2) ? 1 : 2));

    tmpp(0) = n1; tmpp(1) = n2; tmpp(2) = n3;    
    tmpe(ld1) = tmpp(nn1);
    tmpe(ld2) = tmpp(nn2);
    tmpe(ld3) = tmpp(nn3);

    n1 = tmpe(0);
    n2 = tmpe(1);
    n3 = tmpe(2);

    /* Set up deltas */
    Coords delt(rank,0);
    delt(0) = (ext(0)/n1);
    delt(1) = (ext(1)/n2);
    delt(2) = (ext(2)/n3);
    /*$delt(0) =  (gub(0)-glb(0)+step(0))/n1;
    delt(1) =  (gub(1)-glb(1)+step(1))/n2;
    delt(2) =  (gub(2)-glb(2)+step(2))/n3;$*/

    /* Set up correction vector */
    Coords cor(rank,0);
    cor(0) =  (ext(0)%n1);
    cor(1) =  (ext(1)%n2);
    cor(2) =  (ext(2)%n3);
    /*$cor(0) =  (gub(0)-glb(0)+step(0))%n1;
    cor(1) =  (gub(1)-glb(1)+step(1))%n2;
    cor(2) =  (gub(2)-glb(2)+step(2))%n3;$*/
    
#ifdef DEBUG_PRINT_DIST
    /*$comm_service::log() << "glb " << glb << endl;
    comm_service::log() << "gub " << gub << endl;
    comm_service::log() << "deltas " << delt << endl;
    comm_service::log() << "correction " << cor << endl;$*/
#endif 

    /* Initialize the bboxes */
    for (register int p=0;p<np;p++) boxes[p] = wholebbox;

    for (register int ii=0;ii<n1;ii++) {
      for (register int jj=0;jj<n2;jj++) {
        for (register int kk=0;kk<n3;kk++) {
          /* We may care about topology here later... */
          int whichp = ii + jj*n1 + kk*n1*n2;
	  
#ifdef DEBUG_PRINT_DIST
          /*$comm_service::log() << whichp << " "
			      << ii << " "
			      << jj << " "
			      << kk << endl;$*/
#endif

	  Coords c1(rank,0), c2 (rank,0);

	  c1(0) = (cor(0) > ii) ? 1 : 0;
          c1(1) = (cor(1) > jj) ? 1 : 0;
          c1(2) = (cor(2) > kk) ? 1 : 0;

	  /*$c2(0) = n1 - (cor(0) - ii) - 1;
	  c2(1) = n2 - (cor(1) - jj) - 1;
	  c2(2) = n3 - (cor(2) - kk) - 1;$*/

	  c2(0) = min(cor(0),ii);
	  c2(1) = min(cor(1),jj);
	  c2(2) = min(cor(2),kk);

          Coords& lb = boxes[whichp].lower();
          Coords& ub = boxes[whichp].upper();

          lb(0) = glb(0) + (ii * (delt(0)) + c2(0))*step(0);
          lb(1) = glb(1) + (jj * (delt(1)) + c2(1))*step(1);
          lb(2) = glb(2) + (kk * (delt(2)) + c2(2))*step(2);

	  ub(0) = lb(0) + (delt(0) + c1(0) - 1)*step(0);
	  ub(1) = lb(1) + (delt(1) + c1(1) - 1)*step(1);
	  ub(2) = lb(2) + (delt(2) + c1(2) - 1)*step(2);

#ifdef DEBUG_PRINT_DIST
	  /*$comm_service::log() << "lb " << lb << endl;
	  comm_service::log() << "ub " << ub << endl;$*/
#endif

	}
      }
    }
  }

void pwalker_partition(const BBox& wholebbox, BBox* boxes, const int np)
  {
    Coords glb(wholebbox.lower());
    Coords gub(wholebbox.upper());
    /* Great now figure out the decomposition in nx,ny,nz */
    int nx,ny,nz;
    
    /* Initizialize */
    nx = np;
    ny = 1;
    nz = 1;
    for (int i=0;i<2;i++) {
      int twof = 0;
      if (nx % 2 == 0) twof = 1;
      if (twof) {
        while (nx % 2 == 0 && nx > ny
               && (abs(nx-ny) >= abs(nx/2-ny*2))) {
          nx /= 2;
          ny *= 2;
        }
      } else {
        while (nx % 3 == 0 && nx > ny
               && (abs(nx-ny) >= abs(nx/3-ny*3))) {
          nx /= 3;
          ny *= 3;
        }
      }
      twof = 0;
      if (ny % 2 == 0) twof = 1;
      if (twof) {
        while (ny % 2 == 0 && ny > nz
               && (abs(ny-nz) >= abs(ny/2-nz*2))) {
          ny /= 2;
          nz *= 2;
        }
      } else {
        while (ny % 3 == 0 && ny > nz
               && (abs(ny-nz) >= abs(ny/3-nz*3))) {
          ny /= 3;
          nz *= 3;
        }
      }
    }
    /* Sort based on global box (later)... */ 
    
    /* Now make the coordinates for each box ... */
    BBox mt(3,0);
    for (int p=0;p<np;p++) boxes[p] = mt;
    
    int ii,jj,kk;
    int *delt = new int[3], *layout = new int[3];

    /* Set up layout and deltas */
    layout[0] = nx; layout[1] = ny; layout[2] = nz;
    for (int mm=0;mm<3;mm++) {
      delt[mm] =  (gub(mm)-glb(mm))/layout[mm];
    }

    Coords mylb(3,0),myub(3,0);
    for (ii=0;ii<nx;ii++)
      for (jj=0;jj<ny;jj++)
        for (kk=0;kk<nz;kk++) {
          /* We may care about topology here later... */
          int whichp = ii + jj*nx + kk*nx*ny;
          mylb(0) = delt[0]*ii;
          mylb(1) = delt[1]*jj;
          mylb(2) = delt[2]*kk;

          myub(0) = 
            (ii != nx-1 ? delt[0]*(ii+1)-1 : gub(0));
          myub(1) = 
            (jj != ny-1 ? delt[1]*(jj+1)-1 : gub(1));
          myub(2) = 
            (kk != nz-1 ? delt[2]*(kk+1)-1 : gub(2));

          boxes[whichp].setlower(mylb);
          boxes[whichp].setupper(myub);
          boxes[whichp].setstepsize(0,1);
          boxes[whichp].setstepsize(1,1);
          boxes[whichp].setstepsize(2,1);
        }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]