ScaLAPACK 2.1  2.1 ScaLAPACK: Scalable Linear Algebra PACKage
pzgemr2.c
Go to the documentation of this file.
1 #include "redist.h"
2 /* \$Id: pzgemr2.c,v 1.1.1.1 2000/02/15 18:04:10 susan Exp \$
3  *
4  * some functions used by the pzgemr2d routine see file pzgemr.c for more
5  * documentation.
6  *
7  * Created March 1993 by B. Tourancheau (See sccs for modifications). */
8 #define static2 static
10 #define fortran_mr2d pzgemr2do_
11 #define fortran_mr2dnew pzgemr2d_
12 #elif defined(UpCase)
13 #define fortran_mr2dnew PZGEMR2D
14 #define fortran_mr2d PZGEMR2DO
15 #define zcopy_ ZCOPY
16 #define zlacpy_ ZLACPY
17 #else
18 #define fortran_mr2d pzgemr2do
19 #define fortran_mr2dnew pzgemr2d
20 #define zcopy_ zcopy
21 #define zlacpy_ zlacpy
22 #endif
23 #define Clacpy Czgelacpy
24 void Clacpy();
25 typedef struct {
26  double r, i;
27 } dcomplex;
28 typedef struct {
29  int desctype;
30  int ctxt;
31  int m;
32  int n;
33  int nbrow;
34  int nbcol;
35  int sprow;
36  int spcol;
37  int lda;
38 } MDESC;
39 #define BLOCK_CYCLIC_2D 1
40 typedef struct {
41  int lstart;
42  int len;
43 } IDESC;
44 #define SHIFT(row,sprow,nbrow) ((row)-(sprow)+ ((row) >= (sprow) ? 0 : (nbrow)))
45 #define max(A,B) ((A)>(B)?(A):(B))
46 #define min(A,B) ((A)>(B)?(B):(A))
47 #define DIVUP(a,b) ( ((a)-1) /(b)+1)
48 #define ROUNDUP(a,b) (DIVUP(a,b)*(b))
49 #ifdef MALLOCDEBUG
50 #define malloc mymalloc
51 #define free myfree
52 #define realloc myrealloc
53 #endif
54 /* Cblacs */
55 extern void Cblacs_pcoord();
56 extern int Cblacs_pnum();
57 extern void Csetpvmtids();
58 extern void Cblacs_get();
59 extern void Cblacs_pinfo();
60 extern void Cblacs_gridinfo();
61 extern void Cblacs_gridinit();
62 extern void Cblacs_exit();
63 extern void Cblacs_gridexit();
64 extern void Cblacs_setup();
65 extern void Cigebs2d();
66 extern void Cigebr2d();
67 extern void Cigesd2d();
68 extern void Cigerv2d();
69 extern void Cigsum2d();
70 extern void Cigamn2d();
71 extern void Cigamx2d();
72 extern void Czgesd2d();
73 extern void Czgerv2d();
74 /* lapack */
75 void zlacpy_();
76 /* aux fonctions */
77 extern int localindice();
78 extern void *mr2d_malloc();
79 extern int ppcm();
80 extern int localsize();
81 extern int memoryblocksize();
82 extern int changeorigin();
83 extern void paramcheck();
84 /* tools and others function */
85 #define scanD0 zgescanD0
86 #define dispmat zgedispmat
87 #define setmemory zgesetmemory
88 #define freememory zgefreememory
89 #define scan_intervals zgescan_intervals
90 extern void scanD0();
91 extern void dispmat();
92 extern void setmemory();
93 extern void freememory();
94 extern int scan_intervals();
95 extern void Cpzgemr2do();
96 extern void Cpzgemr2d();
97 /* some defines for Cpzgemr2do */
98 #define SENDBUFF 0
99 #define RECVBUFF 1
100 #define SIZEBUFF 2
101 #if 0
102 #define DEBUG
103 #endif
104 #ifndef DEBUG
105 #define NDEBUG
106 #endif
107 #include <stdio.h>
108 #include <stdlib.h>
109 #include <string.h>
110 #include <assert.h>
111 #include <ctype.h>
112 /* Created March 1993 by B. Tourancheau (See sccs for modifications). */
113 /************************************************************************/
114 /* Set the memory space with the malloc function */
115 void
118  int blocksize;
119 {
120  assert(blocksize >= 0);
121  if (blocksize == 0) {
123  return;
124  }
125  *adpointer = (dcomplex *) mr2d_malloc(
126  blocksize * sizeof(dcomplex));
127 }
128 /******************************************************************/
129 /* Free the memory space after the malloc */
130 void
131 freememory(ptrtobefreed)
132  dcomplex *ptrtobefreed;
133 {
134  if (ptrtobefreed == NULL)
135  return;
136  free((char *) ptrtobefreed);
137 }
138 /* extern functions for intersect() extern zcopy_(); */
139 /* scan_intervals: scans two distributions in one dimension, and compute the
140  * intersections on the local processor. result must be long enough to
141  * contains the result that are stocked in IDESC structure, the function
142  * returns the number of intersections found */
143 int
144 scan_intervals(type, ja, jb, n, ma, mb, q0, q1, col0, col1,
145  result)
146  char type;
147  int ja, jb, n, q0, q1, col0, col1;
148  MDESC *ma, *mb;
149  IDESC *result;
150 {
151  int offset, j0, j1, templatewidth0, templatewidth1, nbcol0, nbcol1;
152  int l; /* local indice on the beginning of the interval */
153  assert(type == 'c' || type == 'r');
154  nbcol0 = (type == 'c' ? ma->nbcol : ma->nbrow);
155  nbcol1 = (type == 'c' ? mb->nbcol : mb->nbrow);
156  templatewidth0 = q0 * nbcol0;
157  templatewidth1 = q1 * nbcol1;
158  {
159  int sp0 = (type == 'c' ? ma->spcol : ma->sprow);
160  int sp1 = (type == 'c' ? mb->spcol : mb->sprow);
161  j0 = SHIFT(col0, sp0, q0) * nbcol0 - ja;
162  j1 = SHIFT(col1, sp1, q1) * nbcol1 - jb;
163  }
164  offset = 0;
165  l = 0;
166  /* a small check to verify that the submatrix begin inside the first block
167  * of the original matrix, this done by a sort of coordinate change at the
168  * beginning of the Cpzgemr2d */
169  assert(j0 + nbcol0 > 0);
170  assert(j1 + nbcol1 > 0);
171  while ((j0 < n) && (j1 < n)) {
172  int end0, end1;
173  int start, end;
174  end0 = j0 + nbcol0;
175  end1 = j1 + nbcol1;
176  if (end0 <= j1) {
177  j0 += templatewidth0;
178  l += nbcol0;
179  continue;
180  }
181  if (end1 <= j0) {
182  j1 += templatewidth1;
183  continue;
184  }
185  /* compute the raw intersection */
186  start = max(j0, j1);
187  start = max(start, 0);
188  /* the start is correct now, update the corresponding fields */
189  result[offset].lstart = l + start - j0;
190  end = min(end0, end1);
191  if (end0 == end) {
192  j0 += templatewidth0;
193  l += nbcol0;
194  }
195  if (end1 == end)
196  j1 += templatewidth1;
197  /* throw the limit if they go out of the matrix */
198  end = min(end, n);
199  assert(end > start);
200  /* it is a bit tricky to see why the length is always positive after all
201  * this min and max, first we have the property that every interval
202  * considered is at least partly into the submatrix, second we arrive
203  * here only if the raw intersection is non-void, if we remove a limit
204  * that means the corresponding frontier is in both intervals which
205  * proove the final interval is non-void, clear ?? */
206  result[offset].len = end - start;
207  offset += 1;
208  } /* while */
209  return offset;
210 }
IDESC::lstart
int lstart
Definition: pcgemr.c:176
Cigebs2d
void Cigebs2d()
Cblacs_gridexit
void Cblacs_gridexit()
Cigamn2d
void Cigamn2d()
Clacpy
#define Clacpy
Definition: pzgemr2.c:23
localsize
int localsize()
memoryblocksize
int memoryblocksize()
Cblacs_exit
void Cblacs_exit()
Cigerv2d
void Cigerv2d()
scanD0
#define scanD0
Definition: pzgemr2.c:85
Cblacs_gridinit
void Cblacs_gridinit()
ppcm
int ppcm()
Cblacs_gridinfo
void Cblacs_gridinfo()
MDESC::sprow
int sprow
Definition: pcgemr.c:170
MDESC::nbcol
int nbcol
Definition: pcgemr.c:169
MDESC
Definition: pcgemr.c:163
Cpzgemr2do
void Cpzgemr2do()
changeorigin
int changeorigin()
Cigsum2d
void Cigsum2d()
zlacpy_
#define zlacpy_
Definition: pzgemr2.c:21
Cigamx2d
void Cigamx2d()
min
#define min(A, B)
Definition: pzgemr2.c:46
scan_intervals
#define scan_intervals
Definition: pzgemr2.c:89
Cblacs_pcoord
void Cblacs_pcoord()
mr2d_malloc
void * mr2d_malloc()
SHIFT
#define SHIFT(row, sprow, nbrow)
Definition: pzgemr2.c:44
IDESC
Definition: pcgemr.c:175
setmemory
#define setmemory
Definition: pzgemr2.c:87
Cigebr2d
void Cigebr2d()
dispmat
#define dispmat
Definition: pzgemr2.c:86
Cblacs_get
void Cblacs_get()
MDESC::spcol
int spcol
Definition: pcgemr.c:171
redist.h
max
#define max(A, B)
Definition: pzgemr2.c:45
Cblacs_pinfo
void Cblacs_pinfo()
Czgesd2d
void Czgesd2d()
paramcheck
void paramcheck()
Cblacs_pnum
int Cblacs_pnum()
localindice
int localindice()
Cblacs_setup
void Cblacs_setup()
dcomplex
Definition: pzgemr.c:160
IDESC::len
int len
Definition: pcgemr.c:177
Csetpvmtids
void Csetpvmtids()
Cigesd2d
void Cigesd2d()
Czgerv2d
void Czgerv2d()
Cpzgemr2d
void Cpzgemr2d()
MDESC::nbrow
int nbrow
Definition: pcgemr.c:168
freememory
#define freememory
Definition: pzgemr2.c:88