>

Title: COMP309/509 - Lecture 23

COMP309/509 - Parallel and Distributed Computing

Lecture 23 - Advanced MPI

By Mitchell Welch

###University of New England

Reading


Summary


Collective Communication


Collective Communication


Collective Communication


int MPI_Allreduce(void *sndbuf, void *rcvbuf, int count, MPI_Datatype datatyp, MPI_Op op, MPI_Comm comm );

Collective Communication


Collective Communication

int MPI_Allgather(void *sndbuf,  
    int sndcnt, 
    MPI_Datatype sndtyp, 
    void *rcvbuf,  
    int rcvcnt, 
    MPI_Datatype rcvtyp, 
    MPI_Comm comm
);

Collective Communication


I/O On The Cluster


I/O On The Cluster


I/O On The Cluster



#include <stdio.h> #include <unistd.h> #include <limits.h> #include "mpi.h" #define VERBOSE 0 int get_io_clone(){ int *iop, iorank, flag; MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_IO, &iop, &flag); if(!flag){ if(VERBOSE)fprintf(stderr, "MPI_Attr_get failed, exiting\n"); return -1; } if(*iop == MPI_PROC_NULL){ if(VERBOSE)fprintf(stderr, "No one can do IO!\n"); return -1; } if(*iop == MPI_ANY_SOURCE){ if(VERBOSE)fprintf(stderr, "Anyone can do IO!\n"); return 0; } MPI_Allreduce(iop, &iorank, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD); return iorank; }

I/O On The Cluster


Derived Datatypes

float a; //start of interval
float b; //end of interval
int n;   //number of trapezoids


Derived Datatypes

typedef struct {
  float a;
  float b;
  int   n;
} ParTrapData;
printf("Enter a, b, and n\n");  
scanf("%f %f %d", a_ptr, b_ptr, n_ptr);
ParTrapData  ptd = { *a_ptr, *b_ptr, *n_ptr };
MPI_Bcast(&ptd, 1, ParTrapData, 0, MPI_COMM_WORLD);

Derived Datatypes


Derived Datatypes


Derived Datatypes

#include "mpi.h"
int MPI_Type_create_struct(int count, 
                    int blocklens[], 
               MPI_Aint indices[], 
           MPI_Datatype old_types[], 
           MPI_Datatype *newtype )

Derived Datatypes

MPI_Datatype mpi_ptdatatype;

int count = 3;
MPI_Aint blocks[count]  = {1, 1, 1};
MPI_Aint indices[count];
MPI_Datatype old_types[count] = {MPI_Float, MPI_Float, MPI_Int};
printf("Enter a, b, and n\n");  
scanf("%f %f %d", a_ptr, b_ptr, n_ptr);
ParTrapData  ptd = { *a_ptr, *b_ptr, *n_ptr };

Derived Datatypes

MPI_Aint addresses[count + 1];
MPI_Get_address(&ptd, &addresses[0]);
MPI_Get_address(&(ptd.a) , &addresses[1]);
MPI_Get_address(&(ptd.b) , &addresses[2]);
MPI_Get_address(&(ptd.n) , &addresses[3]);
indices[0] = addresses[1] - addresses[0];
indices[1] = addresses[2] - addresses[0]; 
indices[2] = addresses[3] - addresses[0];
MPI_Type_create_struct(count, blocks, indices, old_types, &mpi_ptdatatype);

Derived Datatypes

#include "mpi.h"
int MPI_Type_commit(MPI_Datatype *datatype);

Derived Datatypes


Derived Datatypes


Derived Datatypes

#define BUFF 100
char buff[BUFF]
int position = 0;

MPI_Pack(a_ptr, 1, MPI_FLOAT, buff, BUFF, &position, MPI_COMM_WORLD);
MPI_Pack(b_ptr, 1, MPI_FLOAT, buff, BUFF, &position, MPI_COMM_WORLD);
MPI_Pack(n_ptr, 1, MPI_INT, buff, BUFF, &position, MPI_COMM_WORLD);

MPI_Bcast(buffer, BUFF, MPI_PACKED, root, MPI_COMM_WORLD);
MPI_Unpack(buff, BUFF, &position, a_ptr, 1, MPI_FLOAT,  MPI_COMM_WORLD);
MPI_Unpack(buff, BUFF, &position, b_ptr, 1, MPI_FLOAT,  MPI_COMM_WORLD);
MPI_Unpack(buff, BUFF, &position,n_ptr, 1, MPI_INT,  MPI_COMM_WORLD);

Derived Datatypes

Review:


Summary


Questions?


Reading