我从FORTRAN 90代码调用C例程.一切正常,但我想知道为什么以及如何用较少的参数调用C例程,我应该编译器不要抱怨.编译器在这做什么?我正在使用Cray编译器.
test.c的
extern "C" void test_(double* x, double* y, double* z){
// do some work
}
Run Code Online (Sandbox Code Playgroud)
driver.F90
MODULE DRIVER
! declare arrays
DOUBLE PRECISION, DIMENSION(dim, dim), INTENT(IN) :: x
DOUBLE PRECISION, DIMENSION(dim, dim), INTENT(IN) :: y
! call C subroutine
CALL test(x, y)
END MODULE DRIVER
Run Code Online (Sandbox Code Playgroud) 我正在测量标准和1Dtexture访问内存之间的差异.为此,我创建了两个内核
__global__ void texture1D(float* doarray,int size)
{
int index;
//calculate each thread global index
index=blockIdx.x*blockDim.x+threadIdx.x;
//fetch global memory through texture reference
doarray[index]=tex1Dfetch(texreference,index);
return;
}
__global__ void standard1D(float* diarray, float* doarray, int size)
{
int index;
//calculate each thread global index
index=blockIdx.x*blockDim.x+threadIdx.x;
//fetch global memory through texture reference
doarray[index]= diarray[index];
return;
}
Run Code Online (Sandbox Code Playgroud)
然后,我调用eache内核来测量它所花费的时间:
//copy array from host to device memory
cudaMemcpy(diarray,harray,sizeof(float)*size,cudaMemcpyHostToDevice);
checkCuda( cudaEventCreate(&startEvent) );
checkCuda( cudaEventCreate(&stopEvent) );
checkCuda( cudaEventRecord(startEvent, 0) );
//bind texture reference with linear memory
cudaBindTexture(0,texreference,diarray,sizeof(float)*size);
//execute device kernel …Run Code Online (Sandbox Code Playgroud) 我想用mpi运行一些函数,main但我不知道它应该如何.看起来像:
#define MAXSIZE 100
int main (int argc, char **argv) {
int i;
float matrixA[MAXSIZE][MAXSIZE], matrixB[MAXSIZE][MAXSIZE], matrixC[MAXSIZE][MAXSIZE];
for(i=0;i<10;i++){
multiply(matrixA, matrixB, matrixC);
}
}
void multiply(float matrixA[MAXSIZE][MAXSIZE], float matrixB[MAXSIZE][MAXSIZE], float matrixC[MAXSIZE][MAXSIZE]) {
int rank; //process rank
int size; //number of processes
MPI_Init(&argc, &argv); //initialize MPI operations
MPI_Comm_rank(MPI_COMM_WORLD, &rank); //get the rank
MPI_Comm_size(MPI_COMM_WORLD, &size); //get number of processes
...someoperation...
MPI_Finalize();
}
Run Code Online (Sandbox Code Playgroud)
我知道如何在不使用其他功能的情况下运行基本MPI,但我需要这种结构.
如果有一个矩阵,我只想访问矩阵的下三角部分.我试图找到一个很好的线索索引,但到目前为止我还没有管理它.有任何想法吗?我需要和索引循环下三角矩阵,说这是我的矩阵
1 2 3 4
5 6 7 8
9 0 1 2
3 5 6 7
Run Code Online (Sandbox Code Playgroud)
索引应该去
1
5 6
9 0 1
3 5 6 7
Run Code Online (Sandbox Code Playgroud)
在该示例中,1D阵列的位置0,4,5,8,9,10,12,13,14,15.
CPU循环是:
for(i = 0; i < N; i++){
for(j = 0; j <= i; j++){
.......
Run Code Online (Sandbox Code Playgroud)
其中N是行数.我在内核中尝试了一些东西:
__global__ void Kernel(int N) {
int row = blockIdx.x * blockDim.x + threadIdx.x;
int col = blockIdx.y * blockDim.y + threadIdx.y;
if((row < N) && (col<=row) )
printf("%d\n", row+col);
}
Run Code Online (Sandbox Code Playgroud)
然后以这种方式调用它:
dim3 Blocks(1,1);
dim3 …Run Code Online (Sandbox Code Playgroud) 我试图理解FTT和卷积(互相关)理论,因此我创建了以下代码来理解它.代码是Matlab/Octave,但我也可以在Python中完成.
在1D:
x = [5 6 8 2 5];
y = [6 -1 3 5 1];
x1 = [x zeros(1,4)];
y1 = [y zeros(1,4)];
c1 = ifft(fft(x1).*fft(y1));
c2 = conv(x,y);
c1 = 30 31 57 47 87 47 33 27 5
c2 = 30 31 57 47 87 47 33 27 5
Run Code Online (Sandbox Code Playgroud)
在2D中:
X=[1 2 3;4 5 6; 7 8 9]
y=[-1 1];
conv1 = conv2(x,y)
conv1 =
24 53 89 29 21
96 140 197 65 42
168 227 …Run Code Online (Sandbox Code Playgroud) 我在Matlab中有一个3D矩阵,它对应于能量剂量传递矩阵.我试图想象和表示矩阵.目前我正在做以下事情(感谢另一篇文章).
diff = double(squeeze(diff));
h = slice(diff, [], [], 1:size(diff,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.1)
Run Code Online (Sandbox Code Playgroud)
这给了我一个很好的3D情节,但仍然很难正确看到它,我必须继续旋转图形才能正确显示它.我也用过:
isosurface(diff,'isovalue')
Run Code Online (Sandbox Code Playgroud)
但同样很难看到任何东西.
我想知道是否有办法摆脱实际剂量表示周围的蓝色区域,因为蓝色区域对应于0值.也许摆脱它可以帮助我看到更清晰的画面.
问题描述
我想知道在C中定义结构以通过其他源文件使用它们的"正确方法".想想以下结构
struct f3{
double x;
double y;
double z;
};
Run Code Online (Sandbox Code Playgroud)
题
应该在头文件或源文件中声明typedef和结构吗?如果在头文件中,为了符合C软件工程技术,应该在该头文件中包含哪些内容?
到目前为止我做了什么:
我可以将它放入types.h,然后struct f3在其他源文件(#include types.h)中使用,或者它可以放在源文件中type.c.
我正在使用文件打印一些值 awk
awk 'NR>1{print $20,$45,$102}' RS='vector'
它打印得很好,但不幸的是,值总是按原样打印,即与...一起打印 :
1 8: 34
1 9: 32
Run Code Online (Sandbox Code Playgroud)
有没有办法:在价值之后删除,所以我可以得到:
1 8 34
1 9 32
Run Code Online (Sandbox Code Playgroud) 我有一个静态库matrixlib.a,我用它来编译一些C代码.这个代码编译,gcc它工作正常.但是,我想将这个库引入C++代码,然后问题就开始了.我编译C代码的方式:
gcc -I/matrix/include -O -Wall example.c -c -o example.o
gfortran example.o /matrix/lib/matrixlib.a -lblas -fopenmp -o example_c
如果现在我们换gcc了g++:
example.c :(.text + 0xf5):未定义的引用`mygemm_solver(int,double const*,double*,double*,int,int)'
是mygemm_solver我正在使用example.c文件的功能.我做错了什么想法?
我想将这两个图组合在一起,我只想使用一个密钥.如果我设置一个,notitle我可以只使用键获得它们,但图形的形状将会改变.
set term postscript eps
set output "temp.eps"
set multiplot layout 1,2
set xtics ("32" 0, "128" 2, "512" 4, "2048" 6, "8192" 8)
#set grid ytics
set xrange [0:8]
set yrange [0:100]
p "8" u ($0):($6) w lp ps 0.75 notitle, "10" u ($0):($6) w lp lc rgb "#228B22" ps 0.75 notitle, "12" u ($0):($6)w lp lc rgb "black" ps 0.75 notitle , "14" u ($0):($6)w lp lc rgb "blue" ps 0.75 notitle, "16" u ($0):($6) w …Run Code Online (Sandbox Code Playgroud)