summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspiros <andyspiros@gmail.com>2011-07-23 00:51:54 +0200
committerspiros <andyspiros@gmail.com>2011-07-23 00:51:54 +0200
commit073daf866484570b163359dc3e50a1c9f57acfa7 (patch)
treec317f6035cd7b027d69a9a65ea4c19662446778f
parentAdded support for parallel LU decomposition in the PBLAS module. Much (diff)
downloadauto-numerical-bench-073daf866484570b163359dc3e50a1c9f57acfa7.tar.gz
auto-numerical-bench-073daf866484570b163359dc3e50a1c9f57acfa7.tar.bz2
auto-numerical-bench-073daf866484570b163359dc3e50a1c9f57acfa7.zip
Added cholesky. Solved some issues.
-rw-r--r--btl/actions/action_parallel_cholesky.hh112
-rw-r--r--btl/actions/action_parallel_lu_decomp.hh36
-rw-r--r--btl/generic_bench/init/init_function.hh2
-rw-r--r--btl/libs/PBLAS/main.cpp42
-rw-r--r--btl/libs/PBLAS/pblas.h5
-rw-r--r--btl/libs/PBLAS/pblas_interface_impl.hh10
-rw-r--r--pblas.py4
7 files changed, 182 insertions, 29 deletions
diff --git a/btl/actions/action_parallel_cholesky.hh b/btl/actions/action_parallel_cholesky.hh
new file mode 100644
index 0000000..f89eb98
--- /dev/null
+++ b/btl/actions/action_parallel_cholesky.hh
@@ -0,0 +1,112 @@
+#ifndef ACTION_PARALLEL_CHOLESKY_HH_
+#define ACTION_PARALLEL_CHOLESKY_HH_
+
+#include "utilities.h"
+#include "init/init_function.hh"
+#include "init/init_vector.hh"
+
+#include "lapack_interface.hh"
+#include "STL_interface.hh"
+
+#include <string>
+
+template<class Interface>
+class Action_parallel_cholesky {
+ typedef lapack_interface<typename Interface::real_type> LapackInterface;
+
+public :
+
+ // Constructor
+ BTL_DONT_INLINE Action_parallel_cholesky( int size ) : _size(size)
+ {
+ MESSAGE("Action_parallel_cholesky Ctor");
+
+ int myid, procnum;
+ blacs_pinfo_(&myid, &procnum);
+ iamroot = (myid == 0);
+
+ // STL matrix and vector initialization
+ if (iamroot) {
+ typename LapackInterface::stl_matrix temp_stl;
+ init_matrix_symm<pseudo_random>(temp_stl, size);
+ Global_A_stl.reserve(size*size);
+ const double add = 5000./size;
+ for (int r = 0; r < size; ++r)
+ for (int c = 0; c < size; ++c)
+ if (r==c)
+ Global_A_stl.push_back((std::abs(temp_stl[r][c])+add)*size);
+ else
+ Global_A_stl.push_back(temp_stl[r][c]);
+ }
+
+ Interface::scatter_matrix(Global_A_stl, Local_A_stl, desc, size, size, 64, 64);
+ LocalRows = desc[8];
+ LocalCols = Local_A_stl.size()/desc[8];
+
+ // Generic local matrix and vectors initialization
+ Interface::matrix_from_stl(Local_A_ref, Local_A_stl);
+ Interface::matrix_from_stl(Local_A , Local_A_stl);
+
+ _cost = 0;
+ for (int j=0; j<_size; ++j) {
+ double r = std::max(_size - j -1,0);
+ _cost += 2*(r*j+r+j);
+ }
+ }
+
+
+ // Invalidate copy constructor
+ Action_parallel_cholesky(const Action_parallel_cholesky&)
+ {
+ INFOS("illegal call to Action_parallel_cholesky copy constructor");
+ exit(1);
+ }
+
+ // Destructor
+ ~Action_parallel_cholesky()
+ {
+ MESSAGE("Action_parallel_cholesky destructor");
+
+ // Deallocation
+ Interface::free_matrix(Local_A_ref, Local_A_stl.size());
+ Interface::free_matrix(Local_A , Local_A_stl.size());
+ }
+
+ // Action name
+ static inline std::string name()
+ {
+ return "cholesky_" + Interface::name();
+ }
+
+ double nb_op_base()
+ {
+ return _cost;
+ }
+
+ BTL_DONT_INLINE void initialize()
+ {
+ Interface::copy_matrix(Local_A_ref, Local_A, Local_A_stl.size());
+ }
+
+ BTL_DONT_INLINE void calculate()
+ {
+ Interface::parallel_cholesky(Local_A, desc);
+ }
+
+ BTL_DONT_INLINE void check_result()
+ {
+ }
+
+
+private:
+ int _size, desc[9], LocalRows, LocalCols;
+ double _cost;
+ bool iamroot;
+
+ typename Interface::stl_matrix Global_A_stl;
+ typename Interface::stl_matrix Local_A_stl;
+ typename Interface::gene_matrix Local_A_ref;
+ typename Interface::gene_matrix Local_A;
+};
+
+#endif /* ACTION_PARALLEL_CHOLESKY_HH_ */
diff --git a/btl/actions/action_parallel_lu_decomp.hh b/btl/actions/action_parallel_lu_decomp.hh
index 4882a21..18b4ac7 100644
--- a/btl/actions/action_parallel_lu_decomp.hh
+++ b/btl/actions/action_parallel_lu_decomp.hh
@@ -81,24 +81,24 @@ public :
BTL_DONT_INLINE void check_result()
{
- /* Gather */
- typename Interface::stl_matrix Global_Y;
- typename Interface::stl_matrix Local_Y(Local_A_stl.size());
- Interface::matrix_to_stl(Local_A, Local_Y);
- Interface::gather_matrix(Global_Y, Local_Y, desc);
-
- if (iamroot) {
-
- typename Interface::gene_matrix A;
- Interface::matrix_from_stl(A, Global_A_stl);
- lapack_interface<typename Interface::real_type>::lu_decomp(&Global_A_stl[0], A, _size);
- typename Interface::stl_vector correct(A, A+_size*_size);
- typename Interface::real_type error = STL_interface<typename Interface::real_type>::norm_diff(Global_Y, correct);
- if (error > 10e-5)
- cerr << " { !! error : " << error << " !! } ";
-
- Interface::free_matrix(A, _size*_size);
- }
+// /* Gather */
+// typename Interface::stl_matrix Global_Y;
+// typename Interface::stl_matrix Local_Y(Local_A_stl.size());
+// Interface::matrix_to_stl(Local_A, Local_Y);
+// Interface::gather_matrix(Global_Y, Local_Y, desc);
+//
+// if (iamroot) {
+//
+// typename Interface::gene_matrix A;
+// Interface::matrix_from_stl(A, Global_A_stl);
+// lapack_interface<typename Interface::real_type>::lu_decomp(&Global_A_stl[0], A, _size);
+// typename Interface::stl_vector correct(A, A+_size*_size);
+// typename Interface::real_type error = STL_interface<typename Interface::real_type>::norm_diff(Global_Y, correct);
+// if (error > 10e-5)
+// cerr << " { !! error : " << error << " !! } ";
+//
+// Interface::free_matrix(A, _size*_size);
+// }
}
private:
diff --git a/btl/generic_bench/init/init_function.hh b/btl/generic_bench/init/init_function.hh
index 5401673..7b3bdba 100644
--- a/btl/generic_bench/init/init_function.hh
+++ b/btl/generic_bench/init/init_function.hh
@@ -32,7 +32,7 @@ double simple_function(int index_i, int index_j)
double pseudo_random(int index)
{
- return static_cast<int>((std::rand()/double(RAND_MAX)-.5)*20);
+ return std::rand()/double(RAND_MAX);
}
double pseudo_random(int index_i, int index_j)
diff --git a/btl/libs/PBLAS/main.cpp b/btl/libs/PBLAS/main.cpp
index a2aae2a..e7b636b 100644
--- a/btl/libs/PBLAS/main.cpp
+++ b/btl/libs/PBLAS/main.cpp
@@ -9,9 +9,11 @@
#include "pblas_interface.hh"
#include "blacsinit.hh"
+
+#include "action_parallel_axpy.hh"
#include "action_parallel_matrix_vector_product.hh"
#include "action_parallel_lu_decomp.hh"
-#include "action_parallel_axpy.hh"
+#include "action_parallel_cholesky.hh"
#include <string>
@@ -21,13 +23,37 @@ int main(int argc, char **argv)
{
bool iamroot = blacsinit(&argc, &argv);
-// distr_bench<Action_parallel_matrix_vector_product<pblas_interface<double> > >(10,MAX_MV,NB_POINT,!iamroot);
-// distr_bench<Action_parallel_axpy<pblas_interface<REAL_TYPE> > >(10,MAX_MV,NB_POINT,!iamroot);
- distr_bench<Action_parallel_lu_decomp<pblas_interface<REAL_TYPE> > >(10,MAX_MV,NB_POINT,!iamroot);
-// Action_parallel_lu_decomp<pblas_interface<REAL_TYPE> > action(8);
-// action.initialize();
-// action.calculate();
-// action.check_result();
+ bool
+ general_solve=false, least_squares=false, lu_decomp=false, cholesky=false,
+ symm_ev=false
+ ;
+
+
+ for (int i = 1; i < argc; ++i) {
+ std::string arg = argv[i];
+ if (arg == "general_solve") general_solve = true;
+ else if (arg == "least_squares") least_squares = true;
+ else if (arg == "lu_decomp") lu_decomp = true;
+ else if (arg == "cholesky") cholesky = true;
+ else if (arg == "symm_ev") symm_ev = true;
+ }
+
+
+// if (general_solve)
+// distr_bench<Action_general_solve<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT, !iamroot);
+
+// if (least_squares)
+// distr_bench<Action_least_squares<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT, !iamroot);
+
+ if (lu_decomp)
+ distr_bench<Action_parallel_lu_decomp<pblas_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT, !iamroot);
+
+ if (cholesky)
+ distr_bench<Action_parallel_cholesky<pblas_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT, !iamroot);
+
+// if (symm_ev)
+// distr_bench<Action_symm_ev<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT, !iamroot);
+
int iZERO = 0;
blacs_exit_(&iZERO);
diff --git a/btl/libs/PBLAS/pblas.h b/btl/libs/PBLAS/pblas.h
index 2b5860e..973b91c 100644
--- a/btl/libs/PBLAS/pblas.h
+++ b/btl/libs/PBLAS/pblas.h
@@ -46,9 +46,14 @@ extern "C" {
/*************
* Scalapack *
*************/
+ // lu_decomp
void psgetrf_(const int*, const int*, float*, const int*, const int*, const int*, int*, int*);
void pdgetrf_(const int*, const int*, double*, const int*, const int*, const int*, int*, int*);
+ // cholesky
+ void pspotrf_(const char*, const int*, float*, const int*, const int*, const int*, int*);
+ void pdpotrf_(const char*, const int*, double*, const int*, const int*, const int*, int*);
+
#ifdef __cplusplus
}
diff --git a/btl/libs/PBLAS/pblas_interface_impl.hh b/btl/libs/PBLAS/pblas_interface_impl.hh
index c36c249..1dbf3b9 100644
--- a/btl/libs/PBLAS/pblas_interface_impl.hh
+++ b/btl/libs/PBLAS/pblas_interface_impl.hh
@@ -54,5 +54,15 @@ public:
PBLAS_FUNC(getrf)(&GlobalRows, &GlobalCols, X, &iONE, &iONE, desc,
&ipiv[0], &info);
}
+
+ static inline void parallel_cholesky(gene_matrix& X, const int* desc)
+ {
+ const int N = desc[2], iONE = 1;
+ const char UPLO = 'U';
+ int info;
+ PBLAS_FUNC(potrf)(&UPLO, &N, X, &iONE, &iONE, desc, &info);
+// if (info != 0)
+// cerr << " { cholesky error : " << info << " } ";
+ }
};
diff --git a/pblas.py b/pblas.py
index 6f0f6cd..9cd087e 100644
--- a/pblas.py
+++ b/pblas.py
@@ -5,7 +5,7 @@ numproc = 4
class Module(btlbase.BTLBase):
def _initialize(self):
self.libname = "scalapack"
- self.avail = ['axpy', 'matrix_vector', 'lu_decomp']
+ self.avail = ['axpy', 'matrix_vector', 'lu_decomp', 'cholesky']
def _parse_args(self, args):
# Parse arguments
@@ -61,7 +61,7 @@ class PBLASTest(btlbase.BTLTest):
@staticmethod
def _btl_includes():
- return ["libs/BLAS", "libs/BLACS", "libs/PBLAS"]
+ return ["libs/BLAS", "libs/BLACS", "libs/PBLAS", "libs/STL"]
def _btl_defines(self):
return ["PBLASNAME="+self.libname] \ No newline at end of file