# Compiling and running a “hello world” program in PETSc

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?

• did you include this at the beginning of the makefile ? CFLAGS = -I${PETSC_DIR}/include – admiral heartbridge Jul 25 '16 at 9:17 ## 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 • Shouldn't there be a hello.c somewhere in the makefile? – Paul Jan 21 '12 at 5:48 • It doesn't seem to work. I keep getting this error: /bin/sh: LINKER}: command not found. – Paul Jan 21 '12 at 5:56 • @Paul: When you added the new line, did you remember to put a $ in front of LINKER? – Dan Jan 21 '12 at 7:46
• @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. – Paul Jan 21 '12 at 14:12
• You might need to include petscksp.h. – Dan Jan 21 '12 at 18:24