<div dir="ltr"><div><div>Thanks Barry and Satish.<br></div>As you said I have a wrong flag in my makefile.<br><br></div>Best Regards<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 7, 2013 at 4:14 PM, Satish Balay <span dir="ltr"><<a href="mailto:balay@mcs.anl.gov" target="_blank">balay@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Fri, 7 Jun 2013, Barry Smith wrote:<br>
<br>
><br>
> How large is your integer on the Fortran side and the C side?<br>
><br>
> Normally a PetscInt is a C int and a Fortran integer*4 which are each 4 bytes long.<br>
><br>
> If PETSc is configured with --with-64-bit-indices then PetscInt is a C long long int and Fortran integer*8 both 8 bytes long.<br>
><br>
> It looks like you are using 8 byte Fortran integers but have not compiled PETSc with --with-64-bit-indices Possibly you are using come fortran compile time flag that "promotes" float to double and integer*4 to integer*8 in Fortran.<br>
><br>
> 1) we recommend never using any fortran compiler flag that promotes types automatically.<br>
<br>
</div>If Petsc datatypes are used in fortran code [i.e declare variable as<br>
PetscInt - and not integer for functions that expect PetscInt] - then<br>
the code [from PETSc part] would be resiliant to -i8 type options.<br>
<span class="HOEnZb"><font color="#888888"><br>
Satish<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> 2) likely you just want to use 4 byte integers in fortran. If you want to use 8 bytes then configure PETSc with --with-64-bit-indices<br>
><br>
> Barry<br>
><br>
><br>
><br>
><br>
> On Jun 7, 2013, at 2:57 PM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
><br>
> > Hello Barry,<br>
> > I have tried to pass to VectSetValues two values<br>
> ><br>
> > call VecSetValues(x_vec_in,2,index_list(1:2),x_vec_local(1:2),INSERT_VALUES,ierr_local)<br>
> ><br>
> > By looking at the values of index_list and x_vec_local with gdb I see the correct numbers:<br>
> ><br>
> > (gdb) print x_vec_local(1)<br>
> > $1 = 0.9394877605834675<br>
> > (gdb) print x_vec_local(2)<br>
> > $2 = 0.55294328167143081<br>
> ><br>
> > (gdb) print index_list(1)<br>
> > $3 = 0<br>
> > (gdb) print index_list(2)<br>
> > $4 = 1<br>
> ><br>
> > Now, when I ask gdb to print the values of ni, ix and y in<br>
> ><br>
> > PetscErrorCode VecSetValues_Seq(Vec xin,PetscInt ni,const PetscInt ix[],const PetscScalar y[],InsertMode m)<br>
> ><br>
> ><br>
> > I get<br>
> ><br>
> > (gdb) print ni<br>
> > $5 = 2<br>
> ><br>
> > (gdb) print ix[0]<br>
> > $6 = 0<br>
> > (gdb) print ix[1]<br>
> > $7 = 0<br>
> ><br>
> ><br>
> > print y[0]<br>
> > $13 = 0.9394877605834675<br>
> > (gdb) print y[1]<br>
> > $14 = 0.55294328167143081<br>
> ><br>
> ><br>
> > The values of y match with the values I am passing in, i.e. x_vec_local. However the index ix is wrong because the first two components of it are zero. Thus, when i = 1 in the VecSetValues_Seq for loop, the first element that was placed correctly is replaced by the second element. This is also waht I see if I use<br>
> ><br>
> > call VecView(x_vec_in,PETSC_VIEWER_STDOUT_WORLD,ierr_local)<br>
> ><br>
> > Now if I keep printing ix in gdb I see the following pattern:<br>
> ><br>
> > (gdb) print ix[0]<br>
> > $18 = 0<br>
> > (gdb) print ix[1]<br>
> > $19 = 0<br>
> > (gdb) print ix[2]<br>
> > $20 = 1<br>
> > (gdb) print ix[3]<br>
> > $21 = 0<br>
> > (gdb) print ix[4]<br>
> > $22 = 2<br>
> > (gdb) print ix[5]<br>
> > $23 = 0<br>
> > (gdb) print ix[6]<br>
> > $24 = 3<br>
> ><br>
> ><br>
> > which I think is strange since I ix should be a vector of length 2 because I am calling VecSetValues as<br>
> ><br>
> ><br>
> > call VecSetValues(x_vec_in,2,index_list(1:2),x_vec_local(1:2),INSERT_VALUES,ierr_local)<br>
> ><br>
> > Am I doing something wrong?<br>
> ><br>
> > Thank you in advance.<br>
> ><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > On Fri, Jun 7, 2013 at 3:03 PM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
> > Yes, they are correct. When asked, the debugger prints the right values for bot the vector of the index and the vector of the values.<br>
> ><br>
> > Sorry, how can I set a break point in VecSetValues_Seq() and VecSetValues_MPI()?<br>
> > If I type<br>
> ><br>
> > break VecSetValues_Seq()<br>
> ><br>
> > or<br>
> ><br>
> > break VecSetValues_MPI()<br>
> ><br>
> > or<br>
> ><br>
> > /home0/pmatteo/research/lib_src/petsc/src/vec/vec/impls/seq/bvec2.c:1050<br>
> ><br>
> > I get<br>
> ><br>
> > Function "vecsetvalues_seq" not defined.<br>
> ><br>
> > or<br>
> ><br>
> > Function "vecsetvalues_mpi" not defined.<br>
> ><br>
> ><br>
> > Thanks<br>
> ><br>
> ><br>
> ><br>
> > On Fri, Jun 7, 2013 at 2:32 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> ><br>
> > Are, seemingly the correct values getting into the vecsetvalues_ call?<br>
> ><br>
> > Put a break point also in VecSetValues_Seq() and VecSetValues_MPI() when it gets into either of those routines you can do step in the debugger and watch it take the values passed in and attempt to put them in the appropriate places in the vector's array.<br>
> ><br>
> > Barry<br>
> ><br>
> > On Jun 7, 2013, at 1:20 PM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
> ><br>
> > > Hello Barry,<br>
> > > I have tried to follow the debugger but I got lost.<br>
> > ><br>
> > > I have run my code in this way:<br>
> > ><br>
> > > ./NSE -start_in_debugger noxterm<br>
> > ><br>
> > > then after getting some output I get<br>
> > ><br>
> > > gdb()<br>
> > ><br>
> > > Then I type break vecsetvalues_<br>
> > ><br>
> > ><br>
> > > and a break point is generated<br>
> > ><br>
> > > Breakpoint 1 at 0x2ae97eda5827: file /scratch/home0/pmatteo/research/lib_src/petsc/src/vec/vec/interface/ftn-auto/rvectorf.c, line 239.<br>
> > ><br>
> > ><br>
> > > I keep typing n and it goes on. It shows me every time vectsetvalues is called but it never goes inside vectsetvalues.<br>
> > ><br>
> > > I have tested the VecSetValues with just two elements and it does not work. It sets correctly the values both in serial and in parallel if I set one value at the time.<br>
> > ><br>
> > > Thanks<br>
> > ><br>
> > ><br>
> > ><br>
> > > On Tue, Apr 30, 2013 at 8:35 AM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> > ><br>
> > > On Apr 30, 2013, at 7:21 AM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
> > ><br>
> > > > Hello Barry,<br>
> > > > it does not work also if m is not so large.<br>
> > ><br>
> > > Then you need to run in the debugger. You can use the command line options<br>
> > ><br>
> > > -start_in_debugger noxterm<br>
> > ><br>
> > > in the debugger put a break point in vecsetvalues_ (yes lower case followed by an underscore) then when it<br>
> > > gets to that point print the size of the array and the values in the integer and double array to see if they match, then step into the VecSetValues() function that is called by vecsetvalues_() and look at the array values ago, continue to step along and it will go into VecSetValues_Seq() and start actually putting the values into the Vec array.<br>
> > ><br>
> > > Barry<br>
> > ><br>
> > > ><br>
> > > > Thanks again.<br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > > On Fri, Apr 26, 2013 at 3:23 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> > > ><br>
> > > > Shouldn't matter that it is called from Fortran we do it all the time.<br>
> > > ><br>
> > > > Does it work if the final m is not very large?<br>
> > > ><br>
> > > > You may need to run in the debugger and follow the values through the code to see why they don't get to where they belong.<br>
> > > ><br>
> > > ><br>
> > > > Barry<br>
> > > ><br>
> > > > Could also be a buggy fortran compiler.<br>
> > > ><br>
> > > ><br>
> > > > On Apr 26, 2013, at 2:06 PM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
> > > ><br>
> > > > > Hello Barry,<br>
> > > > > sorry I modified few things just before to write the mail.<br>
> > > > > The correct loop with the correct name of the variables is the following<br>
> > > > ><br>
> > > > > ! Number of DOFs owned by this process<br>
> > > > > len_local = (elem_high-elem_low+1)*nodesperelem*nequations<br>
> > > > ><br>
> > > > > ! Allocate memory for x_vec_local and index_list<br>
> > > > > allocate(x_vec_local(len_local))<br>
> > > > > allocate(index_list(len_local))<br>
> > > > ><br>
> > > > ><br>
> > > > > m = 1<br>
> > > > > ! Loop over all elements<br>
> > > > > do ielem = elem_low, elem_high<br>
> > > > > ! Loop over all nodes in the element<br>
> > > > > do inode = 1, nodesperelem<br>
> > > > > !Loop over all equations<br>
> > > > > do ieq = 1, nequations<br>
> > > > > ! Add element to x_vec_local<br>
> > > > > x_vec_local(m) = ug(ieq,inode,ielem)<br>
> > > > > ! Add element to index list<br>
> > > > > index_list(m) = (elem_low-1)*nodesperelem*nequations+m-1<br>
> > > > > ! Update m index<br>
> > > > > m = m+1<br>
> > > > > end do<br>
> > > > > end do<br>
> > > > > end do<br>
> > > > ><br>
> > > > > ! HERE I HAVE PRINTED x_vec_local, ug and index_list<br>
> > > > ><br>
> > > > > ! Set values in the portion of the vector owned by the process<br>
> > > > > call VecSetValues(x_vec_in,m-1,index_list,x_vec_local,INSERT_VALUES,&<br>
> > > > > & ierr_local)<br>
> > > > ><br>
> > > > > ! Assemble initial guess<br>
> > > > > call VecAssemblyBegin(x_vec_in,ierr_local)<br>
> > > > > call VecAssemblyEnd(x_vec_in,ierr_local)<br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > I have printed the values and the indices I want to pass to VecSetValues() and they are correct.<br>
> > > > ><br>
> > > > > I also printed the values after VecSetValues() has been called and they are wrong.<br>
> > > > ><br>
> > > > > The attachment shows that.<br>
> > > > ><br>
> > > > ><br>
> > > > > Could it be a problem of VecSetValues() + F90 when more than 1 elements is set?<br>
> > > > ><br>
> > > > > I order to debug my the code I am running just with 1 processor. Thus the process owns all the DOFs.<br>
> > > > ><br>
> > > > > Thank you.<br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > On Fri, Apr 26, 2013 at 2:39 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> > > > ><br>
> > > > > On Apr 26, 2013, at 10:20 AM, Matteo Parsani <<a href="mailto:parsani.matteo@gmail.com">parsani.matteo@gmail.com</a>> wrote:<br>
> > > > ><br>
> > > > > > Hello,<br>
> > > > > > I have some problem when I try to set multiple values to a PETSc vector that I will use later on with SNES. I am using Fortran 90.<br>
> > > > > > Here the problem and two fixes that however are not so good for performances reasons. The code is very simple.<br>
> > > > > ><br>
> > > > > > Standard approach that does not work correctly: (I am probably doing something wrong)<br>
> > > > > ><br>
> > > > > > m = 1<br>
> > > > > > ! Loop over all elements<br>
> > > > > > do ielem = elem_low, elem_high<br>
> > > > > > ! Loop over all nodes in the element<br>
> > > > > > do inode = 1, nodesperelem<br>
> > > > > > !Loop over all equations<br>
> > > > > > do ieq = 1, nequations<br>
> > > > > > ! Add element to x_vec_local<br>
> > > > > > x_vec_local(m) = ug(ieq,inode,ielem)<br>
> > > > > > ! Add element to index list<br>
> > > > > > ind(m) = (elem_low-1)*nodesperelem*nequations+m-1<br>
> > > > > > ! Update m index<br>
> > > > > > m = m+1<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > ><br>
> > > > > > ! Set values in the portion of the vector owned by the process<br>
> > > > > > call VecSetValues(x_vec_in,len_local,index_list,x_vec_local,INSERT_VALUES,&<br>
> > > > ><br>
> > > > > What is len_local and index_list? They do not appear in the loop above. Shouldn't you be passing m-1 for the length and ind for the indices?<br>
> > > > ><br>
> > > > > I would first print out the all the values in your input to VecSetValues() and make sure they are correct.<br>
> > > > ><br>
> > > > > Barry<br>
> > > > ><br>
> > > > > > & ierr_local)<br>
> > > > > ><br>
> > > > > > ! Assemble initial guess<br>
> > > > > > call VecAssemblyBegin(x_vec_in,ierr_local)<br>
> > > > > > call VecAssemblyEnd(x_vec_in,ierr_local)<br>
> > > > > ><br>
> > > > > > Then I print my expected values and the values contained in the PETSc vector to a file. See attachment. I am running in serial for the moment BUT strangely if you look at the file I have attached the first 79 DOFs values have a wrong ordering and the remaining 80 are zero.<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > 1st approach: set just one value at the time inside the loop.<br>
> > > > > > m = 1<br>
> > > > > > ! Loop over all elements<br>
> > > > > > do ielem = elem_low, elem_high<br>
> > > > > > ! Loop over all nodes in the element<br>
> > > > > > do inode = 1, nodesperelem<br>
> > > > > > !Loop over all equations<br>
> > > > > > do ieq = 1, nequations<br>
> > > > > > ! Add element to x_vec_local<br>
> > > > > > value = ug(ieq,inode,ielem)<br>
> > > > > > ! Add element to index list<br>
> > > > > > ind = (elem_low-1)*nodesperelem*nequations+m-1<br>
> > > > > > call VecSetValues(x_vec_in,1,ind,value,INSERT_VALUES,&<br>
> > > > > > & ierr_local)<br>
> > > > > > ! Update m index<br>
> > > > > > m = m+1<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > This works fine. As you can see I am using the same expression used in the previous loop to compute the index of the element that I have to add in the x_vec_in, i.e.<br>
> > > > > > ind = (elem_low-1)*nodesperelem*nequations+m-1<br>
> > > > > ><br>
> > > > > > Thus I cannot see which is the problem.<br>
> > > > > ><br>
> > > > > > 2nd approach: get the pointer to the local part of the global vector and use it to set the values in the global vector<br>
> > > > > ><br>
> > > > > > m = 1<br>
> > > > > > ! Loop over all elements<br>
> > > > > > do ielem = elem_low, elem_high<br>
> > > > > > ! Loop over all nodes in the element<br>
> > > > > > do inode = 1, nodesperelem<br>
> > > > > > !Loop over all equations<br>
> > > > > > do ieq = 1, nequations<br>
> > > > > > ! Add element to x_vec_local<br>
> > > > > > tmp(m) = ug(ieq,inode,ielem)<br>
> > > > > > ! Update m index<br>
> > > > > > m = m+1<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > This works fine too.<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > Jut to be complete. I use the following two approaches to view the vector:<br>
> > > > > ><br>
> > > > > > call VecView(x_vec_in,PETSC_VIEWER_STDOUT_WORLD,ierr_local)<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > and<br>
> > > > > ><br>
> > > > > > call VecGetArrayF90(x_vec_in,tmp,ierr_local)<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > m = 1<br>
> > > > > > ! Loop over all elements<br>
> > > > > > do ielem = elem_low, elem_high<br>
> > > > > > ! Loop over all nodes in the element<br>
> > > > > > do inode = 1, nodesperelem<br>
> > > > > > !Loop over all equations<br>
> > > > > > do ieq = 1, nequations<br>
> > > > > > write(*,*) m,index_list(m),x_vec_local(m),tmp(m)<br>
> > > > > > ! Update m index<br>
> > > > > > m = m+1<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > > end do<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > Thank you.<br>
> > > > > ><br>
> > > > > ><br>
> > > > > > --<br>
> > > > > > Matteo<br>
> > > > > > <values.txt><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > --<br>
> > > > > Matteo<br>
> > > > > <comparison.txt><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > > --<br>
> > > > Matteo<br>
> > ><br>
> > ><br>
> > ><br>
> > ><br>
> > > --<br>
> > > Matteo<br>
> ><br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Matteo<br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Matteo<br>
><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Matteo<br></div>
</div>