ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
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  */
10 void BI_BeComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2,
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 {
50  void BI_Ssend(BLACSCONTEXT *, int, int, BLACBUFF *);
51  void BI_Srecv(BLACSCONTEXT *, int, int, BLACBUFF *);
52  void BI_Rsend(BLACSCONTEXT *, int, int, BLACBUFF *);
53  void BI_Arecv(BLACSCONTEXT *, int, int, BLACBUFF *);
54  void BI_UpdateBuffs(BLACBUFF *);
55  BLACBUFF *BI_GetBuff(int);
56  int BI_BuffIsFree(BLACBUFF *, int);
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 }
BI_BeComb
void BI_BeComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2, int N, VVFUNPTR Xvvop)
Definition: BI_BeComb.c:10
BI_GetBuff
BLACBUFF * BI_GetBuff(int length)
Definition: BI_GetBuff.c:36
bLaCbUfF::Buff
char * Buff
Definition: Bdef.h:56
BI_Stats
MPI_Status * BI_Stats
Definition: BI_GlobalVars.c:14
BI_Ssend
void BI_Ssend(BLACSCONTEXT *ctxt, int dest, int msgid, BLACBUFF *bp)
Definition: BI_Ssend.c:3
bLaCbUfF
Definition: Bdef.h:54
VVFUNPTR
void(* VVFUNPTR)(int, char *, char *)
Definition: Bdef.h:68
bLaCsScOpE::Iam
int Iam
Definition: Bdef.h:17
Mscopeid
#define Mscopeid(ctxt)
Definition: Bdef.h:179
bLaCbUfF::N
int N
Definition: Bdef.h:61
bLaCsCoNtExT
Definition: Bdef.h:23
BI_Rsend
void BI_Rsend(BLACSCONTEXT *ctxt, int dest, int msgid, BLACBUFF *bp)
Definition: BI_Rsend.c:4
bLaCsCoNtExT::scp
BLACSSCOPE * scp
Definition: Bdef.h:26
Bdef.h
bLaCsScOpE::comm
MPI_Comm comm
Definition: Bdef.h:15
BI_Arecv
void BI_Arecv(BLACSCONTEXT *ctxt, int src, int msgid, BLACBUFF *bp)
Definition: BI_Arecv.c:3
bLaCbUfF::dtype
MPI_Datatype dtype
Definition: Bdef.h:60
BI_Srecv
void BI_Srecv(BLACSCONTEXT *ctxt, int src, int msgid, BLACBUFF *bp)
Definition: BI_Srecv.c:3
bLaCsScOpE::Np
int Np
Definition: Bdef.h:17
BI_UpdateBuffs
void BI_UpdateBuffs(BLACBUFF *Newbp)
Definition: BI_UpdateBuffs.c:3
BI_BuffIsFree
int BI_BuffIsFree(BLACBUFF *bp, int Wait)
Definition: BI_BuffIsFree.c:3