Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(迟来的Pr...)
filter_positive()
有什么问题?在一个线程中对counter+1时,可能会有另外一个线程同时取出counter的旧值+1,而不是最新值,因此造成错误。使用
atomicAdd()
原子操作避免上述问题fill_sin
改为网格跨步循环后,可以指定任意的线程数(blockDim)和板块数(gridDim),无需担心越界或漏元素的问题若n = 1025,n / 1024 = 1,总共会启动1*1024=1024个线程,会漏掉1个元素