cmakefilecygwinpetsc

PETSc example not working


I have Windows 7 OS. I have followed the instructions from the PETSc web page; in the command prompt of VS 2005 I have opened cygwin and installed PETSc with the command:

./configure --with-cc='win32fe cl' --with-fc=0 --with-mpi=0 --download-f2cblaslapack

I tried to run the following example from the web page:

cd src/ksp/ksp/examples/tutorials

make ex2

the ex2.c is a c program code. I get the following error:

$ make ex2

makefile:18: /conf/variables: No such file or directory

makefile:19: /conf/rules: No such file or directory

makefile:1151: /conf/test: No such file or directory

make: *** No rule to make target `/conf/test'.  Stop.

What is causing this?

(and more importantly) How do I fix it?

*edit: I could use a general answer as well, because at the moment I don't really even know what to Google for and I don't feel like just contacting PETSc support for everything.


I've decided to work on Ubuntu. So now, here s the deal. After installation I write:

gcc -I$PETSC_DIR/include -L$PETSC_DIR/$PETSC_ARCH/lib -libpetsc ex2

in command line. I get the erros massage:

/usr/bin/ld: cannot find -libpetsc ex2: In function _start': (.text+0x1bc4): multiple definition of_start' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here ex2: In function _fini': (.fini+0x0): multiple definition of_fini' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here ex2:(.rodata+0x0): multiple definition of _IO_stdin_used' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here ex2: In function__data_start': (.data+0x0): multiple definition of __data_start' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here ex2: In function__data_start': (.data+0x8): multiple definition of __dso_handle' /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here ex2: In function_init': (.init+0x0): multiple definition of `_init' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here collect2: ld returned 1 exit status


Solution

  • As mentioned on the PETSc web page under section Encounter problems? for problem related to make you need to set PETSC_DIR and PETSC_ARCH printed by configure.

    What is causing this?:
    The makefile in src/ksp/ksp/examples/tutorials directory refers to PETSC_DIR to include the configuration files i.e.

    include ${PETSC_DIR}/conf/variables
    include ${PETSC_DIR}/conf/rules
    
    ...
    include ${PETSC_DIR}/conf/test
    

    Now as you are executing make as just make ex2 (as from the error it indicates that you have not set PETSC_DIR variable), ${PETSC_DIR} is empty thus make tries to include /conf/variables, /conf/rules & /conf/test files which are not present.

    How do I fix it?
    You have to run make as mentioned on the website as
    make PETSC_DIR=<dir_output_from_configure> PETSC_ARCH=<arch_output_from_configure> ex2
    Before that you need to build the source correctly. To clarify from what you have mentioned in the question ./configure ... does not install PETSc but only configures the source for building. You need to run make. When you run configure if it was successful, it will output the configuration details including PETSC_DIR and PETSC_ARCH. Sample output:

    ./configure --with-mpi=0
    ===============================================================================
                 Configuring PETSc to compile on your system                       
    ===============================================================================
    TESTING: alternateConfigureLibrary from PETSc.packages.petsc4py(config/PETSc/packages/petsc4py.py:65)                                                                   Compilers:
    ...
    ...
    PETSc:
      PETSC_ARCH: arch-linux2-c-debug
      PETSC_DIR: /XXXX/petsc-3.3-p1
      Clanguage: C
      Scalar type: real
      Precision: double
      shared libraries: disabled
      dynamic loading: disabled
      Memory alignment: 16
    xxx=========================================================================xxx
     Configure stage complete. Now build PETSc libraries with (cmake build):
       make PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug all
     or (experimental with python):
       PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug ./config/builder.py
    xxx=========================================================================xxx
    

    Then you have run make PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug all as mentioned in the output of configure. This will build the libraries. Now you should be able to build the example. (Please note that this was run on Linux, you should pretty much be able to do the same on cygwin)
    Side note: There does not seem to be any need to set PETSC_ARCH for building the example, you should be able to build with make PETSC_DIR=<dir_output_from_configure> ex2

    Hope this helps!