COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
splitdiag_genpermute.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <algorithm>
3#include <vector>
4#include <numeric>
5#include <fstream>
6
7using namespace std;
8#define PEPS 0.00001
9#define NEPS -0.00001
10
11template<typename _ForwardIter, typename T>
12static void iota(_ForwardIter __first, _ForwardIter __last, T __val)
13{
14 while (__first != __last)
15 *__first++ = __val++;
16}
17
18
19int main(int argc, char* argv[])
20{
21 if(argc < 2)
22 {
23 cout << "Don't forget to pass the input file name" << endl;
24 }
25 ifstream input(argv[1]);
26 string rhsmatrix = string("restrict_T_") + string(argv[1]);
27 string diagonal = string("diag_") + string(argv[1]);
28 string nondiagmat = string("offdiag_") + string(argv[1]);
29
30 ofstream rhsout(rhsmatrix.c_str());
31 ofstream diagout(diagonal.c_str());
32 ofstream matout(nondiagmat.c_str());
33
34 int m, n, nnz;
35 input >> m >> n >> nnz;
36 vector<int> perm(n);
37 iota(perm.begin(), perm.end(), 1); // 1-based
38 random_shuffle(perm.begin(), perm.end());
39 int half = m/2;
40
41 if(half *2 < m) // odd
42 rhsout << m << "\t" << (half+1) << "\t" << m << endl;
43 else // even
44 rhsout << m << "\t" << half << "\t" << m << endl;
45
46 int one = 1;
47 for(int i=0; i< half; ++i)
48 {
49 rhsout << perm[2*i] << "\t" << (i+1) << "\t" << one << endl;
50 rhsout << perm[2*i+1] << "\t" << (i+1) << "\t" << one << endl;
51 }
52 if (half *2 < m) // m was odd
53 {
54 rhsout << perm.back() << "\t" << (half+1) << "\t" << one << endl;
55 }
56 int row, column;
57 double value;
58 int diagnnz = 0;
59 int nondiagnnz = 0;
60 int zero = 0;
61 diagout << m << "\t" << one << "\t" << zero << endl;
62 matout << m << "\t" << n << "\t" << zero << endl;
63 while(!input.eof())
64 {
65 input >> row >> column >> value;
66 // keep explicit zeros
67 if(row == column)
68 {
69 diagout << row << "\t" << one << "\t" << value << endl;
70 diagnnz++;
71 }
72 else
73 {
74 matout << row << "\t" << column << "\t" << value << endl;
75 nondiagnnz++;
76 }
77 }
78 cout << "Diagonal nnz: " << diagnnz << endl;
79 cout << "Off-diagonal nnz: " << nondiagnnz << endl;
80 // will need to reopen this and write first lines
81 rhsout.close();
82 diagout.close();
83 matout.close();
84
85 return 0;
86}
int main()
Definition Driver.cpp:12
void iota(_ForwardIter __first, _ForwardIter __last, T __value)