gpuSapply | R Documentation |
Please refer to sapply to see the basic usage
gpuSapply(X, FUN, ..., .macroParms = NULL, .device = "auto", loading = "auto", .options = gpuSapply.getOption())
X |
a vector that |
FUN |
The function to be applied to each element of |
... |
optional arguments to |
.macroParms |
The function argument that will be treated as macro in the code. If an argument is treated as macro, its value cannot be changed by the code |
.device |
the device ID(s) indicates the device that the function will be excuted on. Running the code on Multiple devices is supported but is still under development |
loading |
The loading of each device, only useful when having multiple devices. |
.options |
The package and openCL compilation options, please call |
This function compiles the R code and runs it on the openCL-compatible devices. The usage is similar to the sapply function with some addtional opencl-related arguments.
A vector or a matrix
#matrix multiplication function matMul<-function(ind,A,B){ C=A%*%B[,ind] return(C) } n=100 m=200 k=100 #Create the data A=matrix(runif(n*m),n,m) B=matrix(runif(k*m),m,k) #Perform matrix multiplication #GPU res_gpu=gpuSapply(1:k,matMul,A,B) #CPU res_cpu=sapply(1:k,matMul,A,B) #error range(res_gpu-res_cpu)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.