OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
pzgemr.c File Reference
#include "redist.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  dcomplex
struct  MDESC
struct  IDESC

Macros

#define static2   static
#define fortran_mr2d   pzgemr2do
#define fortran_mr2dnew   pzgemr2d
#define zcopy_   zcopy
#define zlacpy_   zlacpy
#define Clacpy   Czgelacpy
#define BLOCK_CYCLIC_2D   1
#define SHIFT(row, sprow, nbrow)
#define max(A, B)
#define min(A, B)
#define DIVUP(a, b)
#define ROUNDUP(a, b)
#define scanD0   zgescanD0
#define dispmat   zgedispmat
#define setmemory   zgesetmemory
#define freememory   zgefreememory
#define scan_intervals   zgescan_intervals
#define SENDBUFF   0
#define RECVBUFF   1
#define SIZEBUFF   2
#define NDEBUG
#define DESCLEN   9
#define NBPARAM
#define MAGIC_MAX   100000000
#define Mlacpy(mo, no, ao, ldao, bo, ldbo)

Functions

void Cblacs_pcoord ()
Int Cblacs_pnum ()
void Csetpvmtids ()
void Cblacs_get ()
void Cblacs_pinfo ()
void Cblacs_gridinfo ()
void Cblacs_gridinit ()
void Cblacs_exit ()
void Cblacs_gridexit ()
void Cblacs_setup ()
void Cigebs2d ()
void Cigebr2d ()
void Cigesd2d ()
void Cigerv2d ()
void Cigsum2d ()
void Cigamn2d ()
void Cigamx2d ()
void Czgesd2d ()
void Czgerv2d ()
Int localindice ()
void * mr2d_malloc ()
Int ppcm ()
Int localsize ()
Int memoryblocksize ()
Int changeorigin ()
void paramcheck ()
void Cpzgemr2do ()
void Cpzgemr2d ()
void fortran_mr2d (Int *m, Int *n, dcomplex *A, Int *ia, Int *ja, Int desc_A[DESCLEN], dcomplex *B, Int *ib, Int *jb, Int desc_B[DESCLEN])
void fortran_mr2dnew (Int *m, Int *n, dcomplex *A, Int *ia, Int *ja, Int desc_A[DESCLEN], dcomplex *B, Int *ib, Int *jb, Int desc_B[DESCLEN], Int *gcontext)
static2 void init_chenille ()
static2 Int inter_len ()
static2 Int block2buff ()
static2 void buff2block ()
static2 void gridreshape ()
void Cpzgemr2do (Int m, Int n, dcomplex *ptrmyblock, Int ia, Int ja, MDESC *ma, dcomplex *ptrmynewblock, Int ib, Int jb, MDESC *mb)
void Cpzgemr2d (Int m, Int n, dcomplex *ptrmyblock, Int ia, Int ja, MDESC *ma, dcomplex *ptrmynewblock, Int ib, Int jb, MDESC *mb, Int globcontext)
static2 void init_chenille (Int mypnum, Int nprocs, Int n0, Int *proc0, Int n1, Int *proc1, Int **psend, Int **precv, Int *myrang)
static2 Int block2buff (IDESC *vi, Int vinb, IDESC *hi, Int hinb, dcomplex *ptra, MDESC *ma, dcomplex *buff)
static2 void buff2block (IDESC *vi, Int vinb, IDESC *hi, Int hinb, dcomplex *buff, dcomplex *ptrb, MDESC *mb)
static2 Int inter_len (Int hinb, IDESC *hi, Int vinb, IDESC *vi)
void Clacpy (Int m, Int n, dcomplex *a, Int lda, dcomplex *b, Int ldb)
static2 void gridreshape (Int *ctxtp)

Macro Definition Documentation

◆ BLOCK_CYCLIC_2D

#define BLOCK_CYCLIC_2D   1

Definition at line 174 of file pzgemr.c.

◆ Clacpy

#define Clacpy   Czgelacpy

Definition at line 158 of file pzgemr.c.

◆ DESCLEN

#define DESCLEN   9

Definition at line 245 of file pzgemr.c.

◆ dispmat

#define dispmat   zgedispmat

Definition at line 221 of file pzgemr.c.

◆ DIVUP

#define DIVUP ( a,
b )
Value:
( ((a)-1) /(b)+1)

Definition at line 182 of file pzgemr.c.

◆ fortran_mr2d

#define fortran_mr2d   pzgemr2do

Definition at line 153 of file pzgemr.c.

◆ fortran_mr2dnew

#define fortran_mr2dnew   pzgemr2d

Definition at line 154 of file pzgemr.c.

◆ freememory

#define freememory   zgefreememory

Definition at line 223 of file pzgemr.c.

◆ MAGIC_MAX

#define MAGIC_MAX   100000000

Definition at line 289 of file pzgemr.c.

◆ max

#define max ( A,
B )
Value:
((A)>(B)?(A):(B))

Definition at line 180 of file pzgemr.c.

◆ min

#define min ( A,
B )
Value:
((A)>(B)?(B):(A))

Definition at line 181 of file pzgemr.c.

◆ Mlacpy

#define Mlacpy ( mo,
no,
ao,
ldao,
bo,
ldbo )
Value:
{ \
dcomplex *_a,*_b; \
Int _m,_n,_lda,_ldb; \
Int _i,_j; \
_m = (mo);_n = (no); \
_a = (ao);_b = (bo); \
_lda = (ldao) - _m; \
_ldb = (ldbo) - _m; \
assert(_lda >= 0 && _ldb >= 0); \
for (_j=0;_j<_n;_j++) { \
for (_i=0;_i<_m;_i++) \
*_b++ = *_a++; \
_b += _ldb; \
_a += _lda; \
} \
}
#define Int
Definition Bconfig.h:22

Definition at line 620 of file pzgemr.c.

620}
621#define Mlacpy(mo,no,ao,ldao,bo,ldbo) \
622{ \
623dcomplex *_a,*_b; \
624Int _m,_n,_lda,_ldb; \
625 Int _i,_j; \
626 _m = (mo);_n = (no); \
627 _a = (ao);_b = (bo); \
628 _lda = (ldao) - _m; \
629 _ldb = (ldbo) - _m; \
630 assert(_lda >= 0 && _ldb >= 0); \
631 for (_j=0;_j<_n;_j++) { \
632 for (_i=0;_i<_m;_i++) \
633 *_b++ = *_a++; \
634 _b += _ldb; \
635 _a += _lda; \
636 } \

◆ NBPARAM

#define NBPARAM
Value:
20 /* p0,q0,p1,q1, puis ma,na,mba,nba,rowa,cola puis
* idem B puis ia,ja puis ib,jb */

Definition at line 288 of file pzgemr.c.

◆ NDEBUG

#define NDEBUG

Definition at line 240 of file pzgemr.c.

◆ RECVBUFF

#define RECVBUFF   1

Definition at line 234 of file pzgemr.c.

◆ ROUNDUP

#define ROUNDUP ( a,
b )
Value:
(DIVUP(a,b)*(b))
#define DIVUP(a, b)
Definition pcgemr.c:182

Definition at line 183 of file pzgemr.c.

◆ scan_intervals

#define scan_intervals   zgescan_intervals

Definition at line 224 of file pzgemr.c.

◆ scanD0

#define scanD0   zgescanD0

Definition at line 220 of file pzgemr.c.

◆ SENDBUFF

#define SENDBUFF   0

Definition at line 233 of file pzgemr.c.

◆ setmemory

#define setmemory   zgesetmemory

Definition at line 222 of file pzgemr.c.

◆ SHIFT

#define SHIFT ( row,
sprow,
nbrow )
Value:
((row)-(sprow)+ ((row) >= (sprow) ? 0 : (nbrow)))

Definition at line 179 of file pzgemr.c.

◆ SIZEBUFF

#define SIZEBUFF   2

Definition at line 235 of file pzgemr.c.

◆ static2

#define static2   static

Id
pzgemr.c,v 1.1.1.1 2000/02/15 18:04:10 susan Exp

– ScaLAPACK routine (version 1.7) – Oak Ridge National Laboratory, Univ. of Tennessee, and Univ. of California, Berkeley. October 31, 1994.

SUBROUTINE PZGEMR2D( M, N, $ A, IA, JA, ADESC, $ B, IB, JB, BDESC,

$ CTXT)

Purpose

PZGEMR2D copies a submatrix of A on a submatrix of B. A and B can have different distributions: they can be on different processor grids, they can have different blocksizes, the beginning of the area to be copied can be at a different places on A and B.

The parameters can be confusing when the grids of A and B are partially or completly disjoint, in the case a processor calls this routines but is either not in the A context or B context, the ADESC[CTXT] or BDESC[CTXT] must be equal to -1, to ensure the routine recognise this situation. To summarize the rule:

  • If a processor is in A context, all parameters related to A must be valid.
  • If a processor is in B context, all parameters related to B must be valid.
  • ADESC[CTXT] and BDESC[CTXT] must be either valid contexts or equal to -1.
  • M and N must be valid for everyone.
  • other parameters are not examined.

Notes

A description vector is associated with each 2D block-cyclicly dis- tributed matrix. This vector stores the information required to establish the mapping between a matrix entry and its corresponding process and memory location.

In the following comments, the character _ should be read as "of the distributed matrix". Let A be a generic term for any 2D block cyclicly distributed matrix. Its description vector is DESC_A:

NOTATION STORED IN EXPLANATION


DT_A (global) DESCA( DT_ ) The descriptor type. CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating the BLACS process grid A is distribu- ted over. The context itself is glo- bal, but the handle (the integer value) may vary. M_A (global) DESCA( M_ ) The number of rows in the distributed matrix A. N_A (global) DESCA( N_ ) The number of columns in the distri- buted matrix A. MB_A (global) DESCA( MB_ ) The blocking factor used to distribute the rows of A. NB_A (global) DESCA( NB_ ) The blocking factor used to distribute the columns of A. RSRC_A (global) DESCA( RSRC_ ) The process row over which the first row of the matrix A is distributed. CSRC_A (global) DESCA( CSRC_ ) The process column over which the first column of A is distributed. LLD_A (local) DESCA( LLD_ ) The leading dimension of the local array storing the local blocks of the distributed matrix A. LLD_A >= MAX(1,LOCp(M_A)).

Important notice

The parameters of the routine have changed in April 1996 There is a new last argument. It must be a context englobing all processors involved in the initial and final distribution.

Be aware that all processors included in this context must call the redistribution routine.

Parameters

M (input) INTEGER. On entry, M specifies the number of rows of the submatrix to be copied. M must be at least zero. Unchanged on exit.

N (input) INTEGER. On entry, N specifies the number of cols of the submatrix to be redistributed.rows of B. M must be at least zero. Unchanged on exit.

A (input) COMPLEX*16 On entry, the source matrix. Unchanged on exit.

IA,JA (input) INTEGER On entry,the coordinates of the beginning of the submatrix of A to copy. 1 <= IA <= M_A - M + 1,1 <= JA <= N_A - N + 1, Unchanged on exit.

ADESC (input) A description vector (see Notes above) If the current processor is not part of the context of A the ADESC[CTXT] must be equal to -1.

B (output) COMPLEX*16 On entry, the destination matrix. The portion corresponding to the defined submatrix are updated.

IB,JB (input) INTEGER On entry,the coordinates of the beginning of the submatrix of B that will be updated. 1 <= IB <= M_B - M + 1,1 <= JB <= N_B - N + 1, Unchanged on exit.

BDESC (input) B description vector (see Notes above) For processors not part of the context of B BDESC[CTXT] must be equal to -1.

CTXT (input) a context englobing at least all processors included in either A context or B context

Memory requirement :

for the processors belonging to grid 0, one buffer of size block 0 and for the processors belonging to grid 1, also one buffer of size block 1.


Created March 1993 by B. Tourancheau (See sccs for modifications).

Modifications by Loic PRYLLI 1995

Definition at line 143 of file pzgemr.c.

◆ zcopy_

#define zcopy_   zcopy

Definition at line 155 of file pzgemr.c.

◆ zlacpy_

void zlacpy_   zlacpy

Definition at line 156 of file pzgemr.c.

Function Documentation

◆ block2buff() [1/2]

static2 Int block2buff ( )

◆ block2buff() [2/2]

static2 Int block2buff ( IDESC * vi,
Int vinb,
IDESC * hi,
Int hinb,
dcomplex * ptra,
MDESC * ma,
dcomplex * buff )

Definition at line 638 of file pzgemr.c.

640{
641 Int h, v, sizebuff;
642 dcomplex *ptr2;
643 sizebuff = 0;
644 for (h = 0; h < hinb; h++) {
645 ptr2 = ptra + hi[h].lstart * ma->lda;
646 for (v = 0; v < vinb; v++) {
647 Mlacpy(vi[v].len, hi[h].len,
648 ptr2 + vi[v].lstart,
649 ma->lda,
650 buff + sizebuff, vi[v].len);
651 sizebuff += hi[h].len * vi[v].len;
652 }
653 }
654 return sizebuff;
#define Mlacpy(mo, no, ao, ldao, bo, ldbo)
Definition pzgemr.c:620
Int lstart
Definition pcgemr.c:176
Int len
Definition pcgemr.c:177
Int lda
Definition pcgemr.c:172

◆ buff2block() [1/2]

static2 void buff2block ( )

◆ buff2block() [2/2]

static2 void buff2block ( IDESC * vi,
Int vinb,
IDESC * hi,
Int hinb,
dcomplex * buff,
dcomplex * ptrb,
MDESC * mb )

Definition at line 656 of file pzgemr.c.

658{
659 Int h, v, sizebuff;
660 dcomplex *ptr2;
661 sizebuff = 0;
662 for (h = 0; h < hinb; h++) {
663 ptr2 = ptrb + hi[h].lstart * mb->lda;
664 for (v = 0; v < vinb; v++) {
665 Mlacpy(vi[v].len, hi[h].len,
666 buff + sizebuff, vi[v].len,
667 ptr2 + vi[v].lstart,
668 mb->lda);
669 sizebuff += hi[h].len * vi[v].len;
670 }
671 }

◆ Cblacs_exit()

void Cblacs_exit ( )
extern

◆ Cblacs_get()

void Cblacs_get ( )
extern

◆ Cblacs_gridexit()

void Cblacs_gridexit ( )
extern

◆ Cblacs_gridinfo()

void Cblacs_gridinfo ( )
extern

◆ Cblacs_gridinit()

void Cblacs_gridinit ( )
extern

◆ Cblacs_pcoord()

void Cblacs_pcoord ( )
extern

◆ Cblacs_pinfo()

void Cblacs_pinfo ( )
extern

◆ Cblacs_pnum()

Int Cblacs_pnum ( )
extern

◆ Cblacs_setup()

void Cblacs_setup ( )
extern

◆ changeorigin()

Int changeorigin ( )
extern

◆ Cigamn2d()

void Cigamn2d ( )
extern

◆ Cigamx2d()

void Cigamx2d ( )
extern

◆ Cigebr2d()

void Cigebr2d ( )
extern

◆ Cigebs2d()

void Cigebs2d ( )
extern

◆ Cigerv2d()

void Cigerv2d ( )
extern

◆ Cigesd2d()

void Cigesd2d ( )
extern

◆ Cigsum2d()

void Cigsum2d ( )
extern

◆ Clacpy()

void Clacpy ( Int m,
Int n,
dcomplex * a,
Int lda,
dcomplex * b,
Int ldb )

Definition at line 685 of file pzgemr.c.

687{
688 Int i, j;
689 lda -= m;
690 ldb -= m;
691 assert(lda >= 0 && ldb >= 0);
692 for (j = 0; j < n; j++) {
693 for (i = 0; i < m; i++)
694 *b++ = *a++;
695 b += ldb;
696 a += lda;
697 }
n

◆ Cpzgemr2d() [1/2]

void Cpzgemr2d ( )
extern

◆ Cpzgemr2d() [2/2]

void Cpzgemr2d ( Int m,
Int n,
dcomplex * ptrmyblock,
Int ia,
Int ja,
MDESC * ma,
dcomplex * ptrmynewblock,
Int ib,
Int jb,
MDESC * mb,
Int globcontext )

Definition at line 291 of file pzgemr.c.

300{
301 dcomplex *ptrsendbuff, *ptrrecvbuff, *ptrNULL = 0;
302 dcomplex *recvptr;
303 MDESC newa, newb;
304 Int *proc0, *proc1, *param;
305 Int mypnum, myprow0, mypcol0, myprow1, mypcol1, nprocs;
306 Int i, j;
307 Int nprow, npcol, gcontext;
308 Int recvsize, sendsize;
309 IDESC *h_inter; /* to store the horizontal intersections */
310 IDESC *v_inter; /* to store the vertical intersections */
311 Int hinter_nb, vinter_nb; /* number of intrsections in both directions */
312 Int dummy;
313 Int p0, q0, p1, q1;
314 Int *ra, *ca;
315 /* end of variables */
316 /* To simplify further calcul we change the matrix indexation from
317 * 1..m,1..n (fortran) to 0..m-1,0..n-1 */
318 if (m == 0 || n == 0)
319 return;
320 ia -= 1;
321 ja -= 1;
322 ib -= 1;
323 jb -= 1;
324 Cblacs_gridinfo(globcontext, &nprow, &npcol, &dummy, &mypnum);
325 gcontext = globcontext;
326 nprocs = nprow * npcol;
327 /* if the global context that is given to us has not the shape of a line
328 * (nprow != 1), create a new context. TODO: to be optimal, we should
329 * avoid this because it is an uncessary synchronisation */
330 if (nprow != 1) {
331 gridreshape(&gcontext);
332 Cblacs_gridinfo(gcontext, &dummy, &dummy, &dummy, &mypnum);
333 }
334 Cblacs_gridinfo(ma->ctxt, &p0, &q0, &myprow0, &mypcol0);
335 /* compatibility T3D, must check myprow and mypcol are within bounds */
336 if (myprow0 >= p0 || mypcol0 >= q0)
337 myprow0 = mypcol0 = -1;
338 assert((myprow0 < p0 && mypcol0 < q0) || (myprow0 == -1 && mypcol0 == -1));
339 Cblacs_gridinfo(mb->ctxt, &p1, &q1, &myprow1, &mypcol1);
340 if (myprow1 >= p1 || mypcol1 >= q1)
341 myprow1 = mypcol1 = -1;
342 assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
343 /* exchange the missing parameters among the processors: shape of grids and
344 * location of the processors */
345 param = (Int *) mr2d_malloc(3 * (nprocs * 2 + NBPARAM) * sizeof(Int));
346 ra = param + nprocs * 2 + NBPARAM;
347 ca = param + (nprocs * 2 + NBPARAM) * 2;
348 for (i = 0; i < nprocs * 2 + NBPARAM; i++)
349 param[i] = MAGIC_MAX;
350 proc0 = param + NBPARAM;
351 proc1 = param + NBPARAM + nprocs;
352 /* we calulate proc0 and proc1 that will give the number of a proc in
353 * respectively a or b in the global context */
354 if (myprow0 >= 0) {
355 proc0[myprow0 * q0 + mypcol0] = mypnum;
356 param[0] = p0;
357 param[1] = q0;
358 param[4] = ma->m;
359 param[5] = ma->n;
360 param[6] = ma->nbrow;
361 param[7] = ma->nbcol;
362 param[8] = ma->sprow;
363 param[9] = ma->spcol;
364 param[10] = ia;
365 param[11] = ja;
366 }
367 if (myprow1 >= 0) {
368 proc1[myprow1 * q1 + mypcol1] = mypnum;
369 param[2] = p1;
370 param[3] = q1;
371 param[12] = mb->m;
372 param[13] = mb->n;
373 param[14] = mb->nbrow;
374 param[15] = mb->nbcol;
375 param[16] = mb->sprow;
376 param[17] = mb->spcol;
377 param[18] = ib;
378 param[19] = jb;
379 }
380 Cigamn2d(gcontext, "All", "H", 2 * nprocs + NBPARAM, (Int)1, param, 2 * nprocs + NBPARAM,
381 ra, ca, 2 * nprocs + NBPARAM, (Int)-1, (Int)-1);
382 newa = *ma;
383 newb = *mb;
384 ma = &newa;
385 mb = &newb;
386 if (myprow0 == -1) {
387 p0 = param[0];
388 q0 = param[1];
389 ma->m = param[4];
390 ma->n = param[5];
391 ma->nbrow = param[6];
392 ma->nbcol = param[7];
393 ma->sprow = param[8];
394 ma->spcol = param[9];
395 ia = param[10];
396 ja = param[11];
397 }
398 if (myprow1 == -1) {
399 p1 = param[2];
400 q1 = param[3];
401 mb->m = param[12];
402 mb->n = param[13];
403 mb->nbrow = param[14];
404 mb->nbcol = param[15];
405 mb->sprow = param[16];
406 mb->spcol = param[17];
407 ib = param[18];
408 jb = param[19];
409 }
410 for (i = 0; i < NBPARAM; i++) {
411 if (param[i] == MAGIC_MAX) {
412 fprintf(stderr, "xxGEMR2D:something wrong in the parameters\n");
413 exit(1);
414 }
415 }
416#ifndef NDEBUG
417 for (i = 0; i < p0 * q0; i++)
418 assert(proc0[i] >= 0 && proc0[i] < nprocs);
419 for (i = 0; i < p1 * q1; i++)
420 assert(proc1[i] >= 0 && proc1[i] < nprocs);
421#endif
422 /* check the validity of the parameters */
423 paramcheck(ma, ia, ja, m, n, p0, q0, gcontext);
424 paramcheck(mb, ib, jb, m, n, p1, q1, gcontext);
425 /* we change the problem so that ia < a->nbrow ... andia + m = a->m ... */
426 {
427 Int decal;
428 ia = changeorigin(myprow0, ma->sprow, p0,
429 ma->nbrow, ia, &decal, &ma->sprow);
430 ptrmyblock += decal;
431 ja = changeorigin(mypcol0, ma->spcol, q0,
432 ma->nbcol, ja, &decal, &ma->spcol);
433 ptrmyblock += decal * ma->lda;
434 ma->m = ia + m;
435 ma->n = ja + n;
436 ib = changeorigin(myprow1, mb->sprow, p1,
437 mb->nbrow, ib, &decal, &mb->sprow);
438 ptrmynewblock += decal;
439 jb = changeorigin(mypcol1, mb->spcol, q1,
440 mb->nbcol, jb, &decal, &mb->spcol);
441 ptrmynewblock += decal * mb->lda;
442 mb->m = ib + m;
443 mb->n = jb + n;
444 if (p0 == 1)
445 ma->nbrow = ma->m;
446 if (q0 == 1)
447 ma->nbcol = ma->n;
448 if (p1 == 1)
449 mb->nbrow = mb->m;
450 if (q1 == 1)
451 mb->nbcol = mb->n;
452#ifndef NDEBUG
453 paramcheck(ma, ia, ja, m, n, p0, q0, gcontext);
454 paramcheck(mb, ib, jb, m, n, p1, q1, gcontext);
455#endif
456 }
457 /* We compute the size of the memory buffer ( we choose the worst case,
458 * when the buffer sizes == the memory block sizes). */
459 if (myprow0 >= 0 && mypcol0 >= 0) {
460 /* Initialize pointer variables */
461 setmemory(&ptrsendbuff, memoryblocksize(ma));
462 }; /* if (mypnum < p0 * q0) */
463 if (myprow1 >= 0 && mypcol1 >= 0) {
464 /* Initialize pointer variables */
465 setmemory(&ptrrecvbuff, memoryblocksize(mb));
466 }; /* if (mypnum < p1 * q1) */
467 /* allocing room for the tabs, alloc for the worst case,local_n or local_m
468 * intervals, in fact the worst case should be less, perhaps half that,I
469 * should think of that one day. */
470 h_inter = (IDESC *) mr2d_malloc(DIVUP(ma->n, q0 * ma->nbcol) *
471 ma->nbcol * sizeof(IDESC));
472 v_inter = (IDESC *) mr2d_malloc(DIVUP(ma->m, p0 * ma->nbrow)
473 * ma->nbrow * sizeof(IDESC));
474 /* We go for the scanning of indices. For each processor including mypnum,
475 * we fill the sendbuff buffer (scanD0(SENDBUFF)) and when it is done send
476 * it. Then for each processor, we compute the size of message to be
477 * receive scanD0(SIZEBUFF)), post a receive and then allocate the elements
478 * of recvbuff the right place (scanD)(RECVBUFF)) */
479 recvptr = ptrrecvbuff;
480 {
481 Int tot, myrang, step, sens;
482 Int *sender, *recver;
483 Int mesending, merecving;
484 tot = max(p0 * q0, p1 * q1);
485 init_chenille(mypnum, nprocs, p0 * q0, proc0, p1 * q1, proc1,
486 &sender, &recver, &myrang);
487 if (myrang == -1)
488 goto after_comm;
489 mesending = myprow0 >= 0;
490 assert(sender[myrang] >= 0 || !mesending);
491 assert(!mesending || proc0[sender[myrang]] == mypnum);
492 merecving = myprow1 >= 0;
493 assert(recver[myrang] >= 0 || !merecving);
494 assert(!merecving || proc1[recver[myrang]] == mypnum);
495 step = tot - 1 - myrang;
496 do {
497 for (sens = 0; sens < 2; sens++) {
498 /* be careful here, when we communicating with ourselves, we must
499 * send first (myrang > step == 0) */
500 if (mesending && recver[step] >= 0 &&
501 (sens == 0)) {
502 i = recver[step] / q1;
503 j = recver[step] % q1;
504 vinter_nb = scan_intervals('r', ia, ib, m, ma, mb, p0, p1, myprow0, i,
505 v_inter);
506 hinter_nb = scan_intervals('c', ja, jb, n, ma, mb, q0, q1, mypcol0, j,
507 h_inter);
508 sendsize = block2buff(v_inter, vinter_nb, h_inter, hinter_nb,
509 ptrmyblock, ma, ptrsendbuff);
510 } /* if (mesending...) { */
511 if (mesending && recver[step] >= 0 &&
512 (sens == myrang > step)) {
513 i = recver[step] / q1;
514 j = recver[step] % q1;
515 if (sendsize > 0
516 && (step != myrang || !merecving)
517 ) {
518 Czgesd2d(gcontext, sendsize, (Int)1, ptrsendbuff, sendsize,
519 (Int)0, proc1[i * q1 + j]);
520 } /* sendsize > 0 */
521 } /* if (mesending ... */
522 if (merecving && sender[step] >= 0 &&
523 (sens == myrang <= step)) {
524 i = sender[step] / q0;
525 j = sender[step] % q0;
526 vinter_nb = scan_intervals('r', ib, ia, m, mb, ma, p1, p0, myprow1, i,
527 v_inter);
528 hinter_nb = scan_intervals('c', jb, ja, n, mb, ma, q1, q0, mypcol1, j,
529 h_inter);
530 recvsize = inter_len(hinter_nb, h_inter, vinter_nb, v_inter);
531 if (recvsize > 0) {
532 if (step == myrang && mesending) {
533 Clacpy(recvsize, (Int)1,
534 ptrsendbuff, recvsize,
535 ptrrecvbuff, recvsize);
536 } else {
537 Czgerv2d(gcontext, recvsize, (Int)1, ptrrecvbuff, recvsize,
538 (Int)0, proc0[i * q0 + j]);
539 }
540 } /* recvsize > 0 */
541 } /* if (merecving ...) */
542 if (merecving && sender[step] >= 0 && sens == 1) {
543 buff2block(v_inter, vinter_nb, h_inter, hinter_nb,
544 recvptr, ptrmynewblock, mb);
545 } /* if (merecving...) */
546 } /* for (sens = 0) */
547 step -= 1;
548 if (step < 0)
549 step = tot - 1;
550 } while (step != tot - 1 - myrang);
551after_comm:
552 free(sender);
553 } /* { int tot,nr,ns ...} */
554 /* don't forget to clean up things! */
555 if (myprow1 >= 0 && mypcol1 >= 0) {
556 freememory((char *) ptrrecvbuff);
557 };
558 if (myprow0 >= 0 && mypcol0 >= 0) {
559 freememory((char *) ptrsendbuff);
560 };
561 if (nprow != 1)
562 Cblacs_gridexit(gcontext);
563 free(v_inter);
564 free(h_inter);
565 free(param);
integer, save, private nprocs
Definition cmumps_load.F:57
#define NBPARAM
Definition pcgemr.c:288
#define MAGIC_MAX
Definition pcgemr.c:289
static2 Int inter_len()
Int memoryblocksize()
Int changeorigin()
#define freememory
Definition pzgemr.c:223
void Czgesd2d()
#define scan_intervals
Definition pzgemr.c:224
void Cblacs_gridexit()
#define max(A, B)
Definition pzgemr.c:180
static2 void gridreshape()
#define DIVUP(a, b)
Definition pzgemr.c:182
#define Clacpy
Definition pzgemr.c:158
void Cigamn2d()
#define setmemory
Definition pzgemr.c:222
void Czgerv2d()
static2 void buff2block()
void paramcheck()
static2 Int block2buff()
void Cblacs_gridinfo()
void * mr2d_malloc()
static2 void init_chenille()
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

◆ Cpzgemr2do() [1/2]

void Cpzgemr2do ( )
extern

◆ Cpzgemr2do() [2/2]

void Cpzgemr2do ( Int m,
Int n,
dcomplex * ptrmyblock,
Int ia,
Int ja,
MDESC * ma,
dcomplex * ptrmynewblock,
Int ib,
Int jb,
MDESC * mb )

Definition at line 268 of file pzgemr.c.

276{
277 Int dummy, nprocs;
278 Int gcontext;
279 /* first we initialize a global grid which serve as a reference to
280 * communicate from grid a to grid b */
281 Cblacs_pinfo(&dummy, &nprocs);
282 Cblacs_get((Int)0, (Int)0, &gcontext);
283 Cblacs_gridinit(&gcontext, "R", (Int)1, nprocs);
284 Cpzgemr2d(m, n, ptrmyblock, ia, ja, ma,
285 ptrmynewblock, ib, jb, mb, gcontext);
286 Cblacs_gridexit(gcontext);
287}
void Cpzgemr2d()
void Cblacs_pinfo()
void Cblacs_get()
void Cblacs_gridinit()

◆ Csetpvmtids()

void Csetpvmtids ( )
extern

◆ Czgerv2d()

void Czgerv2d ( )
extern

◆ Czgesd2d()

void Czgesd2d ( )
extern

◆ fortran_mr2d()

void fortran_mr2d ( Int * m,
Int * n,
dcomplex * A,
Int * ia,
Int * ja,
Int desc_A[DESCLEN],
dcomplex * B,
Int * ib,
Int * jb,
Int desc_B[DESCLEN] )

Definition at line 247 of file pzgemr.c.

249{
250 Cpzgemr2do(*m, *n, A, *ia, *ja, (MDESC *) desc_A,
251 B, *ib, *jb, (MDESC *) desc_B);
252 return;
253}
void Cpzgemr2do()

◆ fortran_mr2dnew()

void fortran_mr2dnew ( Int * m,
Int * n,
dcomplex * A,
Int * ia,
Int * ja,
Int desc_A[DESCLEN],
dcomplex * B,
Int * ib,
Int * jb,
Int desc_B[DESCLEN],
Int * gcontext )

Definition at line 255 of file pzgemr.c.

257{
258 Cpzgemr2d(*m, *n, A, *ia, *ja, (MDESC *) desc_A,
259 B, *ib, *jb, (MDESC *) desc_B, *gcontext);
260 return;
261}

◆ gridreshape() [1/2]

static2 void gridreshape ( )

◆ gridreshape() [2/2]

static2 void gridreshape ( Int * ctxtp)

Definition at line 699 of file pzgemr.c.

701{
702 Int ori, final; /* original context, and new context created, with
703 * line form */
704 Int nprow, npcol, myrow, mycol;
705 Int *usermap;
706 Int i, j;
707 ori = *ctxtp;
708 Cblacs_gridinfo(ori, &nprow, &npcol, &myrow, &mycol);
709 usermap = mr2d_malloc(sizeof(Int) * nprow * npcol);
710 for (i = 0; i < nprow; i++)
711 for (j = 0; j < npcol; j++) {
712 usermap[i + j * nprow] = Cblacs_pnum(ori, i, j);
713 }
714 /* Cblacs_get(0, 0, &final); */
715 Cblacs_get(ori, (Int)10, &final);
716 Cblacs_gridmap(&final, usermap, (Int)1, (Int)1, nprow * npcol);
717 *ctxtp = final;
718 free(usermap);
void Cblacs_gridmap()
Int Cblacs_pnum()

◆ init_chenille() [1/2]

static2 void init_chenille ( )

◆ init_chenille() [2/2]

static2 void init_chenille ( Int mypnum,
Int nprocs,
Int n0,
Int * proc0,
Int n1,
Int * proc1,
Int ** psend,
Int ** precv,
Int * myrang )

Definition at line 567 of file pzgemr.c.

569{
570 Int ns, nr, i, tot;
571 Int *sender, *recver, *g0, *g1;
572 tot = max(n0, n1);
573 sender = (Int *) mr2d_malloc((nprocs + tot) * sizeof(Int) * 2);
574 recver = sender + tot;
575 *psend = sender;
576 *precv = recver;
577 g0 = recver + tot;
578 g1 = g0 + nprocs;
579 for (i = 0; i < nprocs; i++) {
580 g0[i] = -1;
581 g1[i] = -1;
582 }
583 for (i = 0; i < tot; i++) {
584 sender[i] = -1;
585 recver[i] = -1;
586 }
587 for (i = 0; i < n0; i++)
588 g0[proc0[i]] = i;
589 for (i = 0; i < n1; i++)
590 g1[proc1[i]] = i;
591 ns = 0;
592 nr = 0;
593 *myrang = -1;
594 for (i = 0; i < nprocs; i++)
595 if (g0[i] >= 0 && g1[i] >= 0) {
596 if (i == mypnum)
597 *myrang = nr;
598 sender[ns] = g0[i];
599 ns += 1;
600 recver[nr] = g1[i];
601 nr += 1;
602 assert(ns <= n0 && nr <= n1 && nr == ns);
603 }
604 for (i = 0; i < nprocs; i++)
605 if (g0[i] >= 0 && g1[i] < 0) {
606 if (i == mypnum)
607 *myrang = ns;
608 sender[ns] = g0[i];
609 ns += 1;
610 assert(ns <= n0);
611 }
612 for (i = 0; i < nprocs; i++)
613 if (g1[i] >= 0 && g0[i] < 0) {
614 if (i == mypnum)
615 *myrang = nr;
616 recver[nr] = g1[i];
617 nr += 1;
618 assert(nr <= n1);
619 }

◆ inter_len() [1/2]

static2 Int inter_len ( )

◆ inter_len() [2/2]

static2 Int inter_len ( Int hinb,
IDESC * hi,
Int vinb,
IDESC * vi )

Definition at line 673 of file pzgemr.c.

675{
676 Int hlen, vlen, h, v;
677 hlen = 0;
678 for (h = 0; h < hinb; h++)
679 hlen += hi[h].len;
680 vlen = 0;
681 for (v = 0; v < vinb; v++)
682 vlen += vi[v].len;
683 return hlen * vlen;

◆ localindice()

Int localindice ( )
extern

◆ localsize()

Int localsize ( )
extern

◆ memoryblocksize()

Int memoryblocksize ( )
extern

◆ mr2d_malloc()

void * mr2d_malloc ( )
extern

◆ paramcheck()

void paramcheck ( )
extern

◆ ppcm()

Int ppcm ( )
extern