Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/utility/external/print.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_PRINT_HPP
00002 #define SKYLARK_PRINT_HPP
00003 
00004 #include <cstdio>
00005 
00006 #include "../../config.h"
00007 
00008 #if SKYLARK_HAVE_ELEMENTAL
00009 #include <elemental.hpp>
00010 #endif
00011 
00012 #if SKYLARK_HAVE_COMBBLAS
00013 #include <CombBLAS.h>
00014 #include "FullyDistMultiVec.hpp"
00015 #endif
00016 
00017 namespace skylark { namespace utility {
00018 
00019 template <typename DataType> 
00020 struct print_t { };
00021 
00022 #if SKYLARK_HAVE_ELEMENTAL
00023 
00024 template <typename ValueType>
00025 struct print_t <elem::Matrix<ValueType> > {
00026 
00027   typedef int index_t;
00028   typedef ValueType value_t;
00029   typedef elem::Matrix<ValueType> matrix_t;
00030 
00031   static void apply(const matrix_t& X,
00032                     const char* msg,
00033                     bool am_i_printing,
00034                     int debug_level=0) {
00035     if (1>=debug_level) return;
00036 
00037     if (am_i_printing) {
00038       printf ("Dump of %s\n", msg);
00039       for (index_t i=0; i<X.Height(); ++i) {
00040         for (index_t j=0; j<X.Width(); ++j) {
00041           printf ("%lf ", X.Get(i,j));
00042         }
00043         printf ("\n");
00044       }
00045     }
00046   }
00047 
00048   static void apply(const matrix_t& X,
00049                     const matrix_t& Y,
00050                     const char* msg,
00051                     bool am_i_printing,
00052                     int debug_level=0) {
00053     if (1>=debug_level) return;
00054 
00055     if (am_i_printing) {
00056       printf ("Dump of %s\n", msg);
00057       for (index_t i=0; i<X.Height(); ++i) {
00058         for (index_t j=0; j<X.Width(); ++j) {
00059           printf ("(%lf -- %lf) ", X.Get(i,j), Y.Get(i,j));
00060         }
00061         printf ("\n");
00062       }
00063     }
00064   }
00065 };
00066 
00067 template <typename ValueType,
00068           elem::Distribution CD,
00069           elem::Distribution RD>
00070 struct print_t <elem::DistMatrix<ValueType, CD, RD> > {
00071 
00072     typedef int index_t;
00073     typedef ValueType value_t;
00074     typedef elem::DistMatrix<ValueType, CD, RD> mpi_matrix_t;
00075 
00076     static void apply(const mpi_matrix_t& X,
00077         const char* msg,
00078         bool am_i_printing,
00079         int debug_level=0) {
00080 
00081         if (1>=debug_level) return;
00082 
00083         elem::DistMatrix<value_t, elem::STAR, elem::STAR> Xss(X);
00084         if (am_i_printing) {
00085             printf ("Dump of %s\n", msg);
00086             for (index_t i=0; i<Xss.Height(); ++i) {
00087                 for (index_t j=0; j<Xss.Width(); ++j) {
00088                     printf ("%lf ", Xss.Get(i,j));
00089                 }
00090                 printf ("\n");
00091             }
00092         }
00093   }
00094 
00095   static void apply(const mpi_matrix_t& X,
00096                     const mpi_matrix_t& Y,
00097                     const char* msg,
00098                     bool am_i_printing,
00099                     int debug_level=0) {
00100     if (1>=debug_level) return;
00101 
00102     elem::DistMatrix<value_t, elem::STAR, elem::STAR> Xss(X), Yss(Y);
00103     if (am_i_printing) {
00104       printf ("Dump of %s\n", msg);
00105       for (index_t i=0; i<Xss.Height(); ++i) {
00106         for (index_t j=0; j<Xss.Width(); ++j) {
00107           printf ("(%lf -- %lf) ", Xss.Get(i,j), Yss.Get(i,j));
00108         }
00109         printf ("\n");
00110       }
00111     }
00112   }
00113 };
00114 
00115 #endif
00116 
00117 #if SKYLARK_HAVE_COMBBLAS 
00118 
00119 template <typename IndexType, 
00120           typename ValueType>
00121 struct print_t<SpParMat<IndexType,
00122                         ValueType,
00123                         SpDCCols<IndexType,ValueType> > > {
00124 
00125   typedef IndexType index_t;
00126   typedef ValueType value_t;
00127   typedef SpDCCols<index_t,value_t> seq_matrix_t;
00128   typedef typename seq_matrix_t::SpColIter seq_matrix_col_iter_t;
00129   typedef typename seq_matrix_col_iter_t::NzIter seq_matrix_nz_iter_t;
00130   typedef SpParMat<index_t,value_t, seq_matrix_t> mpi_matrix_t;
00131 
00132   static void apply(const mpi_matrix_t& A,
00133                     const char* msg,
00134                     bool am_i_printing,
00135                     int debug_level=0) {
00136     if (1>=debug_level) return;
00137     if (am_i_printing) printf ("Dump of %s\n", msg);
00138     seq_matrix_t& data = (const_cast<mpi_matrix_t&>(A)).seq();    
00139     for(seq_matrix_col_iter_t col=data.begcol();col!=data.endcol();++col) 
00140       for(seq_matrix_nz_iter_t nz=data.begnz(col);nz!=data.endnz(col);++nz) 
00141         if (am_i_printing)
00142           printf ("%d %d %lf\n", 1+col.colid(), 1+nz.rowid(), nz.value());
00143   }
00144 };
00145 
00146 template <typename IndexType, 
00147           typename ValueType>
00148 struct print_t<FullyDistVec<IndexType,ValueType> > {
00149 
00150   typedef IndexType index_t;
00151   typedef ValueType value_t;
00152   typedef FullyDistVec<index_t,value_t> mpi_vector_t;
00153 
00154   static void apply(const mpi_vector_t& x,
00155                     const char* msg,
00156                     bool am_i_printing,
00157                     int debug_level=0) {
00158     if (1>=debug_level) return;
00159     if (am_i_printing) printf ("Dump of %s\n", msg);
00160     for (index_t i=0; i<x.TotalLength(); ++i) {
00161       value_t val = x.GetElement(i);
00162       if (am_i_printing) printf ("%lf\n", val);
00163     }
00164   }
00165 
00166   static void apply(const mpi_vector_t& x, 
00167                     const mpi_vector_t& y, 
00168                     const char* msg,
00169                     bool am_i_printing,
00170                     int debug_level=0) {
00171     if (1>=debug_level) return;
00172     if (am_i_printing) printf ("Dump of %s\n", msg);
00173     for (index_t i=0; i<x.TotalLength(); ++i) {
00174       value_t val1 = x.GetElement(i);
00175       value_t val2 = y.GetElement(i);
00176       if (am_i_printing) printf ("%lf --- %lf\n", val1, val2);
00177     }
00178   }
00179 };
00180 
00181 template <typename IndexType, 
00182           typename ValueType>
00183 struct print_t<FullyDistMultiVec<IndexType,ValueType> > {
00184   typedef IndexType index_t;
00185   typedef ValueType value_t;
00186   typedef FullyDistVec<index_t,value_t> mpi_vector_t;
00187   typedef FullyDistMultiVec<index_t,value_t> mpi_multi_vector_t;
00188   typedef print_t<mpi_vector_t> internal_printer_t;
00189 
00190   static void apply(const mpi_multi_vector_t& X,
00191                     const char* msg,
00192                     bool am_i_printing,
00193                     int debug_level=0) {
00194     if (1>=debug_level) return;
00195     if (am_i_printing) printf ("Dump of %s\n", msg);
00196 
00197     const index_t k = X.size;
00198     const index_t m = X.dim;
00199     for (index_t i=0; i<m; ++i) {
00200       for (index_t j=0; j<k; ++j) {
00201         value_t val = X[j].GetElement(i);
00202         if (am_i_printing) printf ("%lf ", val);
00203       }
00204       if (am_i_printing) printf ("\n");
00205     }
00206   }
00207 
00208   static void apply(const mpi_multi_vector_t& X, 
00209                     const mpi_multi_vector_t& Y, 
00210                     const char* msg,
00211                     bool am_i_printing,
00212                     int debug_level=0) {
00213     if (1>=debug_level) return;
00214     if (am_i_printing) printf ("Dump of %s\n", msg);
00215 
00216     const index_t k = X.size;
00217     const index_t m = X.dim;
00218     for (index_t i=0; i<m; ++i) {
00219       for (index_t j=0; j<k; ++j) {
00220         value_t val_1 = X[j].GetElement(i);
00221         value_t val_2 = Y[j].GetElement(i);
00222         if (am_i_printing) printf ("(%lf --- %lf) ", val_1, val_2);
00223       }
00224       if (am_i_printing) printf ("\n");
00225     }
00226   }
00227 };
00228 
00229 #endif
00230 
00231 } } 
00233 #endif // SKYLARK_PRINT_HPP