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

◆ Cpstrmr2d() [2/2]

void Cpstrmr2d ( char *  uplo,
char *  diag,
Int  m,
Int  n,
float *  ptrmyblock,
Int  ia,
Int  ja,
MDESC ma,
float *  ptrmynewblock,
Int  ib,
Int  jb,
MDESC mb,
Int  globcontext 
)

Definition at line 304 of file pstrmr.c.

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