Parallel Programming
on the Macintosh

Timothy H. Kaiser

University of New Mexico
High Performance Computing
Education and Research Center
Albuquerque Resource Center


Why am I here?
Why parallel program on the Macintosh?
What we have available?
Introduction to Tenon/Mach
Introduction to p4
Introduction to MPI
Porting issues under Mach
Running p4 and MPI under Mach
Running Macintosh native p4

Why am I here?

Ph.D. candidate in Computer Science
MS - EE (Applied Physics)
BS - physics
RA Albuquerque Resource Center
Dissertation topic: Parallelization strategies for adaptive grid programs
Operations Analysis Group
Applied Physics Group - large scale simulation
Macintosh Application development
Adaptive grid visualization
Portable yield estimation
Fourier analysis

Why parallel program on the Macintosh?

Pernode performance greater than SP1
100 x 100 matrix inversion 100 times
gcc -o invert -O3 invert.c
Low end PPC Macintosh = 12.93 seconds
SP1 node = 12 seconds
SP1 node = 9 seconds with IBM compiler
Good development tools
Symantec - Think C
Metrowerks - Code Warrior
F90 will be in beta test in December

What we have available

Message passing systems for distributed Macs
MPI - MPICH running under Tenon/Mach
P4 - also running under Tenon/Mach
P4 - subset running under native Macintosh OS
Do not have anything for the shared memory Macintosh

Overview of Tenon/Mach

A Unix application for the Mac
Most Unix utilities
C, Fortran77
X-window support (fast)
Mach application support for 68k Macs
Good performance for compiled programs
Hope to port Nag Fortran90 conpiler


Tenon at
Support for both PPC and 68k Macs
$695 for full package
About half price for universities


Missing Mach application support for PPC
Program startup slow
Man is very slow
Not 100% stable
Linker bugs
xdr routines are not complete

Overview of p4

Simple message passing system developed at Argonne
Small number of calls
Fortran and C
Generally available for Unix systems
Source available from:

Example p4 program

#include "p4.h"

double f(a)
double a;
    return (4.0 / (1.0 + a*a));

main(int argc, char ** argv)
	double h,sum,x,mypi;
	int ijk,type,from,size,myid,n,numprocs,jid;
    if(myid == 0){
        printf("enter the number of iterations: ");
        for (ijk=1;ijk<=numprocs-1;ijk++)
    else {
    h   = 1.0 / (double) n;
    sum = 0.0;
    for (ijk = myid + 1; ijk <= n; ijk += numprocs) {
        x = h * ((double)ijk - 0.5);
        sum += f(x);
    mypi = h * sum;
    if(myid == 0){
       for (ijk=1;ijk<=numprocs-1;ijk++){
       printf("pi = %g\n",mypi);
    else {

Overview of MPI

Extensive message passing system
Standard developed by Message Passing Interface Fourm
Fortran and C

We use MPICH version of MPI

Created at Argonne and Mississippi State
Source available at:
Compiles to p4
Can also compile to MPL for SP2

Example MPI program

#include "mpi.h"

double f(a)
double a;
    return (4.0 / (1.0 + a*a));

int main(argc,argv)
int argc;
char *argv[];
    int  n, myid, numprocs, i, rc;
    double mypi, pi, h, sum, x;

    if (myid == 0)
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    h   = 1.0 / (double) n;
    sum = 0.0;
    for (i = myid + 1; i <= n; i += numprocs){
        x = h * ((double)i - 0.5);
        sum += f(x);
    mypi = h * sum;
    MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
    if (myid == 0)
        printf("pi is approximately %.16f\n",pi);

Porting issues

Used MPICH 1.10 not 1.11
Minor changes to NeXT implementation
xdr_float.c is missing from Tenon Mach
Loader bug requires the MPI library be broken into sections

Changes to Makefiles and Source

remove top blank lines

/* extern char *sys_errlist[]; */

#define VPRINTF

/* #include  */
#if defined(solaris) || defined(HAVE_SYSINFO)
    sysinfo( SI_SRPC_DOMAIN,name+l,nlen-l);
    getdomainname( name+l, nlen - l );
    getdomainname( name+l, nlen - l );

Running p4 & MPICH under Mach

Write, compile, link program
Uses C or Fortran include files
Link with MPI or p4 library
Create process group file
Specifies which machines and programs to run
Run Program indicating process group file on command line
pi.exe -p4pg

Example p4 makefile

P4_HOME_DIR =/home/tkaiser/p4-1.4
LIBS = $(LIBDIR)/libp4.a $(MDEP_LIBS)
MDEP_LIBS = -lrpc /home/tkaiser/mpich/lib/NeXT/ch_p4/xdr_float.o

	$(CC) $(CFLAGS) -c $*.c 

bcast:$(P) bcast.o  $(LIBDIR)/libp4.a
	$(CLINKER) $(CFLAGS) -o bcast bcast.o  $(LIBS)

Example MPI makefile

SHELL       = /bin/sh
ARCH        = NeXT
COMM        = ch_p4
MPIR_HOME   = /home/tkaiser/mpich
CC          = cc
CLINKER     = cc
LIB_PATH    = -L$(MPIR_HOME)/lib/$(ARCH)/$(COMM)
LIB_LIST    = -lmpi -lrpc $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/*.o
MPILIB	  = $(MPIR_HOME)/lib/$(ARCH)/$(COMM)/libmpi.a 

cpi: cpi.o $(MPIR_HOME)/include/mpir.h $(MPILIB)
	$(CLINKER) $(OPTFLAGS) -o cpi cpi.o \
	$(LIB_PATH) $(LIB_LIST) -lm
	$(CC) $(CFLAGS) -c $*.c

Example p4pg file

local 0 1 /home/tkaiser/p4-1.4/contrib/bcast 1 /home/tkaiser/p4/SGI/bcast 1 /home/tkaiser/p4/RS6000/bcast

Why run native

Not tied to Unix
Better code development tools

Problems in running native

P4 and MPI not written for Mac
Convoluted with makefiles and setup scripts
Many #ifdefs
No Unix rsh
No Unix sockets
Very difficult time getting Mac native IPC to work

My work arounds for problems

Simulate rsh with Applescript
GUSI utilities simulate sockets
Written routines call compatable with original p4
Message passing routines
Have core routines written

How Unix starts p4 jobs

Get name of p4pg file from command line
Read p4pg file for full path name of application
Do rsh to each of the machines to launch jobs
Set up sockets

Overview of Applescript

Scripting mechanism for Macintosh
Syntax Similar to Hypertalk
Scripts can be compiled to applications
Purpose: automate tasks
Copy, move, launch files
Send commands to programs
AppleScript Extension
Finder Scripting Extension
System 7.5?

What p4_startup Applescript does

Open and read p4pg file
Full path name of each application
Macintosh machine name
FTP address
Copy p4pg file to preference folder of every machine
Launches application on every machine

Format of p4pg file

One line per application
No blanks in any names
Macintosh Name
Ftp name
Full pathname to application

Example Macintosh p4pg file

alice hd:pi.68k
ozark   pb520hd:pi.68k
osage   hd:pi.PPC

The p4_startup script

-- script to send a preference file and launch a remote job
set filespec to choose file with prompt "Select Process Group File"
set p5_file to (open for access filespec without write permission)
set mac_list to ""
set ftp_list to ""
set app_list to {}
set mlist to ""
set the_count to 0
set theline to "continue"
repeat while theline  ""
		set mac_name to " "
		repeat while mac_name = " "
			set mac_name to read p5_file until " "
		end repeat
		set ftp_name to " "
		repeat while ftp_name = " "
			set ftp_name to read p5_file until " "
		end repeat
		set app_name to read p5_file before return as string
		--display dialog app_name
		repeat while character 1 of app_name is " "
			set z to number of characters of app_name
			set app_name to subString(2, z, app_name)
		end repeat
		set mlist to mlist & mac_name & " " & ftp_name & " " & app_name & return
		if theline  "" then
			set the_count to the_count + 1
			set mac_list to mac_list & " " & mac_name
			set ftp_list to ftp_list & " " & ftp_name
			set app_list to app_list & app_name
		end if
	on error
		set theline to ""
	end try
end repeat

set launched to 0
repeat with i from 1 to the_count
	set machine_name to word i of mac_list
	set app_name to "" & item i of app_list
	set launched to launched + open_remote(machine_name, app_name, mlist)
end repeat
if launched  the_count then
	repeat with i from 1 to the_count - launched
	end repeat
end if

on open_remote(machine_name, app_path, machine_list)
	tell application "Finder" of machine machine_name
			set the_path to path to preferences folder as string
			set the_path to the_path & ""
			set p4_file to (open for access file the_path with write permission)
			set eof p4_file to 0
			write machine_list to p4_file
			close access p4_file
			open file app_path
			set worked to 1
		on error
			set worked to 0
		end try
	end tell
	return worked
end open_remote

on subString(x, y, theString)
	return (characters x thru y of theString) as string
end subString

GUSI overview

What: Grand Unified Socket Interface
Purpose: Provide simple and consistent interface to files, Appletalk, Native IPC, Internet, Printer
Access Protocal
Who: Matthias Neeracher ,
Where: sortware/mac/src/mpw_c
PowerMac & 68k
Metrowerks C, MPW
We use the Unix style sockets

What happens in Mac p4 application

Read preference file with ip names
Requires Ethernet connection and name server
Converts ip name to ip address
Assign process id
Create an array of sockets
Open sockets to each Macintosh application
Read & write sockets (blocking and nonblocking)

Supported p4 calls

p4_initenv(&argc,argv);                    Init p4
p4_create_procgroup();                     Init p4
p4_get_my_id();                            Get my id
p4_num_total_ids();                        Number of processors
p4_send(1,ijk,(char*)&n,sizeof(int));      Nonblocking send
p4_recv(&type,&from,(char**)&n,&size);     Blocking Receive
p4_wait_for_end();                         Termination   

Will support all message passing calls

Challenges in native p4 port using GUSI

No major problems, many headaches
No machines to use in testing
Out of order messages
Requires buffering of incoming messages
Check list of old messages before new
Send to self also requires buffering
Wild cards
Many different cases
Still has bugs

Creating p4 application with Metrowerks C

Create Project
Use precompiled headers:
Add Libraries
Write in C using supported p4 calls
Do for both 68k and PPC if needed
Move application to each machine
Create p4pg file
launch script p4_startup

Running the p4 application

Launch p4_startup script
Select p4pg file
Enter passwords
Let them run
For now, kill all jobs when finished

Future Plans

Finish native p4 Port
Do native Fortran port
Port native MPI
Port to Apple IPC
Port version 1.11 of MPICH
Fortran port

The Albuquerque Resource Center

© Copyright 1995, The Maui Project/UNM
Last Revised: November 10, 1995