Closed szarnyasg closed 5 years ago
As a good practice start by initialising graphBLAS
assert(GrB_init(GrB_NONBLOCKING) == GrB_SUCCESS);
When debugging or in general check return value from GraphBLAS calls as it might give information why an operation failed.
I'm not sure why but GraphBLAS won't update element
to ZERO when entry [i,j] is not set, and so element
would cary its previous value.
`void printDoubleVector(GrB_Vector vec) {
GrB_Index size;
GrB_Vector_size(&size, vec);
double element;
for(unsigned int i = 0; i < size; i++) {
GrB_Vector_extractElement(&element, vec, i);
printf("%lf ", element);
element = 0.0;
}
printf("\n");
}`
I’ll take a look and get back to you shortly.
Tim Davis
GrB_extractElement does not return anything in &element if the entry is not present. It does not return zero. It leaves the values in 'element' unmodified. It returns an info value:
info = GrB_Vector_extractElement ( ... )
with info equal to GrB_NO_VALUE.
It can't return zero in the scalar 'element'. The value of the entry that is not present in the matrix or vector is not zero, but the identity value of the additive monoid. That could be anything. It is -INFINITY if the monoid is 'max', for example. It is unknown entirely.
So the value of element is undefined on the 2nd usage. It happens to be 20, but that is likely just what's randomly at that memory location from the last call to the printDoubleVector.
I will send you a fix to your code soon.
Here is the fixed code:
The fixed.c just checks the return value of the extractElement functions and prints 'no value' if the return value is GrB_NO_VALUE.
Here is the correct output:
MATLAB does the same thing, but it only has two semirings, and for both of them, the identity value of the additive monoid is zero:
One thing that would help would be a "GxB_print" method that would print the contents of a GraphBLAS object. That would have clarified your problem. I've seen others write their own 'print matrix' function, too. It's a common need. I have my own functions, but they are internal and "can't" be called by the user.
However, if you do
and also put -IGraphBLAS/Source in your compile step, then do
GB_check (A, "my matrix A is:", level) ;
where level = 0 (nothing), 1 (print a terse line), 2: print 30 entries or so, 3: print it all. I plan on adding a user interface to that function. It's not in the spec.
Thank you for the quick response and correction. I changed the print method as you suggested and it works correctly now, it solved our problem.
Hi everyone,
I am working on graph analytics with my Master's student, @Lehel44.
When using GraphBLAS, we encountered some strange behaviour, documented in the code snippet below. We are beginners with GraphBLAS, so it's possible that we use the API incorrectly -- please advise on what changes we should make. We are aware that this is not an official repository, but it might be a good place to start.
Thank you.