I was able to implement the following tutorial using ublas and viennacl for a few different iterative solvers:
My issue arose when trying to pass vectors calculated in C++ for the matrix.
// Global Variables
vector< vector<float> > Jacobian(0, vector<float>(0)); //Jacobian matrix
vector<float> delta_PQ; //rhs
// Set up some ublas objects
using namespace boost::numeric;
typedef float ScalarType;
// Resize RHS from main program
//copy content to GPU vector (recommended initialization)
copy(delta_PQ.begin(), delta_PQ.end(), rhs.begin()); //works
copy(Jacobian.begin(), Jacobian.end(), ublas_matrix); //won't compile
The last line throws an error. I tried using this form (below) as well but would need to convert the ublas::compressed_matrix to a viennacl::compressed_matrix.
Doing that results in a bunch of compile errors which I have another discussion topic open about. I have also posted on stackoverflow in hopes someone there will be able to help.
Thanks in advance!
what are you trying to achieve? Please include the namespaces in the types. Is vector from std:: or from viennacl::? Regardless, if you're using vector<vector<T> >, this is always a dense data storage, whereas compressed_matrix<> is intended for sparse matrices. You usually don't want to mix the two.
Thank you for the quick reply. The vector is using namespace std::. I presently have a program which computes a sparse matrix and stores is in the form:
vector< vector<float> > Jacobian(0, vector<float>(0)); //Jacobian
This matrix is presently about 90% zeros however, I have not been able to get it to fit any standard form such as diagonal, yet. Pre-processing of the model files to produce a cleaner and more usable matrix is a future phase of my project.
I am attempting to use the iterative solvers in viennacl from your tutorial below to place the precomputed jacobian into the ublas matrix which is of type ublas::compressed_matrix. I already have the rhs using the function copy(delta_PQ.begin(), delta_PQ.end(), rhs.begin());
Would you recommend using the ublas compressed matrix from the start and then using my C++ program to populate it? If so, what would the ublas::compressed_matrix equivalent of Jacobian = 54.28f; be?
vector< vector> is not an efficient sparse matrix format, it is in almost all use cases a dense vector format. Use vector< map > instead (it has the same [i][j] bracket acess), and you can use
directly. As an alternative, fill the ublas-matrix directly via operator(), i.e.
ublas_matrix(1,1) = value1;
ublas_matrix(7,8) = value2;
etc. Depending on the order of the values, filling ublas_matrix directly may be slower or faster. As a rule of thumb, vector< map > is faster whenever the entries are written in a 'random' fashion, whereas ublas_matrix is faster if you fill row and column entries in consecutive order (and eventually supply the number of nonzero entries to the matrix constructor upfront).
Hope that helps :-)
It does and I will let you know how I make out! Thank you very much, you guys are going a phenomenal job!
Works like a charm. Thank you Karli! I am hopeful the bug or my misconfiguration with using the viennacl library as opposed to the boost ublas will be fix for VS2013 and AMD APP 2.8 soon so I can start harnessing the gpu for these calculations.
Log in to post a comment.