平行strlen的?

编程入门 行业动态 更新时间:2024-10-27 00:26:42
本文介绍了平行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的?

本文发布于:2023-07-30 00:45:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1245047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:strlen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!