OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
pigemrdrv.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   pigemr2do
#define fortran_mr2dnew   pigemr2d
#define icopy_   icopy
#define ilacpy_   ilacpy
#define Clacpy   Cigelacpy
#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   igescanD0
#define dispmat   igedispmat
#define setmemory   igesetmemory
#define freememory   igefreememory
#define scan_intervals   igescan_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 ()
Int localindice ()
void * mr2d_malloc ()
Int ppcm ()
Int localsize ()
Int memoryblocksize ()
Int changeorigin ()
void paramcheck ()
void Cpigemr2do ()
void Cpigemr2d ()
static2 void initblock (Int *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 pigemrdrv.c.

◆ Clacpy

#define Clacpy   Cigelacpy

Definition at line 75 of file pigemrdrv.c.

◆ dispmat

#define dispmat   igedispmat

Definition at line 135 of file pigemrdrv.c.

◆ DIVUP

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

Definition at line 96 of file pigemrdrv.c.

◆ fortran_mr2d

#define fortran_mr2d   pigemr2do

Definition at line 70 of file pigemrdrv.c.

◆ fortran_mr2dnew

#define fortran_mr2dnew   pigemr2d

Definition at line 71 of file pigemrdrv.c.

◆ freememory

#define freememory   igefreememory

Definition at line 137 of file pigemrdrv.c.

◆ icopy_

#define icopy_   icopy

Definition at line 72 of file pigemrdrv.c.

◆ ilacpy_

#define ilacpy_   ilacpy

Definition at line 73 of file pigemrdrv.c.

◆ max

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

Definition at line 94 of file pigemrdrv.c.

◆ min

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

Definition at line 95 of file pigemrdrv.c.

◆ nbparameter

#define nbparameter   24

◆ NDEBUG

#define NDEBUG

Definition at line 154 of file pigemrdrv.c.

◆ RECVBUFF

#define RECVBUFF   1

Definition at line 148 of file pigemrdrv.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 pigemrdrv.c.

◆ scan_intervals

#define scan_intervals   igescan_intervals

Definition at line 138 of file pigemrdrv.c.

◆ scanD0

#define scanD0   igescanD0

Definition at line 134 of file pigemrdrv.c.

◆ SENDBUFF

#define SENDBUFF   0

Definition at line 147 of file pigemrdrv.c.

◆ setmemory

#define setmemory   igesetmemory

Definition at line 136 of file pigemrdrv.c.

◆ SHIFT

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

Definition at line 93 of file pigemrdrv.c.

◆ SIZEBUFF

#define SIZEBUFF   2

Definition at line 149 of file pigemrdrv.c.

◆ static2

#define static2   static

Definition at line 60 of file pigemrdrv.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

◆ Cpigemr2d()

void Cpigemr2d ( )
extern

◆ Cpigemr2do()

void Cpigemr2do ( )
extern

◆ Csetpvmtids()

void Csetpvmtids ( )
extern

◆ getparam()

void getparam ( va_alist )
static

Definition at line 183 of file pigemrdrv.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 ( Int * block,
Int m,
Int n )

Definition at line 164 of file pigemrdrv.c.

165{
166 Int *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 pigemrdrv.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:xigemr 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 pigemrdrv.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 Int *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// IGEMR2D TESTER for INTEGER //\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(int));
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 Cpigemr2d(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 Cpigemr2d(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 printf("Proc %d : Error element number %d, value = %d , initvalue =%d \n"
452 ,mypnum, i, ptrmyblockvide[i], ptrmyblockcopy[i]);
453 };
454 };
455 if (nberrors > 0) {
456 printf("Processor %d, has tested %d INTEGER elements,\
457Number of redistribution errors = %d \n",
458 mypnum, blocksize0, nberrors);
459 }
460 }
461 /* Look at the errors on all the processors at this point. */
462 Cigsum2d(gcontext, "All", "H", (Int)1, (Int)1, &nberrors, (Int)1, (Int)0, (Int)0);
463 if (mypnum == 0)
464 if (nberrors)
465 printf(" => Total number of redistribution errors = %d \n",
466 nberrors);
467 else
468 printf("TEST PASSED OK\n");
469 /* release memory for the next iteration */
470 if (myprow0 >= 0 && mypcol0 >= 0) {
471 freememory((char *) ptrmyblock);
472 freememory((char *) ptrmyblockvide);
473 freememory((char *) ptrmyblockcopy);
474 }; /* if (mypnum < p0 * q0) */
475 /* release memory for the next iteration */
476 if (myprow1 >= 0 && mypcol1 >= 0) {
477 freememory((char *) ptrsavemyblock);
478 };
479 if (myprow0 >= 0)
480 Cblacs_gridexit(context0);
481 if (myprow1 >= 0)
482 Cblacs_gridexit(context1);
483 }; /* while nbre != 0 */
484 if (mypnum == 0) {
485 fclose(fp);
486 };
487 Cblacs_exit((Int)0);
488 return 0;
489}/* 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()
#define freememory
Definition pigemrdrv.c:137
#define SHIFT(row, sprow, nbrow)
Definition pigemrdrv.c:93
void Cblacs_gridexit()
#define max(A, B)
Definition pigemrdrv.c:94
void Cpigemr2d()
void Cigsum2d()
static2 void initblock(Int *block, Int m, Int n)
Definition pigemrdrv.c:164
Int localsize()
#define setmemory
Definition pigemrdrv.c:136
void Cblacs_get()
void Cigebs2d()
static void getparam(va_alist)
Definition pigemrdrv.c:183
void Cblacs_gridinit()
void Cblacs_gridinfo()
void initforpvm(Int argc, char *argv[])
Definition pigemrdrv.c:222
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