14 #include "../PBpblas.h"
15 #include "../PBtools.h"
16 #include "../PBblacs.h"
17 #include "../PBblas.h"
20 void PB_Cainfog2l(
int M,
int N,
int I,
int J,
int * DESC,
int NPROW,
21 int NPCOL,
int MYROW,
int MYCOL,
int * IMB1,
22 int * INB1,
int * MP,
int * NQ,
int * II,
int * JJ,
23 int * PROW,
int * PCOL,
int * RPROW,
int * RPCOL )
25 void PB_Cainfog2l( M, N, I, J, DESC, NPROW, NPCOL, MYROW, MYCOL, IMB1,
26 INB1, MP, NQ, II, JJ, PROW, PCOL, RPROW, RPCOL )
30 int I, * II, * IMB1, * INB1, J, * JJ, M, * MP, MYCOL,
31 MYROW, N, NPCOL, NPROW, * NQ, * PCOL, * PROW, * RPCOL,
220 int i1, ilocblk, j1, mb, mydist, nb, nblocks, csrc, rsrc;
229 rsrc = DESC[
RSRC_ ];
231 if( ( rsrc == -1 ) || ( NPROW == 1 ) )
241 if( ( *IMB1 = DESC[
IMB_] - I ) <= 0 )
242 *IMB1 += ( ( -(*IMB1) ) / mb + 1 ) * mb;
243 *IMB1 =
MIN( *IMB1, M );
262 *II = ( ( MYROW == *PROW ) ? I : 0 );
287 nblocks = i1 / mb + 1;
288 *PROW = rsrc + nblocks;
289 *PROW -= ( *PROW / NPROW ) * NPROW;
308 if( nblocks < NPROW )
314 ilocblk = nblocks / NPROW;
315 if( ilocblk * NPROW >= nblocks )
317 *II = ( ( MYROW == *PROW ) ? I + ( ilocblk - nblocks ) * mb :
318 *IMB1 + ( ilocblk - 1 ) * mb );
322 *II = *IMB1 + ilocblk * mb;
331 nblocks = i1 / mb + 1;
332 *PROW = rsrc + nblocks;
333 *PROW -= ( *PROW / NPROW ) * NPROW;
338 if( ( mydist = MYROW - rsrc ) < 0 ) mydist += NPROW;
347 if( nblocks < NPROW )
350 *II = ( ( mydist < 0 ) ? mb : ( ( MYROW == *PROW ) ?
351 i1 + ( 1 - nblocks ) * mb : 0 ) );
355 ilocblk = nblocks / NPROW;
356 mydist -= nblocks - ilocblk * NPROW;
357 *II = ( ( mydist < 0 ) ? ( ilocblk + 1 ) * mb :
358 ( ( MYROW == *PROW ) ?
359 ( ilocblk - nblocks + 1 ) * mb + i1 :
366 *IMB1 = nblocks * mb - i1;
380 *MP = ( ( MYROW == *PROW ) ? M : 0 );
388 nblocks = ( M - *IMB1 ) / mb + 1;
409 if( nblocks < NPROW )
415 ilocblk = nblocks / NPROW;
416 *MP = ( ( nblocks - ilocblk * NPROW ) ?
417 *IMB1 + ilocblk * mb :
418 M + ( ilocblk - nblocks ) * mb );
427 if( ( mydist = MYROW - *PROW ) < 0 ) mydist += NPROW;
444 if( nblocks < NPROW )
447 *MP = ( ( mydist < 0 ) ? mb : ( ( mydist > 0 ) ? 0 :
448 M - *IMB1 + mb * ( 1 - nblocks ) ) );
452 ilocblk = nblocks / NPROW;
453 mydist -= nblocks - ilocblk * NPROW;
454 *MP = ( ( mydist < 0 ) ? ( ilocblk + 1 ) * mb :
455 ( ( mydist > 0 ) ? ilocblk * mb :
456 M - *IMB1 + mb * ( ilocblk - nblocks + 1 ) ) );
463 *IMB1 =
MIN( *IMB1, M );
464 if( ( *RPROW = MYROW - *PROW ) < 0 ) *RPROW += NPROW;
470 csrc = DESC[
CSRC_ ];
472 if( ( csrc == -1 ) || ( NPCOL == 1 ) )
475 if( ( *INB1 = DESC[
INB_] - J ) <= 0 )
476 *INB1 += ( ( -(*INB1) ) / nb + 1 ) * nb;
477 *INB1 =
MIN( *INB1, N );
488 *JJ = ( ( MYCOL == *PCOL ) ? J : 0 );
496 nblocks = j1 / nb + 1;
497 *PCOL = csrc + nblocks;
498 *PCOL -= ( *PCOL / NPCOL ) * NPCOL;
500 if( nblocks < NPCOL )
506 ilocblk = nblocks / NPCOL;
507 if( ilocblk * NPCOL >= nblocks )
509 *JJ = ( ( MYCOL == *PCOL ) ? J + ( ilocblk - nblocks ) * nb :
510 *INB1 + ( ilocblk - 1 ) * nb );
514 *JJ = *INB1 + ilocblk * nb;
520 nblocks = j1 / nb + 1;
521 *PCOL = csrc + nblocks;
522 *PCOL -= ( *PCOL / NPCOL ) * NPCOL;
524 if( ( mydist = MYCOL - csrc ) < 0 ) mydist += NPCOL;
526 if( nblocks < NPCOL )
529 *JJ = ( ( mydist < 0 ) ? nb : ( ( MYCOL == *PCOL ) ?
530 j1 + ( 1 - nblocks ) * nb : 0 ) );
534 ilocblk = nblocks / NPCOL;
535 mydist -= nblocks - ilocblk * NPCOL;
536 *JJ = ( ( mydist < 0 ) ? ( ilocblk + 1 ) * nb :
537 ( ( MYCOL == *PCOL ) ?
538 ( ilocblk - nblocks + 1 ) * nb + j1 :
542 *INB1 = nblocks * nb - j1;
547 *NQ = ( ( MYCOL == *PCOL ) ? N : 0 );
551 nblocks = ( N - *INB1 ) / nb + 1;
555 if( nblocks < NPCOL )
561 ilocblk = nblocks / NPCOL;
562 *NQ = ( ( nblocks - ilocblk * NPCOL ) ?
563 *INB1 + ilocblk * nb :
564 N + ( ilocblk - nblocks ) * nb );
569 if( ( mydist = MYCOL - *PCOL ) < 0 ) mydist += NPCOL;
571 if( nblocks < NPCOL )
574 *NQ = ( ( mydist < 0 ) ? nb : ( ( mydist > 0 ) ? 0 :
575 N - *INB1 + nb * ( 1 - nblocks ) ) );
579 ilocblk = nblocks / NPCOL;
580 mydist -= nblocks - ilocblk * NPCOL;
581 *NQ = ( ( mydist < 0 ) ? ( ilocblk + 1 ) * nb :
582 ( ( mydist > 0 ) ? ilocblk * nb :
583 N - *INB1 + nb * ( ilocblk - nblocks + 1 ) ) );
587 *INB1 =
MIN( *INB1, N );
588 if( ( *RPCOL = MYCOL - *PCOL ) < 0 ) *RPCOL += NPCOL;