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

◆ Cpcgemr2d() [2/2]

void Cpcgemr2d ( Int  m,
Int  n,
complex ptrmyblock,
Int  ia,
Int  ja,
MDESC ma,
complex ptrmynewblock,
Int  ib,
Int  jb,
MDESC mb,
Int  globcontext 
)

Definition at line 291 of file pcgemr.c.

300{
301 complex *ptrsendbuff, *ptrrecvbuff, *ptrNULL = 0;
302 complex *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 Ccgesd2d(gcontext, sendsize, 1, ptrsendbuff, sendsize,
519 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, 1,
534 ptrsendbuff, recvsize,
535 ptrrecvbuff, recvsize);
536 } else {
537 Ccgerv2d(gcontext, recvsize, (Int)1, ptrrecvbuff, recvsize,
538 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);
#define Int
Definition Bconfig.h:22
static2 Int inter_len()
Int memoryblocksize()
Int changeorigin()
void Ccgesd2d()
#define Clacpy
Definition pcgemr.c:158
#define freememory
Definition pcgemr.c:223
void Cblacs_gridexit()
#define max(A, B)
Definition pcgemr.c:180
#define setmemory
Definition pcgemr.c:222
#define scan_intervals
Definition pcgemr.c:224
static2 void gridreshape()
#define DIVUP(a, b)
Definition pcgemr.c:182
#define NBPARAM
Definition pcgemr.c:288
void Cigamn2d()
void Ccgerv2d()
static2 void buff2block()
void paramcheck()
static2 Int block2buff()
void Cblacs_gridinfo()
#define MAGIC_MAX
Definition pcgemr.c:289
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: