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