9 #if defined(Add_) || defined(f77IsF2C)
10 #define fortran_mr2d pigemr2do_
11 #define fortran_mr2dnew pigemr2d_
13 #define fortran_mr2dnew PIGEMR2D
14 #define fortran_mr2d PIGEMR2DO
16 #define ilacpy_ ILACPY
18 #define fortran_mr2d pigemr2do
19 #define fortran_mr2dnew pigemr2d
21 #define ilacpy_ ilacpy
23 #define Clacpy Cigelacpy
36 #define BLOCK_CYCLIC_2D 1
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))
47 #define malloc mymalloc
49 #define realloc myrealloc
82 #define scanD0 igescanD0
83 #define dispmat igedispmat
84 #define setmemory igesetmemory
85 #define freememory igefreememory
86 #define scan_intervals igescan_intervals
113 ptr = (
void *) malloc(n);
115 fprintf(stderr,
"xxmr2d:out of memory\n");
149 int myprow, p, nbrow, m;
151 int templateheight, blockheight;
152 templateheight = p * nbrow;
153 if (m % templateheight != 0) {
154 if ((m % templateheight) > (nbrow * myprow)) {
158 if ((m % templateheight) >= (nbrow * (myprow + 1))) {
161 blockheight = (m / templateheight) * nbrow + nbrow;
163 blockheight = (m / templateheight) * nbrow + (m % nbrow);
167 blockheight = (m / templateheight) * nbrow;
180 int myprow, mypcol, p, q;
186 assert(myprow >= 0 && mypcol >= 0);
194 int np, dummy, nbrow, myp, b;
201 Cigerv2d(ctxt, 1, 1, &b, 1, 0, np - 1);
204 Cigerv2d(ctxt, 1, 1, &b, 1, 0, myp - 1);
206 Cigesd2d(ctxt, 1, 1, &a, 1, 0, (myp + 1) % np);
212 int i, j, m, n, p, q;
214 int p2, q2, myprow, mypcol;
229 if (myprow >= p2 || mypcol >= q2)
230 myprow = mypcol = -1;
231 if ((myprow >= 0 || mypcol >= 0) && (p2 != p && q2 != q)) {
232 fprintf(stderr,
"??MR2D:incoherent p,q parameters\n");
235 assert(myprow < p && mypcol < q);
237 fprintf(stderr,
"??MR2D:Bad first processor coordinates\n");
240 if (i < 0 || j < 0 || i + m > a->
m || j + n > a->
n) {
241 fprintf(stderr,
"??MR2D:Bad submatrix:i=%d,j=%d,\
242 m=%d,n=%d,M=%d,N=%d\n",
243 i, j, m, n, a->
m, a->
n);
246 if ((myprow >= 0 || mypcol >= 0) &&
248 fprintf(stderr,
"??MR2D:bad lda arg:row=%d,m=%d,p=%d,\
249 nbrow=%d,lda=%d,sprow=%d\n",
259 int myp, sp, p, bs, i;
262 int tempheight, firstblock, firsttemp;
265 firsttemp = i / tempheight;
266 firstblock = (i / bs) % p;
267 *newsp = (sp + firstblock) % p;
269 *decal = firsttemp * bs + (
SHIFT(myp, sp, p) < firstblock ? bs : 0);
278 int templateheight, templatewidth, ig, jg;
283 int vtemp, htemp, vsubtemp, hsubtemp, il, jl;
284 assert(ig >= 0 && ig < a->m && jg >= 0 && jg < a->n);
288 vtemp = ig / templateheight;
289 htemp = jg / templatewidth;
292 vsubtemp = ig % a->
nbrow;
293 hsubtemp = jg % a->
nbcol;
295 il = a->
nbrow * vtemp + vsubtemp;
296 jl = a->
nbcol * htemp + hsubtemp;
300 int pr, pc, p, q, lp, lq;
302 p = templateheight / a->
nbrow;
303 q = templatewidth / a->
nbcol;
304 lp = ig % templateheight / a->
nbrow;
305 lq = jg % templatewidth / a->
nbcol;
310 return (jl * a->
lda + il);