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