~gcrosswhite/charon/projects-ParallelIO

« back to all changes in this revision

Viewing changes to src/scalapack_test.C

  • Committer: Gregory Crosswhite
  • Date: 2009-04-15 02:23:24 UTC
  • Revision ID: gcross@phys.washington.edu-20090415022324-oru26n83btrfrsbn
Finished clearing out code that has been split into the other branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//@+leo-ver=4-thin
2
 
//@+node:gcross.20081103140450.3:@thin scalapack_test.C
3
 
//@@language cplusplus
4
 
//@@tabwidth -4
5
 
//@+others
6
 
//@+node:gcross.20081103140450.4:scalapack_test declarations
7
 
#include "mpi.h"
8
 
#include <iostream>
9
 
 
10
 
#include "blitz/blitz.h"
11
 
#include "blitz/array.h"
12
 
#include "blitz/indexexpr.h"
13
 
#include "blitz/range.h"
14
 
#include "blitz/tinyvec.h"
15
 
#include "blitz/tinyvec-et.h"
16
 
#include "blitz/array/domain.h"
17
 
#include "blitz/array/expr.h"
18
 
#include "blitz/array/fastiter.h"
19
 
 
20
 
#include "c++pblas.h"
21
 
 
22
 
//#include "charm++.h"
23
 
 
24
 
extern "C" {
25
 
    #include "Cblacs.h"
26
 
}
27
 
 
28
 
 
29
 
using namespace blitz;
30
 
using namespace std;
31
 
 
32
 
class Descriptor {
33
 
    int descriptor[9];
34
 
public:
35
 
    int& type() { return descriptor[0]; }
36
 
    int& context() { return descriptor[1]; }
37
 
    int& number_of_rows() { return descriptor[2]; }
38
 
    int& number_of_columns() { return descriptor[3]; }
39
 
    int& row_blocking_factor() { return descriptor[4]; }
40
 
    int& column_blocking_factor() { return descriptor[5]; }
41
 
    int& first_process_row() { return descriptor[6]; }
42
 
    int& first_process_column() { return descriptor[7]; }
43
 
    int& leading_dimension() { return descriptor[8]; }
44
 
    operator int*() { return descriptor; }
45
 
};
46
 
 
47
 
 
48
 
//@-node:gcross.20081103140450.4:scalapack_test declarations
49
 
//@+node:gcross.20081103140450.5:main
50
 
int main(int argc,char **argv) {
51
 
 
52
 
    MPI_Init(NULL,NULL);
53
 
    int rank;
54
 
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
55
 
 
56
 
    int mpi_context;
57
 
    Cblacs_get(0,0,&mpi_context);  // get system default context
58
 
    int blacs_context = mpi_context;
59
 
 
60
 
    Cblacs_gridinit(&blacs_context,"Row Major Ordering",2,2);
61
 
 
62
 
    Descriptor descriptor;
63
 
    descriptor.type() = 1;
64
 
    descriptor.context() = blacs_context;
65
 
    descriptor.number_of_rows() = 6;
66
 
    descriptor.number_of_columns() = 6;
67
 
    descriptor.row_blocking_factor() = 3;
68
 
    descriptor.column_blocking_factor() = 3;
69
 
    descriptor.first_process_row() = 0;
70
 
    descriptor.first_process_column() = 0;
71
 
    descriptor.leading_dimension() = 3;
72
 
 
73
 
 
74
 
    Array<double,2> Alocal(6,6), Blocal(6,6);
75
 
    Alocal = 0;
76
 
    Blocal = 0;
77
 
 
78
 
    int IPIV[100];
79
 
 
80
 
 
81
 
    Alocal = 0.0,1.0,8.0,27.0,64.0,125.0,
82
 
1.0,4.0,15.0,40.0,85.0,156.0,
83
 
8.0,15.0,32.0,65.0,120.0,203.0,
84
 
27.0,40.0,65.0,108.0,175.0,272.0,
85
 
64.0,85.0,120.0,175.0,256.0,369.0,
86
 
125.0,156.0,203.0,272.0,369.0,500.0;
87
 
 
88
 
    Blocal = 20515.0,26144.0,35081.0,48676.0,68279.0,95240.0,
89
 
26144.0,33403.0,45016.0,62789.0,88528.0,124039.0,
90
 
35081.0,45016.0,61147.0,86132.0,122629.0,173296.0,
91
 
48676.0,62789.0,86132.0,122827.0,176996.0,252761.0,
92
 
68279.0,88528.0,122629.0,176996.0,258043.0,372184.0,
93
 
95240.0,124039.0,173296.0,252761.0,372184.0,541315.0;
94
 
 
95
 
    Array<double,2> A(3,3,fortranArray);
96
 
    Array<double,2> B(3,3,fortranArray);
97
 
 
98
 
    switch(rank) {
99
 
    case 0:
100
 
      A = Alocal(Range(0,2),Range(0,2));
101
 
      B = Blocal(Range(0,2),Range(0,2));
102
 
      break;
103
 
    case 1:
104
 
      A = Alocal(Range(0,2),Range(3,5));
105
 
      B = Blocal(Range(0,2),Range(3,5));
106
 
      break;
107
 
    case 2:
108
 
      A = Alocal(Range(3,5),Range(0,2));
109
 
      B = Blocal(Range(3,5),Range(0,2));
110
 
      break;
111
 
    case 3:
112
 
      A = Alocal(Range(3,5),Range(3,5));
113
 
      B = Blocal(Range(3,5),Range(3,5));
114
 
      break;
115
 
    }
116
 
 
117
 
    PBLAS::solve<double>(6,6,A.data(),1,1,(int*)descriptor,IPIV,B.data(),1,1,(int*)descriptor);
118
 
 
119
 
    MPI_Barrier(MPI_COMM_WORLD);
120
 
 
121
 
    if(rank == 3) {
122
 
      cout << rank << A << endl;
123
 
      cout << rank << B << endl;
124
 
    }
125
 
 
126
 
    MPI_Finalize();
127
 
 
128
 
}
129
 
//@-node:gcross.20081103140450.5:main
130
 
//@-others
131
 
 
132
 
//@-node:gcross.20081103140450.3:@thin scalapack_test.C
133
 
//@-leo