Appendix A

Example MPI code

 

 

 

 

A-1 Programs in the ScaMPItst package

The ScaMPItst package is installed together with installation of Scali MPI Connect. The package contains a number of programs in /opt/scali/examples with executable code in bin/ and source code in src/. A description of the programs can be found in the README file, located in the /opt/scali/doc/ScaMPItst directory. These programs can be used to experiement with the features of Scali MPI Connect.

A-2 Image contrast enhancement

*

*Adopted from "MPI Tutorial", by Puri Bangalore, Anthony Skjellum and

*Shane Herbert, High Performance Computing Lab, Dept. of Computer Science

*and NSF Engineering Research Center, Mississippi State University,

*Feb 2000

*/

#include <mpi.h> #include <stdio.h> #include <math.h>

int main( int argc, char** argv )

{

int width, height, rank, size, sum, my_sum; int numpixels, my_count, i, val;

unsigned char pixels[65536], recvbuf[65536]; unsigned int buffer;

double rms; FILE *infile; FILE *outfile; char line[80];

MPI_Init( &argc, &argv );

MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); if ( rank == 0 )

{

/* assume valid file name in argv[1] */ infile = fopen( argv[1], "r" );

if ( ! infile )

{

printf("%s :: can't open file\n", argv[1]); MPI_Finalize();

exit(-1);

}

/* valid file available */ fscanf( infile, "%s", line ); fscanf( infile, "%d", &height ); fscanf( infile, "%d", &width ); fscanf( infile, "%u", &buffer ); numpixels = width * height;

Scali MPI Connect Release 4.4 Users Guide

51

Page 63
Image 63
Escali 4.4 manual Appendix a, Programs in the ScaMPItst package, Image contrast enhancement