The following program:
using SparseArrays
function go()
A = sprandn(10, 10, 0.1)
v = Vector(undef, 2)
for i = 1:2
v[i] = SparseMatrixCSC(A.m, A.n, A.colptr, A.rowval, copy(A.nzval))
end
end
@time go()
Results in a segmentation fault for me:
signal (11): Segmentation fault: 11
in expression starting at no file:0
_ZN4llvm9LiveRange4joinERS0_PKiS3_RNS_15SmallVectorImplIPNS_6VNInfoEEE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer8joinCopyEPN4llvm12MachineInstrERb at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer20copyCoalesceWorkListEN4llvm15MutableArrayRefIPNS1_12MachineInstrEEE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer20runOnMachineFunctionERN4llvm15MachineFunctionE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /Applications/Julia-0.7.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
I’m using Julia 0.7.0 on Mac. If I replace the for loop with v[1] =
and v[2] =
, the program works. Also, if I use copy(A.colptr)
it works. It also works in Julia 0.6.4.
What I’m trying to achieve is to create a few new matrices with the same sparsity pattern as an existing matrix, but with modified values, and in order to save memory I want to reuse the colptr
and rowval
vectors.
Any idea what’s going on? Perhaps it’s not allowed to reuse the column/row vectors this way?