The purpose of this chapter is to quickly introduce the concepts needed to start using the LSF Parallel system. They are: compiling, linking, and submitting parallel applications. The example used in this chapter is a distributed version of the Hello World program named myjob; written in C.
This chapter discusses the following topics:
Writing a Distributed Application 10
Compiling and Linking the Application 11
If the commands cannot be executed or the man pages cannot be viewed, the appropriate directories may need to added to the systems path; check with the system administrator.
This example program, written in C, is a distributed version of the Hello World program named myjob. Use an editor to enter the code for this application. After the code is entered, save it in a file named myjob.c
/*
* File: myjob.c
*/
#include <stdio.h>
#include "mpi.h" /* MPI header file */
int
main(int argc, char **argv)
{
int myrank; /* Rank of this process */
int n_processes; /* Number of Processes */
int srcrank; /* Rank of the Sender */
int destrank; /* Rank of the receiver */
char mbuf[512]; /* Message buffer */
MPI_Status mstat; /* Return Status of an MPI operation */
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &n_processes);
if (myrank != 0) {
sprintf(mbuf, "Hello, from process %d!", myrank);
destrank = 0;
MPI_Send(mbuf, strlen(mbuf)+1, MPI_CHAR,
destrank, 90,MPI_COMM_WORLD);
} else {
for (srcrank = 1; srcrank < n_processes; srcrank++) {
MPI_Recv(mbuf, 512, MPI_CHAR,
srcrank, 90, MPI_COMM_WORLD,&mstat);
printf("From process %d: %s\n", srcrank, mbuf);
}
}
MPI_Finalize();
}
After the example program is entered and saved as myjob.c, use the mpicc script to compile and link the application. The mpicc script is used in a similar manner to other UNIX-based C compilers. This script provides the options and special libraries needed to compile and link a parallel application for the LSF Parallel environment.
To compile and link the source code in the myjob.c file in one step, enter the following command:
% mpicc myjob.c -o myjob
The binary created is called myjob.
To submit the parallel application myjob to the LSF Batch system, requesting three processors, enter the following command:
This command creates three processes and each runs an instance of myjob. The bsub command has a number of command line options, which are discussed in more detail in Submitting Batch Jobs on page 26. To view the status of the parallel batch job, enter the following command:
% bjobs JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME |
The bjobs command has a number of command line options, which are discussed in more detail in Monitoring Job Status on page 30.
To interactively execute the parallel application myjob on three processors, enter the following command:
The pam command has a number of command line options, which are discussed in more detail in The pam Command on page 35.