CUDA
C/C++    Fortran   

fortran/examples/basic.f95

00001 program basic
00002   use arrayfire
00003   implicit none
00004 
00005   real, dimension(3,3) :: a
00006   real, dimension(:,:), allocatable :: b
00007   type(array) M1, M2, tmp
00008 
00009   a(1,:) = (/ 1, 0, 0 /)
00010   a(2,:) = (/ 0, 3, 0 /)
00011   a(3,:) = (/ 0, 0, 2 /)
00012 
00013   ! Copy data from host to device
00014   M1 = a
00015   write(*,*) "Showing the matrix after mem copy from host (M1)"
00016   call print(M1)
00017 
00018   ! Generate a uniformly random, single precision matrix
00019   M2 = randu(3,3, ty=f32)
00020   write(*,*) "Showing a randomly generated matrix (M2)"
00021   call print(M2)
00022 
00023   ! Transpose of matrix
00024   tmp = transpose(M2)
00025   call print(tmp, "Transpose of M2") ! Displays array after printing message
00026 
00027   ! Element wise addition
00028   tmp = M1 + M2
00029   call print(tmp, "M1 + M2")
00030 
00031   ! element wise subtraction
00032   call print(-M2, "-M2")
00033 
00034   ! Trignometric functions
00035   write(*,*) "Displaying sin(M2)**2 + cos(M2)**2"
00036   call print(sin(M2)**2.0 + cos(M2)**2.0)
00037 
00038   ! Multiplication of matrices
00039   ! Matrix multiply
00040   write(*, *) "Matrix multiply: matmul(M1, M2)"
00041   call print(matmul(M1, M2))
00042 
00043   ! Element wise multiplication
00044   write(*, *) "Element wise multiplication: M1 * M2"
00045   call print(M1 * M2)
00046 
00047   ! minimum value
00048   tmp = min(M2)
00049   call print(tmp, "min(M2)")
00050 
00051   ! Get back to host
00052   b = tmp
00053   write(*,*) "Showing min(M2) data back on host "
00054   write(*,*) b(:,:)
00055 
00056 end program basic