Re: [petsc-dev] SETERRQ in fortran

2018-01-04 Thread Smith, Barry F.


> On Jan 4, 2018, at 5:10 PM, Blaise A Bourdin  wrote:
> 
> 
> 
>> On Jan 4, 2018, at 3:16 PM, Smith, Barry F.  wrote:
>> 
>> 
>> It's changed a bit.  It is better but you need to understand how the new one 
>> works, so take a few minutes to see how it works before converting.
> Got it.
> An example or a link to the fortran macro definition from the man page would 
> be nice 
> I am confused about the rationale for putting the endif in the macro, though.

  It matches the C paradigm

> Beside not having unmatched if / end if in my code, in a select case 
> construct, I have to write something as ugly as
> 
> select case (i)
>   case(1) 
>   !do something
>   case(2)
>   !do something else
>   case default
>   if (0 == 0) then
>   
> SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANG,”invalid value”)
> end select
> 
  What is ugly about this ? except that you put the SETERRQ on a new line which 
you did not need to do.

  How do you want to write it so it is prettier?


  Barry

> Am I missing something again?
> 
> Blaise
> 
> 
>> 
>> Use CHKERRA() for main Fortran problem and CHKERRQ() for subroutines.
>> 
>> Also look at their definitions to see how the if () business is handled. 
>> 
>> Barry
>> 
>> 
>>> On Jan 4, 2018, at 2:02 PM, Matthew Knepley  wrote:
>>> 
>>> On Thu, Jan 4, 2018 at 2:42 PM, Blaise A Bourdin  wrote:
>>> Hi,
>>> 
>>> Is SETERRQ still available in fortran? I notice that it is not used in any 
>>> of the example, but the man page still mentions fortran. Using it in a 
>>> fortran code leads to compiler errors.
>>> Am I doing something wrong?
>>> 
>>> I see it here:
>>> 
>>> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Fpetsc%2Fpetsc%2Fsrc%2Fc925fbded0167f274f0216824a05edb59a5721f5%2Finclude%2Fpetsc%2Ffinclude%2Fpetscsys.h%3Fat%3Dmaster%26fileviewer%3Dfile-view-default%23petscsys.h-197=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=R6xnRLTzelnxPz39tkA0warCI%2BUFt%2FAnM8haZbjANQA%3D=0
>>> 
>>> I think its complaining about the 'return;endif'
>>> 
>>> Matt
>>> 
>>> MacBookGray:F90 $ cat TestSETERRQ.F90
>>> Program TestSETERRQ
>>> #include 
>>>  Use petsc
>>> 
>>>  Implicit NONE
>>>  PetscInt   :: ierr
>>>  Character(len=256) :: IOBuffer
>>> 
>>>  Call PetscInitialize(PETSC_NULL_CHARACTER, ierr);CHKERRA(ierr)
>>>  write(IOBuffer,'("This is a test ierr = ",I2,"\n")') ierr
>>>  SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>>  call foo()
>>>  Call PetscFinalize(ierr)
>>> Contains
>>>   subroutine foo()
>>>  Character(len=256) :: IOBuffer
>>> 
>>>  write(IOBuffer,'("This is a test ierr = ",I2,"\n")') 42
>>>  SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>>   end subroutine foo
>>> End Program TestSETERRQ
>>> 
>>> MacBookGray:F90 $ make -f makefile.TestSETERRQ TestSETERRQ
>>> mpif90 -c -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g
>>> -I/opt/HPC/petsc-next/include -I/opt/HPC/petsc-next/Darwin-gcc7.2-g/include 
>>> -I/opt/X11/include-o TestSETERRQ.o TestSETERRQ.F90
>>> TestSETERRQ.F90:11:61:
>>> 
>>>   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>>1
>>> Error: Expecting END PROGRAM statement at (1)
>>> TestSETERRQ.F90:19:65:
>>> 
>>>   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>>1
>>> Error: Expecting END SUBROUTINE statement at (1)
>>> make: [TestSETERRQ.o] Error 1 (ignored)
>>> 
>>> 
>>> Blaise
>>> 
>>> --
>>> Department of Mathematics and Center for Computation & Technology
>>> Louisiana State University, Baton Rouge, LA 70803, USA
>>> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 
>>> https://na01.safelinks.protection.outlook.com/?url=http:%2F%2Fwww.math.lsu.edu%2F~bourdin=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=DM5ZtUYkEBxwU%2FVS7eHC8dF%2Fw2w9aSbP9l8YvL3Nj6o%3D=0
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> What most experimenters take for granted before they begin their 
>>> experiments is infinitely more interesting than any results to which their 
>>> experiments lead.
>>> -- Norbert Wiener
>>> 
>>> https://na01.safelinks.protection.outlook.com/?url=https:%2F%2Fwww.cse.buffalo.edu%2F~knepley%2F=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=99K5TljrSNkF7MGImBkWQTjXCUt%2BdwB8XAHB%2FQztQZY%3D=0
>> 
> 
> -- 
> Department of Mathematics and Center for Computation & Technology
> Louisiana State University, Baton Rouge, LA 70803, USA
> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 
> http://www.math.lsu.edu/~bourdin



Re: [petsc-dev] SETERRQ in fortran

2018-01-04 Thread Blaise A Bourdin


> On Jan 4, 2018, at 3:16 PM, Smith, Barry F.  wrote:
> 
> 
>  It's changed a bit.  It is better but you need to understand how the new one 
> works, so take a few minutes to see how it works before converting.
Got it.
An example or a link to the fortran macro definition from the man page would be 
nice 
I am confused about the rationale for putting the endif in the macro, though.
Beside not having unmatched if / end if in my code, in a select case construct, 
I have to write something as ugly as

select case (i)
case(1) 
!do something
case(2)
!do something else
case default
if (0 == 0) then

SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANG,”invalid value”)
end select

Am I missing something again?

Blaise


> 
>  Use CHKERRA() for main Fortran problem and CHKERRQ() for subroutines.
> 
>  Also look at their definitions to see how the if () business is handled. 
> 
>  Barry
> 
> 
>> On Jan 4, 2018, at 2:02 PM, Matthew Knepley  wrote:
>> 
>> On Thu, Jan 4, 2018 at 2:42 PM, Blaise A Bourdin  wrote:
>> Hi,
>> 
>> Is SETERRQ still available in fortran? I notice that it is not used in any 
>> of the example, but the man page still mentions fortran. Using it in a 
>> fortran code leads to compiler errors.
>> Am I doing something wrong?
>> 
>> I see it here:
>> 
>>  
>> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Fpetsc%2Fpetsc%2Fsrc%2Fc925fbded0167f274f0216824a05edb59a5721f5%2Finclude%2Fpetsc%2Ffinclude%2Fpetscsys.h%3Fat%3Dmaster%26fileviewer%3Dfile-view-default%23petscsys.h-197=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=R6xnRLTzelnxPz39tkA0warCI%2BUFt%2FAnM8haZbjANQA%3D=0
>> 
>> I think its complaining about the 'return;endif'
>> 
>>  Matt
>> 
>> MacBookGray:F90 $ cat TestSETERRQ.F90
>> Program TestSETERRQ
>> #include 
>>   Use petsc
>> 
>>   Implicit NONE
>>   PetscInt   :: ierr
>>   Character(len=256) :: IOBuffer
>> 
>>   Call PetscInitialize(PETSC_NULL_CHARACTER, ierr);CHKERRA(ierr)
>>   write(IOBuffer,'("This is a test ierr = ",I2,"\n")') ierr
>>   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>   call foo()
>>   Call PetscFinalize(ierr)
>> Contains
>>subroutine foo()
>>   Character(len=256) :: IOBuffer
>> 
>>   write(IOBuffer,'("This is a test ierr = ",I2,"\n")') 42
>>   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>>end subroutine foo
>> End Program TestSETERRQ
>> 
>> MacBookGray:F90 $ make -f makefile.TestSETERRQ TestSETERRQ
>> mpif90 -c -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g
>> -I/opt/HPC/petsc-next/include -I/opt/HPC/petsc-next/Darwin-gcc7.2-g/include 
>> -I/opt/X11/include-o TestSETERRQ.o TestSETERRQ.F90
>> TestSETERRQ.F90:11:61:
>> 
>>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>> 1
>> Error: Expecting END PROGRAM statement at (1)
>> TestSETERRQ.F90:19:65:
>> 
>>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>> 1
>> Error: Expecting END SUBROUTINE statement at (1)
>> make: [TestSETERRQ.o] Error 1 (ignored)
>> 
>> 
>> Blaise
>> 
>> --
>> Department of Mathematics and Center for Computation & Technology
>> Louisiana State University, Baton Rouge, LA 70803, USA
>> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 
>> https://na01.safelinks.protection.outlook.com/?url=http:%2F%2Fwww.math.lsu.edu%2F~bourdin=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=DM5ZtUYkEBxwU%2FVS7eHC8dF%2Fw2w9aSbP9l8YvL3Nj6o%3D=0
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> What most experimenters take for granted before they begin their experiments 
>> is infinitely more interesting than any results to which their experiments 
>> lead.
>> -- Norbert Wiener
>> 
>> https://na01.safelinks.protection.outlook.com/?url=https:%2F%2Fwww.cse.buffalo.edu%2F~knepley%2F=02%7C01%7Cbourdin%40lsu.edu%7C9e126b88c4de4bb5b1c108d553b87d8a%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636506974199979974=99K5TljrSNkF7MGImBkWQTjXCUt%2BdwB8XAHB%2FQztQZY%3D=0
> 

-- 
Department of Mathematics and Center for Computation & Technology
Louisiana State University, Baton Rouge, LA 70803, USA
Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin









Re: [petsc-dev] SETERRQ in fortran

2018-01-04 Thread Smith, Barry F.

  It's changed a bit.  It is better but you need to understand how the new one 
works, so take a few minutes to see how it works before converting.

  Use CHKERRA() for main Fortran problem and CHKERRQ() for subroutines.

  Also look at their definitions to see how the if () business is handled. 

  Barry


> On Jan 4, 2018, at 2:02 PM, Matthew Knepley  wrote:
> 
> On Thu, Jan 4, 2018 at 2:42 PM, Blaise A Bourdin  wrote:
> Hi,
> 
> Is SETERRQ still available in fortran? I notice that it is not used in any of 
> the example, but the man page still mentions fortran. Using it in a fortran 
> code leads to compiler errors.
> Am I doing something wrong?
> 
> I see it here:
> 
>   
> https://bitbucket.org/petsc/petsc/src/c925fbded0167f274f0216824a05edb59a5721f5/include/petsc/finclude/petscsys.h?at=master=file-view-default#petscsys.h-197
> 
> I think its complaining about the 'return;endif'
> 
>   Matt
> 
> MacBookGray:F90 $ cat TestSETERRQ.F90
> Program TestSETERRQ
> #include 
>Use petsc
> 
>Implicit NONE
>PetscInt   :: ierr
>Character(len=256) :: IOBuffer
> 
>Call PetscInitialize(PETSC_NULL_CHARACTER, ierr);CHKERRA(ierr)
>write(IOBuffer,'("This is a test ierr = ",I2,"\n")') ierr
>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>call foo()
>Call PetscFinalize(ierr)
> Contains
> subroutine foo()
>Character(len=256) :: IOBuffer
> 
>write(IOBuffer,'("This is a test ierr = ",I2,"\n")') 42
>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
> end subroutine foo
> End Program TestSETERRQ
> 
> MacBookGray:F90 $ make -f makefile.TestSETERRQ TestSETERRQ
> mpif90 -c -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g
> -I/opt/HPC/petsc-next/include -I/opt/HPC/petsc-next/Darwin-gcc7.2-g/include 
> -I/opt/X11/include-o TestSETERRQ.o TestSETERRQ.F90
> TestSETERRQ.F90:11:61:
> 
> SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>  1
> Error: Expecting END PROGRAM statement at (1)
> TestSETERRQ.F90:19:65:
> 
> SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>  1
> Error: Expecting END SUBROUTINE statement at (1)
> make: [TestSETERRQ.o] Error 1 (ignored)
> 
> 
> Blaise
> 
> --
> Department of Mathematics and Center for Computation & Technology
> Louisiana State University, Baton Rouge, LA 70803, USA
> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 
> http://www.math.lsu.edu/~bourdin
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments 
> is infinitely more interesting than any results to which their experiments 
> lead.
> -- Norbert Wiener
> 
> https://www.cse.buffalo.edu/~knepley/



Re: [petsc-dev] SETERRQ in fortran

2018-01-04 Thread Matthew Knepley
On Thu, Jan 4, 2018 at 2:42 PM, Blaise A Bourdin  wrote:

> Hi,
>
> Is SETERRQ still available in fortran? I notice that it is not used in any
> of the example, but the man page still mentions fortran. Using it in a
> fortran code leads to compiler errors.
> Am I doing something wrong?
>

I see it here:


https://bitbucket.org/petsc/petsc/src/c925fbded0167f274f0216824a05edb59a5721f5/include/petsc/finclude/petscsys.h?at=master=file-view-default#petscsys.h-197

I think its complaining about the 'return;endif'

  Matt

MacBookGray:F90 $ cat TestSETERRQ.F90
> Program TestSETERRQ
> #include 
>Use petsc
>
>Implicit NONE
>PetscInt   :: ierr
>Character(len=256) :: IOBuffer
>
>Call PetscInitialize(PETSC_NULL_CHARACTER, ierr);CHKERRA(ierr)
>write(IOBuffer,'("This is a test ierr = ",I2,"\n")') ierr
>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>call foo()
>Call PetscFinalize(ierr)
> Contains
> subroutine foo()
>Character(len=256) :: IOBuffer
>
>write(IOBuffer,'("This is a test ierr = ",I2,"\n")') 42
>SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
> end subroutine foo
> End Program TestSETERRQ
>
> MacBookGray:F90 $ make -f makefile.TestSETERRQ TestSETERRQ
> mpif90 -c -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g
> -I/opt/HPC/petsc-next/include -I/opt/HPC/petsc-next/Darwin-gcc7.2-g/include
> -I/opt/X11/include-o TestSETERRQ.o TestSETERRQ.F90
> TestSETERRQ.F90:11:61:
>
> SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>  1
> Error: Expecting END PROGRAM statement at (1)
> TestSETERRQ.F90:19:65:
>
> SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
>  1
> Error: Expecting END SUBROUTINE statement at (1)
> make: [TestSETERRQ.o] Error 1 (ignored)
>
>
> Blaise
>
> --
> Department of Mathematics and Center for Computation & Technology
> Louisiana State University, Baton Rouge, LA 70803, USA
> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 http://www.math.lsu.edu/~
> bourdin
>
>
>
>
>
>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


[petsc-dev] SETERRQ in fortran

2018-01-04 Thread Blaise A Bourdin
Hi,

Is SETERRQ still available in fortran? I notice that it is not used in any of 
the example, but the man page still mentions fortran. Using it in a fortran 
code leads to compiler errors.
Am I doing something wrong?

MacBookGray:F90 $ cat TestSETERRQ.F90 
Program TestSETERRQ
#include 
   Use petsc

   Implicit NONE
   PetscInt   :: ierr
   Character(len=256) :: IOBuffer
   
   Call PetscInitialize(PETSC_NULL_CHARACTER, ierr);CHKERRA(ierr)
   write(IOBuffer,'("This is a test ierr = ",I2,"\n")') ierr
   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
   call foo()
   Call PetscFinalize(ierr)
Contains
subroutine foo()
   Character(len=256) :: IOBuffer
   
   write(IOBuffer,'("This is a test ierr = ",I2,"\n")') 42
   SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
end subroutine foo
End Program TestSETERRQ

MacBookGray:F90 $ make -f makefile.TestSETERRQ TestSETERRQ
mpif90 -c -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g
-I/opt/HPC/petsc-next/include -I/opt/HPC/petsc-next/Darwin-gcc7.2-g/include 
-I/opt/X11/include-o TestSETERRQ.o TestSETERRQ.F90
TestSETERRQ.F90:11:61:

SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
 1
Error: Expecting END PROGRAM statement at (1)
TestSETERRQ.F90:19:65:

SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,IOBuffer)
 1
Error: Expecting END SUBROUTINE statement at (1)
make: [TestSETERRQ.o] Error 1 (ignored)


Blaise

-- 
Department of Mathematics and Center for Computation & Technology
Louisiana State University, Baton Rouge, LA 70803, USA
Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin









Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Smith, Barry F.

  I just forward it to you there times, if you don't get it then send me an 
alternative email to use. It is a small message and should not get blocked or 
delayed.


> On Jan 4, 2018, at 11:27 AM, Franck Houssen  wrote:
> 
> 
> 
> - Mail original -
>> De: "Barry F. Smith" 
>> À: "Franck Houssen" 
>> Cc: "Barry F. Smith" , "For users of the development 
>> version of PETSc" 
>> Envoyé: Jeudi 4 Janvier 2018 18:13:32
>> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
>> vector on the zeroth processor into a
>> parallel PETSc vector ?
>> 
>> 
>> 
>>> On Jan 4, 2018, at 11:10 AM, Franck Houssen 
>>> wrote:
>>> 
>>> Do you reproduce the error at your side ? Or is the pattern I use wrong ?
>> 
>>   You should have received an email from me with a patch for PETSc code.
>>   Yes I could reproduce, clearly our bug your code was fine.
> 
> Didn't get the (other) mail yet: guess I'll get it tomorrow. The mail server 
> seems to be messy/capricious... I also noticed some attachments may be "cut" 
> if you open them from your web browser (?!). Anyway...
> OK. bug fixed : good news ! I'm on maint, I guess you pushed on master and I 
> need to apply the patch on maint: no problem.
> 
> Thanks Barry
> 
>> 
>>  Barry
>> 
>>> 
>>> Franck
>>> 
>>> - Mail original -
 De: "Franck Houssen" 
 À: "Barry F. Smith" 
 Cc: "For users of the development version of PETSc"
 
 Envoyé: Jeudi 4 Janvier 2018 09:31:05
 Objet: Re: [petsc-dev] How do I collect all the values from a sequential
 vector on the zeroth processor into a
 parallel PETSc vector ?
 
 I attached it in the very first mail.
 
 Franck
 
>> more vecScatterGatherRoot.cpp
 // How do I collect all the values from a sequential vector on the zeroth
 processor into a parallel PETSc vector ?
 //
 // ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc
 -lm;
 mpirun -n X vecScatterGatherRoot.exe
 
 #include "petsc.h"
 
 int main(int argc,char **argv) {
 PetscInitialize(, , NULL, NULL);
 int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
 int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );
 
 PetscInt globSize = size;
 Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
 VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
 VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
 VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
 PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
 
 // Collect all the values from a parallel PETSc vector into a vector on
 the
 zeroth processor.
 
 Vec locVec = NULL;
 if (rank == 0) {
   PetscInt locSize = globSize;
   VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
 }
 VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
 VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES,
 SCATTER_FORWARD);
 VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES,
 SCATTER_FORWARD);
 
 // Modify sequential vector on the zeroth processor.
 
 if (rank == 0) {
   VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
   PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
   VecScale(locVec, -1.);
   VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
   PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
 }
 MPI_Barrier(MPI_COMM_WORLD);
 
 // How do I collect all the values from a sequential vector on the zeroth
 processor into a parallel PETSc vector ?
 
 VecSet(globVec, 0.);
 VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
 VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
 VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
 PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
 
 PetscFinalize();
 }
 
 
 - Mail original -
> De: "Barry F. Smith" 
> À: "Franck Houssen" 
> Cc: "Barry F. Smith" , "Matthew Knepley"
> , "For users of the development
> version of PETSc" 
> Envoyé: Mercredi 3 Janvier 2018 18:20:21
> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> vector on the zeroth processor into a
> parallel PETSc vector ?
> 
> 
> Send the complete code as an attachment.
> 
> 
>> On Jan 3, 2018, at 11:08 AM, Franck Houssen 
>> wrote:
>> 
>> - Mail original -
>>> De: "Barry F. Smith" 
>>> À: "Franck Houssen" 
>>> Cc: "Matthew Knepley" , "For users of the
>>> development
>>> 

Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Franck Houssen


- Mail original -
> De: "Barry F. Smith" 
> À: "Franck Houssen" 
> Cc: "Barry F. Smith" , "For users of the development 
> version of PETSc" 
> Envoyé: Jeudi 4 Janvier 2018 18:13:32
> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
> vector on the zeroth processor into a
> parallel PETSc vector ?
> 
> 
> 
> > On Jan 4, 2018, at 11:10 AM, Franck Houssen 
> > wrote:
> > 
> > Do you reproduce the error at your side ? Or is the pattern I use wrong ?
> 
>You should have received an email from me with a patch for PETSc code.
>Yes I could reproduce, clearly our bug your code was fine.

Didn't get the (other) mail yet: guess I'll get it tomorrow. The mail server 
seems to be messy/capricious... I also noticed some attachments may be "cut" if 
you open them from your web browser (?!). Anyway...
OK. bug fixed : good news ! I'm on maint, I guess you pushed on master and I 
need to apply the patch on maint: no problem.

Thanks Barry

> 
>   Barry
> 
> > 
> > Franck
> > 
> > - Mail original -
> >> De: "Franck Houssen" 
> >> À: "Barry F. Smith" 
> >> Cc: "For users of the development version of PETSc"
> >> 
> >> Envoyé: Jeudi 4 Janvier 2018 09:31:05
> >> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> >> vector on the zeroth processor into a
> >> parallel PETSc vector ?
> >> 
> >> I attached it in the very first mail.
> >> 
> >> Franck
> >> 
>  more vecScatterGatherRoot.cpp
> >> // How do I collect all the values from a sequential vector on the zeroth
> >> processor into a parallel PETSc vector ?
> >> //
> >> // ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc
> >> -lm;
> >> mpirun -n X vecScatterGatherRoot.exe
> >> 
> >> #include "petsc.h"
> >> 
> >> int main(int argc,char **argv) {
> >>  PetscInitialize(, , NULL, NULL);
> >>  int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
> >>  int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );
> >> 
> >>  PetscInt globSize = size;
> >>  Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
> >>  VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
> >>  VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
> >>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
> >>  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> >> 
> >>  // Collect all the values from a parallel PETSc vector into a vector on
> >>  the
> >>  zeroth processor.
> >> 
> >>  Vec locVec = NULL;
> >>  if (rank == 0) {
> >>PetscInt locSize = globSize;
> >>VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
> >>  }
> >>  VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
> >>  VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES,
> >>  SCATTER_FORWARD);
> >>  VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES,
> >>  SCATTER_FORWARD);
> >> 
> >>  // Modify sequential vector on the zeroth processor.
> >> 
> >>  if (rank == 0) {
> >>VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
> >>PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
> >>VecScale(locVec, -1.);
> >>VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
> >>PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
> >>  }
> >>  MPI_Barrier(MPI_COMM_WORLD);
> >> 
> >>  // How do I collect all the values from a sequential vector on the zeroth
> >>  processor into a parallel PETSc vector ?
> >> 
> >>  VecSet(globVec, 0.);
> >>  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> >>  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> >>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
> >>  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> >> 
> >>  PetscFinalize();
> >> }
> >> 
> >> 
> >> - Mail original -
> >>> De: "Barry F. Smith" 
> >>> À: "Franck Houssen" 
> >>> Cc: "Barry F. Smith" , "Matthew Knepley"
> >>> , "For users of the development
> >>> version of PETSc" 
> >>> Envoyé: Mercredi 3 Janvier 2018 18:20:21
> >>> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> >>> vector on the zeroth processor into a
> >>> parallel PETSc vector ?
> >>> 
> >>> 
> >>>  Send the complete code as an attachment.
> >>> 
> >>> 
>  On Jan 3, 2018, at 11:08 AM, Franck Houssen 
>  wrote:
>  
>  - Mail original -
> > De: "Barry F. Smith" 
> > À: "Franck Houssen" 
> > Cc: "Matthew Knepley" , "For users of the
> > development
> > version of PETSc" 
> > Envoyé: Mercredi 3 Janvier 2018 18:01:35
> > Objet: Re: [petsc-dev] How do I collect all the values from a
> > sequential
> > vector on the zeroth processor into a
> > parallel PETSc 

Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Smith, Barry F.


> On Jan 4, 2018, at 11:10 AM, Franck Houssen  wrote:
> 
> Do you reproduce the error at your side ? Or is the pattern I use wrong ? 

   You should have received an email from me with a patch for PETSc code.  Yes 
I could reproduce, clearly our bug your code was fine.

  Barry

> 
> Franck
> 
> - Mail original -
>> De: "Franck Houssen" 
>> À: "Barry F. Smith" 
>> Cc: "For users of the development version of PETSc" 
>> Envoyé: Jeudi 4 Janvier 2018 09:31:05
>> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
>> vector on the zeroth processor into a
>> parallel PETSc vector ?
>> 
>> I attached it in the very first mail.
>> 
>> Franck
>> 
 more vecScatterGatherRoot.cpp
>> // How do I collect all the values from a sequential vector on the zeroth
>> processor into a parallel PETSc vector ?
>> //
>> // ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc -lm;
>> mpirun -n X vecScatterGatherRoot.exe
>> 
>> #include "petsc.h"
>> 
>> int main(int argc,char **argv) {
>>  PetscInitialize(, , NULL, NULL);
>>  int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
>>  int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );
>> 
>>  PetscInt globSize = size;
>>  Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
>>  VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
>>  VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
>>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
>>  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
>> 
>>  // Collect all the values from a parallel PETSc vector into a vector on the
>>  zeroth processor.
>> 
>>  Vec locVec = NULL;
>>  if (rank == 0) {
>>PetscInt locSize = globSize;
>>VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
>>  }
>>  VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
>>  VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
>>  VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
>> 
>>  // Modify sequential vector on the zeroth processor.
>> 
>>  if (rank == 0) {
>>VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
>>PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
>>VecScale(locVec, -1.);
>>VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
>>PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
>>  }
>>  MPI_Barrier(MPI_COMM_WORLD);
>> 
>>  // How do I collect all the values from a sequential vector on the zeroth
>>  processor into a parallel PETSc vector ?
>> 
>>  VecSet(globVec, 0.);
>>  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>>  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
>>  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
>> 
>>  PetscFinalize();
>> }
>> 
>> 
>> - Mail original -
>>> De: "Barry F. Smith" 
>>> À: "Franck Houssen" 
>>> Cc: "Barry F. Smith" , "Matthew Knepley"
>>> , "For users of the development
>>> version of PETSc" 
>>> Envoyé: Mercredi 3 Janvier 2018 18:20:21
>>> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
>>> vector on the zeroth processor into a
>>> parallel PETSc vector ?
>>> 
>>> 
>>>  Send the complete code as an attachment.
>>> 
>>> 
 On Jan 3, 2018, at 11:08 AM, Franck Houssen 
 wrote:
 
 - Mail original -
> De: "Barry F. Smith" 
> À: "Franck Houssen" 
> Cc: "Matthew Knepley" , "For users of the development
> version of PETSc" 
> Envoyé: Mercredi 3 Janvier 2018 18:01:35
> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> vector on the zeroth processor into a
> parallel PETSc vector ?
> 
> 
> 
>> On Jan 3, 2018, at 10:59 AM, Franck Houssen 
>> wrote:
>> 
>> I need the exact opposite operation of an entry in the FAQ called "How
>> do
>> I
>> collect all the values from a parallel PETSc vector into a vector on
>> the
>> zeroth processor?"
> 
> You can use VecScatterCreateToZero() then do the scatter with scatter
> reverse.
> 
 
 That's what I tried but got an error. Did I miss something ?
 
>> tail vecScatterGatherRoot.cpp
 
 // How do I collect all the values from a sequential vector on the
 zeroth
 processor into a parallel PETSc vector ?
 
 VecSet(globVec, 0.);
 VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
 VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
 VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
 PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
 
 PetscFinalize();
 }
 
>> mpirun -n 2 

Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Smith, Barry F.

  Frank,

   This is our bug. I have attached a patch and also fixed it in the PETSc 
repository master branch.

  apply with

patch -p1 < franck.patch

if you are using the tarball version of PETSc.


   Barry


> On Jan 4, 2018, at 2:31 AM, Franck Houssen  wrote:
>
> I attached it in the very first mail.
>
> Franck
>
>>> more vecScatterGatherRoot.cpp
> // How do I collect all the values from a sequential vector on the zeroth 
> processor into a parallel PETSc vector ?
> //
> // ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc -lm; 
> mpirun -n X vecScatterGatherRoot.exe
>
> #include "petsc.h"
>
> int main(int argc,char **argv) {
>  PetscInitialize(, , NULL, NULL);
>  int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
>  int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );
>
>  PetscInt globSize = size;
>  Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
>  VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
>  VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD); 
> PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
>
>  // Collect all the values from a parallel PETSc vector into a vector on the 
> zeroth processor.
>
>  Vec locVec = NULL;
>  if (rank == 0) {
>PetscInt locSize = globSize;
>VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
>  }
>  VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
>  VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
>  VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
>
>  // Modify sequential vector on the zeroth processor.
>
>  if (rank == 0) {
>VecView(locVec, PETSC_VIEWER_STDOUT_SELF); 
> PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
>VecScale(locVec, -1.);
>VecView(locVec, PETSC_VIEWER_STDOUT_SELF); 
> PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
>  }
>  MPI_Barrier(MPI_COMM_WORLD);
>
>  // How do I collect all the values from a sequential vector on the zeroth 
> processor into a parallel PETSc vector ?
>
>  VecSet(globVec, 0.);
>  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD); 
> PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
>
>  PetscFinalize();
> }
>
>
> - Mail original -
>> De: "Barry F. Smith" 
>> À: "Franck Houssen" 
>> Cc: "Barry F. Smith" , "Matthew Knepley" 
>> , "For users of the development
>> version of PETSc" 
>> Envoyé: Mercredi 3 Janvier 2018 18:20:21
>> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
>> vector on the zeroth processor into a
>> parallel PETSc vector ?
>>
>>
>>  Send the complete code as an attachment.
>>
>>
>>> On Jan 3, 2018, at 11:08 AM, Franck Houssen 
>>> wrote:
>>>
>>> - Mail original -
 De: "Barry F. Smith" 
 À: "Franck Houssen" 
 Cc: "Matthew Knepley" , "For users of the development
 version of PETSc" 
 Envoyé: Mercredi 3 Janvier 2018 18:01:35
 Objet: Re: [petsc-dev] How do I collect all the values from a sequential
 vector on the zeroth processor into a
 parallel PETSc vector ?



> On Jan 3, 2018, at 10:59 AM, Franck Houssen 
> wrote:
>
> I need the exact opposite operation of an entry in the FAQ called "How do
> I
> collect all the values from a parallel PETSc vector into a vector on the
> zeroth processor?"

 You can use VecScatterCreateToZero() then do the scatter with scatter
 reverse.

>>>
>>> That's what I tried but got an error. Did I miss something ?
>>>
> tail vecScatterGatherRoot.cpp
>>>
>>> // How do I collect all the values from a sequential vector on the zeroth
>>> processor into a parallel PETSc vector ?
>>>
>>> VecSet(globVec, 0.);
>>> VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>>> VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>>> VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
>>> PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
>>>
>>> PetscFinalize();
>>> }
>>>
> mpirun -n 2 ./vecScatterGatherRoot.exe
>>> Vec Object: 2 MPI processes
>>> type: mpi
>>> Process [0]
>>> 1.
>>> Process [1]
>>> 2.
>>> Vec Object: 1 MPI processes
>>> type: seq
>>> 1.
>>> 2.
>>> Vec Object: 1 MPI processes
>>> type: seq
>>> -1.
>>> -2.
>>> ...
>>> [1]PETSC ERROR: [1] VecScatterBegin_MPI_ToOne line 161
>>> /home/fghoussen/Documents/INRIA/petsc/src/vec/vec/utils/vscat.c
>>> [1]PETSC ERROR: [1] VecScatterBegin line 1698
>>> /home/fghoussen/Documents/INRIA/petsc/src/vec/vec/utils/vscat.c
>>> [1]PETSC ERROR: - Error Message
>>> 

Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Franck Houssen
Do you reproduce the error at your side ? Or is the pattern I use wrong ? 

Franck

- Mail original -
> De: "Franck Houssen" 
> À: "Barry F. Smith" 
> Cc: "For users of the development version of PETSc" 
> Envoyé: Jeudi 4 Janvier 2018 09:31:05
> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
> vector on the zeroth processor into a
> parallel PETSc vector ?
> 
> I attached it in the very first mail.
> 
> Franck
> 
> >> more vecScatterGatherRoot.cpp
> // How do I collect all the values from a sequential vector on the zeroth
> processor into a parallel PETSc vector ?
> //
> // ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc -lm;
> mpirun -n X vecScatterGatherRoot.exe
> 
> #include "petsc.h"
> 
> int main(int argc,char **argv) {
>   PetscInitialize(, , NULL, NULL);
>   int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
>   int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );
> 
>   PetscInt globSize = size;
>   Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
>   VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
>   VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
>   VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
>   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> 
>   // Collect all the values from a parallel PETSc vector into a vector on the
>   zeroth processor.
> 
>   Vec locVec = NULL;
>   if (rank == 0) {
> PetscInt locSize = globSize;
> VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
>   }
>   VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
>   VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
>   VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
> 
>   // Modify sequential vector on the zeroth processor.
> 
>   if (rank == 0) {
> VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
> PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
> VecScale(locVec, -1.);
> VecView(locVec, PETSC_VIEWER_STDOUT_SELF);
> PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
>   }
>   MPI_Barrier(MPI_COMM_WORLD);
> 
>   // How do I collect all the values from a sequential vector on the zeroth
>   processor into a parallel PETSc vector ?
> 
>   VecSet(globVec, 0.);
>   VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>   VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
>   VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
>   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> 
>   PetscFinalize();
> }
> 
> 
> - Mail original -
> > De: "Barry F. Smith" 
> > À: "Franck Houssen" 
> > Cc: "Barry F. Smith" , "Matthew Knepley"
> > , "For users of the development
> > version of PETSc" 
> > Envoyé: Mercredi 3 Janvier 2018 18:20:21
> > Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> > vector on the zeroth processor into a
> > parallel PETSc vector ?
> > 
> > 
> >   Send the complete code as an attachment.
> > 
> > 
> > > On Jan 3, 2018, at 11:08 AM, Franck Houssen 
> > > wrote:
> > > 
> > > - Mail original -
> > >> De: "Barry F. Smith" 
> > >> À: "Franck Houssen" 
> > >> Cc: "Matthew Knepley" , "For users of the development
> > >> version of PETSc" 
> > >> Envoyé: Mercredi 3 Janvier 2018 18:01:35
> > >> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> > >> vector on the zeroth processor into a
> > >> parallel PETSc vector ?
> > >> 
> > >> 
> > >> 
> > >>> On Jan 3, 2018, at 10:59 AM, Franck Houssen 
> > >>> wrote:
> > >>> 
> > >>> I need the exact opposite operation of an entry in the FAQ called "How
> > >>> do
> > >>> I
> > >>> collect all the values from a parallel PETSc vector into a vector on
> > >>> the
> > >>> zeroth processor?"
> > >> 
> > >>  You can use VecScatterCreateToZero() then do the scatter with scatter
> > >>  reverse.
> > >> 
> > > 
> > > That's what I tried but got an error. Did I miss something ?
> > > 
> > >>> tail vecScatterGatherRoot.cpp
> > > 
> > >  // How do I collect all the values from a sequential vector on the
> > >  zeroth
> > >  processor into a parallel PETSc vector ?
> > > 
> > >  VecSet(globVec, 0.);
> > >  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> > >  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> > >  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
> > >  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> > > 
> > >  PetscFinalize();
> > > }
> > > 
> > >>> mpirun -n 2 ./vecScatterGatherRoot.exe
> > > Vec Object: 2 MPI processes
> > >  type: mpi
> > > Process [0]
> > > 1.
> > > Process [1]
> > > 2.
> > > Vec Object: 1 MPI processes
> > >  type: seq
> > > 1.
> > > 2.
> > > Vec Object: 

Re: [petsc-dev] How do I collect all the values from a sequential vector on the zeroth processor into a parallel PETSc vector ?

2018-01-04 Thread Franck Houssen
I attached it in the very first mail.

Franck

>> more vecScatterGatherRoot.cpp 
// How do I collect all the values from a sequential vector on the zeroth 
processor into a parallel PETSc vector ?
//
// ~> g++ -o vecScatterGatherRoot.exe vecScatterGatherRoot.cpp -lpetsc -lm; 
mpirun -n X vecScatterGatherRoot.exe

#include "petsc.h"

int main(int argc,char **argv) {
  PetscInitialize(, , NULL, NULL);
  int size = 0; MPI_Comm_size(MPI_COMM_WORLD, );
  int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, );

  PetscInt globSize = size;
  Vec globVec; VecCreateMPI(PETSC_COMM_WORLD, 1, globSize, );
  VecSetValue(globVec, rank, (PetscScalar) (1.+rank), INSERT_VALUES);
  VecAssemblyBegin(globVec); VecAssemblyEnd(globVec);
  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD); 
PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);

  // Collect all the values from a parallel PETSc vector into a vector on the 
zeroth processor.

  Vec locVec = NULL;
  if (rank == 0) {
PetscInt locSize = globSize;
VecCreateSeq(PETSC_COMM_SELF, locSize, ); VecSet(locVec, -1.);
  }
  VecScatter scatCtx; VecScatterCreateToZero(globVec, , );
  VecScatterBegin(scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);
  VecScatterEnd  (scatCtx, globVec, locVec, INSERT_VALUES, SCATTER_FORWARD);

  // Modify sequential vector on the zeroth processor.

  if (rank == 0) {
VecView(locVec, PETSC_VIEWER_STDOUT_SELF); 
PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
VecScale(locVec, -1.);
VecView(locVec, PETSC_VIEWER_STDOUT_SELF); 
PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);
  }
  MPI_Barrier(MPI_COMM_WORLD);

  // How do I collect all the values from a sequential vector on the zeroth 
processor into a parallel PETSc vector ?

  VecSet(globVec, 0.);
  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD); 
PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);

  PetscFinalize();
}


- Mail original -
> De: "Barry F. Smith" 
> À: "Franck Houssen" 
> Cc: "Barry F. Smith" , "Matthew Knepley" 
> , "For users of the development
> version of PETSc" 
> Envoyé: Mercredi 3 Janvier 2018 18:20:21
> Objet: Re: [petsc-dev] How do I collect all the values from a sequential 
> vector on the zeroth processor into a
> parallel PETSc vector ?
> 
> 
>   Send the complete code as an attachment.
> 
> 
> > On Jan 3, 2018, at 11:08 AM, Franck Houssen 
> > wrote:
> > 
> > - Mail original -
> >> De: "Barry F. Smith" 
> >> À: "Franck Houssen" 
> >> Cc: "Matthew Knepley" , "For users of the development
> >> version of PETSc" 
> >> Envoyé: Mercredi 3 Janvier 2018 18:01:35
> >> Objet: Re: [petsc-dev] How do I collect all the values from a sequential
> >> vector on the zeroth processor into a
> >> parallel PETSc vector ?
> >> 
> >> 
> >> 
> >>> On Jan 3, 2018, at 10:59 AM, Franck Houssen 
> >>> wrote:
> >>> 
> >>> I need the exact opposite operation of an entry in the FAQ called "How do
> >>> I
> >>> collect all the values from a parallel PETSc vector into a vector on the
> >>> zeroth processor?"
> >> 
> >>  You can use VecScatterCreateToZero() then do the scatter with scatter
> >>  reverse.
> >> 
> > 
> > That's what I tried but got an error. Did I miss something ?
> > 
> >>> tail vecScatterGatherRoot.cpp
> > 
> >  // How do I collect all the values from a sequential vector on the zeroth
> >  processor into a parallel PETSc vector ?
> > 
> >  VecSet(globVec, 0.);
> >  VecScatterBegin(scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> >  VecScatterEnd  (scatCtx, locVec, globVec, ADD_VALUES, SCATTER_REVERSE);
> >  VecView(globVec, PETSC_VIEWER_STDOUT_WORLD);
> >  PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
> > 
> >  PetscFinalize();
> > }
> > 
> >>> mpirun -n 2 ./vecScatterGatherRoot.exe
> > Vec Object: 2 MPI processes
> >  type: mpi
> > Process [0]
> > 1.
> > Process [1]
> > 2.
> > Vec Object: 1 MPI processes
> >  type: seq
> > 1.
> > 2.
> > Vec Object: 1 MPI processes
> >  type: seq
> > -1.
> > -2.
> > ...
> > [1]PETSC ERROR: [1] VecScatterBegin_MPI_ToOne line 161
> > /home/fghoussen/Documents/INRIA/petsc/src/vec/vec/utils/vscat.c
> > [1]PETSC ERROR: [1] VecScatterBegin line 1698
> > /home/fghoussen/Documents/INRIA/petsc/src/vec/vec/utils/vscat.c
> > [1]PETSC ERROR: - Error Message
> > --
> > [1]PETSC ERROR: Signal received
> > [1]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for
> > trouble shooting.
> > 
> > 
> >>> 
> >>> Shall I use VecScatterCreateToZero "backward", or, use VecScatterCreate
> >>> instead ? If yes, how ? (my understanding is that VecScatterCreate can
> >>> take only