14 #include "../PBpblas.h"
15 #include "../PBtools.h"
16 #include "../PBblacs.h"
17 #include "../PBblas.h"
27 int * IOFF, * JOFF, * NCPQ, * NRPQ;
77 int ColCont=1, FirstD=0, GoSouth, GoEast, RowCont=1, ilow, imbloc,
78 inbloc, iupp, lcmt, lcmtnn=0, lcmt00, lmbloc, lnbloc, low, mb,
79 mblks, mbloc, mcur=0, mcurd, md=0, nb, nblks, nbloc, ncur=0,
80 ncurd, nd=0, npq=0, pmb, qnb, tmp1, tmp2, upp;
85 *NRPQ = 0; *NCPQ = 0; *IOFF = 0; *JOFF = 0;
90 if( ( mblks == 0 ) || ( nblks == 0 ) )
return;
104 GoSouth = ( lcmt00 > iupp );
105 GoEast = ( lcmt00 < ilow );
109 if( !( GoSouth ) && !( GoEast ) )
118 tmp2 = ( ( tmp1 = imbloc - lcmt00 ) > 0 ? tmp1 : 0 );
119 if( tmp2 < inbloc ) { npq = tmp2; lcmtnn = -npq; }
120 else if ( tmp2 == inbloc ) { npq = inbloc; lcmtnn = 0; }
121 else { npq = inbloc; lcmtnn = lcmt00 + npq; }
126 tmp2 = ( ( tmp1 = inbloc + lcmt00 ) > 0 ? tmp1 : 0 );
127 if( tmp2 < imbloc ) { npq = tmp2; lcmtnn = npq; }
128 else if ( tmp2 == imbloc ) { npq = tmp2; lcmtnn = 0; }
129 else { npq = imbloc; lcmtnn = lcmt00 - npq; }
136 md = 0; nd = 0; FirstD = 1;
146 GoSouth = !( GoEast = ( lcmt00 - iupp + upp - pmb < ilow ) );
154 lcmt00 -= iupp - upp + pmb; mcur++;
155 if( !FirstD ) *IOFF += imbloc;
160 while( ( mcur < mblks ) && ( lcmt00 > upp ) )
164 if( !FirstD ) *IOFF += mb;
169 if( mcur >= mblks )
goto l_end;
176 lcmt = lcmt00; mbloc = mb; mcurd = mcur;
178 while( ( mcurd < mblks ) && ( lcmt >= ilow ) )
180 if( mcurd == mblks-1 ) mbloc = lmbloc;
189 ( ( ( mcurd == md+1 ) && ( lcmtnn <= 0 ) && ( lcmt <= 0 ) ) ||
190 ( ( mcurd == md ) && ( ncur == nd+1 ) && ( lcmtnn == lcmt ) ) );
192 ( ( ( ncur == nd+1 ) && ( lcmtnn >= 0 ) && ( lcmt >= 0 ) ) ||
193 ( ( ncur == nd ) && ( mcurd == md+1 ) && ( lcmtnn == lcmt ) ) );
201 tmp2 = ( ( tmp1 = mbloc - lcmt ) > 0 ? tmp1 : 0 );
202 if( tmp2 < inbloc ) { npq = tmp2; lcmtnn = -npq; }
203 else if ( tmp2 == inbloc ) { npq = inbloc; lcmtnn = 0; }
204 else { npq = inbloc; lcmtnn = lcmt + npq; }
205 if( !FirstD ) *IOFF += lcmt;
209 tmp2 = ( ( tmp1 = inbloc + lcmt ) > 0 ? tmp1 : 0 );
210 if( tmp2 < mbloc ) { npq = tmp2; lcmtnn = npq; }
211 else if ( tmp2 == mbloc ) { npq = tmp2; lcmtnn = 0; }
212 else { npq = mbloc; lcmtnn = lcmt - npq; }
213 if( !FirstD ) *JOFF -= lcmt;
219 md = mcurd; nd = ncur; FirstD = 1;
224 if( RowCont ) *NRPQ += npq;
225 if( ColCont ) *NCPQ += npq;
236 lcmt00 += low - ilow + qnb; ncur++;
237 if( !FirstD ) *JOFF += inbloc;
244 lcmt00 += low - ilow + qnb; ncur++;
245 if( !FirstD ) *JOFF += inbloc;
250 while( ( ncur < nblks ) && ( lcmt00 < low ) )
254 if( !FirstD ) *JOFF += nb;
259 if( ncur >= nblks )
goto l_end;
265 lcmt = lcmt00; nbloc = nb; ncurd = ncur;
267 while( ( ncurd < nblks ) && ( lcmt <= iupp ) )
269 if( ncurd == nblks-1 ) nbloc = lnbloc;
278 ( ( ( mcur == md+1 ) && ( lcmtnn <= 0 ) && ( lcmt <= 0 ) ) ||
279 ( ( mcur == md ) && ( ncurd == nd+1 ) && ( lcmtnn == lcmt ) ) );
281 ( ( ( ncurd == nd+1 ) && ( lcmtnn >= 0 ) && ( lcmt >= 0 ) ) ||
282 ( ( ncurd == nd ) && ( mcur == md+1 ) && ( lcmtnn == lcmt ) ) );
290 tmp2 = ( ( tmp1 = imbloc - lcmt ) > 0 ? tmp1 : 0 );
291 if( tmp2 < nbloc ) { npq = tmp2; lcmtnn = -npq; }
292 else if ( tmp2 == nbloc ) { npq = nbloc; lcmtnn = 0; }
293 else { npq = nbloc; lcmtnn = lcmt + npq; }
294 if( !FirstD ) *IOFF += lcmt;
298 tmp2 = ( ( tmp1 = nbloc + lcmt ) > 0 ? tmp1 : 0 );
299 if( tmp2 < imbloc ) { npq = tmp2; lcmtnn = npq; }
300 else if ( tmp2 == imbloc ) { npq = tmp2; lcmtnn = 0; }
301 else { npq = imbloc; lcmtnn = lcmt - npq; }
302 if( !FirstD ) *JOFF -= lcmt;
308 md = mcur; nd = ncurd; FirstD = 1;
313 if( RowCont ) *NRPQ += npq;
314 if( ColCont ) *NCPQ += npq;
318 lcmt00 = lcmt; lcmt += qnb; ncur = ncurd++;
323 lcmt00 -= iupp - upp + pmb; mcur++;
324 if( !FirstD ) *IOFF += imbloc;
331 while( ( RowCont || ColCont ) && ( ncur < nblks ) )
333 if( ncur == nblks-1 ) nbloc = lnbloc;
338 while( ( mcur < mblks ) && ( lcmt00 > upp ) )
342 if( !FirstD ) *IOFF += mb;
347 if( mcur >= mblks )
goto l_end;
354 lcmt = lcmt00; mbloc = mb; mcurd = mcur;
356 while( ( mcurd < mblks ) && ( lcmt >= low ) )
358 if( mcurd == mblks-1 ) mbloc = lmbloc;
367 ( ( ( mcurd == md+1 ) && ( lcmtnn <= 0 ) && ( lcmt <= 0 ) ) ||
368 ( ( mcurd == md ) && ( ncur == nd+1 ) && ( lcmtnn == lcmt ) ) );
370 ( ( ( ncur == nd+1 ) && ( lcmtnn >= 0 ) && ( lcmt >= 0 ) ) ||
371 ( ( ncur == nd ) && ( mcurd == md+1 ) && ( lcmtnn == lcmt ) ) );
379 tmp2 = ( ( tmp1 = mbloc - lcmt ) > 0 ? tmp1 : 0 );
380 if( tmp2 < nbloc ) { npq = tmp2; lcmtnn = -npq; }
381 else if ( tmp2 == nbloc ) { npq = nbloc; lcmtnn = 0; }
382 else { npq = nbloc; lcmtnn = lcmt + npq; }
383 if( !FirstD ) *IOFF += lcmt;
387 tmp2 = ( ( tmp1 = nbloc + lcmt ) > 0 ? tmp1 : 0 );
388 if( tmp2 < mbloc ) { npq = tmp2; lcmtnn = npq; }
389 else if ( tmp2 == mbloc ) { npq = tmp2; lcmtnn = 0; }
390 else { npq = mbloc; lcmtnn = lcmt - npq; }
391 if( !FirstD ) *JOFF -= lcmt;
397 md = mcurd; nd = ncur; FirstD = 1;
402 if( RowCont ) *NRPQ += npq;
403 if( ColCont ) *NCPQ += npq;
415 lcmt00 += qnb; ncur++;
416 if( !FirstD ) *JOFF += nb;
423 if( !FirstD ) { *IOFF = 0; *JOFF = 0; }