plerros / helsing Goto Github PK
View Code? Open in Web Editor NEWA mostly POSIX-compliant utility that scans a given interval for vampire numbers.
License: BSD 3-Clause "New" or "Revised" License
A mostly POSIX-compliant utility that scans a given interval for vampire numbers.
License: BSD 3-Clause "New" or "Revised" License
When there is bad data in line 1 item 2, the warning points to item 1.
length(0) should return 1
If a.checkpoint is:
1260 1260
The code will return 0 vampire numbers.
a.checkpoint:
0 1
0
The last '0' should cause an unexpected EOF error.
When compiling with -flto:
In function ‘taskboard_new’,
inlined from ‘main’ at src/main.c:44:2:
src/task/taskboard.c:30:22: warning: ‘options.min’ may be used uninitialized [-Wmaybe-uninitialized]
30 | new->options = options;
| ^
src/main.c: In function ‘main’:
src/main.c:33:26: note: ‘options.min’ was declared here
33 | struct options_t options;
| ^
In function ‘taskboard_new’,
inlined from ‘main’ at src/main.c:44:2:
src/task/taskboard.c:30:22: warning: ‘options.max’ may be used uninitialized [-Wmaybe-uninitialized]
30 | new->options = options;
| ^
src/main.c: In function ‘main’:
src/main.c:33:26: note: ‘options.max’ was declared here
33 | struct options_t options;
| ^
When loading from checkpoint, the code tries to 'touch' that file. That fails, resulting in an error.
POSIX standard Line definition:
A sequence of zero or more non- characters plus a terminating character.
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
Current implementation:
Line [1] : A sequence of zero or more non- characters.
Line [2,n] : A terminating character followed by a sequence of zero or more non- characters.
./helsing 0 0
causes division by 0.
While working on #37 any sort of release build was segfaulting. After some investigation I found out that the reason for this is that CMake defaults to defining NDEBUG
in release builds. Looking at
Line 65 in 1f27c7d
pthread_join
segfaults.
A possible fix, which I confirmed to work, is:
diff --git a/helsing/src/main.c b/helsing/src/main.c
index f0028c6..4ee5bba 100644
--- a/helsing/src/main.c
+++ b/helsing/src/main.c
@@ -61,8 +61,10 @@ int main(int argc, char *argv[])
continue;
fprintf(stderr, "Checking interval: [%llu, %llu]\n", lmin, lmax);
- for (thread_t thread = 0; thread < options.threads; thread++)
- assert(pthread_create(&threads[thread], NULL, thread_function, (void *)(thhandle->targs[thread])) == 0);
+ for (thread_t thread = 0; thread < options.threads; thread++) {
+ int pthread_create_return = pthread_create(&threads[thread], NULL, thread_function, (void*) (thhandle->targs[thread]));
+ assert(pthread_create_return == 0);
+ }
for (thread_t thread = 0; thread < options.threads; thread++)
pthread_join(threads[thread], 0);
}
a.checkpoint:
1000 9999
1001
It ignores the 2nd line, and executes normally.
It should detect the error and exit.
Setting cache to 32 can result in 8~13 % performance regression on some 64-bit systems.
Compilation on Ubuntu 21.04 fails with:
undefined reference to 'OPENSSL_init_crypto'
With a numeral base system of 12, the expected behavior is:
$ ./helsing -l 8879963803050 -u 8879963803050
Found: 1 vampire number(s).
but if we enable pdep
$ ./helsing -l 8879963803050 -u 8879963803050
Found: 0 vampire number(s).
Variable multiplicand_max in vargs.c can get out of range, and could potentially cause overflow.
For the 18 digit range cache_new allocates 76.3 MiB, which is way more than the required 7.6 MiB.
This is a regression introduced in commit a868d04
Set in configuration.h:
CHECKPOINT true
Compile & Run:
$ make
...
$ ./helsing -t 1 -n 4
Checking interval: [1000, 9999]
Found: 7 vampire number(s).
$ cat a.checkpoint
1000 9999
2466 6
3933 6
5400 6
6867 6
8334 7
9801 7
(It stops at 9801, because there are no vampire numbers in the range [9802, 9999])
The program completed, and we got our results.
If we were to resume from checkpoint, the program shouldn't calculate anything and the checkpoint file shouldn't change:
$ ./helsing -t 1
Found: 7 vampire number(s).
$ cat a.checkpoint
1000 9999
2466 6
3933 6
5400 6
6867 6
8334 7
9801 7
However:
$ ./helsing -t 1
Checking interval: [9802, 9999]
Found: 7 vampire number(s).
$ cat a.checkpoint
1000 9999
2466 6
3933 6
5400 6
6867 6
8334 7
9801 7
9834 7
9867 7
9900 7
9933 7
9966 7
9999 7
Compile & Run:
$ make
...
$ ./helsing -l 10000000000000000000 -u 10000000000000000000
Expected behavior:
Checking interval: [10000000000000000000, 10000000000000000000]
Found: 0 vampire number(s).
Actual behavior:
Found: 0 vampire number(s).
I get an error:
Invalid arguments, min <= max
min & max take the values 416611827737, 0 respectively
fflush is used way too often, and the code ends up waiting for the system
Observed 20% less cpu utilization, with spikes up to 99%
Set in configuration.h:
Compile & Run:
make
./helsing -l 544 -u 544
Result:
Checking interval: [544, 544]
544 = 32 x 17
Found: 1 valid fang pairs.
This is not a vampire number, because 544 is 10 digit (in base 2) and the fang pairs should be 10/2 = 5 digit, but 32 is 6 digit
error: initializer element is not a compile-time constant
static digits_t digbase = pow(2.0, ((double)ELEMENT_BITS)/9.0);
$ make CC=clang
mkdir -p build/./src/array/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/array/array.c -o build/./src/array/array.c.o
src/array/array.c:54:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
54 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/array/array.c:55:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
55 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
src/array/array.c:56:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
56 | OPTIONAL_ASSERT(count_ptr != NULL);
| ^
3 warnings generated.
mkdir -p build/./src/checkpoint/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/checkpoint/checkpoint.c -o build/./src/checkpoint/checkpoint.c.o
mkdir -p build/./src/hash/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/hash/hash.c -o build/./src/hash/hash.c.o
mkdir -p build/./src/helper/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/helper/helper.c -o build/./src/helper/helper.c.o
src/helper/helper.c:40:50: warning: too many arguments in call to 'no_args'
40 | OPTIONAL_ASSERT(exponent <= length(VAMP_MAX) - 1);
| ~~~~~~~~~~~~~~~ ^
src/helper/helper.c:40:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
40 | OPTIONAL_ASSERT(exponent <= length(VAMP_MAX) - 1);
| ^
2 warnings generated.
mkdir -p build/./src/interval/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/interval/interval.c -o build/./src/interval/interval.c.o
mkdir -p build/./src/linked_list/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/linked_list/llnode.c -o build/./src/linked_list/llnode.c.o
src/linked_list/llnode.c:23:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
23 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/linked_list/llnode.c:24:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
24 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
src/linked_list/llnode.c:54:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
54 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/linked_list/llnode.c:55:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
55 | OPTIONAL_ASSERT(value != 0);
| ^
4 warnings generated.
mkdir -p build/./src/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/main.c -o build/./src/main.c.o
mkdir -p build/./src/options/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/options/options.c -o build/./src/options/options.c.o
mkdir -p build/./src/task/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/task/taskboard.c -o build/./src/task/taskboard.c.o
src/task/taskboard.c:23:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
23 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/task/taskboard.c:24:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
24 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
2 warnings generated.
mkdir -p build/./src/task/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/task/task.c -o build/./src/task/task.c.o
src/task/task.c:18:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
18 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/task/task.c:19:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
19 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
src/task/task.c:44:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
44 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/task/task.c:45:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
45 | OPTIONAL_ASSERT(vamp_args != NULL);
| ^
4 warnings generated.
mkdir -p build/./src/thread/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/thread/targs.c -o build/./src/thread/targs.c.o
src/thread/targs.c:28:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
28 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/thread/targs.c:29:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
29 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
2 warnings generated.
mkdir -p build/./src/thread/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/thread/targs_handle.c -o build/./src/thread/targs_handle.c.o
src/thread/targs_handle.c:20:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
20 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/thread/targs_handle.c:21:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
21 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
2 warnings generated.
mkdir -p build/./src/vampire/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/vampire/cache.c -o build/./src/vampire/cache.c.o
src/vampire/cache.c:31:18: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
31 | OPTIONAL_ASSERT(tmp[i] < DIGBASE(ACTIVE_BITS));
| ^
src/vampire/cache.c:40:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
40 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/vampire/cache.c:41:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
41 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
3 warnings generated.
mkdir -p build/./src/vampire/
clang -I. -I./src -I./src/array -I./src/checkpoint -I./src/hash -I./src/helper -I./src/interval -I./src/linked_list -I./src/options -I./src/task -I./src/thread -I./src/vampire -MMD -MP -Wall -Wextra -O2 -c src/vampire/vargs.c -o build/./src/vampire/vargs.c.o
src/vampire/vargs.c:103:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
103 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/vampire/vargs.c:104:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
104 | OPTIONAL_ASSERT(*ptr == NULL);
| ^
src/vampire/vargs.c:231:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
231 | OPTIONAL_ASSERT(ptr != NULL);
| ^
src/vampire/vargs.c:334:17: warning: passing arguments to 'no_args' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
334 | OPTIONAL_ASSERT(ptr->product[3 - 1].iterator == 0);
| ^
4 warnings generated.
clang -Wall -Wextra -O2 build/./src/array/array.c.o build/./src/checkpoint/checkpoint.c.o build/./src/hash/hash.c.o build/./src/helper/helper.c.o build/./src/interval/interval.c.o build/./src/linked_list/llnode.c.o build/./src/main.c.o build/./src/options/options.c.o build/./src/task/taskboard.c.o build/./src/task/task.c.o build/./src/thread/targs.c.o build/./src/thread/targs_handle.c.o build/./src/vampire/cache.c.o build/./src/vampire/vargs.c.o -o helsing -lpthread -lm
This is invalid:
./helsing a a
It should result in an error.
Same source files on different folders result in different executable.
I don't know where the problem is.
A temporary workaround is to add this flag -L/usr/local/lib to LFLAGS in Makefile.
./helsing -l 0 -u 9999
causes an infinite loop
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.