SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
pgemraux.c
Go to the documentation of this file.
1#include "redist.h"
2/* $Id: pgemraux.c,v 1.1.1.1 2000/02/15 18:04:10 susan Exp $
3 *
4 * some functions used by the pigemr2d routine see file pigemr.c for more
5 * documentation.
6 *
7 * Created March 1993 by B. Tourancheau (See sccs for modifications). */
8#define static2 static
9#if defined(Add_) || defined(f77IsF2C)
10#define fortran_mr2d pigemr2do_
11#define fortran_mr2dnew pigemr2d_
12#elif defined(UpCase)
13#define fortran_mr2dnew PIGEMR2D
14#define fortran_mr2d PIGEMR2DO
15#define icopy_ ICOPY
16#define ilacpy_ ILACPY
17#else
18#define fortran_mr2d pigemr2do
19#define fortran_mr2dnew pigemr2d
20#define icopy_ icopy
21#define ilacpy_ ilacpy
22#endif
23#define Clacpy Cigelacpy
24void Clacpy();
25typedef struct {
26 Int desctype;
27 Int ctxt;
28 Int m;
29 Int n;
30 Int nbrow;
31 Int nbcol;
32 Int sprow;
33 Int spcol;
34 Int lda;
35} MDESC;
36#define BLOCK_CYCLIC_2D 1
37typedef struct {
38 Int lstart;
39 Int len;
40} IDESC;
41#define SHIFT(row,sprow,nbrow) ((row)-(sprow)+ ((row) >= (sprow) ? 0 : (nbrow)))
42#define max(A,B) ((A)>(B)?(A):(B))
43#define min(A,B) ((A)>(B)?(B):(A))
44#define DIVUP(a,b) ( ((a)-1) /(b)+1)
45#define ROUNDUP(a,b) (DIVUP(a,b)*(b))
46#ifdef MALLOCDEBUG
47#define malloc mymalloc
48#define free myfree
49#define realloc myrealloc
50#endif
51/* Cblacs */
52extern void Cblacs_pcoord();
54extern void Csetpvmtids();
55extern void Cblacs_get();
56extern void Cblacs_pinfo();
57extern void Cblacs_gridinfo();
58extern void Cblacs_gridinit();
59extern void Cblacs_exit();
60extern void Cblacs_gridexit();
61extern void Cblacs_setup();
62extern void Cigebs2d();
63extern void Cigebr2d();
64extern void Cigesd2d();
65extern void Cigerv2d();
66extern void Cigsum2d();
67extern void Cigamn2d();
68extern void Cigamx2d();
69extern void Cigesd2d();
70extern void Cigerv2d();
71/* lapack */
72void ilacpy_();
73/* aux fonctions */
75extern void *mr2d_malloc();
76extern Int ppcm();
77extern Int localsize();
80extern void paramcheck();
81/* tools and others function */
82#define scanD0 igescanD0
83#define dispmat igedispmat
84#define setmemory igesetmemory
85#define freememory igefreememory
86#define scan_intervals igescan_intervals
87extern void scanD0();
88extern void dispmat();
89extern void setmemory();
90extern void freememory();
91extern Int scan_intervals();
92extern void Cpigemr2do();
93extern void Cpigemr2d();
94/* some defines for Cpigemr2do */
95#define SENDBUFF 0
96#define RECVBUFF 1
97#define SIZEBUFF 2
98#if 0
99#define DEBUG
100#endif
101#ifndef DEBUG
102#define NDEBUG
103#endif
104#include <stdio.h>
105#include <stdlib.h>
106#include <assert.h>
107void *
109{
110 void *ptr;
111 assert(n > 0);
112 ptr = (void *) malloc(n);
113 if (ptr == NULL) {
114 fprintf(stderr, "xxmr2d:out of memory\n");
115 exit(2);
116 }
117 return ptr;
118}
119Int
121{
122 Int aux;
123 if (a < b)
124 return pgcd(b, a);
125 else {
126 aux = a % b;
127 if (aux == 0)
128 return b;
129 else
130 return pgcd(b, aux);
131 }
132}
133Int
135{
136 Int pg;
137 pg = pgcd(a, b);
138 return a * (b / pg);
139}
140/* localsize:return the number of rows on the local processor given by its
141 * row number myprow, of a distributed matrix with m rows distributed of on a
142 * grid of processors with p rows with blocksize nbrow : this procedure can
143 * also be used to compute the number of cols by replacing rows by cols */
144Int
145localsize(Int myprow, Int p, Int nbrow, Int m)
146{
147 Int templateheight, blockheight;
148 templateheight = p * nbrow;
149 if (m % templateheight != 0) { /* not an exact boundary */
150 if ((m % templateheight) > (nbrow * myprow)) { /* processor
151 * (myprow,mypcol) has
152 * some elements in that
153 * incomplete template */
154 if ((m % templateheight) >= (nbrow * (myprow + 1))) { /* processor
155 * (myprow,mypcol)'s
156 * part is complete */
157 blockheight = (m / templateheight) * nbrow + nbrow;
158 } else { /* processor (myprow,mypcol)'s part is not complete */
159 blockheight = (m / templateheight) * nbrow + (m % nbrow);
160 }; /* if ((m%templateheight) > (nbrow*(myprow+1))) */
161 } else { /* processor (myprow,mypcol) has no element in that
162 * incomplete template */
163 blockheight = (m / templateheight) * nbrow;
164 }; /* if ((m%templateheight) > (nbrow*myprow)) */
165 } else { /* exact boundary */
166 blockheight = m / p; /* (m/templateheight) * nbrow */
167 }; /* if (m%templateheight !=0) */
168 return blockheight;
169}
170/****************************************************************/
171/* Returns the exact memory block size corresponding to the parameters */
172Int
174{
175 Int myprow, mypcol, p, q;
176 /* Compute the (myprow,mypcol) indices of processor mypnum in P0xQ0 We
177 * assume the row-major ordering of the BLACS */
178 Cblacs_gridinfo(a->ctxt, &p, &q, &myprow, &mypcol);
179 myprow = SHIFT(myprow, a->sprow, p);
180 mypcol = SHIFT(mypcol, a->spcol, q);
181 assert(myprow >= 0 && mypcol >= 0);
182 return localsize(myprow, p, a->nbrow, a->m) *
183 localsize(mypcol, q, a->nbcol, a->n);
184}
185void
187{
188 Int np, dummy, nbrow, myp, b;
189 Cblacs_gridinfo(ctxt, &nbrow, &np, &dummy, &myp);
190 assert(nbrow == 1);
191 if (np == 1)
192 return;
193 if (myp == 0) {
194 Cigesd2d(ctxt, (Int)1, (Int)1, &a, (Int)1, (Int)0, (Int)1);
195 Cigerv2d(ctxt, (Int)1, (Int)1, &b, (Int)1, (Int)0, np - 1);
196 assert(a == b);
197 } else {
198 Cigerv2d(ctxt, (Int)1, (Int)1, &b, (Int)1, (Int)0, myp - 1);
199 assert(a == b);
200 Cigesd2d(ctxt, (Int)1, (Int)1, &a, (Int)1, (Int)0, (myp + 1) % np);
201 }
202}
203void
204paramcheck(MDESC *a, Int i, Int j, Int m, Int n, Int p, Int q, Int gcontext)
205{
206 Int p2, q2, myprow, mypcol;
207#ifndef NDEBUG
208 checkequal(gcontext, p);
209 checkequal(gcontext, q);
210 checkequal(gcontext, a->sprow);
211 checkequal(gcontext, a->spcol);
212 checkequal(gcontext, a->m);
213 checkequal(gcontext, a->n);
214 checkequal(gcontext, i);
215 checkequal(gcontext, j);
216 checkequal(gcontext, a->nbrow);
217 checkequal(gcontext, a->nbcol);
218#endif
219 Cblacs_gridinfo(a->ctxt, &p2, &q2, &myprow, &mypcol);
220 /* compatibility T3D, must check myprow and mypcol are within bounds */
221 if (myprow >= p2 || mypcol >= q2)
222 myprow = mypcol = -1;
223 if ((myprow >= 0 || mypcol >= 0) && (p2 != p && q2 != q)) {
224 fprintf(stderr, "??MR2D:incoherent p,q parameters\n");
225 exit(1);
226 }
227 assert(myprow < p && mypcol < q);
228 if (a->sprow < 0 || a->sprow >= p || a->spcol < 0 || a->spcol >= q) {
229 fprintf(stderr, "??MR2D:Bad first processor coordinates\n");
230 exit(1);
231 }
232 if (i < 0 || j < 0 || i + m > a->m || j + n > a->n) {
233 fprintf(stderr, "??MR2D:Bad submatrix:i=%d,j=%d,\
234m=%d,n=%d,M=%d,N=%d\n",
235 i, j, m, n, a->m, a->n);
236 exit(1);
237 }
238 if ((myprow >= 0 || mypcol >= 0) &&
239 localsize(SHIFT(myprow, a->sprow, p), p, a->nbrow, a->m) > a->lda) {
240 fprintf(stderr, "??MR2D:bad lda arg:row=%d,m=%d,p=%d,\
241nbrow=%d,lda=%d,sprow=%d\n",
242 myprow, a->m, p, a->nbrow, a->lda, a->sprow);
243 exit(1);
244 }
245}
246/* to change from the submatrix beginning at line i to one beginning at line
247 * i' with i'< blocksize return the line number on the local process where
248 * the new matrix begin, the new process number, and i' */
249Int
250changeorigin(Int myp, Int sp, Int p, Int bs, Int i, Int *decal, Int *newsp)
251{
252 Int tempheight, firstblock, firsttemp;
253 /* we begin by changing the parameters so that ia < templatewidth,... */
254 tempheight = bs * p;
255 firsttemp = i / tempheight;
256 firstblock = (i / bs) % p;
257 *newsp = (sp + firstblock) % p;
258 if (myp >= 0)
259 *decal = firsttemp * bs + (SHIFT(myp, sp, p) < firstblock ? bs : 0);
260 else
261 *decal = 0;
262 return i % bs;
263}
264/******************************************************************/
265/* Return the indice in local memory of element of indice a in the matrix */
266Int
267localindice(Int ig, Int jg, Int templateheight, Int templatewidth, MDESC *a)
268/* Return the indice in local memory (scattered distribution) of the element
269 * of indice a in global matrix */
270{
271 Int vtemp, htemp, vsubtemp, hsubtemp, il, jl;
272 assert(ig >= 0 && ig < a->m && jg >= 0 && jg < a->n);
273 /* coordinates in global matrix with the tests in intersect, ig MUST BE in
274 * [0..m] and jg in [0..n] */
275 /* coordinates of the template that "owns" the element */
276 vtemp = ig / templateheight;
277 htemp = jg / templatewidth;
278 /* coordinates of the element in the subblock of the (vtemp, htemp)
279 * template */
280 vsubtemp = ig % a->nbrow;
281 hsubtemp = jg % a->nbcol;
282 /* coordinates of the element in the local block of the processor */
283 il = a->nbrow * vtemp + vsubtemp;
284 jl = a->nbcol * htemp + hsubtemp;
285 assert(il < a->lda);
286#ifndef NDEBUG
287 {
288 Int pr, pc, p, q, lp, lq;
289 Cblacs_gridinfo(a->ctxt, &p, &q, &pr, &pc);
290 p = templateheight / a->nbrow;
291 q = templatewidth / a->nbcol;
292 lp = ig % templateheight / a->nbrow;
293 lq = jg % templatewidth / a->nbcol;
294 assert(lp == SHIFT(pr, a->sprow, p));
295 assert(lq == SHIFT(pc, a->spcol, q));
296 }
297#endif
298 return (jl * a->lda + il);
299}
#define Int
Definition Bconfig.h:22
Int memoryblocksize()
Int changeorigin()
void checkequal(Int ctxt, Int a)
Definition pgemraux.c:186
#define freememory
Definition pgemraux.c:85
#define scan_intervals
Definition pgemraux.c:86
void Cpigemr2do()
#define SHIFT(row, sprow, nbrow)
Definition pgemraux.c:41
void Cblacs_gridexit()
void Cpigemr2d()
void Cigsum2d()
#define scanD0
Definition pgemraux.c:82
Int Cblacs_pnum()
#define Clacpy
Definition pgemraux.c:23
void Cigamx2d()
void Cblacs_pinfo()
void Cblacs_pcoord()
void Cigamn2d()
Int localsize()
#define setmemory
Definition pgemraux.c:84
void Cblacs_get()
void Cigerv2d()
void Cigebs2d()
#define dispmat
Definition pgemraux.c:83
void paramcheck()
void Cblacs_setup()
void Cblacs_gridinit()
void Cblacs_gridinfo()
void Csetpvmtids()
Int localindice()
void Cigesd2d()
Int ppcm()
void Cigebr2d()
void Cblacs_exit()
void * mr2d_malloc()
Int pgcd(Int a, Int b)
Definition pgemraux.c:120
#define ilacpy_
Definition pgemraux.c:21
Int m
Definition pcgemr.c:166
Int spcol
Definition pcgemr.c:171
Int nbcol
Definition pcgemr.c:169
Int sprow
Definition pcgemr.c:170
Int nbrow
Definition pcgemr.c:168
Int ctxt
Definition pcgemr.c:165
Int n
Definition pcgemr.c:167
Int lda
Definition pcgemr.c:172