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

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 239 of file pitrmrdrv.c.

240{
241 /* We initialize the data-block on the current processor, then redistribute
242 * it, and perform the inverse redistribution to compare the local memory
243 * with the initial one. */
244 /* Data file */
245 FILE *fp;
246 Int nbre, nbremax;
247 /* Data distribution 0 parameters */
248 Int p0, /* # of rows in the processor grid */
249 q0; /* # of columns in the processor grid */
250 /* Data distribution 1 parameters */
251 Int p1, q1;
252 /* # of parameter to be read on the keyboard */
253#define nbparameter 24
254 /* General variables */
255 Int blocksize0;
256 Int mypnum, nprocs;
257 Int parameters[nbparameter], nberrors;
258 Int i;
259 Int ia, ja, ib, jb, m, n;
260 Int gcontext, context0, context1;
261 Int myprow1, myprow0, mypcol0, mypcol1;
262 Int dummy;
263 MDESC ma, mb;
264 char *uplo, *diag;
265 Int *ptrmyblock, *ptrsavemyblock, *ptrmyblockcopy, *ptrmyblockvide;
266#ifdef UsingMpiBlacs
267 MPI_Init(&argc, &argv);
268#endif
269 setvbuf(stdout, NULL, _IOLBF, 0);
270 setvbuf(stderr, NULL, _IOLBF, 0);
271#ifdef T3D
272 free(malloc(14000000));
273#endif
274 initforpvm(argc, argv);
275 /* Read physical parameters */
276 Cblacs_pinfo(&mypnum, &nprocs);
277 /* initialize BLACS for the parameter communication */
278 Cblacs_get((Int)0, (Int)0, &gcontext);
279 Cblacs_gridinit(&gcontext, "R", nprocs, (Int)1);
280 Cblacs_gridinfo(gcontext, &dummy, &dummy, &mypnum, &dummy);
281 if (mypnum == 0) {
282 if ((fp = fopen("TRMR2D.dat", "r")) == NULL) {
283 fprintf(stderr, "Can't open TRMR2D.dat\n");
284 exit(1);
285 };
286 printf("\n// ITRMR2D TESTER for INTEGER //\n");
287 getparam(fp, &nbre, NULL);
288 printf("////////// %d tests \n\n", nbre);
289 parameters[0] = nbre;
290 Cigebs2d(gcontext, "All", "H", (Int)1, (Int)1, parameters, (Int)1);
291 } else {
292 Cigebr2d(gcontext, "All", "H", (Int)1, (Int)1, parameters, (Int)1, (Int)0, (Int)0);
293 nbre = parameters[0];
294 };
295 if (mypnum == 0) {
296 printf("\n m n m0 n0 sr0 sc0 i0 j0 p0 q0 nbr0 nbc0 \
297m1 n1 sr1 sc1 i1 j1 p1 q1 nbr1 nbc1\n\n");
298 };
299 /****** TEST LOOP *****/
300 /* Here we are in grip 1xnprocs */
301 nbremax = nbre;
302#ifdef DEBUG
303 fprintf(stderr, "bonjour,je suis le noeud %d\n", mypnum);
304#endif
305 while (nbre-- != 0) { /* Loop on the serie of tests */
306 /* All the processors read the parameters so we have to be in a 1xnprocs
307 * grid at each iteration */
308 /* Read processors grid and matrices parameters */
309 if (mypnum == 0) {
310 Int u, d;
311 getparam(fp,
312 &m, &n,
313 &ma.m, &ma.n, &ma.sprow, &ma.spcol,
314 &ia, &ja, &p0, &q0, &ma.nbrow, &ma.nbcol,
315 &mb.m, &mb.n, &mb.sprow, &mb.spcol,
316 &ib, &jb, &p1, &q1, &mb.nbrow, &mb.nbcol,
317 &u, &d,
318 NULL);
319 uplo = u ? "UPPER" : "LOWER";
320 diag = d ? "UNIT" : "NONUNIT";
321 printf("\t\t************* TEST # %d **********\n",
322 nbremax - nbre);
323 printf(" %3d %3d %3d %3d %3d %3d %3d %3d \
324%3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d",
325 m, n,
326 ma.m, ma.n, ma.sprow, ma.spcol,
327 ia, ja, p0, q0, ma.nbrow, ma.nbcol,
328 mb.m, mb.n, mb.sprow, mb.spcol,
329 ib, jb, p1, q1, mb.nbrow, mb.nbcol);
330 printf(" %s %s", toupper(*uplo) == 'U' ? "up" : "low",
331 toupper(*diag) == 'U' ? "unit" : "nonunit");
332 printf("\n");
333 if (p0 * q0 > nprocs || p1 * q1 > nprocs) {
334 fprintf(stderr, "not enough nodes:%d processors required\n",
335 max(p0 * q0, p1 * q1));
336 exit(1);
337 }
338 parameters[0] = p0;
339 parameters[1] = q0;
340 parameters[2] = ma.nbrow;
341 parameters[3] = ma.nbcol;
342 parameters[4] = p1;
343 parameters[5] = q1;
344 parameters[6] = mb.nbrow;
345 parameters[7] = mb.nbcol;
346 parameters[8] = ma.m;
347 parameters[9] = ma.n;
348 parameters[10] = ma.sprow;
349 parameters[11] = ma.spcol;
350 parameters[12] = mb.sprow;
351 parameters[13] = mb.spcol;
352 parameters[14] = ia;
353 parameters[15] = ja;
354 parameters[16] = ib;
355 parameters[17] = jb;
356 parameters[18] = m;
357 parameters[19] = n;
358 parameters[20] = mb.m;
359 parameters[21] = mb.n;
360 parameters[22] = *uplo == 'U';
361 parameters[23] = *diag == 'U';
362 Cigebs2d(gcontext, "All", "H", (Int)1, nbparameter, parameters, (Int)1);
363 } else {
364 Cigebr2d(gcontext, "All", "H", (Int)1, nbparameter, parameters, (Int)1, (Int)0, (Int)0);
365 p0 = parameters[0];
366 q0 = parameters[1];
367 ma.nbrow = parameters[2];
368 ma.nbcol = parameters[3];
369 p1 = parameters[4];
370 q1 = parameters[5];
371 mb.nbrow = parameters[6];
372 mb.nbcol = parameters[7];
373 ma.m = parameters[8];
374 ma.n = parameters[9];
375 ma.sprow = parameters[10];
376 ma.spcol = parameters[11];
377 mb.sprow = parameters[12];
378 mb.spcol = parameters[13];
379 ia = parameters[14];
380 ja = parameters[15];
381 ib = parameters[16];
382 jb = parameters[17];
383 m = parameters[18];
384 n = parameters[19];
385 mb.m = parameters[20];
386 mb.n = parameters[21];
389 uplo = parameters[22] ? "UPPER" : "LOWER";
390 diag = parameters[23] ? "UNIT" : "NONUNIT";
391 };
392 Cblacs_get((Int)0, (Int)0, &context0);
393 Cblacs_gridinit(&context0, "R", p0, q0);
394 Cblacs_get((Int)0, (Int)0, &context1);
395 Cblacs_gridinit(&context1, "R", p1, q1);
396 Cblacs_gridinfo(context0, &dummy, &dummy, &myprow0, &mypcol0);
397 if (myprow0 >= p0 || mypcol0 >= q0)
398 myprow0 = mypcol0 = -1;
399 Cblacs_gridinfo(context1, &dummy, &dummy, &myprow1, &mypcol1);
400 if (myprow1 >= p1 || mypcol1 >= q1)
401 myprow1 = mypcol1 = -1;
402 assert((myprow0 < p0 && mypcol0 < q0) || (myprow0 == -1 && mypcol0 == -1));
403 assert((myprow1 < p1 && mypcol1 < q1) || (myprow1 == -1 && mypcol1 == -1));
404 ma.ctxt = context0;
405 mb.ctxt = context1;
406 /* From here, we are not assuming that only the processors working in the
407 * redistribution are calling xxMR2D, but the ones not concerned will do
408 * nothing. */
409 /* We compute the exact size of the local memory block for the memory
410 * allocations */
411 if (myprow0 >= 0 && mypcol0 >= 0) {
412 blocksize0 = memoryblocksize(&ma);
413 ma.lda = localsize(SHIFT(myprow0, ma.sprow, p0), p0, ma.nbrow, ma.m);
414 setmemory(&ptrmyblock, blocksize0);
415 initblock(ptrmyblock, 1, blocksize0);
416 setmemory(&ptrmyblockcopy, blocksize0);
417 memcpy((char *) ptrmyblockcopy, (char *) ptrmyblock,
418 blocksize0 * sizeof(Int));
419 setmemory(&ptrmyblockvide, blocksize0);
420 for (i = 0; i < blocksize0; i++)
421 ptrmyblockvide[i] = -1;
422 }; /* if (mypnum < p0 * q0) */
423 if (myprow1 >= 0 && mypcol1 >= 0) {
424 setmemory(&ptrsavemyblock, memoryblocksize(&mb));
425 mb.lda = localsize(SHIFT(myprow1, mb.sprow, p1), p1, mb.nbrow, mb.m);
426 }; /* if (mypnum < p1 * q1) */
427 /* Redistribute the matrix from grid 0 to grid 1 (memory location
428 * ptrmyblock to ptrsavemyblock) */
429 Cpitrmr2d(uplo, diag, m, n,
430 ptrmyblock, ia, ja, &ma,
431 ptrsavemyblock, ib, jb, &mb, gcontext);
432 /* Perform the inverse redistribution of the matrix from grid 1 to grid 0
433 * (memory location ptrsavemyblock to ptrmyblockvide) */
434 Cpitrmr2d(uplo, diag, m, n,
435 ptrsavemyblock, ib, jb, &mb,
436 ptrmyblockvide, ia, ja, &ma, gcontext);
437 /* Check the differences */
438 nberrors = 0;
439 if (myprow0 >= 0 && mypcol0 >= 0) {
440 /* only for the processors that do have data at the begining */
441 for (i = 0; i < blocksize0; i++) {
442 Int li, lj, gi, gj;
443 Int in;
444 in = 1;
445 li = i % ma.lda;
446 lj = i / ma.lda;
447 gi = (li / ma.nbrow) * p0 * ma.nbrow +
448 SHIFT(myprow0, ma.sprow, p0) * ma.nbrow + li % ma.nbrow;
449 gj = (lj / ma.nbcol) * q0 * ma.nbcol +
450 SHIFT(mypcol0, ma.spcol, q0) * ma.nbcol + lj % ma.nbcol;
451 assert(gi < ma.m && gj < ma.n);
452 gi -= (ia - 1);
453 gj -= (ja - 1);
454 if (gi < 0 || gj < 0 || gi >= m || gj >= n)
455 in = 0;
456 else if (toupper(*uplo) == 'U')
457 in = (gi <= gj + max(0, m - n) - (toupper(*diag) == 'U'));
458 else
459 in = (gi >= gj - max(0, n - m) + (toupper(*diag) == 'U'));
460 if (!in) {
461 ptrmyblockcopy[i] = -1;
462 }
463 if (ptrmyblockvide[i] != ptrmyblockcopy[i]) {
464 nberrors++;
465 printf("Proc %d : Error element number %d, value = %d , initvalue =%d \n"
466 ,mypnum, i, ptrmyblockvide[i], ptrmyblockcopy[i]);
467 };
468 };
469 if (nberrors > 0) {
470 printf("Processor %d, has tested %d INTEGER elements,\
471Number of redistribution errors = %d \n",
472 mypnum, blocksize0, nberrors);
473 }
474 }
475 /* Look at the errors on all the processors at this point. */
476 Cigsum2d(gcontext, "All", "H", (Int)1, (Int)1, &nberrors, (Int)1, (Int)0, (Int)0);
477 if (mypnum == 0)
478 if (nberrors)
479 printf(" => Total number of redistribution errors = %d \n",
480 nberrors);
481 else
482 printf("TEST PASSED OK\n");
483 /* release memory for the next iteration */
484 if (myprow0 >= 0 && mypcol0 >= 0) {
485 freememory((char *) ptrmyblock);
486 freememory((char *) ptrmyblockvide);
487 freememory((char *) ptrmyblockcopy);
488 }; /* if (mypnum < p0 * q0) */
489 /* release memory for the next iteration */
490 if (myprow1 >= 0 && mypcol1 >= 0) {
491 freememory((char *) ptrsavemyblock);
492 };
493 if (myprow0 >= 0)
494 Cblacs_gridexit(context0);
495 if (myprow1 >= 0)
496 Cblacs_gridexit(context1);
497 }; /* while nbre != 0 */
498 if (mypnum == 0) {
499 fclose(fp);
500 };
501 Cblacs_exit((Int)0);
502 return 0;
503}/* main */
#define Int
Definition Bconfig.h:22
Int memoryblocksize()
#define freememory
Definition pitrmrdrv.c:137
#define SHIFT(row, sprow, nbrow)
Definition pitrmrdrv.c:93
void Cblacs_gridexit()
#define max(A, B)
Definition pitrmrdrv.c:94
void Cigsum2d()
static2 void initblock(Int *block, Int m, Int n)
Definition pitrmrdrv.c:164
void Cblacs_pinfo()
Int localsize()
#define setmemory
Definition pitrmrdrv.c:136
void Cblacs_get()
void Cigebs2d()
void Cpitrmr2d()
#define BLOCK_CYCLIC_2D
Definition pitrmrdrv.c:88
void Cblacs_gridinit()
void Cblacs_gridinfo()
void initforpvm(Int argc, char *argv[])
Definition pitrmrdrv.c:222
void Cigebr2d()
void Cblacs_exit()
#define nbparameter
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 desctype
Definition pcgemr.c:164
Int n
Definition pcgemr.c:167
Int lda
Definition pcgemr.c:172
Here is the call graph for this function: