1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <mpi.h>
#include <sys/time.h>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include "CombBLAS/CombBLAS.h"
using namespace std;
using namespace combblas;
template <class IT, class NT>
class PairReadSaveHandler
{
public:
PairReadSaveHandler() {};
pair<NT,NT> getNoNum(IT index) { return make_pair((NT) 0, (NT) 0); }
template <typename c, typename t>
pair<NT,NT> read(std::basic_istream<c,t>& is, IT index)
{
pair<NT,NT> pp;
is >> pp.first >> pp.second;
return pp;
}
template <typename c, typename t>
void save(std::basic_ostream<c,t>& os, const pair<NT,NT> & pp, IT index)
{
os << pp.first << "\t" << pp.second;
}
};
int main(int argc, char* argv[])
{
int nprocs, myrank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
if(argc < 5)
{
if(myrank == 0)
{
cout << "Usage: ./VectorIO <DictionaryVector> <UnPermutedVector> <OutputName> base(0 or 1)" << endl;
cout << "Example: ./VectorIO vertex_dict.mtx clusters.mtx original_clusters.mtx 0" << endl;
}
MPI_Finalize();
return -1;
}
{
string vec1name(argv[1]);
string vec2name(argv[2]);
string voutname(argv[3]);
int base = atoi(argv[4]);
FullyDistVec<int64_t,string> vecdict, clusters; // keep cluster ids as "string" for generality
// the "index sets" of vecdict and clusters are the same
// goal here is to just convert the indices in "clusters" to values in vecdict
vecdict.ParallelRead(vec1name, base, // keeps lexicographically larger one in case of duplicates (after warning)
[](string s1, string s2) { cout << "Unexpected duplicate in dictionary" << endl; return std::max<string>(s1, s2); });
clusters.ParallelRead(vec2name, base, // keeps lexicographically larger one in case of duplicates (after warning)
[](string s1, string s2) { cout << "Unexpected duplicate in unpermuted vector" << endl; return std::max<string>(s1, s2); });
vecdict.PrintInfo("dictionary");
clusters.PrintInfo("unpermuted cluster vector");
// FullyDistVec<IT,NT>::EWiseOut(const FullyDistVec<IT,NT> & rhs, _BinaryOperation __binary_op, FullyDistVec<IT,OUT> & result)
// Perform __binary_op(*this[i], rhs[i]) for every element in rhs and *this, write the result output vector
FullyDistVec<int64_t, pair<string, string> > newclusters;
clusters.EWiseOut(vecdict, [] (string s1, string s2) { return make_pair(s1,s2); }, newclusters);
newclusters.ParallelWrite(voutname, base, PairReadSaveHandler<int64_t, string>(), false); // don't print the index
}
MPI_Finalize();
return 0;
}
|