Function does not complete

Stefan Manegold stefan.manegold at cwi.nl
Thu Apr 7 23:52:22 CEST 2016


Run it in it attach a debugger to check where and why it "gets stuck" (or rather gets trapped in an endless loop?).

My guess is the while(c) loop, because c is (signed) int rather than unsigned int.

Also, assigning 64-bit long values to 32-bit unsigned int variables will loose bits, and is probably not what you intens to do. You might want to use ulng instead of unsigned int. (See the MonetDB type system page for details; if I recall correctly, I shared the link in an earlier thread)

Stefan


On April 7, 2016 8:04:35 PM CEST, Shmagi Kavtaradze <kavtaradze.s at gmail.com> wrote:
>When I run the own written function it runs and does no exit. I was
>waiting
>for 5-6 hours, checked dstats, no disk writes, only 1 core works and no
>memory usage. It is like stuck and can not exit. It happens when I use
>function separately for each variable, without callingm for example:
>
>while( *a ){
>        countA += *a & 1;
>        *a >>= 1;
>    }
>   while( *b ){
>        countB += *b & 1;
>        *b >>= 1;
>    }
>   while( c ){
>        countC += c & 1;
>        c >>= 1;
>    }
>
>but when I call functions like this monetdb works fine:
>
>int countSetBits1(unsigned int n){
>        unsigned int count = 0;
>        while(n){
>            count += n & 1;
>            n >>= 1;
>        }
>    return count;
>    }
>
>countA = countSetBits1(*a);
>countB = countSetBits1(*b);
>countC = countSetBits1(c);
>
>
>I am not strong in C or monetdb internals, but in Netbeans both codes
>work
>well. The entire code :
>
>
>str
>UDFbitanddec(flt *ret, lng *a, lng *b) {
>    int c = 0;
>    int countA = 0;
>int countB = 0;
>    int countC = 0;
>int maxCount = 0;
>unsigned int iA = *a;
>unsigned int iB = *b;
>
>    c = iA & iB;
>
>    while( iA ){
>        countA += iA & 1;
>        iA >>= 1;
>    }
>   while( iB ){
>        countB += iB & 1;
>        iB >>= 1;
>    }
>   while( c ){
>        countC += c & 1;
>        c >>= 1;
>    }
>if (countA >= countB) {
>maxCount = countA;
>}
>else {
>maxCount = countB;
>}
>
>    *ret = (float)countC /maxCount;
>    return MAL_SUCCEED;
>
>}
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>users-list mailing list
>users-list at monetdb.org
>https://www.monetdb.org/mailman/listinfo/users-list

--
| Stefan.Manegold at CWI.nl | DB Architectures   (DA) |
| www.CWI.nl/~manegold/  | Science Park 123 (L321) |
| +31 (0)20 592-4212     | 1098 XG Amsterdam  (NL) |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.monetdb.org/pipermail/users-list/attachments/20160407/db6b998e/attachment-0001.html>


More information about the users-list mailing list