Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/ml/convert2hdf5.cpp
Go to the documentation of this file.
00001 /*
00002  * convert2hdf5.cpp
00003  *
00004  *  Created on: Feb 13, 2014
00005  *      Author: vikas
00006  */
00007 
00008 
00009 #include <string>
00010 #include <skylark.hpp>
00011 #include <boost/mpi.hpp>
00012 #include <elemental.hpp>
00013 #include <cstdlib>
00014 #include "io.hpp"
00015 #include "../base/context.hpp"
00016 
00017 
00018 
00019 int main (int argc, char** argv) {
00020     int provided;
00021     MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
00022 
00023     if (argc!=5)
00024     {
00025         std::cout << "convert2hdf5 inputfile hdf5file mode[0:dense,1:sparse] min_d" << std::endl;
00026         exit(1);
00027     }
00028 
00029     std::string inputfile = argv[1];
00030     std::string hdf5file = argv[2];
00031     int mode = atoi(argv[3]);
00032     int min_d  = atoi(argv[4]);
00033 
00034     boost::mpi::environment env (argc, argv);
00035 
00036     // get communicator
00037     boost::mpi::communicator comm;
00038     int rank = comm.rank();
00039 
00040     elem::Initialize (argc, argv);
00041 
00042 
00043     if (rank == 0)
00044         std::cout << "input: " << inputfile << " hdf5file:" << hdf5file << " mode:" <<  mode << " min_d:" << min_d << std::endl;
00045 
00046     if (mode==0) { // dense
00047         LocalMatrixType X;
00048         LocalMatrixType Y;
00049         read_libsvm(comm, inputfile, X, Y, min_d);
00050         write_hdf5(comm, hdf5file, X,Y);
00051     } else {
00052         sparse_matrix_t X;
00053         LocalMatrixType Y;
00054         read_libsvm(comm, inputfile, X, Y, min_d);
00055         if(rank==0)
00056                 write_hdf5(hdf5file, X,Y);
00057     }
00058 
00059 }