0
$\begingroup$

I am trying to write an algebraic multi-grid solver (in c++). At a given level I determine which nodes are c-points and which nodes are f-points (where the total number of c and f points equals the matrix dimension on that level). Therefore I need two arrays: one array to hold the indices of the c-points, and one array to hold the indices of the f-points. The problem is I do not know how many c-points (or f-points) there will be before hand and so I don't know how large to make these arrays. One option is to just make both arrays to have size the same as the number of rows in the matrix that way ensuring no overflow. This is what I am doing right now, but this entails significant extra storage wasted. I could also essentially run my function that determines the c-points and f-points twice, where the first time I just record the final sizes, but this is obviously a lot of extra work. Does anyone know what is the best strategy for dealing with this? There does not seem to be any way of determining the final number of c-points without actually computing them one after another.

$\endgroup$
2
$\begingroup$

Maybe you could make one array that's sized for the total number of points, then fill it with coarse points from the front and fine points from the back. They'll meet up somewhere in the middle (but not overlap).

$\endgroup$
  • 1
    $\begingroup$ Thats an interesting idea!! I didn't think of that thanks. $\endgroup$ – James Sep 18 '14 at 13:45
0
$\begingroup$

In C the command calloc creates an array at runtime and realloc makes a previous array bigger or smaller. In reality you may need a linked list, there's an open source library called Gobject. It'll require further programming skill to use it but may lead to massive memory savings and will allow for a stupidly large number of nodes per layer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.