<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Hi PETSc-developers, </p>
<p style="margin:0px 0px 1.2em!important">Is it valid to allocate matrix values on host for use on a GPU later by embedding all allocation logic (i.e the code block that calls PetscMalloc1 for values and indices and sets them using MatSetValues) within a section marked by PetscMalloc(Re)SetCUDAHost ? </p>
<p style="margin:0px 0px 1.2em!important">My understanding was that PetscMallocSetCUDAHost would set mallocs to be on the host but I’m getting an error as shown below (for some strange reason it happens to be the 5th column on the 0th row (if that helps) both when setting one value at a time and when setting the whole 0th row together):</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">[sajid@xrmlite cuda]$ mpirun -np 1 ~/packages/pirt/src/pirt -inputfile shepplogan.h5
PIRT -- Parallel Iterative Reconstruction Tomography
Reading in real data from shepplogan.h5
After loading data, nTau:100, nTheta:50
After detector geometry context initialization
Initialized PIRT
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Error in external library
[0]PETSC ERROR: cuda error 1 (cudaErrorInvalidValue) : invalid argument
[0]PETSC ERROR: See <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.
[0]PETSC ERROR: Petsc Development GIT revision: v3.13.2-947-gc2372adeb2  GIT Date: 2020-08-25 21:07:25 +0000
[0]PETSC ERROR: /home/sajid/packages/pirt/src/pirt on a arch-linux-c-debug named xrmlite by sajid Tue Aug 25 18:30:55 2020
[0]PETSC ERROR: Configure options --with-hdf5=1 --with-cuda=1
[0]PETSC ERROR: #1 PetscCUDAHostFree() line 14 in /home/sajid/packages/petsc/src/sys/memory/cuda/<a href="http://mcudahost.cu">mcudahost.cu</a>
[0]PETSC ERROR: #2 PetscFreeA() line 475 in /home/sajid/packages/petsc/src/sys/memory/mal.c
[0]PETSC ERROR: #3 MatSeqXAIJFreeAIJ() line 135 in /home/sajid/packages/petsc/include/../src/mat/impls/aij/seq/aij.h
[0]PETSC ERROR: #4 MatSetValues_SeqAIJ() line 498 in /home/sajid/packages/petsc/src/mat/impls/aij/seq/aij.c
[0]PETSC ERROR: #5 MatSetValues() line 1392 in /home/sajid/packages/petsc/src/mat/interface/matrix.c
[0]PETSC ERROR: #6 setMatrixElements() line 248 in /home/sajid/packages/pirt/src/geom.cxx
[0]PETSC ERROR: #7 construct_matrix() line 91 in /home/sajid/packages/pirt/src/<a href="http://matrix.cu">matrix.cu</a>
[0]PETSC ERROR: #8 main() line 20 in /home/sajid/packages/pirt/src/pirt.cxx
[0]PETSC ERROR: PETSc Option Table entries:
[0]PETSC ERROR: -inputfile shepplogan.h5
[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_SELF
with errorcode 20076.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
[sajid@xrmlite cuda]$
</code></pre><p style="margin:0px 0px 1.2em!important">PetscCUDAHostFree is called within the  PetscMalloc(Re)SetCUDAHost block as described earlier which should’ve created valid memory on the host. </p>
<p style="margin:0px 0px 1.2em!important">Could someone explain if this is the correct approach to take and what the above error means ?</p>
<p style="margin:0px 0px 1.2em!important">(PS : I’ve run ksp tutorial-ex2 with -vec_type cuda -mat_type aijcusparse to test the installation and everything works as expected.)</p>
<p style="margin:0px 0px 1.2em!important">Thank You,<br>Sajid Ali | PhD Candidate<br>Applied Physics<br>Northwestern University<br><a href="http://s-saj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