143 #define static2 static
144 #if defined(Add_) || defined(f77IsF2C)
145 #define fortran_mr2d pdgemr2do_
146 #define fortran_mr2dnew pdgemr2d_
147 #elif defined(UpCase)
148 #define fortran_mr2dnew PDGEMR2D
149 #define fortran_mr2d PDGEMR2DO
151 #define dlacpy_ DLACPY
153 #define fortran_mr2d pdgemr2do
154 #define fortran_mr2dnew pdgemr2d
156 #define dlacpy_ dlacpy
158 #define Clacpy Cdgelacpy
171 #define BLOCK_CYCLIC_2D 1
176 #define SHIFT(row,sprow,nbrow) ((row)-(sprow)+ ((row) >= (sprow) ? 0 : (nbrow)))
177 #define max(A,B) ((A)>(B)?(A):(B))
178 #define min(A,B) ((A)>(B)?(B):(A))
179 #define DIVUP(a,b) ( ((a)-1) /(b)+1)
180 #define ROUNDUP(a,b) (DIVUP(a,b)*(b))
182 #define malloc mymalloc
184 #define realloc myrealloc
217 #define scanD0 dgescanD0
218 #define dispmat dgedispmat
219 #define setmemory dgesetmemory
220 #define freememory dgefreememory
221 #define scan_intervals dgescan_intervals
246 int *ia, *ib, *ja, *jb, *m, *n;
251 B, *ib, *jb, (
MDESC *) desc_B);
256 B, ib, jb, desc_B, gcontext)
257 int *ia, *ib, *ja, *jb, *m, *n;
263 B, *ib, *jb, (
MDESC *) desc_B, *gcontext);
273 ptrmyblock, ia, ja, ma,
274 ptrmynewblock, ib, jb, mb)
275 double *ptrmyblock, *ptrmynewblock;
279 int ia, ja, ib, jb, m, n;
289 ptrmynewblock, ib, jb, mb, gcontext);
294 #define MAGIC_MAX 100000000
297 ptrmyblock, ia, ja, ma,
298 ptrmynewblock, ib, jb, mb, globcontext)
299 double *ptrmyblock, *ptrmynewblock;
303 int ia, ja, ib, jb, m, n, globcontext;
305 double *ptrsendbuff, *ptrrecvbuff, *ptrNULL = 0;
308 int *proc0, *proc1, *param;
309 int mypnum, myprow0, mypcol0, myprow1, mypcol1, nprocs;
311 int nprow, npcol, gcontext;
312 int recvsize, sendsize;
315 int hinter_nb, vinter_nb;
322 if (m == 0 || n == 0)
329 gcontext = globcontext;
330 nprocs = nprow * npcol;
340 if (myprow0 >= p0 || mypcol0 >= q0)
341 myprow0 = mypcol0 = -1;
342 assert((myprow0 < p0 && mypcol0 < q0) || (myprow0 == -1 && mypcol0 == -1));
344 if (myprow1 >= p1 || mypcol1 >= q1)
345 myprow1 = mypcol1 = -1;
346 assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
350 ra = param + nprocs * 2 +
NBPARAM;
351 ca = param + (nprocs * 2 +
NBPARAM) * 2;
352 for (i = 0; i < nprocs * 2 +
NBPARAM; i++)
355 proc1 = param +
NBPARAM + nprocs;
359 proc0[myprow0 * q0 + mypcol0] = mypnum;
364 param[6] = ma->
nbrow;
365 param[7] = ma->
nbcol;
366 param[8] = ma->
sprow;
367 param[9] = ma->
spcol;
372 proc1[myprow1 * q1 + mypcol1] = mypnum;
377 param[14] = mb->
nbrow;
378 param[15] = mb->
nbcol;
379 param[16] = mb->
sprow;
380 param[17] = mb->
spcol;
385 ra, ca, 2 * nprocs +
NBPARAM, -1, -1);
395 ma->
nbrow = param[6];
396 ma->
nbcol = param[7];
397 ma->
sprow = param[8];
398 ma->
spcol = param[9];
407 mb->
nbrow = param[14];
408 mb->
nbcol = param[15];
409 mb->
sprow = param[16];
410 mb->
spcol = param[17];
414 for (i = 0; i <
NBPARAM; i++) {
416 fprintf(stderr,
"xxGEMR2D:something wrong in the parameters\n");
421 for (i = 0; i < p0 * q0; i++)
422 assert(proc0[i] >= 0 && proc0[i] < nprocs);
423 for (i = 0; i < p1 * q1; i++)
424 assert(proc1[i] >= 0 && proc1[i] < nprocs);
427 paramcheck(ma, ia, ja, m, n, p0, q0, gcontext);
428 paramcheck(mb, ib, jb, m, n, p1, q1, gcontext);
437 ptrmyblock += decal * ma->
lda;
442 ptrmynewblock += decal;
445 ptrmynewblock += decal * mb->
lda;
457 paramcheck(ma, ia, ja, m, n, p0, q0, gcontext);
458 paramcheck(mb, ib, jb, m, n, p1, q1, gcontext);
463 if (myprow0 >= 0 && mypcol0 >= 0) {
467 if (myprow1 >= 0 && mypcol1 >= 0) {
483 recvptr = ptrrecvbuff;
485 int tot, myrang, step, sens;
486 int *sender, *recver;
487 int mesending, merecving;
488 tot =
max(p0 * q0, p1 * q1);
489 init_chenille(mypnum, nprocs, p0 * q0, proc0, p1 * q1, proc1,
490 &sender, &recver, &myrang);
493 mesending = myprow0 >= 0;
494 assert(sender[myrang] >= 0 || !mesending);
495 assert(!mesending || proc0[sender[myrang]] == mypnum);
496 merecving = myprow1 >= 0;
497 assert(recver[myrang] >= 0 || !merecving);
498 assert(!merecving || proc1[recver[myrang]] == mypnum);
499 step = tot - 1 - myrang;
501 for (sens = 0; sens < 2; sens++) {
504 if (mesending && recver[step] >= 0 &&
506 i = recver[step] / q1;
507 j = recver[step] % q1;
508 vinter_nb =
scan_intervals(
'r', ia, ib, m, ma, mb, p0, p1, myprow0, i,
510 hinter_nb =
scan_intervals(
'c', ja, jb, n, ma, mb, q0, q1, mypcol0, j,
512 sendsize =
block2buff(v_inter, vinter_nb, h_inter, hinter_nb,
513 ptrmyblock, ma, ptrsendbuff);
515 if (mesending && recver[step] >= 0 &&
516 (sens == myrang > step)) {
517 i = recver[step] / q1;
518 j = recver[step] % q1;
520 && (step != myrang || !merecving)
522 Cdgesd2d(gcontext, sendsize, 1, ptrsendbuff, sendsize,
523 0, proc1[i * q1 + j]);
526 if (merecving && sender[step] >= 0 &&
527 (sens == myrang <= step)) {
528 i = sender[step] / q0;
529 j = sender[step] % q0;
530 vinter_nb =
scan_intervals(
'r', ib, ia, m, mb, ma, p1, p0, myprow1, i,
532 hinter_nb =
scan_intervals(
'c', jb, ja, n, mb, ma, q1, q0, mypcol1, j,
534 recvsize =
inter_len(hinter_nb, h_inter, vinter_nb, v_inter);
536 if (step == myrang && mesending) {
538 ptrsendbuff, recvsize,
539 ptrrecvbuff, recvsize);
541 Cdgerv2d(gcontext, recvsize, 1, ptrrecvbuff, recvsize,
542 0, proc0[i * q0 + j]);
546 if (merecving && sender[step] >= 0 && sens == 1) {
547 buff2block(v_inter, vinter_nb, h_inter, hinter_nb,
548 recvptr, ptrmynewblock, mb);
554 }
while (step != tot - 1 - myrang);
559 if (myprow1 >= 0 && mypcol1 >= 0) {
562 if (myprow0 >= 0 && mypcol0 >= 0) {
573 int nprocs, mypnum, n0, n1;
574 int *proc0, *proc1, **psend, **precv, *myrang;
577 int *sender, *recver, *g0, *g1;
579 sender = (
int *)
mr2d_malloc((nprocs + tot) *
sizeof(int) * 2);
580 recver = sender + tot;
585 for (i = 0; i < nprocs; i++) {
589 for (i = 0; i < tot; i++) {
593 for (i = 0; i < n0; i++)
595 for (i = 0; i < n1; i++)
600 for (i = 0; i < nprocs; i++)
601 if (g0[i] >= 0 && g1[i] >= 0) {
608 assert(ns <= n0 && nr <= n1 && nr == ns);
610 for (i = 0; i < nprocs; i++)
611 if (g0[i] >= 0 && g1[i] < 0) {
618 for (i = 0; i < nprocs; i++)
619 if (g1[i] >= 0 && g0[i] < 0) {
627 #define Mlacpy(mo,no,ao,ldao,bo,ldbo) \
630 int _m,_n,_lda,_ldb; \
632 _m = (mo);_n = (no); \
633 _a = (ao);_b = (bo); \
634 _lda = (ldao) - _m; \
635 _ldb = (ldbo) - _m; \
636 assert(_lda >= 0 && _ldb >= 0); \
637 for (_j=0;_j<_n;_j++) { \
638 for (_i=0;_i<_m;_i++) \
654 for (h = 0; h < hinb; h++) {
656 for (v = 0; v < vinb; v++) {
657 Mlacpy(vi[v].len, hi[h].len,
660 buff + sizebuff, vi[v].
len);
661 sizebuff += hi[h].
len * vi[v].
len;
676 for (h = 0; h < hinb; h++) {
678 for (v = 0; v < vinb; v++) {
679 Mlacpy(vi[v].len, hi[h].len,
680 buff + sizebuff, vi[v].len,
683 sizebuff += hi[h].
len * vi[v].
len;
692 int hlen, vlen, h, v;
694 for (h = 0; h < hinb; h++)
697 for (v = 0; v < vinb; v++)
709 assert(lda >= 0 && ldb >= 0);
710 for (j = 0; j < n; j++) {
711 for (i = 0; i < m; i++)
723 int nprow, npcol, myrow, mycol;
728 usermap =
mr2d_malloc(
sizeof(
int) * nprow * npcol);
729 for (i = 0; i < nprow; i++)
730 for (j = 0; j < npcol; j++) {