ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
pcgemr2.c
Go to the documentation of this file.
1 #include "redist.h"
2 /* $Id: pcgemr2.c,v 1.1.1.1 2000/02/15 18:04:09 susan Exp $
3  *
4  * some functions used by the pcgemr2d routine see file pcgemr.c for more
5  * documentation.
6  *
7  * Created March 1993 by B. Tourancheau (See sccs for modifications). */
8 #define static2 static
9 #if defined(Add_) || defined(f77IsF2C)
10 #define fortran_mr2d pcgemr2do_
11 #define fortran_mr2dnew pcgemr2d_
12 #elif defined(UpCase)
13 #define fortran_mr2dnew PCGEMR2D
14 #define fortran_mr2d PCGEMR2DO
15 #define ccopy_ CCOPY
16 #define clacpy_ CLACPY
17 #else
18 #define fortran_mr2d pcgemr2do
19 #define fortran_mr2dnew pcgemr2d
20 #define ccopy_ ccopy
21 #define clacpy_ clacpy
22 #endif
23 #define Clacpy Ccgelacpy
24 void Clacpy();
25 typedef struct {
26  float r, i;
27 } complex;
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 Ccgesd2d();
73 extern void Ccgerv2d();
74 /* lapack */
75 void clacpy_();
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 cgescanD0
86 #define dispmat cgedispmat
87 #define setmemory cgesetmemory
88 #define freememory cgefreememory
89 #define scan_intervals cgescan_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 Cpcgemr2do();
96 extern void Cpcgemr2d();
97 /* some defines for Cpcgemr2do */
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
116 setmemory(adpointer, blocksize)
117  complex **adpointer;
118  int blocksize;
119 {
120  assert(blocksize >= 0);
121  if (blocksize == 0) {
122  *adpointer = NULL;
123  return;
124  }
125  *adpointer = (complex *) mr2d_malloc(
126  blocksize * sizeof(complex));
127 }
128 /******************************************************************/
129 /* Free the memory space after the malloc */
130 void
131 freememory(ptrtobefreed)
132  complex *ptrtobefreed;
133 {
134  if (ptrtobefreed == NULL)
135  return;
136  free((char *) ptrtobefreed);
137 }
138 /* extern functions for intersect() extern ccopy_(); */
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 Cpcgemr2d */
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
Cblacs_pcoord
void Cblacs_pcoord()
freememory
#define freememory
Definition: pcgemr2.c:88
paramcheck
void paramcheck()
scanD0
#define scanD0
Definition: pcgemr2.c:85
dispmat
#define dispmat
Definition: pcgemr2.c:86
changeorigin
int changeorigin()
ppcm
int ppcm()
Cpcgemr2d
void Cpcgemr2d()
Cblacs_gridinit
void Cblacs_gridinit()
Cigesd2d
void Cigesd2d()
Ccgesd2d
void Ccgesd2d()
Ccgerv2d
void Ccgerv2d()
MDESC::sprow
int sprow
Definition: pcgemr.c:170
MDESC::nbcol
int nbcol
Definition: pcgemr.c:169
Cpcgemr2do
void Cpcgemr2do()
MDESC
Definition: pcgemr.c:163
Cigsum2d
void Cigsum2d()
localsize
int localsize()
clacpy_
#define clacpy_
Definition: pcgemr2.c:21
Cblacs_exit
void Cblacs_exit()
min
#define min(A, B)
Definition: pcgemr2.c:46
Clacpy
#define Clacpy
Definition: pcgemr2.c:23
SHIFT
#define SHIFT(row, sprow, nbrow)
Definition: pcgemr2.c:44
scan_intervals
#define scan_intervals
Definition: pcgemr2.c:89
Cblacs_gridexit
void Cblacs_gridexit()
IDESC
Definition: pcgemr.c:175
Cigebr2d
void Cigebr2d()
localindice
int localindice()
Cblacs_get
void Cblacs_get()
Cigamn2d
void Cigamn2d()
MDESC::spcol
int spcol
Definition: pcgemr.c:171
Cblacs_pinfo
void Cblacs_pinfo()
redist.h
max
#define max(A, B)
Definition: pcgemr2.c:45
Cigebs2d
void Cigebs2d()
mr2d_malloc
void * mr2d_malloc()
memoryblocksize
int memoryblocksize()
IDESC::len
int len
Definition: pcgemr.c:177
MDESC::nbrow
int nbrow
Definition: pcgemr.c:168
Cblacs_pnum
int Cblacs_pnum()
Cblacs_gridinfo
void Cblacs_gridinfo()
setmemory
#define setmemory
Definition: pcgemr2.c:87
Cblacs_setup
void Cblacs_setup()
complex
Definition: pcgemr.c:160
Cigamx2d
void Cigamx2d()
Csetpvmtids
void Csetpvmtids()
Cigerv2d
void Cigerv2d()