Post
Topic
Board Development & Technical Discussion
Re: How to use brainflayer on each cpu core ? multithreaded ?
by
nunucbka
on 17/01/2019, 15:42:37 UTC
Hi there!

how to run parallel on a multi-core computer, I know. The question is how to run on multi-core, where are 2 threads per core? Suppose on a 10-core computer where there are 20 threads? (-n 1/10/1 -n 1/10/2 ...) or each thread, regardless of whether it's a real kernel or a virtual one, is handled separately? ( from -n 1/20 to -n 20/20? )
On a 10-core computer with 20 threads, how many processes can be run simultaneously at the same time? 10 or 20 ?

Best speed is on threads_count=physical_cores_count
Following code generates random 64-char hex string and then starts bg processes and kills them after "$2" seconds.
Code:
#!/bin/bash
trap "exit" INT TERM ERR
trap "kill 0" EXIT
let "thr = $(lscpu | grep -E '^CPU\(s\)' | sed 's/CPU(s)://' | sed s/' '//g) / 2"
# if you want to get more parallel processes uncomment following (or set 'thr' value as much as you want)
# thr = $(lscpu | grep -E '^CPU\(s\)' | sed 's/CPU(s)://' | sed s/' '//g)
blfname=$1 #your_bloom_filter_filename
tosleep=$2 #time_to_sleep
while 2>1
do
hexval=$(openssl rand $[32] | xxd -p -c32 | grep -E -o '.{64}$')
for n in  $(seq 1 $thr)
do
./brainflayer -a -v -I $hexval -b $blfname -n $n/$thr -o out$n -m 1tab.tab &
done
sleep $tosleep
kill $(pgrep brainflayer | echo $(tr '\n' ' '))
done

Hope this helps  Wink