Re: [petsc-users] Null Pointer Issue (Eigen-Value-Problem with user input Matrices)

2023-07-25 Thread Barry Smith

  You never called MatCreate(comm, );

> On Jul 25, 2023, at 6:06 PM, maitri ksh  wrote:
> 
> I am using the following setup:
> 1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
> 2. MATLAB-R2022a
> 3. slepc-3.19.1
> 4.  configured using:  './configure --with-cc=gcc --with-cxx=g++ 
> --with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab 
> --with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'
> 
> I am trying to solve an eigenvalue problem with user input matrices 'A.petsc' 
> & 'B.petsc' using  'solveEigValProb.c', there was no issue during compiling 
> but when I try to run the executable it produces error ('ERROR.txt') 
> indicating a null pointer issue but I am not sure what the issue is.
> 
> Maitri
> 



[petsc-users] Null Pointer Issue (Eigen-Value-Problem with user input Matrices)

2023-07-25 Thread maitri ksh
I am using the following setup:
1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
2. MATLAB-R2022a
3. slepc-3.19.1
4.  configured using:  './configure --with-cc=gcc --with-cxx=g++
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'

I am trying to solve an eigenvalue problem with user input matrices
'A.petsc' & 'B.petsc' using  '*solveEigValProb.c*', there was no issue
during compiling but when I try to run the executable it produces error ('
*ERROR.txt*') indicating a null pointer issue but I am not sure what the
issue is.

Maitri
#include 
#include 
#include 

int main(int argc, char **argv)
{
PetscInitialize(, , NULL, NULL);

/*PetscViewer viewer;*/
Mat A, B;
EPS eps;
MPI_Comm comm = PETSC_COMM_WORLD;

PetscInt nev = 2; // Number of eigenvalues to compute
PetscScalar sigma = 0.0; // Shift value

MatCreate(comm, );
PetscObjectSetName((PetscObject)A, "A");

/* open file for reading */
PetscViewer viewerA;
PetscErrorCode ierr;
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, "A.petsc", FILE_MODE_READ, 
);CHKERRQ(ierr);
ierr = MatLoad(A, viewerA);CHKERRQ(ierr);
PetscViewerDestroy();

/* open file for reading */
PetscViewer viewerB;
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, "B.petsc", FILE_MODE_READ, 
);CHKERRQ(ierr);
ierr = MatLoad(B, viewerB);CHKERRQ(ierr);
PetscViewerDestroy();

/* ... use matrices in computation ... */
// Create the eigensolver context
ierr = EPSCreate(PETSC_COMM_WORLD, ); CHKERRQ(ierr);

// Set operators A and B
ierr = EPSSetOperators(eps, A, B); CHKERRQ(ierr);

// Set dimensions and target (if needed)
ierr = EPSSetDimensions(eps, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE); 
CHKERRQ(ierr);
ierr = EPSSetTarget(eps, sigma); CHKERRQ(ierr);

// Solve the eigenvalue problem
ierr = EPSSolve(eps); CHKERRQ(ierr);

// Get the number of computed eigenvalues
ierr = EPSGetConverged(eps, ); CHKERRQ(ierr);

// Get the computed eigenvalues and eigenvectors
PetscScalar eigenvalue, kr;
Vec eigenvector;
Vec xr, xi;
PetscPrintf(PETSC_COMM_WORLD, "Eigenvalues:\n");
for (PetscInt i = 0; i < nev; i++)
{
ierr = EPSGetEigenpair(eps, i, , , xr, xi); CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD, "Eigenvalue %d: %.8f + %.8fi\n", i, 
PetscRealPart(eigenvalue), PetscImaginaryPart(eigenvalue));

}

// Destroy everything
ierr = EPSDestroy(); CHKERRQ(ierr);
ierr = MatDestroy(); CHKERRQ(ierr);
ierr = MatDestroy(); CHKERRQ(ierr);

PetscFinalize();
return 0;
}
maitri@LAPTOP-0CP4FI1T:~/my_executables$ ./new2
[0]PETSC ERROR: - Error Message 
--
[0]PETSC ERROR: Null argument, when expecting valid pointer
[0]PETSC ERROR: Null Pointer: Parameter # 1
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.19.3, unknown
[0]PETSC ERROR: ./new2 on a arch-linux-c-debug named LAPTOP-0CP4FI1T by maitri 
Wed Jul 26 00:54:45 2023
[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ 
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab 
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1
[0]PETSC ERROR: #1 MatLoad() at 
/home/maitri/petsc/src/mat/interface/matrix.c:1317
[0]PETSC ERROR: #2 main() at new2.c:30
[0]PETSC ERROR: No PETSc Option Table entries
[0]PETSC ERROR: End of Error Message ---send entire error 
message to petsc-ma...@mcs.anl.gov--
application called MPI_Abort(MPI_COMM_SELF, 85) - process 0
[unset]: PMIU_write error; fd=-1 buf=:cmd=abort exitcode=85 message=application 
called MPI_Abort(MPI_COMM_SELF, 85) - process 0
:
system msg for write_line failure : Bad file descriptor

Re: [petsc-users] Question about using PETSc to generate matrix preconditioners

2023-07-25 Thread Jed Brown
I think random matrices will produce misleading results. The chance of randomly 
generating a matrix that resembles an application is effectively zero. I think 
you'd be better off with some model problems varying parameters that control 
the physical regime (e.g., shifts to a Laplacian, advection with/without 
upwinding at varying cell Peclet numbers, varying nondimensional parameters, 
time step, and boundary layers for fluids, varying Poisson ratio and material 
contrast in elasticity).

"Sun, Yixuan via petsc-users"  writes:

> Hello PETSc team,
>
> My name is Yixuan, and I am a postdoc at MCS. We are working on a project 
> where we want to predict the preconditioners from the corresponding matrices. 
> For preliminary exploration purposes, we generated random matrices and their 
> preconditioners using PETSc. The current deep learning models look promising 
> with the generated data. However, we are not sure about the correctness of 
> the data generation code and wanted to ask if you could help check the 
> correctness of our script (< 100 lines) and let us know if there were any 
> issues. Here is the 
> link
>  to the script.
>
> Please let me know if you have any questions or concerns. Thank you in 
> advance!
>
>
> Warm regards,
> Yixuan
> 
> Yixuan Sun
> Postdoctoral Researcher
> Mathematics and Computer Science
> Argonne National Laboratory


[petsc-users] Question about using PETSc to generate matrix preconditioners

2023-07-25 Thread Sun, Yixuan via petsc-users
Hello PETSc team,

My name is Yixuan, and I am a postdoc at MCS. We are working on a project where 
we want to predict the preconditioners from the corresponding matrices. For 
preliminary exploration purposes, we generated random matrices and their 
preconditioners using PETSc. The current deep learning models look promising 
with the generated data. However, we are not sure about the correctness of the 
data generation code and wanted to ask if you could help check the correctness 
of our script (< 100 lines) and let us know if there were any issues. Here is 
the 
link
 to the script.

Please let me know if you have any questions or concerns. Thank you in advance!


Warm regards,
Yixuan

Yixuan Sun
Postdoctoral Researcher
Mathematics and Computer Science
Argonne National Laboratory


Re: [petsc-users] UNABLE to read '.mat' file with 'PetscViewerHDF5Open' (WSL-Ubuntu22.04)

2023-07-25 Thread maitri ksh
I tried using  '$PETSC_DIR/$PETSC_ARCH/bin/h5dump myfile.mat', but it gave
'h5dump error: unable to open file "/path/to/directory/myfile.mat"',
*saving* the *MATLAB file* with  “*-v7.3*” option *solved* the issue.

Thank you, Matthew & Samar.

On Tue, Jul 25, 2023 at 12:18 PM Matthew Knepley  wrote:

> On Tue, Jul 25, 2023 at 3:12 AM maitri ksh  wrote:
>
>> Hi,
>> I am new to Petsc, here are some details of the relevant softwares I am
>> using:
>> 1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
>> 2. MATLAB-R2022a
>> 3. hdf5-1.10.7 (checked using 'pkg-config --modversion hdf5')
>> 4. configured using:  './configure --with-cc=gcc --with-cxx=g++
>> --with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab
>> --with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'
>>
>> I am trying to read a '.mat' file ('*myfile.mat*') using
>> 'PetscViewerHDF5Open'  (the source code '*read_Matrix.c*' is attached
>> herewith). I could compile the source code with no error, but I am getting
>> an error ('*ERROR.txt*') indicating that there is an issue opening the
>> HDF5 file. Could you please help me to resolve this issue
>>
>
> HDF5 thinks that this is not an HDF5 file. Since PETSc built HDF5 for you,
> you can check this using
>
>   $PETSC_DIR/$PETSC_ARCH/bin/h5dump myfile.mat
>
> It could be a version incompatibility between the HDF5 on your machine and
> the one you asked PETSc to download.
>
>   Thanks,
>
> Matt
>
>
>> Maitri
>>
>>
>
> --
> 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-users] UNABLE to read '.mat' file with 'PetscViewerHDF5Open' (WSL-Ubuntu22.04)

2023-07-25 Thread Samar Khatiwala
Another possibility is that the Matlab file wasn’t saved in HDF5. Try resaving 
it with the “-v7.3” option.

Samar

On Jul 25, 2023, at 10:18 AM, Matthew Knepley  wrote:

On Tue, Jul 25, 2023 at 3:12 AM maitri ksh 
mailto:maitri@gmail.com>> wrote:
Hi,
I am new to Petsc, here are some details of the relevant softwares I am using:
1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
2. MATLAB-R2022a
3. hdf5-1.10.7 (checked using 'pkg-config --modversion hdf5')
4. configured using:  './configure --with-cc=gcc --with-cxx=g++ 
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab 
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'

I am trying to read a '.mat' file ('myfile.mat') using 'PetscViewerHDF5Open'  
(the source code 'read_Matrix.c' is attached herewith). I could compile the 
source code with no error, but I am getting an error ('ERROR.txt') indicating 
that there is an issue opening the HDF5 file. Could you please help me to 
resolve this issue

HDF5 thinks that this is not an HDF5 file. Since PETSc built HDF5 for you, you 
can check this using

  $PETSC_DIR/$PETSC_ARCH/bin/h5dump myfile.mat

It could be a version incompatibility between the HDF5 on your machine and the 
one you asked PETSc to download.

  Thanks,

Matt

Maitri



--
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-users] UNABLE to read '.mat' file with 'PetscViewerHDF5Open' (WSL-Ubuntu22.04)

2023-07-25 Thread Matthew Knepley
On Tue, Jul 25, 2023 at 3:12 AM maitri ksh  wrote:

> Hi,
> I am new to Petsc, here are some details of the relevant softwares I am
> using:
> 1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
> 2. MATLAB-R2022a
> 3. hdf5-1.10.7 (checked using 'pkg-config --modversion hdf5')
> 4. configured using:  './configure --with-cc=gcc --with-cxx=g++
> --with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab
> --with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'
>
> I am trying to read a '.mat' file ('*myfile.mat*') using
> 'PetscViewerHDF5Open'  (the source code '*read_Matrix.c*' is attached
> herewith). I could compile the source code with no error, but I am getting
> an error ('*ERROR.txt*') indicating that there is an issue opening the
> HDF5 file. Could you please help me to resolve this issue
>

HDF5 thinks that this is not an HDF5 file. Since PETSc built HDF5 for you,
you can check this using

  $PETSC_DIR/$PETSC_ARCH/bin/h5dump myfile.mat

It could be a version incompatibility between the HDF5 on your machine and
the one you asked PETSc to download.

  Thanks,

Matt


> Maitri
>
>

-- 
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-users] UNABLE to read '.mat' file with 'PetscViewerHDF5Open' (WSL-Ubuntu22.04)

2023-07-25 Thread maitri ksh
Hi,
I am new to Petsc, here are some details of the relevant softwares I am
using:
1. petsc-3.19.3 (on wsl-ubuntu22.04 platform)
2. MATLAB-R2022a
3. hdf5-1.10.7 (checked using 'pkg-config --modversion hdf5')
4. configured using:  './configure --with-cc=gcc --with-cxx=g++
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1'

I am trying to read a '.mat' file ('*myfile.mat*') using
'PetscViewerHDF5Open'  (the source code '*read_Matrix.c*' is attached
herewith). I could compile the source code with no error, but I am getting
an error ('*ERROR.txt*') indicating that there is an issue opening the HDF5
file. Could you please help me to resolve this issue?

Maitri
#include 
#include 

int main(int argc, char **argv)
{
PetscInitialize(, , NULL, NULL);

PetscViewer viewer;
Mat A;
MPI_Comm comm = PETSC_COMM_WORLD;

MatCreate(comm, );
PetscObjectSetName((PetscObject)A, "A");

/* open HDF5 file for reading */
PetscViewerHDF5Open(comm, "/home/maitri/my_executables/myfile.mat", 
FILE_MODE_READ, );
PetscViewerPushFormat(viewer, PETSC_VIEWER_HDF5_MAT);

/* view matrix */
MatLoad(A, viewer); /* look up by name */

/* ... use matrix A in computation ... */

PetscViewerPopFormat(viewer);
PetscViewerDestroy();
MatDestroy();

PetscFinalize();
return 0;
}


myfile.mat
Description: Binary data
maitri@LAPTOP-0CP4FI1T:~/my_executables$ ./read_Matrix
HDF5-DIAG: Error detected in HDF5 (1.12.2) MPI-process 0:
  #000: H5F.c line 620 in H5Fopen(): unable to open file
major: File accessibility
minor: Unable to open file
  #001: H5VLcallback.c line 3501 in H5VL_file_open(): failed to iterate over 
available VOL connector plugins
major: Virtual Object Layer
minor: Iteration failed
  #002: H5PLpath.c line 578 in H5PL__path_table_iterate(): can't iterate over 
plugins in plugin path '(null)'
major: Plugin for dynamically loaded library
minor: Iteration failed
  #003: H5PLpath.c line 620 in H5PL__path_table_iterate_process_path(): can't 
open directory: /usr/local/hdf5/lib/plugin
major: Plugin for dynamically loaded library
minor: Can't open directory or file
  #004: H5VLcallback.c line 3351 in H5VL__file_open(): open failed
major: Virtual Object Layer
minor: Can't open object
  #005: H5VLnative_file.c line 97 in H5VL__native_file_open(): unable to open 
file
major: File accessibility
minor: Unable to open file
  #006: H5Fint.c line 1990 in H5F_open(): unable to read superblock
major: File accessibility
minor: Read failed
  #007: H5Fsuper.c line 405 in H5F__super_read(): file signature not found
major: File accessibility
minor: Not an HDF5 file
[0]PETSC ERROR: - Error Message 
--
[0]PETSC ERROR: Error in external library
[0]PETSC ERROR: Error in HDF5 call H5Fopen() Status -1
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.19.3, unknown
[0]PETSC ERROR: ./read_Matrix on a arch-linux-c-debug named LAPTOP-0CP4FI1T by 
maitri Tue Jul 25 09:35:41 2023
[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ 
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab 
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1
[0]PETSC ERROR: #1 PetscViewerFileSetName_HDF5() at 
/home/maitri/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:423
[0]PETSC ERROR: #2 PetscViewerFileSetName() at 
/home/maitri/petsc/src/sys/classes/viewer/impls/ascii/filev.c:612
[0]PETSC ERROR: #3 PetscViewerHDF5Open() at 
/home/maitri/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:628
HDF5-DIAG: Error detected in HDF5 (1.12.2) MPI-process 0:
  #000: H5L.c line 938 in H5Lexists(): invalid location identifier
major: Invalid arguments to routine
minor: Inappropriate type
[0]PETSC ERROR: - Error Message 
--
[0]PETSC ERROR: Error in external library
[0]PETSC ERROR: Error in HDF5 call H5Lexists() Status -1
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.19.3, unknown
[0]PETSC ERROR: ./read_Matrix on a arch-linux-c-debug named LAPTOP-0CP4FI1T by 
maitri Tue Jul 25 09:35:41 2023
[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ 
--with-fc=gfortran --download-mpich --download-fblaslapack --with-matlab 
--with-matlab-dir=/usr/local/MATLAB/R2022a --download-hdf5 --with-hdf5=1
[0]PETSC ERROR: #1 PetscViewerHDF5Traverse_Inner_Internal() at 
/home/maitri/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:1314
[0]PETSC ERROR: #2 PetscViewerHDF5Traverse_Internal() at 
/home/maitri/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:1367
[0]PETSC ERROR: #3 PetscViewerHDF5ReadAttribute() at