SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
BI_TreeComb.c
Go to the documentation of this file.
1#include "Bdef.h"
2
3/*
4 * This topology supports trees with arbitrary numbers of branches at
5 * each step. The following pictures show the tree that should be visualized
6 * when examining the algorithm.
7 *
8 * TREE GLOBAL OP, NBRANCHES = 2 * TREE GLOBAL OP, NBRANCHES = 3
9 * *
10 * i=4 &______________ *
11 * | \ *
12 * i=2 &______ &______ * i=3 &______________________
13 * | \ | \ * | \ \
14 * i=1 &__ &__ &__ &__ * i=1 &______ &______ &__
15 * | \ | \ | \ | \ * | \ \ | \ \ | \
16 * 0 1 2 3 4 5 6 7 * 0 1 2 3 4 5 6 7
17 */
18
20 Int N, VVFUNPTR Xvvop, Int dest, Int nbranches)
21/*
22 * -- V1.1ALPHA (test version) BLACS routine --
23 * University of Tennessee, October 1, 1995
24 * Written by Clint Whaley.
25 *
26 * Purpose
27 * =======
28 * Perform a element-by-element combine on vectors.
29 * If rdest1 = -1, the answer will be left on all participating processes.
30 * Otherwise, only the process at grid coordinates {rdest1, cdest1} will
31 * have the final answer. Other Processes will have intermediate (useless)
32 * values.
33 *
34 * Arguments
35 * =========
36 * CTXT (input) pointer to BLACSCONTEXT
37 * The BLACS context where operation is taking place.
38 *
39 * BP (input/output) pointer to BLACBUFF.
40 * BLACBUFF is a special data type used by the BLACS to control
41 * buffers and the asynchronous operations coming out of them.
42 * This BLACBUFF should have a buffer who's first N elements
43 * contain the data to be combined. Additional space may be
44 * required, depending upon what combine is being performed.
45 *
46 * BP2 (workspace) pointer to BLACBUFF.
47 * This BLACBUFF is used to receive information for combining with
48 * this process's information.
49 *
50 * DEST (input) Int
51 * Node to receive answer. If DEST == -1, all nodes in receive
52 * the answer.
53 *
54 * N (input) Int
55 * The number of elements in the vector. N >= 0.
56 *
57 * Xvvop (input) pointer to typed operation function
58 * Points to a typed function which performs the required operation
59 * (e.g. summation) on the two N-element vectors.
60 *
61 * NBRANCHES (input) Int
62 * Indicates the degree of the tree to use (see picture above).
63 *
64 * ------------------------------------------------------------------------
65 */
66{
74
75 Int Np, Iam, msgid, Rmsgid, i, j;
76 Int nrcvs=0; /* Number of ReCeiVeS to do */
77 Int REBS; /* should info be RE-BroadcaSt? */
78 Int rightedge; /* right-most receiving node */
79 Int mydist; /* my distance from destination node */
80 Int dist;
81 Int src; /* Used if we must force repeatability */
82
83 Np = ctxt->scp->Np;
84 if (Np < 2) return;
85 Iam = ctxt->scp->Iam;
86 msgid = Mscopeid(ctxt);
87 Rmsgid = Mscopeid(ctxt);
88 if (REBS = (dest == -1)) dest = 0;
89
90 mydist = (Np + Iam - dest) % Np;
91 if (REBS)
92 {
93 dist = mydist;
94 if (mydist != 0) BI_Arecv(ctxt, BANYNODE, Rmsgid, bp);
95 }
96
97 if (nbranches == FULLCON) nbranches = Np;
98 rightedge = Np - 1 - (Np-1)%nbranches;
99
100 for (i=1; (i < Np); i *= nbranches)
101 {
102 if (mydist%nbranches) /* nodes that send to other nodes */
103 {
104 BI_Ssend(ctxt, (dest + (mydist-mydist%nbranches)*i)%Np, msgid, bp);
105 break; /* I'm done */
106 }
107 else
108 {
109 if (mydist != rightedge) nrcvs = nbranches - 1;
110 else nrcvs = (Np + i - 1) / i - rightedge - 1;
111 mydist /= nbranches;
112 rightedge /= nbranches;
113 rightedge -= (rightedge % nbranches);
114
115 if (!ctxt->TopsRepeat)
116 {
117 for (j=nrcvs; j; j--)
118 {
119 BI_Srecv(ctxt, BANYNODE, msgid, bp2);
120 Xvvop(N, bp->Buff, bp2->Buff);
121 }
122 }
123 else
124 {
125 src = (Iam + i) % Np;
126 for (j=nrcvs; j; j--)
127 {
128 BI_Srecv(ctxt, src, msgid, bp2);
129 Xvvop(N, bp->Buff, bp2->Buff);
130 src = (src + i) % Np;
131 }
132 }
133 }
134 }
135
136/*
137 * Broadcast answer to everyone if RDEST == -1
138 */
139 if (REBS)
140 {
141 mydist = dist;
142 for (i=2; i < Np; i <<= 1);
143 if (mydist > 0) BI_BuffIsFree(bp, 1);
144
145 while (i > 1)
146 {
147 if ( !(mydist%i) )
148 {
149 i >>= 1;
150 dist = mydist + i;
151 if (dist < Np) BI_Rsend(ctxt, dist, Rmsgid, bp);
152 }
153 else i >>= 1;
154 }
155 }
156} /* end BI_TreeComb */
void BI_Arecv(BLACSCONTEXT *ctxt, Int src, Int msgid, BLACBUFF *bp)
Definition BI_Arecv.c:3
Int BI_BuffIsFree(BLACBUFF *bp, Int Wait)
BLACBUFF * BI_GetBuff(Int length)
Definition BI_GetBuff.c:37
void BI_Rsend(BLACSCONTEXT *ctxt, Int dest, Int msgid, BLACBUFF *bp)
Definition BI_Rsend.c:4
void BI_Srecv(BLACSCONTEXT *ctxt, Int src, Int msgid, BLACBUFF *bp)
Definition BI_Srecv.c:3
void BI_Ssend(BLACSCONTEXT *ctxt, Int dest, Int msgid, BLACBUFF *bp)
Definition BI_Ssend.c:3
void BI_TreeComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2, Int N, VVFUNPTR Xvvop, Int dest, Int nbranches)
Definition BI_TreeComb.c:19
void BI_UpdateBuffs(BLACBUFF *Newbp)
#define Int
Definition Bconfig.h:22
void(* VVFUNPTR)(Int, char *, char *)
Definition Bdef.h:68
#define Mscopeid(ctxt)
Definition Bdef.h:179
#define FULLCON
Definition Bdef.h:100
#define BANYNODE
Definition Bdef.h:76
char * Buff
Definition Bdef.h:56
Int TopsRepeat
Definition Bdef.h:27
BLACSSCOPE * scp
Definition Bdef.h:26
Int Np
Definition Bdef.h:17
Int Iam
Definition Bdef.h:17