Parallel strlen?

I am wondering if there would be any merit in trying to encode a function strlento find the sequence \0in parallel. If so, what should such a function take into account? Thank.

+5
source share
6 answers

You need to make sure that the NULone found by the stream is the first NULin the line, which means that the streams will need to synchronize with what is their lowest location NUL. Therefore, although this can be done, the overhead for synchronization will be much more expensive than any potential gains from parallelization.

There is also a caching issue. One thread can read a line that is a cache. Several threads control the risk of switching to each other.

+4
source

strlen() is consistent in spirit - one step outside the null terminator is undefined behavior, and the null terminator can be anywhere — the first character or millionth character, so you need to scan sequentially.

+8
source

, , ; , , . , , , 256 , 4 . , , 4K- ( 256 , ), . , , parallelism, , .

+1

, . , .

, ( ), .

NUL-, . , NUL , , , NUL, .

, 8 (0-7). NUL- 3, , NUL- 0-2, , . 1 NUL-, 0, .

0

FIXED-WIDTH, .

0

It depends on the architecture. Nothing wrong with the fact that several computing devices are hunting for this first null character, but you will need to support them with a constant stream of data from memory. You will probably want to configure a specific platform for exact parameters that take into account cache boundaries.

0
source

All Articles