JuliaLinearAlgebra / IterativeSolvers.jl

Iterative algorithms for solving linear systems, eigensystems, and singular value problems
MIT License
399 stars 105 forks source link

example GPU cg has a warning for scalar operations #256

Open xzackli opened 5 years ago

xzackli commented 5 years ago

When I run the CuArrays example in the documentation for cg on Julia 1.1/1.2, I get a warning about scalar operations.

using LinearAlgebra, CuArrays, IterativeSolvers
n = 100
A = cu(rand(n, n))
A = A + A' + 2*n*I
b = cu(rand(n))
x = cg(A, b)
┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`

This fails on the uniformscaling. Messing around a bit with CuArrays.allowscalar(false), I find that replacing it with

A = A + A' + cu(Diagonal(fill(2 * n * 1.0f0,n)))

seems to work. Maybe just update the documentation?