<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="ltr">How many MPI ranks do you use? The following line is suspicious. I guess you do not want a vector of global length 1.
<div>66 VecSetSizes(b,PETSC_DECIDE,1);</div>
<div><br clear="all">
<div>
<div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">--Junchao Zhang</div>
</div>
</div>
<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Apr 24, 2019 at 4:14 PM Karl Lin via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div>Hi, there</div>
<div><br>
</div>
<div>I have been trying to get a simple program run with the following code:</div>
<div><br>
</div>
<div> 12 int main(int argc,char **args)<br>
13 {<br>
14 PetscErrorCode ierr;<br>
15 Mat A;<br>
16 Mat AT;<br>
17 Mat N;<br>
18 char name[1024];<br>
19 char vname[1024];<br>
20 char pass[1024];<br>
21 PetscBool flg;<br>
22 Vec b,x,u,Ab,Au;<br>
23 PetscViewer viewer; /* viewer */<br>
24 PetscMPIInt rank,size;<br>
25<br>
26 KSP QRsolver;<br>
27 PC pc;<br>
28 PetscInt its;<br>
29 PetscReal norm;<br>
30<br>
31 PetscInt n1, n2, n3, np1, np2, np3, p, jj;<br>
32<br>
33 PetscInt *cols, *dnz, *onz;<br>
34 PetscScalar *vals;<br>
35<br>
36 ierr = PetscInitialize(&argc,&args,0,help);if (ierr) return ierr;<br>
37<br>
38 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);<br>
39 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);<br>
40<br>
41 PetscMalloc1(1, &dnz);<br>
42 PetscMalloc1(1, &onz);<br>
43<br>
44 dnz[0]=2;<br>
45 onz[0]=1;<br>
46<br>
47 MatCreateMPIAIJMKL(PETSC_COMM_WORLD, 1, 2, 1, 2, 2, dnz, 2, onz, &A); CHKERRQ(ierr);<br>
48<br>
49 PetscMalloc1(2, &cols);<br>
50 PetscMalloc1(2, &vals);<br>
51<br>
52 jj = rank;<br>
53 cols[0]=0; cols[1]=1;<br>
54 vals[0]=1.0;vals[1]=1.0;<br>
55<br>
56 MatSetValues(A, 1, &jj, 2, cols, vals, INSERT_VALUES);<br>
57<br>
58 MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);<br>
59 MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);<br>
60<br>
61 VecCreate(PETSC_COMM_WORLD,&x);<br>
62 VecSetSizes(x,PETSC_DECIDE,2);<br>
63 VecSetFromOptions(x);<br>
64<br>
65 VecCreate(PETSC_COMM_WORLD,&b);<br>
66 VecSetSizes(b,PETSC_DECIDE,1);<br>
67 VecSetFromOptions(b);<br>
68<br>
69 VecCreate(PETSC_COMM_WORLD,&u);<br>
70 VecSetSizes(u,PETSC_DECIDE,1);<br>
71 VecSetFromOptions(u);<br>
72<br>
73 VecSet(b, 2.0);<br>
74 VecSet(u, 0.0);<br>
75 VecSet(x, 0.0);<br>
76<br>
77 MatMult(A, x, u);<br>
78<br>
79 VecView(x, PETSC_VIEWER_STDOUT_WORLD);<br>
80 VecView(b, PETSC_VIEWER_STDOUT_WORLD);<br>
81 VecView(u, PETSC_VIEWER_STDOUT_WORLD);<br>
82<br>
83 VecAXPY(u,-1.0,b);<br>
</div>
<div><br>
</div>
<div>However, it always crashes at line 83 even with single process saying:</div>
<div>[0]PETSC ERROR: ------------------------------------------------------------------------<br>
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>
[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank">
http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>
[0]PETSC ERROR: or try <a href="http://valgrind.org" target="_blank">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run<br>
[0]PETSC ERROR: to get more information on the crash.<br>
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
[0]PETSC ERROR: Signal received<br>
[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">
http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
[0]PETSC ERROR: Petsc Release Version 3.10.4, Feb, 26, 2019</div>
<div><br>
</div>
<div>I can't figure out why this would happen. The printout from VecView shows every vec value is correct. I will greatly appreciate any tips.
</div>
<div><br>
</div>
<div>Regards,</div>
<div>Karl<br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</body>
</html>