SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
BI_BeComb.c
Go to the documentation of this file.
1#include "Bdef.h"
2
3/*
4 * The bidirectional exchange topology (BE) is specialized for dealing with
5 * case where all nodes participating in the operation need to
6 * receive the answer. It works best when # of nodes is some even
7 * power of two. This topology is based on an algorithm presented by
8 * Robert van de Geijn, et al.
9 */
11 Int N, VVFUNPTR Xvvop)
12/*
13 * -- V1.1ALPHA (test version) BLACS routine --
14 * University of Tennessee, October 1, 1995
15 * Written by Clint Whaley.
16 *
17 * Purpose
18 * =======
19 * Perform a element-by-element combine on vectors.
20 * The answer will be left on all participating processes. Since this method
21 * uses a hypercube communication pattern, the number of nodes participating
22 * in the operation must be a power of 2 for it to perform efficiently.
23 *
24 * Arguments
25 * =========
26 * CTXT (input) pointer to BLACSCONTEXT
27 * The BLACS context where operation is taking place.
28 *
29 * BP (input/output) pointer to BLACBUFF.
30 * BLACBUFF is a special data type used by the BLACS to control
31 * buffers and the asynchronous operations coming out of them.
32 * This BLACBUFF should have a buffer who's first N elements
33 * contain the data to be combined. Additional space may be
34 * required, depending upon what combine is being performed.
35 *
36 * BP2 (workspace) pointer to BLACBUFF.
37 * This BLACBUFF is used to receive information for combining with
38 * this process's information.
39 *
40 * N (input) int
41 * The number of elements in the vector to be combined.
42 *
43 * Xvvop (input) pointer to typed operation function
44 * Points to a typed function which performs the required operation
45 * (e.g. summation) on the two N-element vectors.
46 *
47 * ------------------------------------------------------------------------
48 */
49{
57
58 Int Np, Iam, dest, msgid, Rmsgid, np2, bit, ierr;
59 extern MPI_Status *BI_Stats;
60
61 Np = ctxt->scp->Np;
62 if (Np < 2) return;
63 Iam = ctxt->scp->Iam;
64 msgid = Mscopeid(ctxt);
65 Rmsgid = Mscopeid(ctxt);
66
67 for (np2=4; np2 < Np; np2 <<= 1);
68 if (np2 > Np) np2 >>= 1;
69
70 if (np2 != Np)
71 {
72 dest = (Iam ^ np2);
73 if (Iam >= np2) /* I'm node beyond power of 2 */
74 {
75 BI_Arecv(ctxt, dest, Rmsgid, bp);
76 BI_Ssend(ctxt, dest, msgid, bp);
77 BI_BuffIsFree(bp, 1);
78 }
79 else if (Iam < (Np^np2)) /* need to fan in contents of */
80 { /* non-power of 2 nodes */
81 BI_Srecv(ctxt, dest, msgid, bp2);
82 Xvvop(N, bp->Buff, bp2->Buff);
83 }
84 }
85
86 if (Iam < np2)
87 {
88 for (bit=1; (bit ^ np2); bit <<= 1)
89 {
90 dest = Iam ^ bit;
91 ierr=MPI_Sendrecv(bp->Buff, bp->N, bp->dtype, dest, msgid, bp2->Buff,
92 bp2->N, bp2->dtype, dest, msgid, ctxt->scp->comm,
93 BI_Stats);
94 Xvvop(N, bp->Buff, bp2->Buff);
95 }
96/*
97 * For nodes that are not part of the hypercube proper, we must
98 * send data back.
99 */
100 if (Iam < (Np^np2)) BI_Rsend(ctxt, (Iam ^ np2), Rmsgid, bp);
101 } /* end if (nodes inside power of 2) */
102}
void BI_Arecv(BLACSCONTEXT *ctxt, Int src, Int msgid, BLACBUFF *bp)
Definition BI_Arecv.c:3
void BI_BeComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2, Int N, VVFUNPTR Xvvop)
Definition BI_BeComb.c:10
Int BI_BuffIsFree(BLACBUFF *bp, Int Wait)
BLACBUFF * BI_GetBuff(Int length)
Definition BI_GetBuff.c:37
MPI_Status * BI_Stats
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_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
Int N
Definition Bdef.h:61
MPI_Datatype dtype
Definition Bdef.h:60
char * Buff
Definition Bdef.h:56
BLACSSCOPE * scp
Definition Bdef.h:26
Int Np
Definition Bdef.h:17
MPI_Comm comm
Definition Bdef.h:15
Int Iam
Definition Bdef.h:17