Building in parallel on a Mac

From VisItusers.org

Revision as of 23:56, 24 May 2010 by BradWhitlock (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Newer MacOS X computers are being shipped with 4 or even 8 cores and several Gb of memory. This makes the Mac a terrific platform for running parallel VisIt. Mac OS 10.5 and later come with OpenMPI installed. Since Mac development for VisIt is now primarily on MacOS X 10.5 and 10.6, versions of VisIt starting with VisIt 2.0 come with the parallel version enabled. This page describes how to get parallel VisIt working on a Mac.

Contents

[edit] Using OpenMPI 1.2.4

If you are using MacOS X 10.5 or later, you don't need to build your own MPI and you can skip this section.

VisIt can be built with OpenMPI 1.2.4 on MacOS X. Other MPI implementations no doubt will work but OpenMPI has been tried and has been verified to work.

These instructions assume that you have used the build_visit script to build all of the required 3rd party libraries and that you are ready to build VisIt.

[edit] Testing MPI

This page does not cover building OpenMPI but the build process is simple enough on MacOS X.

MAKE SURE THAT MPI WORKS BEFORE YOU BUILD VISIT!

Users often build VisIt using a bad MPI installation or at least one that they've never tested. Don't be that user since you will waste a lot of time! You can try any test programs that come with your MPI installation or you can write a simple hello world MPI application.

#include <stdio.h>
#include <string.h>
#include <mpi.h>
 
int
main(int argc, char *argv[])
{
    const char *s = "HELLO FROM THE MASTER PROCESS!";
    int par_rank, par_size;
    FILE *fp = NULL;
    char msgbuf[100], filename[100];
 
    /* Init MPI */
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &par_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &par_size);
 
    msgbuf[0] = '\0';
 
    /* Broadcast message from master to all other processors. */
    if(par_rank == 0)
    {
        MPI_Bcast((void*)s, strlen(s)+1, MPI_CHAR, 0, MPI_COMM_WORLD);
        strcpy(msgbuf, s);
    }
    else
        MPI_Bcast((void*)msgbuf, strlen(s)+1, MPI_CHAR, 0, MPI_COMM_WORLD);
 
    /* Write the message from the master to a file. */
    sprintf(filename, "%s.%04d.log", argv[0], par_rank);
    if((fp = fopen(filename, "wt")) != NULL)
    {
        fprintf(fp, "Running %s with %d processors.\n", argv[0], par_size);
        fprintf(fp, "This is the log for processor %d.\n", par_rank);
        fprintf(fp, "Message: \"%s\"\n", msgbuf);
        fclose(fp);
    }
 
    /* Finalize MPI */
    MPI_Finalize();
 
    return 0;
}

The above hello world program runs on several processors and processor 0 will broadcast a message to all of the other processors, which then write the message to their log files. To compile the example program, you can use a command line similar to this:

gcc -o mpihello mpihello.c -D_REENTRANT -I/Users/whitlocb/i386-apple-darwin8.8.1/include \
-L/Users/whitlocb/i386-apple-darwin8.8.1/lib -Wl,-undefined,dynamic_lookup -Wl,-u,_munmap \
-Wl,-multiply_defined,suppress -lmpi_cxx -lmpi -lopen-rte -lopen-pal

Or, better yet, you can use mpic++ to compile your program:

mpic++ -o mpihello mpihello.C

If the example program runs, you will have output like the following:

[dantooine:~/play/mpihello] whitlocb% mpirun -n 4 mpihello
[dantooine:~/play/mpihello] whitlocb% cat *.log
Running mpihello with 4 processors.
This is the log for processor 0.
Message: "HELLO FROM THE MASTER PROCESS!"
Running mpihello with 4 processors.
This is the log for processor 1.
Message: "HELLO FROM THE MASTER PROCESS!"
Running mpihello with 4 processors.
This is the log for processor 2.
Message: "HELLO FROM THE MASTER PROCESS!"
Running mpihello with 4 processors.
This is the log for processor 3.
Message: "HELLO FROM THE MASTER PROCESS!"

Once you are satisfied that MPI works on your system, be sure to put mpirun in your path so VisIt will be able to find it later. You add items to your path typically by editing your shell program's rc file. This is typically one of the following: ~/.cshrc, ~/.bashrc, ~/.tcshrc.

[edit] The host.cmake file

The build_visit script creates a host.cmake file where host is replaced with the name of your computer. The host.cmake file contains various variable definitions that will be inputs to VisIt's cmake build system. We recommend setting the VISIT_MPI_COMPILER variable so it contains the path to your mpic++ compiler. This will enable the build system to discover all of the relevant flags that are needed for parallel compilation. Add the following to your host.conf file, which you'll need to place in the src/config-site directory within VisIt's source tree.


##
## Add parallel arguments.
##
VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON)
VISIT_OPTION_DEFAULT(VISIT_MPI_COMPILER /usr/bin/mpic++)

The above code came from the src/config-site/dantooine.llnl.gov.cmake file, which is the host.cmake file for an 8-core Mac running MacOS 10.6.3. If you have questions about editing the host.cmake file, first look at the dantooine cmake file.

[edit] Building VisIt

Now that you've changed your host.cmake file, you can build parallel VisIt with the following commands:

cd src
cmake -DCMAKE_BUILD_TYPE:STRING=Release .
make -j 4

[edit] Running VisIt

Now that MPI is up and running, just run: visit -np 4 to run in parallel with 4 processors.

Personal tools