SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
SL_gridreshape.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <stdio.h>
3
4#ifndef Int
5#define Int int
6#endif
7
8Int SL_Cgridreshape(Int ctxt, Int pstart, Int row_major_in, Int row_major_out, Int P, Int Q)
9{
11 Int nctxt, P0, Q0, Np, i, *g;
12
13 Cblacs_gridinfo(ctxt, &P0, &Q0, &i, &Np);
14 Np = P * Q;
15 if (Np+pstart > P0*Q0)
16 {
17 fprintf(stderr, "Illegal reshape command in %s\n",__FILE__);
18 Cblacs_abort(ctxt, -22);
19 }
20 g = (Int *) malloc(Np * sizeof(Int));
21 if (!g)
22 {
23 fprintf(stderr, "Cannot allocate memory in %s\n",__FILE__);
24 Cblacs_abort(ctxt, -23);
25 }
26 if (row_major_in) /* Read in in row-major order */
27 {
28 if (row_major_out)
29 for (i=0; i != Np; i++)
30 g[(i%Q)*P+i/Q] = Cblacs_pnum(ctxt, (pstart+i)/Q0, (pstart+i)%Q0);
31 else
32 for (i=0; i != Np; i++)
33 g[i] = Cblacs_pnum(ctxt, (pstart+i)/Q0, (pstart+i)%Q0);
34 }
35 else /* read in in column-major order */
36 {
37 if (row_major_out)
38 for (i=0; i != Np; i++)
39 g[(i%Q)*P+i/Q] = Cblacs_pnum(ctxt, (pstart+i)%P0, (pstart+i)/P0);
40 else
41 for (i=0; i != Np; i++)
42 g[i] = Cblacs_pnum(ctxt, (pstart+i)%P0, (pstart+i)/P0);
43 }
44 Cblacs_get(ctxt, 10, &nctxt);
45 Cblacs_gridmap(&nctxt, g, P, P, Q);
46 free(g);
47
48 return(nctxt);
49}
50
51Int sl_gridreshape_(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
52{
53 return( SL_Cgridreshape(*ctxt, *pstart, *row_major_in, *row_major_out,
54 *P, *Q) );
55}
56
57Int SL_GRIDRESHAPE(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
58{
59 return( SL_Cgridreshape(*ctxt, *pstart, *row_major_in, *row_major_out,
60 *P, *Q) );
61}
62
63Int sl_gridreshape__(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
64{
65 return( SL_Cgridreshape(*ctxt, *pstart, *row_major_in, *row_major_out,
66 *P, *Q) );
67}
68
69Int sl_gridreshape(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
70{
71 return( SL_Cgridreshape(*ctxt, *pstart, *row_major_in, *row_major_out,
72 *P, *Q) );
73}
void Cblacs_gridmap()
void Cblacs_abort()
Int Cblacs_pnum()
void Cblacs_get()
void Cblacs_gridinfo()
Int sl_gridreshape__(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
Int sl_gridreshape(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
Int sl_gridreshape_(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
#define Int
Int SL_GRIDRESHAPE(Int *ctxt, Int *pstart, Int *row_major_in, Int *row_major_out, Int *P, Int *Q)
Int SL_Cgridreshape(Int ctxt, Int pstart, Int row_major_in, Int row_major_out, Int P, Int Q)