File: VectorIOPermute.cpp

package info (click to toggle)
combblas 2.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 190,476 kB
  • sloc: cpp: 55,912; ansic: 25,134; sh: 3,691; makefile: 548; csh: 66; python: 49; perl: 21
file content (119 lines) | stat: -rw-r--r-- 3,242 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#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;

#define myidlen 35
#define myseqlen 150

template <unsigned int IDLEN, unsigned int SEQLEN>
class ShortRead
{
public:
	ShortRead(){ id[0] = '\0'; seq[0] = '\0'; qual[0] = '\0'; };
    ShortRead(const string & s_id, const string & s_seq, const string & s_qual)
    {
        s_id.copy(id, IDLEN);
        s_seq.copy(seq, SEQLEN);
        s_qual.copy(qual, SEQLEN);
        id[IDLEN] = '\0';
        seq[SEQLEN] = '\0';
        qual[SEQLEN] = '\0';

    }
	template <unsigned int NS_IDLEN, unsigned int NS_SEQLEN>
	friend ostream& operator<<( ostream& os, const ShortRead<NS_IDLEN,NS_SEQLEN> & sread);
    
private:
	char id[IDLEN+1];   // (+1)s are for null termination
    char seq[SEQLEN+1];
    char qual[SEQLEN+1];
	
	template <typename IT,unsigned int NS_IDLEN, unsigned int NS_SEQLEN>    // NS: no-shadow
	friend class ShortReadSaveHandler;
};

template <unsigned int IDLEN, unsigned int SEQLEN>
ostream& operator<<(ostream& os, const ShortRead<IDLEN, SEQLEN> & sread )
{
	os << sread.id << " " << sread.seq << " " << sread.qual << endl;
	return os;
};


template <class IT, unsigned int IDLEN, unsigned int SEQLEN>
class ShortReadSaveHandler
{
public:
    ShortReadSaveHandler() {};
    ShortRead<IDLEN,SEQLEN> getNoNum(IT ind) { return ShortRead<IDLEN,SEQLEN>(); }
    
    MPI_Datatype getMPIType()
    {
        return MPIType< ShortRead<IDLEN,SEQLEN> >(); // utilize the MPI type cache
    }
    
    void binaryfill(FILE * rFile, IT & ind, ShortRead<IDLEN,SEQLEN> & val)
    {
        size_t entryLength = fread (&ind,sizeof(ind),1,rFile);      // read the index first
        entryLength += fread (&val,sizeof(ShortRead<IDLEN,SEQLEN>),1,rFile);
        if(entryLength != 2)
            cout << "Not enough bytes read in binaryfill " << endl;
    }
    size_t entrylength() { return sizeof(ShortRead<IDLEN,SEQLEN>); }
    
    template <typename c, typename t>
    ShortRead<IDLEN,SEQLEN> read(std::basic_istream<c,t>& is, IT ind)
    {
        string s_id, s_seq, s_qual, s_null;
        getline (is,s_id);
        getline (is,s_seq);
        getline (is,s_null); // basically the '+' sign
        getline (is,s_qual);
        
        return ShortRead<IDLEN,SEQLEN>(s_id, s_seq, s_qual);
    }
	
    template <typename c, typename t>
    void save(std::basic_ostream<c,t>& os, const ShortRead<IDLEN,SEQLEN> & tw, IT ind)
    {
       // make it compatible with read...
    }
};



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 < 4)
	{
		if(myrank == 0)
		{
			cout << "Usage: ./VectorIOPermute <VectorFile>" << endl;
			cout << "<VectorFile> is a binary file" << endl;
		}
		MPI_Finalize(); 
		return -1;
	}				
	{

        FullyDistSpVec<int64_t, ShortRead<myidlen, myseqlen> > ShortReads;
        ShortReads.ReadDistribute(string(argv[1]), 0, ShortReadSaveHandler<int64_t, myidlen, myseqlen>(), true);	// read it from binary file in parallel
			
		
	}
	MPI_Finalize();
	return 0;
}