OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
pstrmrdrv.c File Reference
#include "redist.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <varargs.h>

Go to the source code of this file.

Data Structures

struct  MDESC
struct  IDESC

Macros

#define static2   static
#define fortran_mr2d   pstrmr2do
#define fortran_mr2dnew   pstrmr2d
#define scopy_   scopy
#define slacpy_   slacpy
#define Clacpy   Cstrlacpy
#define BLOCK_CYCLIC_2D   1
#define SHIFT(row, sprow, nbrow)
#define max(A, B)
#define min(A, B)
#define DIVUP(a, b)
#define ROUNDUP(a, b)
#define scanD0   strscanD0
#define dispmat   strdispmat
#define setmemory   strsetmemory
#define freememory   strfreememory
#define scan_intervals   strscan_intervals
#define SENDBUFF   0
#define RECVBUFF   1
#define SIZEBUFF   2
#define NDEBUG
#define nbparameter   24

Functions

void Cblacs_pcoord ()
Int Cblacs_pnum ()
void Csetpvmtids ()
void Cblacs_get ()
void Cblacs_pinfo ()
void Cblacs_gridinfo ()
void Cblacs_gridinit ()
void Cblacs_exit ()
void Cblacs_gridexit ()
void Cblacs_setup ()
void Cigebs2d ()
void Cigebr2d ()
void Cigesd2d ()
void Cigerv2d ()
void Cigsum2d ()
void Cigamn2d ()
void Cigamx2d ()
void Csgesd2d ()
void Csgerv2d ()
Int localindice ()
void * mr2d_malloc ()
Int ppcm ()
Int localsize ()
Int memoryblocksize ()
Int changeorigin ()
void paramcheck ()
void Cpstrmr2do ()
void Cpstrmr2d ()
static2 void initblock (float *block, Int m, Int n)
static void getparam (va_alist)
void initforpvm (Int argc, char *argv[])
int main (int argc, char *argv[])

Macro Definition Documentation

◆ BLOCK_CYCLIC_2D

#define BLOCK_CYCLIC_2D   1

Definition at line 88 of file pstrmrdrv.c.

◆ Clacpy

#define Clacpy   Cstrlacpy

Definition at line 75 of file pstrmrdrv.c.

◆ dispmat

#define dispmat   strdispmat

Definition at line 135 of file pstrmrdrv.c.

◆ DIVUP

#define DIVUP ( a,
b )
Value:
( ((a)-1) /(b)+1)

Definition at line 96 of file pstrmrdrv.c.

◆ fortran_mr2d

#define fortran_mr2d   pstrmr2do

Definition at line 70 of file pstrmrdrv.c.

◆ fortran_mr2dnew

#define fortran_mr2dnew   pstrmr2d

Definition at line 71 of file pstrmrdrv.c.

◆ freememory

#define freememory   strfreememory

Definition at line 137 of file pstrmrdrv.c.

◆ max

#define max ( A,
B )
Value:
((A)>(B)?(A):(B))

Definition at line 94 of file pstrmrdrv.c.

◆ min

#define min ( A,
B )
Value:
((A)>(B)?(B):(A))

Definition at line 95 of file pstrmrdrv.c.

◆ nbparameter

#define nbparameter   24

◆ NDEBUG

#define NDEBUG

Definition at line 154 of file pstrmrdrv.c.

◆ RECVBUFF

#define RECVBUFF   1

Definition at line 148 of file pstrmrdrv.c.

◆ ROUNDUP

#define ROUNDUP ( a,
b )
Value:
(DIVUP(a,b)*(b))
#define DIVUP(a, b)
Definition pcgemr.c:182

Definition at line 97 of file pstrmrdrv.c.

◆ scan_intervals

#define scan_intervals   strscan_intervals

Definition at line 138 of file pstrmrdrv.c.

◆ scanD0

#define scanD0   strscanD0

Definition at line 134 of file pstrmrdrv.c.

◆ scopy_

#define scopy_   scopy

Definition at line 72 of file pstrmrdrv.c.

◆ SENDBUFF

#define SENDBUFF   0

Definition at line 147 of file pstrmrdrv.c.

◆ setmemory

#define setmemory   strsetmemory

Definition at line 136 of file pstrmrdrv.c.

◆ SHIFT

#define SHIFT ( row,
sprow,
nbrow )
Value:
((row)-(sprow)+ ((row) >= (sprow) ? 0 : (nbrow)))

Definition at line 93 of file pstrmrdrv.c.

◆ SIZEBUFF

#define SIZEBUFF   2

Definition at line 149 of file pstrmrdrv.c.

◆ slacpy_

#define slacpy_   slacpy

Definition at line 73 of file pstrmrdrv.c.

◆ static2

#define static2   static

Definition at line 60 of file pstrmrdrv.c.

Function Documentation

◆ Cblacs_exit()

void Cblacs_exit ( )
extern

◆ Cblacs_get()

void Cblacs_get ( )
extern

◆ Cblacs_gridexit()

void Cblacs_gridexit ( )
extern

◆ Cblacs_gridinfo()

void Cblacs_gridinfo ( )
extern

◆ Cblacs_gridinit()

void Cblacs_gridinit ( )
extern

◆ Cblacs_pcoord()

void Cblacs_pcoord ( )
extern

◆ Cblacs_pinfo()

void Cblacs_pinfo ( )
extern

◆ Cblacs_pnum()

Int Cblacs_pnum ( )
extern

◆ Cblacs_setup()

void Cblacs_setup ( )
extern

◆ changeorigin()

Int changeorigin ( )
extern

◆ Cigamn2d()

void Cigamn2d ( )
extern

◆ Cigamx2d()

void Cigamx2d ( )
extern

◆ Cigebr2d()

void Cigebr2d ( )
extern

◆ Cigebs2d()

void Cigebs2d ( )
extern

◆ Cigerv2d()

void Cigerv2d ( )
extern

◆ Cigesd2d()

void Cigesd2d ( )
extern

◆ Cigsum2d()

void Cigsum2d ( )
extern

◆ Cpstrmr2d()

void Cpstrmr2d ( )
extern

◆ Cpstrmr2do()

void Cpstrmr2do ( )
extern

◆ Csetpvmtids()

void Csetpvmtids ( )
extern

◆ Csgerv2d()

void Csgerv2d ( )
extern

◆ Csgesd2d()

void Csgesd2d ( )
extern

◆ getparam()

void getparam ( va_alist )
static

Definition at line 183 of file pstrmrdrv.c.

185{
186 FILE *f;
187#endif
188 va_list ap;
189 Int i;
190 static Int nbline;
191 char *ptr, *next;
192 Int *var;
193 static char buffer[200];
194#ifdef __STDC__
195 va_start(ap, f);
196#else
197 va_start(ap);
198 f = va_arg(ap, FILE *);
199#endif
200 do {
201 next = fgets(buffer, 200, f);
202 if (next == NULL) {
203 fprintf(stderr, "bad configuration driver file:after line %d\n", nbline);
204 exit(1);
205 }
206 nbline += 1;
207 } while (buffer[0] == '#');
208 ptr = buffer;
209 var = va_arg(ap, Int *);
210 while (var != NULL) {
211 *var = strtol(ptr, &next, 10);
212 if (ptr == next) {
213 fprintf(stderr, "bad configuration driver file:error line %d\n", nbline);
214 exit(1);
215 }
216 ptr = next;
217 var = va_arg(ap, Int *);
218 }
219 va_end(ap);
220}
#define Int
Definition Bconfig.h:22

◆ initblock()

static2 void initblock ( float * block,
Int m,
Int n )

Definition at line 164 of file pstrmrdrv.c.

165{
166 float *pdata;
167 Int i;
168 pdata = block;
169 for (i = 0; i < m * n; i++, pdata++) {
170 (*pdata) = i;
171 };
172}
n

◆ initforpvm()

void initforpvm ( Int argc,
char * argv[] )

Definition at line 222 of file pstrmrdrv.c.

223{
224 Int pnum, nproc;
225 Cblacs_pinfo(&pnum, &nproc);
226 if (nproc < 1) { /* we are with PVM */
227 if (pnum == 0) {
228 if (argc < 2) {
229 fprintf(stderr, "usage with PVM:xstrmr nbproc\n\
230\t where nbproc is the number of nodes to initialize\n");
231 exit(1);
232 }
233 nproc = atoi(argv[1]);
234 }
235 Cblacs_setup(&pnum, &nproc);
236 }
237}
void Cblacs_pinfo()
void Cblacs_setup()

◆ localindice()

Int localindice ( )
extern

◆ localsize()

Int localsize ( )
extern

◆ main()

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

Definition at line 239 of file pstrmrdrv.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 float *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// STRMR2D TESTER for REAL //\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(float));
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 Cpstrmr2d(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 Cpstrmr2d(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 };
466 };
467 if (nberrors > 0) {
468 printf("Processor %d, has tested %d REAL elements,\
469Number of redistribution errors = %d \n",
470 mypnum, blocksize0, nberrors);
471 }
472 }
473 /* Look at the errors on all the processors at this point. */
474 Cigsum2d(gcontext, "All", "H", (Int)1, (Int)1, &nberrors, (Int)1, (Int)0, (Int)0);
475 if (mypnum == 0)
476 if (nberrors)
477 printf(" => Total number of redistribution errors = %d \n",
478 nberrors);
479 else
480 printf("TEST PASSED OK\n");
481 /* release memory for the next iteration */
482 if (myprow0 >= 0 && mypcol0 >= 0) {
483 freememory((char *) ptrmyblock);
484 freememory((char *) ptrmyblockvide);
485 freememory((char *) ptrmyblockcopy);
486 }; /* if (mypnum < p0 * q0) */
487 /* release memory for the next iteration */
488 if (myprow1 >= 0 && mypcol1 >= 0) {
489 freememory((char *) ptrsavemyblock);
490 };
491 if (myprow0 >= 0)
492 Cblacs_gridexit(context0);
493 if (myprow1 >= 0)
494 Cblacs_gridexit(context1);
495 }; /* while nbre != 0 */
496 if (mypnum == 0) {
497 fclose(fp);
498 };
499 Cblacs_exit((Int)0);
500 return 0;
501}/* main */
#define BLOCK_CYCLIC_2D
Definition PBtools.h:20
LIBSEQ_INT LIBSEQ_CALL MPI_Init(LIBSEQ_INT *pargc, char ***pargv)
Definition mpic.c:18
integer, save, private nprocs
Definition cmumps_load.F:57
#define SHIFT(row, sprow, nbrow)
Definition pcgemr.c:179
#define nbparameter
Int memoryblocksize()
static2 void initblock(float *block, Int m, Int n)
Definition pstrmrdrv.c:164
#define freememory
Definition pstrmrdrv.c:137
#define SHIFT(row, sprow, nbrow)
Definition pstrmrdrv.c:93
void Cblacs_gridexit()
#define max(A, B)
Definition pstrmrdrv.c:94
void Cigsum2d()
Int localsize()
#define setmemory
Definition pstrmrdrv.c:136
void Cblacs_get()
void Cigebs2d()
static void getparam(va_alist)
Definition pstrmrdrv.c:183
void Cblacs_gridinit()
void Cblacs_gridinfo()
void initforpvm(Int argc, char *argv[])
Definition pstrmrdrv.c:222
void Cpstrmr2d()
void Cigebr2d()
void Cblacs_exit()
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

◆ memoryblocksize()

Int memoryblocksize ( )
extern

◆ mr2d_malloc()

void * mr2d_malloc ( )
extern

◆ paramcheck()

void paramcheck ( )
extern

◆ ppcm()

Int ppcm ( )
extern