COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
SegTest.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <random>
3#include <chrono>
4#include "CombBLAS/CombBLAS.h"
5
6using namespace combblas;
7
8typedef std::vector<int64_t> vec64_t;
9
10/* Copied from MultTest.cpp in CombBLAS */
11// Simple helper class for declarations: Just the numerical type is templated
12// The index type and the sequential matrix type stays the same for the whole code
13// In this case, they are "int" and "SpDCCols"
14template<class NT>
15class PSpMat {
16public:
19};
20
22 int count = 0;
23 std::pair<int64_t, int64_t> first;
24 std::pair<int64_t, int64_t> second;
25
26 friend std::ostream &operator<<(std::ostream &os, const CommonKmers &m) {
27 os << "|" << m.count << "(" << m.first.first << "," << m.first.second
28 << ")(" <<
29 m.second.first << "," << m.second.second << ")| ";
30 return os;
31 }
32};
33
34
35template<typename IN, typename OUT>
37 static OUT id() {
38 OUT a;
39 return a;
40 }
41
42 static bool returnedSAID() { return false; }
43
44 static OUT add(const OUT &arg1, const OUT &arg2) {
45 OUT res;
46 res.count = arg1.count + arg2.count;
47 res.first.first = arg1.first.first;
48 res.first.second = arg1.first.second;
49 res.second.first = arg2.first.first;
50 res.second.second = arg2.first.second;
51 return res;
52 }
53
54 static OUT multiply(const IN &arg1, const IN &arg2) {
55 OUT a;
56 a.count++;
57 a.first.first = arg1;
58 a.first.second = arg2;
59 return a;
60 }
61
62 static void axpy(IN a, const IN &x, OUT &y) {
63 y = add(y, multiply(a, x));
64 }
65
66 static MPI_Op mpi_op() {
67 static MPI_Op mpiop;
68 static bool exists = false;
69 if (exists)
70 return mpiop;
71 else {
73 exists = true;
74 return mpiop;
75 }
76 }
77
78 static void
80 for (int i = 0; i < *len; ++i) {
81 *((OUT) inoutvec + i) = add(*((OUT) invec + i), *((OUT) inoutvec + i));
82 }
83
84 }
85};
86
87int read_matrix(std::string fname, int offset, int row_offset,
89
90int main(int argc, char **argv) {
91 std::cout << "hello";
93 MPI_Init(&argc, &argv);
96 {
97
98 // assert(world_size == 4);
99
108 unsigned int base = 20; // Represents the protein alphabet size
109 unsigned int k = 2; // Kmer size
110 unsigned long total_k = static_cast<unsigned int>(pow(base, k));
111
112 // This is how many nnzs were there in each local matrix when segfaulted
113 int nnzs[4] = {146, 56, 100, 141};
114 int lrows[4] = {2, 1, 1, 1};
115
116 int vec_size = world_size > 1 ? nnzs[world_rank] : (146 + 56 + 100 + 141);
117 std::vector<int64_t> lrow_ids(static_cast<unsigned long>(vec_size));
118 std::vector<int64_t> lcol_ids(static_cast<unsigned long>(vec_size));
119 std::vector<int64_t> lvals(static_cast<unsigned long>(vec_size));
120
121 std::string fnames[4] = {"mat.0.txt", "mat.1.txt", "mat.2.txt", "mat.3.txt"};
122 int offset = 0;
123 if (world_size > 1) {
125 lvals);
126 } else {
127 int row_offset = 0;
128 for (int i = 0; i < 4; ++i) {
130 lvals);
131 row_offset += lrows[i];
132 }
133 }
134
135 /*if (world_size == 1) {
136 *//*
137 std::ofstream f;
138 std::string fname = "mat.concat.txt";
139 f.open(fname);
140 for (int i = 0; i < lrow_ids.size(); ++i) {
141 f << lrow_ids[i] << "," << lcol_ids[i] << "," << lvals[i] << std::endl;
142 }
143 f.close();
144 }*/
145
146 std::printf("Rank: %d lrow_ids %ld lcol_ids %ld lvals %ld\n",
147 world_rank, lrow_ids.size(), lcol_ids.size(), lvals.size());
148
149 std::shared_ptr<CommGrid> grid =
150 std::make_shared<CommGrid>(MPI_COMM_WORLD, std::sqrt(world_size),
151 std::sqrt(world_size));
152
156
157 int m = 5, n = static_cast<int>(total_k);
159
160 A.PrintInfo();
161
162 auto At = A;
163 At.Transpose();
164
166
167 if (world_rank == 0){
168 std::cout<<"before multiplication";
169 }
172 A, At);
173
174 //seg faults here
175 C.PrintInfo();
176 }
177
178/* Hmm, someone else seems to call MPI_Finalize */
179 int flag;
181 if (!flag) {
182 MPI_Finalize();
183 }
184}
185
186int read_matrix(std::string fname, int offset, int row_offset,
188 std::ifstream f(fname);
189 std::string v;
190 while (f.good()){
191 getline(f, v, ',');
192 if (v.empty()) break;
193 int val = stoi(v);
195 getline(f, v, ',');
196 val = stoi(v);
197 lcol_ids[offset] = val;
198 getline(f, v);
199 val = stoi(v);
200 lvals[offset] = val;
201 ++offset;
202 }
203 return offset;
204}
205
int main()
Definition Driver.cpp:12
int read_matrix(std::string fname, int offset, int row_offset, vec64_t &lrow_ids, vec64_t &lcol_ids, vec64_t &lvals)
Definition SegTest.cpp:186
std::vector< int64_t > vec64_t
Definition SegTest.cpp:8
SpParMat< int64_t, NT, DCCols > MPI_DCCols
Definition SegTest.cpp:18
SpDCCols< int64_t, NT > DCCols
Definition SegTest.cpp:17
double A
double C
Definition options.h:15
std::pair< int64_t, int64_t > second
Definition SegTest.cpp:24
friend std::ostream & operator<<(std::ostream &os, const CommonKmers &m)
Definition SegTest.cpp:26
std::pair< int64_t, int64_t > first
Definition SegTest.cpp:23
static bool returnedSAID()
Definition SegTest.cpp:42
static OUT add(const OUT &arg1, const OUT &arg2)
Definition SegTest.cpp:44
static void MPI_func(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
Definition SegTest.cpp:79
static MPI_Op mpi_op()
Definition SegTest.cpp:66
static OUT multiply(const IN &arg1, const IN &arg2)
Definition SegTest.cpp:54
static OUT id()
Definition SegTest.cpp:37
static void axpy(IN a, const IN &x, OUT &y)
Definition SegTest.cpp:62