-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRS Arrays of Sparse Matrices #44
Comments
which
and
The 2nd returns a triplets vector, as needed to construct a sparse matrix in eigen. The 1st assumes you are passing in a dense eigen matrix. You could probably adapt the 2nd to instead return the CRS format required by amgcl? |
I am using the first assemble function. |
The 1st function is only for dense matrices, I'm not surprised if it is
slow for sparse matrices. Use the 2nd assemble function, and then Eigen
`setFromTriplets` function (see
https://eigen.tuxfamily.org/dox/group__TutorialSparse.html) to create an
Eigen sparse matrix, then get the CRS arrays from that.
…On Tue, 8 Jan 2019 at 10:15, JabirSS ***@***.***> wrote:
I am using the first assemble function.
Eigen actually does a pretty good job in generating the CRS arrays, so I
can live with it but the assemble function runs in serial and is currently
the slowest part of the entire routine. Adding the #pragma omp parallel
for didn't seem to help with either the first or 2nd function. Is it
possible to get them to work in parallel?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#44 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABGF9EN6yEeo7RhrN3rfAMSGhCRu3AiWks5vBG-ngaJpZM4Z00w8>
.
|
Sorry but I am unable to get the second function to compile. Here's what I did:
The compiler throws the following error for the
seems like it's still calling the wrong function? |
Sorry, I was looking at the code for the try this:
|
^^^^^^^^^^^ |
Unfortunately |
yes, this runs in serial. Its tricky, as unless you know how many non-zero values there are going to be in each row of the sparse matrix, it is going to be difficult to construct it in parallel. Do you absolutly need to construct the matrix? Is there any way you can use your multigrid solver in a matrix-free fashion? |
what you could do construct each row of the sparse matrix (i.e. a sequence of triplets) in parallel, and then have a serial portion at the end that concatenates them? If you could rewrite the 2nd function above to do this, then I'd (very) happily merge it into Aboria! |
Alright, I'll give it a shot and let you know!
…On Wed, Jan 9, 2019, 21:43 Martin Robinson ***@***.*** wrote:
what you could do construct each row of the sparse matrix (i.e. a sequence
of triplets) in parallel, and then have a serial portion at the end that
concatenates them? If you could rewrite the 2nd function above to do this,
then I'd (very) happily merge it into Aboria!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#44 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Aku2sIjHwYHGFvwgfDXblC0XDNcge8Qbks5vBeQGgaJpZM4Z00w8>
.
|
Unfortunately the library I'm using doesn't support matrix free operations yet.
I'm not sure if this is useful to you at all, since it is way too specific when compared to the function in |
Great you were able to speed it up. This is useful, and along the lines of what I was thinking. Before putting it into Aboria, it would have to be able to handle matrix-valued kernels (i.e. a kernel function returning a matrix rather than a scalar). If you wish to do this, you are more than welcome of course (I can explain more about how this works), but I'd understand if you wish to move on with your own simulation! |
Thank you, it would be great if you could explain the matrix-valued kernels or refer me to some reading materials, and I'll more than gladly write it down for addition to Aboria. |
Unfortunately this isn't really documented anywhere. I was originally using the matrix-valued kernels for Boundary Element Simulations of stokes flow. This is a kernel based method that uses greens functions for the kernel, in this case the greens function for stokes flow, which returns a matrix of size 2x2, where 2 in this case is the number of spatial dimensions Below is the current code for the The To assemble the matrix, the code does an outer loop down the rows: for (size_t i = 0; i < na; ++i) { an inner loop down each non-zero block in that row for (auto pairj =
euclidean_search(b.get_query(), get<position>(ai), radius);
pairj != false; ++pairj) { and then an inner-inner double loop for each element of that block
Does this make sense? You just have to use template <typename Triplet>
void assemble(std::vector<Triplet> &triplets, const size_t startI = 0, const size_t startJ = 0) const {
const RowElements &a = this->m_row_elements;
const ColElements &b = this->m_col_elements;
const size_t na = a.size();
// sparse a x b block
// std::cout << "sparse a x b block" << std::endl;
for (size_t i = 0; i < na; ++i) {
const_row_reference ai = a[i];
const double radius = m_radius_function(ai);
for (auto pairj =
euclidean_search(b.get_query(), get<position>(ai), radius);
pairj != false; ++pairj) {
const_col_reference bj = *pairj;
const_position_reference dx = pairj.dx();
const size_t j = &get<position>(bj) - get<position>(b).data();
const Block element = static_cast<Block>(m_dx_function(dx, ai, bj));
for (size_t ii = 0; ii < BlockRows; ++ii) {
for (size_t jj = 0; jj < BlockCols; ++jj) {
triplets.push_back(Triplet(i * BlockRows + ii + startI,
j * BlockCols + jj + startJ,
element(ii, jj)));
}
}
}
}
} |
Yup, citing the SoftwareX paper would do it, thanks! I should put this in a |
Thank you for the explanation. Yes, that makes perfect sense! I'll let you know how it goes. |
Dear @martinjrobins,
Thank you for your continuous development and support of Aboria.
I have been solving large systems of equations using Aboria and recently I found myself needing to use a different linear solver than Eigen since it's missing the Algebraic MultiGrid method which is a lot faster for my problem.
To do this, I created the sparse operator then used Eigen to assemble the matrix and obtain the compressed sparse row arrays I needed to pass to the external linear solver library (amgcl).
However, I noticed that the assemble command is quite slow (2x slower than the solution of the linear system) and runs in serial.
I would really appreciate any suggestions you may have to improve this. Currently is there any other way to get the CRS arrays directly from Aboria without resorting to Eigen?
The text was updated successfully, but these errors were encountered: