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

◆ Cpztrmr2d() [2/2]

void Cpztrmr2d ( char *  uplo,
char *  diag,
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 307 of file pztrmr.c.

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