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