SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
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
9#if defined(Add_) || defined(f77IsF2C)
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
24void Clacpy();
25typedef struct {
26 double r, i;
27} dcomplex;
28typedef 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
40typedef 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 */
55extern void Cblacs_pcoord();
57extern void Csetpvmtids();
58extern void Cblacs_get();
59extern void Cblacs_pinfo();
60extern void Cblacs_gridinfo();
61extern void Cblacs_gridinit();
62extern void Cblacs_exit();
63extern void Cblacs_gridexit();
64extern void Cblacs_setup();
65extern void Cigebs2d();
66extern void Cigebr2d();
67extern void Cigesd2d();
68extern void Cigerv2d();
69extern void Cigsum2d();
70extern void Cigamn2d();
71extern void Cigamx2d();
72extern void Czgesd2d();
73extern void Czgerv2d();
74/* lapack */
75void zlacpy_();
76/* aux fonctions */
78extern void *mr2d_malloc();
79extern Int ppcm();
80extern Int localsize();
83extern 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
90extern void scanD0();
91extern void dispmat();
92extern void setmemory();
93extern void freememory();
94extern Int scan_intervals();
95extern void Cpzgemr2do();
96extern 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 */
115void
116setmemory(dcomplex **adpointer, Int blocksize)
117{
118 assert(blocksize >= 0);
119 if (blocksize == 0) {
120 *adpointer = NULL;
121 return;
122 }
123 *adpointer = (dcomplex *) mr2d_malloc(
124 blocksize * sizeof(dcomplex));
125}
126/******************************************************************/
127/* Free the memory space after the malloc */
128void
129freememory(dcomplex *ptrtobefreed)
130{
131 if (ptrtobefreed == NULL)
132 return;
133 free((char *) ptrtobefreed);
134}
135/* extern functions for intersect() extern zcopy_(); */
136/* scan_intervals: scans two distributions in one dimension, and compute the
137 * intersections on the local processor. result must be long enough to
138 * contains the result that are stocked in IDESC structure, the function
139 * returns the number of intersections found */
140Int
141scan_intervals(type, ja, jb, n, ma, mb, q0, q1, col0, col1,
142 result)
143 char type;
144 Int ja, jb, n, q0, q1, col0, col1;
145 MDESC *ma, *mb;
146 IDESC *result;
147{
148 Int offset, j0, j1, templatewidth0, templatewidth1, nbcol0, nbcol1;
149 Int l; /* local indice on the beginning of the interval */
150 assert(type == 'c' || type == 'r');
151 nbcol0 = (type == 'c' ? ma->nbcol : ma->nbrow);
152 nbcol1 = (type == 'c' ? mb->nbcol : mb->nbrow);
153 templatewidth0 = q0 * nbcol0;
154 templatewidth1 = q1 * nbcol1;
155 {
156 Int sp0 = (type == 'c' ? ma->spcol : ma->sprow);
157 Int sp1 = (type == 'c' ? mb->spcol : mb->sprow);
158 j0 = SHIFT(col0, sp0, q0) * nbcol0 - ja;
159 j1 = SHIFT(col1, sp1, q1) * nbcol1 - jb;
160 }
161 offset = 0;
162 l = 0;
163 /* a small check to verify that the submatrix begin inside the first block
164 * of the original matrix, this done by a sort of coordinate change at the
165 * beginning of the Cpzgemr2d */
166 assert(j0 + nbcol0 > 0);
167 assert(j1 + nbcol1 > 0);
168 while ((j0 < n) && (j1 < n)) {
169 Int end0, end1;
170 Int start, end;
171 end0 = j0 + nbcol0;
172 end1 = j1 + nbcol1;
173 if (end0 <= j1) {
174 j0 += templatewidth0;
175 l += nbcol0;
176 continue;
177 }
178 if (end1 <= j0) {
179 j1 += templatewidth1;
180 continue;
181 }
182 /* compute the raw intersection */
183 start = max(j0, j1);
184 start = max(start, 0);
185 /* the start is correct now, update the corresponding fields */
186 result[offset].lstart = l + start - j0;
187 end = min(end0, end1);
188 if (end0 == end) {
189 j0 += templatewidth0;
190 l += nbcol0;
191 }
192 if (end1 == end)
193 j1 += templatewidth1;
194 /* throw the limit if they go out of the matrix */
195 end = min(end, n);
196 assert(end > start);
197 /* it is a bit tricky to see why the length is always positive after all
198 * this min and max, first we have the property that every interval
199 * considered is at least partly into the submatrix, second we arrive
200 * here only if the raw intersection is non-void, if we remove a limit
201 * that means the corresponding frontier is in both intervals which
202 * proove the final interval is non-void, clear ?? */
203 result[offset].len = end - start;
204 offset += 1;
205 } /* while */
206 return offset;
207}
#define Int
Definition Bconfig.h:22
Int memoryblocksize()
Int changeorigin()
#define freememory
Definition pzgemr2.c:88
void Czgesd2d()
#define scan_intervals
Definition pzgemr2.c:89
#define SHIFT(row, sprow, nbrow)
Definition pzgemr2.c:44
void Cblacs_gridexit()
#define max(A, B)
Definition pzgemr2.c:45
#define min(A, B)
Definition pzgemr2.c:46
void Cigsum2d()
void Cpzgemr2d()
#define scanD0
Definition pzgemr2.c:85
Int Cblacs_pnum()
void Cpzgemr2do()
#define Clacpy
Definition pzgemr2.c:23
void Cigamx2d()
void Cblacs_pinfo()
void Cblacs_pcoord()
void Cigamn2d()
Int localsize()
#define setmemory
Definition pzgemr2.c:87
void Cblacs_get()
#define zlacpy_
Definition pzgemr2.c:21
void Czgerv2d()
void Cigerv2d()
void Cigebs2d()
#define dispmat
Definition pzgemr2.c:86
void paramcheck()
void Cblacs_setup()
void Cblacs_gridinit()
void Cblacs_gridinfo()
void Csetpvmtids()
Int localindice()
void Cigesd2d()
Int ppcm()
void Cigebr2d()
void Cblacs_exit()
void * mr2d_malloc()
Int lstart
Definition pcgemr.c:176
Int len
Definition pcgemr.c:177
Int spcol
Definition pcgemr.c:171
Int nbcol
Definition pcgemr.c:169
Int sprow
Definition pcgemr.c:170
Int nbrow
Definition pcgemr.c:168