Im new to using cusp library for cuda. I'm trying to implement revised simplex algorithm for CUDA. For that I need to multiply 2 sparse matrices to update the base matrix.
So the question is - how can I multiply 2 sparse matrices(doesn't really matter in what format) using cusp library? Also is there a way to know how many nonzero elements is the result matrix going to contain(for memory allocation purposes)?
I tried:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdlib.h>
#include <stdio.h>
#include "cusparse.h"
#include <cusp/version.h>
#include <cusp/multiply.h>
#include <cusp/array2d.h>
#include <cusp/print.h>
#include <cusp/coo_matrix.h>
int main(void)
{
cusp::coo_matrix<int,double,cusp::device_memory> A(2,2,2);
A.values[0] = 1;
A.row_indices[0] = 0;
A.column_indices[0]= 0;
A.values[1] = 1;
A.row_indices[1] = 1;
A.column_indices[1]= 1;
cusp::coo_matrix<int, double, cusp::device_memory> B(2,2,4);
B.values[0] = 1;
B.row_indices[0] = 0;
B.column_indices[0]= 0;
B.values[1] = 2;
B.row_indices[1] = 0;
B.column_indices[1]= 1;
B.values[2] = 3;
B.row_indices[2] = 1;
B.column_indices[2]= 0;
B.values[3] = 4;
B.row_indices[3] = 1;
B.column_indices[3]= 1;
cusp::print(A);
cusp::print(B);
cusp::coo_matrix<int,double, cusp::device_memory> C(2,2,4);
cusp::multiply(A,B,C);
cusp::print(C);
}
As cusp:multiply() was the only function for multiplication I found.
cusp v.0.4 CUDA v.5.5
cusp::coo_matrix<int,double, cusp::device_memory> C;
and your code still works. – Robert Crovella