(use-modules (guix) (gnu)) (define code (plain-file "mpi.c" " #include #include #include int main (int argc, char *argv[]) { int err, np, rank; err = MPI_Init (&argc, &argv); assert (err == 0); err = MPI_Comm_size(MPI_COMM_WORLD, &np); assert (err == 0); err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); assert (err == 0); printf (\"np = %i, rank = %i\\n\", np, rank); return 0; } ")) (define toolchain (specification->package "gcc-toolchain")) (define mpich (specification->package "mpich")) (computed-file "mpi-init" (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) (setenv "PATH" (string-append #$(file-append toolchain "/bin") ":" #$(file-append mpich "/bin"))) (setenv "CPATH" #$(file-append mpich "/include")) (setenv "LIBRARY_PATH" (string-append #$(file-append mpich "/lib") ":" #$(file-append toolchain "/lib"))) (invoke "mpicc" "-o" #$output "-Wall" "-g" #$code) ;; Run the MPI code in the build environment. (invoke "mpiexec" "-np" "2" #$output))))