ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
reshape.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 
3 void Creshape( context_in, major_in, context_out, major_out,
4  first_proc, nprow_new, npcol_new )
5 int context_in, *context_out, first_proc, major_in, major_out, nprow_new, npcol_new;
6 /* major in, major out represent whether processors go row major (1) or
7 column major (2) in the input and output grids */
8 {
9 
11  void proc_inc();
12  void Cblacs_gridinfo();
13  int Cblacs_pnum();
14  void Cblacs_get();
15  void Cblacs_gridmap();
16 
18  int i, j;
19  int nprow_in, npcol_in, myrow_in, mycol_in;
20  int nprocs_new;
21  int myrow_old, mycol_old, myrow_new, mycol_new;
22  int pnum;
23  int *grid_new;
24 
25 /********** executable statements ************/
26 
27  nprocs_new = nprow_new * npcol_new;
28 
29  Cblacs_gridinfo( context_in, &nprow_in, &npcol_in, &myrow_in, &mycol_in );
30 
31  /* Quick return if possible */
32  if( ( nprow_in == nprow_new ) && ( npcol_in == npcol_new ) &&
33  ( first_proc == 0 ) && ( major_in == major_out ) )
34  {
35  *context_out = context_in;
36  return;
37  }
38 
39  /* allocate space for new process mapping */
40  grid_new = (int *) malloc( nprocs_new * sizeof( int ) );
41 
42  /* set place in old grid to start grabbing processors for new grid */
43  myrow_old = 0; mycol_old = 0;
44  if ( major_in == 1 ) /* row major */
45  {
46  myrow_old = first_proc / nprow_in;
47  mycol_old = first_proc % nprow_in;
48  }
49  else /* col major */
50  {
51  myrow_old = first_proc % nprow_in;
52  mycol_old = first_proc / nprow_in;
53  }
54 
55  myrow_new = 0; mycol_new = 0;
56 
57  /* Set up array of process numbers for new grid */
58  for (i=0; i< nprocs_new; i++ )
59  {
60  pnum = Cblacs_pnum( context_in, myrow_old, mycol_old );
61  grid_new[ (mycol_new * nprow_new) + myrow_new ] = pnum;
62  proc_inc( &myrow_old, &mycol_old, nprow_in, npcol_in, major_in );
63  proc_inc( &myrow_new, &mycol_new, nprow_new, npcol_new, major_out );
64  }
65 
66  /* get context */
67  Cblacs_get( context_in, 10, context_out );
68 
69  /* allocate grid */
70  Cblacs_gridmap( context_out, grid_new, nprow_new, nprow_new, npcol_new );
71 
72  /* free malloced space */
73  free( grid_new );
74 }
75 
76 /*************************************************************************/
77 void reshape( context_in, major_in, context_out, major_out,
78  first_proc, nprow_new, npcol_new )
79 int *context_in, *context_out, *first_proc, *major_in, *major_out, *nprow_new, *npcol_new;
80 {
81  Creshape( *context_in, *major_in, context_out, *major_out,
82  *first_proc, *nprow_new, *npcol_new );
83 }
84 /*************************************************************************/
85 void RESHAPE( context_in, major_in, context_out, major_out,
86  first_proc, nprow_new, npcol_new )
87 int *context_in, *context_out, *first_proc, *major_in, *major_out, *nprow_new, *npcol_new;
88 {
89  Creshape( *context_in, *major_in, context_out, *major_out,
90  *first_proc, *nprow_new, *npcol_new );
91 }
92 /*************************************************************************/
93 void reshape_( context_in, major_in, context_out, major_out,
94  first_proc, nprow_new, npcol_new )
95 int *context_in, *context_out, *first_proc, *major_in, *major_out, *nprow_new, *npcol_new;
96 {
97  Creshape( *context_in, *major_in, context_out, *major_out,
98  *first_proc, *nprow_new, *npcol_new );
99 }
100 /*************************************************************************/
101 void proc_inc( myrow, mycol, nprow, npcol, major )
102 int *myrow, *mycol, nprow, npcol, major;
103 {
104  if( major == 1) /* row major */
105  {
106  if( *mycol == npcol-1 )
107  {
108  *mycol = 0;
109  if( *myrow == nprow-1 )
110  {
111  *myrow = 0;
112  }
113  else
114  {
115  *myrow = *myrow + 1;
116  }
117  }
118  else
119  {
120  *mycol = *mycol + 1;
121  }
122  }
123  else /* col major */
124  {
125  if( *myrow == nprow-1 )
126  {
127  *myrow = 0;
128  if( *mycol == npcol-1 )
129  {
130  *mycol = 0;
131  }
132  else
133  {
134  *mycol = *mycol + 1;
135  }
136  }
137  else
138  {
139  *myrow = *myrow + 1;
140  }
141  }
142 }
143 
proc_inc
void proc_inc(int *myrow, int *mycol, int nprow, int npcol, int major)
Definition: reshape.c:101
reshape
void reshape(int *context_in, int *major_in, int *context_out, int *major_out, int *first_proc, int *nprow_new, int *npcol_new)
Definition: reshape.c:77
Creshape
void Creshape(int context_in, int major_in, int *context_out, int major_out, int first_proc, int nprow_new, int npcol_new)
Definition: reshape.c:3
RESHAPE
void RESHAPE(int *context_in, int *major_in, int *context_out, int *major_out, int *first_proc, int *nprow_new, int *npcol_new)
Definition: reshape.c:85
Cblacs_gridmap
void Cblacs_gridmap()
Cblacs_pnum
int Cblacs_pnum()
Cblacs_get
void Cblacs_get()
Cblacs_gridinfo
void Cblacs_gridinfo()
reshape_
void reshape_(int *context_in, int *major_in, int *context_out, int *major_out, int *first_proc, int *nprow_new, int *npcol_new)
Definition: reshape.c:93