我不知道是否会有任何好处在试图codeA 的strlen 函数查找 \\ 0 并行顺序。如果是这样,应该这样的功能考虑?谢谢你。
I'm wondering if there would be any merit in trying to code a strlen function to find the \0 sequence in parallel. If so, what should such a function take into account? Thanks.
推荐答案您不得不确保 NUL 由一个线程中是第一个 NUL 字符串中的,这意味着线程需要对他们的最低 NUL 位置是同步的。因此,尽管它可以做到的,同步的开销会远远大于从并行的任何潜在收益更加昂贵。
You'd have to make sure the NUL found by a thread is the first NUL in the string, which means that the threads would need to synchronize on what their lowest NUL location is. So while it could be done, the overhead for the sync would be far more expensive than any potential gain from parallelization.
此外,还有缓存的问题。单个线程可以读取连续的字符串,这是高速缓存友好。多线程运行踩着对方的脚趾的风险。
Also, there's the issue of caching. A single thread can read a string contiguously, which is cache friendly. Multiple threads run the risk of stepping on each other's toes.
更多推荐
平行strlen的?
发布评论