Hi, I have a Fortran90 program that solves a complex linear generalized eigenvalue problem (GEVP) using standard fortran 90 programming: Subroutines, modules, allocatable arrays, real(8), int,... This program uses Lapack to solve the GEVP. The program is mainly made off: 1) set dimensions of problem and initialize arrays,... 2) compute the baseflow (for instance boundary layer flow) 3) build the (stability) complex generalized eigenvalue problem ==> build (dense) matrices A and B 4) solve the GEVP with Lapack Now I want to use PETSc + SLEPc to use sparse matrices. Do I need to rewrite/modify everything in terms of PETSc variables as follows: - int -> PetscInt - real(8) -> PetscScalar - complex*16 -> PetscScalar or is it possible to reuse all that F90 code? For instance I have a similarity solver that computes Blasius solution. If that similarity solver provides me with u and v velocities in terms of standard fortran90 real(8) variables, how should I do to use these variables to build my complex matrix? Should I convert them to Petsc variables? How? what should I do with my Fortran90 allocatable arrays? real(dp),allocatable,dimension(:,:) :: u--> PetscScalar,allocatable,dimension(:,:) :: u ???? Thanks a lot, Anthony
On Fri, 19 Jun 2015, Anthony Haas wrote:
Hi,
I have a Fortran90 program that solves a complex linear generalized eigenvalue problem (GEVP) using standard fortran 90 programming:
Subroutines, modules, allocatable arrays, real(8), int,...
This program uses Lapack to solve the GEVP. The program is mainly made off:
1) set dimensions of problem and initialize arrays,... 2) compute the baseflow (for instance boundary layer flow) 3) build the (stability) complex generalized eigenvalue problem ==> build (dense) matrices A and B 4) solve the GEVP with Lapack
Now I want to use PETSc + SLEPc to use sparse matrices. Do I need to rewrite/modify everything in terms of PETSc variables as follows:
- int -> PetscInt - real(8) -> PetscScalar perhaps you mean: PetscReal
- complex*16 -> PetscScalar
or is it possible to reuse all that F90 code? For instance I have a similarity solver that computes Blasius solution. If that similarity solver provides me with u and v velocities in terms of standard fortran90 real(8) variables, how should I do to use these variables to build my complex matrix? Should I convert them to Petsc variables? How?
You can use the current datatypes used in your code - And always make sure the types match manually. [Fortran does not have typecheck anyway..]
what should I do with my Fortran90 allocatable arrays?
real(dp),allocatable,dimension(:,:) :: u--> PetscScalar,allocatable,dimension(:,:) :: u ????
Either should work. You can add the following to your code: #if !defined(PETSC_USE_COMPLEX) #error "this code requires PETSc --with-scalar-type=complex build" #endif #if !defined(PETSC_USE_REAL_DOUBLE) #error "this code requires PETSc --with-precision=real build" #endif Satish
Hi Satish, Thanks for your answer. In the attached program, I have declared the following standard fortran arrays: real(dp),dimension(:,:),allocatable :: D1X,D2X,D1Y,D2Y Let's say these are real matrix derivatives that I need to insert in my complex A matrix (it could also be some real baseflow from a similarity solver). I have filled D1Y with 999.d0 just to test (see line 169). Then I insert D1Y in the global (complex) matrix with call MatSetValues(A,ny,idxm2,ny,idxn2,D1Y,INSERT_VALUES,ierr). I expected that in the Matrix A, this would be automatically converted to 999.0 + 0.0i but when I view A, I see 999 + 999 i or even 999 + 1.0326e-321 i. Is there a way to insert D1Y as is and obtain the proper behavior? How would you do it? Thanks Anthony On Fri, Jun 19, 2015 at 11:08 AM, Satish Balay <[email protected]> wrote:
On Fri, 19 Jun 2015, Anthony Haas wrote:
Hi,
I have a Fortran90 program that solves a complex linear generalized eigenvalue problem (GEVP) using standard fortran 90 programming:
Subroutines, modules, allocatable arrays, real(8), int,...
This program uses Lapack to solve the GEVP. The program is mainly made off:
1) set dimensions of problem and initialize arrays,... 2) compute the baseflow (for instance boundary layer flow) 3) build the (stability) complex generalized eigenvalue problem ==> build (dense) matrices A and B 4) solve the GEVP with Lapack
Now I want to use PETSc + SLEPc to use sparse matrices. Do I need to rewrite/modify everything in terms of PETSc variables as follows:
- int -> PetscInt - real(8) -> PetscScalar perhaps you mean: PetscReal
- complex*16 -> PetscScalar
or is it possible to reuse all that F90 code? For instance I have a similarity solver that computes Blasius solution. If that similarity solver provides me with u and v velocities in terms of standard fortran90 real(8) variables, how should I do to use these variables to build my complex matrix? Should I convert them to Petsc variables? How?
You can use the current datatypes used in your code - And always make sure the types match manually. [Fortran does not have typecheck anyway..]
what should I do with my Fortran90 allocatable arrays?
real(dp),allocatable,dimension(:,:) :: u--> PetscScalar,allocatable,dimension(:,:) :: u ????
Either should work.
You can add the following to your code:
#if !defined(PETSC_USE_COMPLEX) #error "this code requires PETSc --with-scalar-type=complex build" #endif #if !defined(PETSC_USE_REAL_DOUBLE) #error "this code requires PETSc --with-precision=real build" #endif
Satish
Sorry - I should have checked the code closer. [real(dp) vs PetscScalar] MatSetValues() expects PetscScalar. You cannot pass in 'real*8' in place of 'complex*16' [i.e PetscScalar] - and expect it to work. This is what I meat by 'make sure the types match manually' You'll have to convert real*8 to complex*16 yourself before calling MatSetValues(). Satish On Fri, 19 Jun 2015, Anthony Paul Haas wrote:
Hi Satish,
Thanks for your answer. In the attached program, I have declared the following standard fortran arrays: real(dp),dimension(:,:),allocatable :: D1X,D2X,D1Y,D2Y
Let's say these are real matrix derivatives that I need to insert in my complex A matrix (it could also be some real baseflow from a similarity solver). I have filled D1Y with 999.d0 just to test (see line 169). Then I insert D1Y in the global (complex) matrix with call MatSetValues(A,ny,idxm2,ny,idxn2,D1Y,INSERT_VALUES,ierr). I expected that in the Matrix A, this would be automatically converted to 999.0 + 0.0i but when I view A, I see 999 + 999 i or even 999 + 1.0326e-321 i. Is there a way to insert D1Y as is and obtain the proper behavior? How would you do it?
Thanks
Anthony
On Fri, Jun 19, 2015 at 11:08 AM, Satish Balay <[email protected]> wrote:
On Fri, 19 Jun 2015, Anthony Haas wrote:
Hi,
I have a Fortran90 program that solves a complex linear generalized eigenvalue problem (GEVP) using standard fortran 90 programming:
Subroutines, modules, allocatable arrays, real(8), int,...
This program uses Lapack to solve the GEVP. The program is mainly made off:
1) set dimensions of problem and initialize arrays,... 2) compute the baseflow (for instance boundary layer flow) 3) build the (stability) complex generalized eigenvalue problem ==> build (dense) matrices A and B 4) solve the GEVP with Lapack
Now I want to use PETSc + SLEPc to use sparse matrices. Do I need to rewrite/modify everything in terms of PETSc variables as follows:
- int -> PetscInt - real(8) -> PetscScalar perhaps you mean: PetscReal
- complex*16 -> PetscScalar
or is it possible to reuse all that F90 code? For instance I have a similarity solver that computes Blasius solution. If that similarity solver provides me with u and v velocities in terms of standard fortran90 real(8) variables, how should I do to use these variables to build my complex matrix? Should I convert them to Petsc variables? How?
You can use the current datatypes used in your code - And always make sure the types match manually. [Fortran does not have typecheck anyway..]
what should I do with my Fortran90 allocatable arrays?
real(dp),allocatable,dimension(:,:) :: u--> PetscScalar,allocatable,dimension(:,:) :: u ????
Either should work.
You can add the following to your code:
#if !defined(PETSC_USE_COMPLEX) #error "this code requires PETSc --with-scalar-type=complex build" #endif #if !defined(PETSC_USE_REAL_DOUBLE) #error "this code requires PETSc --with-precision=real build" #endif
Satish
participants (3)
-
Anthony Haas -
Anthony Paul Haas -
Satish Balay