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

◆ main()

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

Definition at line 243 of file pztrmrdrv.c.

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