SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ cgsum2d_()

F_VOID_FUNC cgsum2d_ ( Int ConTxt,
F_CHAR  scope,
F_CHAR  top,
Int m,
Int n,
float *  A,
Int lda,
Int rdest,
Int cdest 
)

Definition at line 8 of file cgsum2d_.c.

58{
59 void BI_ArgCheck(Int, Int, char *, char, char, char, Int, Int, Int, Int,
60 Int *, Int *);
64 MPI_Datatype BI_GetMpiGeType(BLACSCONTEXT *, Int, Int, Int,
65 MPI_Datatype, Int *);
66 BLACBUFF *BI_Pack(BLACSCONTEXT *, BVOID *, BLACBUFF *, MPI_Datatype);
67 MPI_Datatype BI_GetMpiGeType(BLACSCONTEXT *, Int, Int, Int,
68 MPI_Datatype, Int *);
69 void BI_Unpack(BLACSCONTEXT *, BVOID *, BLACBUFF *, MPI_Datatype);
71 Int, Int);
73 Int, Int);
75 void BI_cvvsum(Int, char *, char *);
76 void BI_cMPI_sum(void *, void *, MpiInt *, MPI_Datatype *);
77/*
78 * Variable Declarations
79 */
80 BLACBUFF *bp, *bp2;
81 BLACSCONTEXT *ctxt;
82 char ttop, tscope;
83 Int N, length, dest, tlda, trdest, ierr;
84 MPI_Op BlacComb;
85 extern BLACBUFF *BI_ActiveQ;
86 extern BLACBUFF BI_AuxBuff;
87
88 MGetConTxt(Mpval(ConTxt), ctxt);
89 ttop = F2C_CharTrans(top);
90 ttop = Mlowcase(ttop);
91 tscope = F2C_CharTrans(scope);
92 tscope = Mlowcase(tscope);
93/*
94 * If the user has set the default combine topology, use it instead of
95 * BLACS default
96 */
97#ifdef DefCombTop
98 if (ttop == ' ') ttop = DefCombTop;
99#endif
100 if (Mpval(cdest) == -1) trdest = -1;
101 else trdest = Mpval(rdest);
102#if (BlacsDebugLvl > 0)
103 BI_ArgCheck(Mpval(ConTxt), RT_COMB, __FILE__, tscope, 'u', 'u', Mpval(m),
104 Mpval(n), Mpval(lda), 1, &trdest, Mpaddress(cdest));
105#endif
106 if (Mpval(lda) >= Mpval(m)) tlda = Mpval(lda);
107 else tlda = Mpval(m);
108 switch(tscope)
109 {
110 case 'r':
111 ctxt->scp = &ctxt->rscp;
112 if (trdest == -1) dest = -1;
113 else dest = Mpval(cdest);
114 break;
115 case 'c':
116 ctxt->scp = &ctxt->cscp;
117 dest = trdest;
118 break;
119 case 'a':
120 ctxt->scp = &ctxt->ascp;
121 if (trdest == -1) dest = -1;
122 else dest = Mvkpnum(ctxt, trdest, Mpval(cdest));
123 break;
124 default:
125 BI_BlacsErr(Mpval(ConTxt), __LINE__, __FILE__, "Unknown scope '%c'",
126 tscope);
127 }
128/*
129 * It's not defined how MPI reacts to 0 element reductions, so use BLACS 1-tree
130 * topology if we've got one. Also, we can't use MPI functions if we need to
131 * guarantee repeatability.
132 */
133 if (ttop == ' ')
134 if ( (Mpval(m) < 1) || (Mpval(n) < 1) || (ctxt->TopsRepeat) ) ttop = '1';
135 N = Mpval(m) * Mpval(n);
136 length = N * sizeof(SCOMPLEX);
137/*
138 * If A is contiguous, we can use it as one of the buffers
139 */
140 if ( (Mpval(m) == tlda) || (Mpval(n) == 1) )
141 {
142 bp = &BI_AuxBuff;
143 bp->Buff = (char *) A;
144 bp2 = BI_GetBuff(length);
145 }
146/*
147 * Otherwise, we must allocate both buffers
148 */
149 else
150 {
151 bp = BI_GetBuff(length*2);
152 bp2 = &BI_AuxBuff;
153 bp2->Buff = &bp->Buff[length];
154 BI_cmvcopy(Mpval(m), Mpval(n), A, tlda, bp->Buff);
155 }
156 bp->dtype = bp2->dtype = MPI_COMPLEX;
157 bp->N = bp2->N = N;
158
159 switch(ttop)
160 {
161 case ' ': /* use MPI's reduction by default */
162 length = 1;
163 ierr=MPI_Op_create(BI_cMPI_sum, length, &BlacComb);
164 if (dest != -1)
165 {
166 ierr=MPI_Reduce(bp->Buff, bp2->Buff, bp->N, bp->dtype, BlacComb,
167 dest, ctxt->scp->comm);
168 if (ctxt->scp->Iam == dest)
169 BI_cvmcopy(Mpval(m), Mpval(n), A, tlda, bp2->Buff);
170 }
171 else
172 {
173 ierr=MPI_Allreduce(bp->Buff, bp2->Buff, bp->N, bp->dtype, BlacComb,
174 ctxt->scp->comm);
175 BI_cvmcopy(Mpval(m), Mpval(n), A, tlda, bp2->Buff);
176 }
177 ierr=MPI_Op_free(&BlacComb);
178 if (BI_ActiveQ) BI_UpdateBuffs(NULL);
179 return;
180 break;
181 case 'i':
182 BI_MringComb(ctxt, bp, bp2, N, BI_cvvsum, dest, 1);
183 break;
184 case 'd':
185 BI_MringComb(ctxt, bp, bp2, N, BI_cvvsum, dest, -1);
186 break;
187 case 's':
188 BI_MringComb(ctxt, bp, bp2, N, BI_cvvsum, dest, 2);
189 break;
190 case 'm':
191 BI_MringComb(ctxt, bp, bp2, N, BI_cvvsum, dest, ctxt->Nr_co);
192 break;
193 case '1':
194 case '2':
195 case '3':
196 case '4':
197 case '5':
198 case '6':
199 case '7':
200 case '8':
201 case '9':
202 BI_TreeComb(ctxt, bp, bp2, N, BI_cvvsum, dest, ttop-47);
203 break;
204 case 'f':
205 BI_TreeComb(ctxt, bp, bp2, N, BI_cvvsum, dest, FULLCON);
206 break;
207 case 't':
208 BI_TreeComb(ctxt, bp, bp2, N, BI_cvvsum, dest, ctxt->Nb_co);
209 break;
210 case 'h':
211/*
212 * Use bidirectional exchange if everyone wants answer
213 */
214 if ( (trdest == -1) && !(ctxt->TopsCohrnt) )
215 BI_BeComb(ctxt, bp, bp2, N, BI_cvvsum);
216 else
217 BI_TreeComb(ctxt, bp, bp2, N, BI_cvvsum, dest, 2);
218 break;
219 default :
220 BI_BlacsErr(Mpval(ConTxt), __LINE__, __FILE__, "Unknown topology '%c'",
221 ttop);
222 }
223
224/*
225 * If I am selected to receive answer
226 */
227 if (bp != &BI_AuxBuff)
228 {
229 if ( (ctxt->scp->Iam == dest) || (dest == -1) )
230 BI_cvmcopy(Mpval(m), Mpval(n), A, tlda, bp->Buff);
231 BI_UpdateBuffs(bp);
232 }
233 else
234 {
235 if (BI_ActiveQ) BI_UpdateBuffs(NULL);
236 BI_BuffIsFree(bp, 1);
237 }
238}
void BI_ArgCheck(Int ConTxt, Int RoutType, char *routine, char scope, char uplo, char diag, Int m, Int n, Int lda, Int nprocs, Int *prows, Int *pcols)
Definition BI_ArgCheck.c:4
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_Datatype BI_GetMpiGeType(BLACSCONTEXT *ctxt, Int m, Int n, Int lda, MPI_Datatype Dtype, Int *N)
BLACBUFF * BI_ActiveQ
BLACBUFF BI_AuxBuff
void BI_MringComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2, Int N, VVFUNPTR Xvvop, Int dest, Int nrings)
Definition BI_MringComb.c:2
BLACBUFF * BI_Pack(BLACSCONTEXT *ctxt, BVOID *A, BLACBUFF *bp, MPI_Datatype Dtype)
Definition BI_Pack.c:2
void BI_TreeComb(BLACSCONTEXT *ctxt, BLACBUFF *bp, BLACBUFF *bp2, Int N, VVFUNPTR Xvvop, Int dest, Int nbranches)
Definition BI_TreeComb.c:19
void BI_Unpack(BLACSCONTEXT *ctxt, BVOID *A, BLACBUFF *bp, MPI_Datatype Dtype)
Definition BI_Unpack.c:3
void BI_UpdateBuffs(BLACBUFF *Newbp)
void BI_cMPI_sum(void *in, void *inout, MpiInt *N, MPI_Datatype *dtype)
Definition BI_cMPI_sum.c:2
void BI_cvvsum(Int N, char *vec1, char *vec2)
Definition BI_cvvsum.c:2
#define Int
Definition Bconfig.h:22
#define MpiInt
Definition Bconfig.h:25
void BI_BlacsErr(Int ConTxt, Int line, char *file, char *form,...)
Definition BI_BlacsErr.c:3
#define BI_cvmcopy(m, n, A, lda, buff)
Definition Bdef.h:292
#define F2C_CharTrans(c)
Definition Bdef.h:246
#define Mvkpnum(ctxt, prow, pcol)
Definition Bdef.h:174
#define MGetConTxt(Context, ctxtptr)
Definition Bdef.h:200
void(* VVFUNPTR)(Int, char *, char *)
Definition Bdef.h:68
#define Mpaddress(para)
Definition Bdef.h:262
#define Mpval(para)
Definition Bdef.h:261
#define BI_cmvcopy(m, n, A, lda, buff)
Definition Bdef.h:290
#define FULLCON
Definition Bdef.h:100
#define Mlowcase(C)
Definition Bdef.h:145
#define RT_COMB
Definition Bdef.h:109
#define BVOID
Definition Bdef.h:136
Int N
Definition Bdef.h:61
MPI_Datatype dtype
Definition Bdef.h:60
char * Buff
Definition Bdef.h:56
Int TopsCohrnt
Definition Bdef.h:28
Int TopsRepeat
Definition Bdef.h:27
BLACSSCOPE * scp
Definition Bdef.h:26
Int Nb_co
Definition Bdef.h:30
BLACSSCOPE ascp
Definition Bdef.h:25
BLACSSCOPE rscp
Definition Bdef.h:25
BLACSSCOPE cscp
Definition Bdef.h:25
Int Nr_co
Definition Bdef.h:30
MPI_Comm comm
Definition Bdef.h:15
Int Iam
Definition Bdef.h:17
Here is the call graph for this function: