平行strlen的? [英] parallel strlen?

查看:157
本文介绍了平行strlen的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否会有任何好处在试图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的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆