1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include "Bdef.h"
void BI_TreeBR(BLACSCONTEXT *ctxt, BLACBUFF *bp, SDRVPTR send, int src, int nbranches)
{
void BI_Srecv(BLACSCONTEXT *, int, int, BLACBUFF *);
int Np, Iam, msgid, i, j;
int mydist; /* my distance from src */
int destdist; /* the distance of the destination node */
Np = ctxt->scp->Np;
if (Np < 2) return;
Iam = ctxt->scp->Iam;
msgid = Mscopeid(ctxt);
mydist = (Np + Iam - src) % Np;
/*
* Go up to first step of tree where I send data to other nodes
*/
for (i=nbranches; i < Np; i *= nbranches);
for (i /= nbranches; (mydist%i); i /= nbranches);
BI_Srecv(ctxt, BANYNODE, msgid, bp);
/*
* While I need to send data to others
*/
while ( (i > 1) && !(mydist%i) )
{
i /= nbranches;
j = 1;
do
{
destdist = mydist + j*i;
if (destdist < Np)
send(ctxt, (src+destdist)%Np, msgid, bp);
}
while(++j < nbranches);
}
} /* end BI_TreeBR */
|