Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:23

0001 /**
0002 name=tcomplexTest ; nvcc $name.cu -I.. -I/usr/local/cuda -o /tmp/$name && /tmp/$name 
0003 
0004 **/
0005 
0006 #include <iostream>
0007 #include <iomanip>
0008 
0009 #include "scuda.h"
0010 #include "tcomplex.h"
0011 
0012 
0013 /*
0014  we test the follow calculation:
0015 
0016    a = 0 + 4i;
0017    sqrt of a = 2^0.5 + i* 2^0.5
0018 
0019 */
0020 
0021 __global__ void test_complex()
0022 {
0023      
0024    unsigned ix = blockIdx.x * blockDim.x + threadIdx.x;
0025    unsigned iy = blockIdx.y * blockDim.y + threadIdx.y;
0026 
0027    cuFloatComplex a = make_cuFloatComplex(ix, iy);
0028    cuFloatComplex b = tcomplex::cuSqrtf(a); 
0029 
0030    float  a_rho = tcomplex::cuRhof(a);
0031    float  a_the = tcomplex::cuThetaf(a);
0032    
0033    float  b_rho = tcomplex::cuRhof(b);
0034    float  b_the = tcomplex::cuThetaf(b); 
0035    
0036    printf("//test_complex  (ix,iy) (%2i, %2i) (x,y) (%10.4f, %10.4f) a(rho,the)(%10.4f, %10.4f)  b(rho,the)(%10.4f, %10.4f ) \n", 
0037          ix, iy, a.x, a.y, a_rho, a_the, b_rho, b_the );
0038 }
0039 
0040 
0041 void test_device_complex_api()
0042 {
0043     dim3 block(16,16); 
0044     dim3 grid(1,1);
0045 
0046     test_complex<<< grid , block >>>();  
0047     cudaDeviceSynchronize();
0048 }
0049 
0050 int main()
0051 {
0052     test_device_complex_api();
0053     return 0 ; 
0054 }
0055 
0056