Exercise 1: Hello World - the minimal MPI program
- Write a minimal MPI program which prints "hello world" from multiple
processes. Compile and run it on 1, 2 and 4 procesors.
- Add the writing processes rank as part of the output. (Also note the
-t
option for mpirun.)
- Use Fortran:
integer mpi_log_fd=11
character*10 filenm
...
write(filenm,'("mpilog.",i2.2)') mpirank
open(unit=mpi_log_fd, file=filenm)
or C:
FILE *mpi_log_fd;
char filenm[10];
...
sprintf(filenm, "mpilog.%2.2d" , mpirank);
mpi_log_fd = fopen(filenm,"w" );
to open a log file for each process and write to it.
(To use such
log files for debugging, it may be necessary to use flush()
after each write/fprintf -- dont use flush() except for
debugging.)
- What happens to IO before
MPI_Init() or after MPI_Finalize()
on different machines?
[Solution in hello.f/f90/c ]
|