<div dir="ltr"><div dir="ltr">On Mon, Jan 15, 2024 at 11:57 AM MIA via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I am trying to solve a large linear equation, which needs a GPU solver as comparison. I install a CUDA-enabled PETSc and petsc4py from sources using the release tarball. According to the test results after installation, the PETSc can successfully work with cuda.<br></blockquote><div><br></div><div>Here is a How-To for GPUs: <a href="https://petsc.org/main/faq/#doc-faq-gpuhowto">https://petsc.org/main/faq/#doc-faq-gpuhowto</a></div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
All my programs are written in python, so I turn to petsc4py. But I do not find any commands that define variables on coda device or define where the direct solver is executed. I check `nvidia-smi` and find my cuda does not work at all when executing my python script:<br>
<br>
from petsc4py import PETSc<br>
import numpy as np<br>
<br>
n = 1000<br>
<br>
nnz = 3 * np.ones(n, dtype=np.int32)<br>
nnz[0] = nnz[-1] = 2<br>
<br>
A = PETSc.Mat()<br>
A.createAIJ([n, n], nnz=nnz)<br>
<br>
# First set the first row<br>
A.setValue(0, 0, 2)<br>
A.setValue(0, 1, -1)<br>
# Now we fill the last row<br>
A.setValue(999, 998, -1)<br>
A.setValue(999, 999, 2)<br>
<br>
# And now everything else<br>
for index in range(1, n - 1):<br>
A.setValue(index, index - 1, -1)<br>
A.setValue(index, index, 2)<br>
A.setValue(index, index + 1, -1) <br>
<br>
A.assemble()<br>
<br>
indexptr, indices, data = A.getValuesCSR()<br>
b = A.createVecLeft()<br>
b.array[:] = 1<br>
for i in range(10):<br>
ksp = PETSc.KSP().create()<br>
ksp.setOperators(A)<br>
ksp.setType('preonly')<br>
ksp.setConvergenceHistory()<br>
ksp.getPC().setType('lu')<br>
x = A.createVecRight()<br>
ksp.solve(2*b, x)<br>
residual = A * x - 2*b<br>
if i % 10 == 0:<br>
print(f"The relative residual is: {residual.norm() / b.norm()}.”)<br>
<br>
What should I do to utlize GPU to execute the KSP task? Are there some settings to be modified?<br>
<br>
Looking forward to your early reply. Thanks a lot.<br>
<br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>