I'm trying to compile a hello world program using PETSc, based off of this tutorial, slide 33 . How would I compile this? I know that I can't use a simple 'mpicc' command. When running the program, would I use the standard mpirun or mpiexec?
1 Answer
Slides from 2002 are ancient. Have a look at newer tutorials at http://www.mcs.anl.gov/petsc/documentation/tutorials/index.html
To answer your question, though, you will want to look at some of the examples in, say, $PETSC_DIR/src/ksp/ksp/examples/tutorials
. In particular, the makefile is how to compile an example program.
A short example to compile hello.c
:
include ${PETSC_DIR}/conf/variables include ${PETSC_DIR}/conf/rules hello: hello.o chkopts -${CLINKER} -o hello hello.o ${PETSC_LIB} ${RM} hello.o
You would then run:
export PETSC_DIR=/path/to/petsc
and export PETSC_ARCH=petsc-arch
Please review the installation instructions:
http://www.mcs.anl.gov/petsc/documentation/installation.html
After a successful installation of PETSc, run your own test:
make hello
A good tip for debugging (where you want to leave the .o files around) is to run:
make hello RM=echo
-
$\begingroup$ Shouldn't there be a hello.c somewhere in the makefile? $\endgroup$– PaulJan 21, 2012 at 5:48
-
$\begingroup$ It doesn't seem to work. I keep getting this error: /bin/sh: LINKER}: command not found. $\endgroup$– PaulJan 21, 2012 at 5:56
-
$\begingroup$ @Paul: When you added the new line, did you remember to put a
$
in front ofLINKER
? $\endgroup$– DanJan 21, 2012 at 7:46 -
$\begingroup$ @Dan: You were almost right... there was a '{' missing before the LINKER. Now that i've changed it, I get a slightly different error: hello.c:1:19: error: petsc.h: No such file or directory I'm thinking that there's some problem with the path to the petsc.h file. $\endgroup$– PaulJan 21, 2012 at 14:12
-