Skylark (Sketching Library)
0.1
|
00001 #include <iostream> 00002 #include <functional> 00003 #include <cstring> 00004 #include <vector> 00005 #include <utility> 00006 #include <ext/hash_map> 00007 00008 #include <elemental.hpp> 00009 #include <boost/mpi.hpp> 00010 #include <skylark.hpp> 00011 00012 #include "utilities.hpp" 00013 #include "parser.hpp" 00014 00015 /*******************************************/ 00016 namespace bmpi = boost::mpi; 00017 namespace skyb = skylark::base; 00018 /*******************************************/ 00019 00020 /* These were declared as extern in utilities.hpp --- defining it here */ 00021 int int_params [NUM_INT_PARAMETERS]; 00022 char* chr_params[NUM_CHR_PARAMETERS]; 00023 00025 typedef std::vector<int> IntContainer; 00026 typedef std::vector<double> DblContainer; 00027 typedef elem::Matrix<double> MatrixType; 00028 typedef elem::DistMatrix<double, elem::VR, elem::STAR> DistMatrixType; 00029 00030 int main (int argc, char** argv) { 00031 /* Initialize Elemental (and MPI) */ 00032 elem::Initialize (argc, argv); 00033 00034 /* MPI sends argc and argv everywhere --- parse everywhere */ 00035 parse_parameters (argc,argv); 00036 00037 // get communicator 00038 boost::mpi::communicator comm; 00039 int rank = comm.rank(); 00040 00041 MPI_Comm mpi_world(world); 00042 elem::Grid grid (mpi_world); 00043 00044 /* Initialize skylark */ 00045 skyb::context_t context (int_params[RAND_SEED_INDEX], comm); 00046 00047 int m = int_params[M_INDEX]; 00048 int n = int_params[N_INDEX]; 00049 int k = int_params[S_INDEX]; 00050 00051 /* Create matrices A and B */ 00052 DistMatrixType A1(grid); 00053 DistMatrixType A2(grid); 00054 00055 elem::DistMatrix<double> A11,A22,A33,V33; 00056 DistMatrixType s33(grid); 00057 DistMatrixType A(grid); 00058 DistMatrixType U(grid); 00059 MatrixType s(k,1); 00060 MatrixType V(n,k); 00061 00062 00064 if (0==int_params[USE_RANDOM_INDEX]) { 00066 std::cout << "We don't support reading --- yet --" << std::endl; 00067 } else { 00068 elem::Uniform (A1, m, k); 00069 elem::Uniform (A2, m, k); 00070 elem::Matrix<double> A3(k,k); 00071 00072 skylark::nla::Gemm(A1,A2,A3,context); 00073 00074 elem::Uniform (A3, k, k); 00075 00076 skylark::nla::Gemm(A1,A3,A2); 00077 00078 elem::Uniform(A11, m, k); 00079 elem::Uniform(A22, k, n); 00080 A33.Resize(m,n); 00081 Gemm(elem::NORMAL, elem::NORMAL, 1.0, A11, A22, 0.0, A33); 00082 A.Resize(m,n); 00083 A = A33; 00084 elem::SVD(A33, s33, V33); 00085 elem::Display(s33, "True singular values"); 00086 00087 } 00088 00092 if (0==strcmp("JLT", chr_params[TRANSFORM_INDEX]) ) { 00093 00094 if (SKETCH_LEFT == int_params[SKETCH_DIRECTION_INDEX]) { 00095 elem::Display(s, "Approximate singular values"); 00096 } else { 00097 //std::cout << "We only have left sketching. Please retry" << std::endl; 00098 } 00099 } else { 00100 std::cout << "We only have JLT sketching. Please retry" << 00101 std::endl; 00102 } 00103 00104 elem::Finalize(); 00105 00106 return 0; 00107 }