我只是编写我的第一个CUDA程序,它实际上是对C++代码的重写.现在它处理了很多矢量数学,所以我使用了float4数据类型,它提供了我所需要的.但是,旧代码包含很多
float *vec;
vec = new float[4];
for(int i=0; i<4; i++) vec[i] = ...;
Run Code Online (Sandbox Code Playgroud)
现在使用float4,我所能做的就是为每个.x,.y,.z,.w写一行,我觉得有点讨厌.有没有办法以类似的方式访问float4元素,即
float4 vec;
for(int i=0; i<4; i++) vec[i] = ...;
Run Code Online (Sandbox Code Playgroud)
不幸的是我在互联网上找不到任何提示.
提前致谢.
我手边有以下程序
program foo
type bar
real, dimension(2) :: vector
end type
type(bar), dimension(3) :: bararray
call doSomething(bararray%vector)
end program
subroutine doSomething(v)
real, dimension(3,2), intent(inout) :: v
...
end subroutine
Run Code Online (Sandbox Code Playgroud)
现在这给了我一个编译错误.
Error: Two or more part references with nonzero rank must not be specified at (1)
Run Code Online (Sandbox Code Playgroud)
如果我将呼叫更改为
call doSomething((/bararray%vector(1), bararray%vector(2)/))
Run Code Online (Sandbox Code Playgroud)
一切顺利.问题是,这似乎有点麻烦,所以问题是,是否还有其他方法来编写子程序的参数?
提前致谢.