MPI関数の説明と例
MPI
(1) :int MPI_Init(int *argc,char ***argv)
:argc ,argv , main
(2) : int MPI_Finalize()
:hello.c
#include "./mpich2/include/mpi.h"
#include <stdio.h>
int main(int argc,char **argv){
MPI_Init(&argc,&argv);//
printf("hello parallel world!
");
MPI_Finalize();
}
(3) :int MPI_Comm_rank(MPI_Comm comm,int *rank)
:comm ,rank
(4) :int MPI_Comm_size(MPI_Comm comm,int *size)
:comm ,size comm
(5) :int MPI_Get_processor_name(char *name,int *resultlen)
:name ,resultlen
:who.c
#include "./mpich2/include/mpi.h"
#include <stdio.h>
int main(int argc,char **argv)
{
int myid,numprocs;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);// ID
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);//
MPI_Get_processor_name(processor_name,&namelen);//
printf("hello World!Process %d of %d on %s
",myid,numprocs,processor_name);
MPI_Finalize();
}
(6) :int MPI_Send(void *buf,int count,MPI_Datatype datatype,int dest,int tag,MPI_Comm comm)
:buf ,count ( ),datatype ,dest ,tag ,comm
MPI_Send() buf count datatype dest , tag
(7) :int MPI_Recv(void *buf,int count,MPI_Datatype datatype,int source,int tag,MPI_Comm,MPI_Status *status)
:buf ,count ,datatype ,source ,tag , ,comm ,status
:message.c
#include <stdio.h>
#include <string.h>
#include "./mpich2/include/mpi.h"
int main(int argc,char **argv)
{
int myid,numprocs,source;
MPI_Status status;
char message[100];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
if(myid != 0)
{
strcpy(message,"Hello World!");//
// 1,
MPI_Send(message,strlen(message)+1,MPI_CHAR,0,99,MPI_COMM_WORLD);
}
else
{
// 0 0
for(source = 1;source < numprocs;source++)
{
MPI_Recv(message,100,MPI_CHAR,source,99,MPI_COMM_WORLD,&status);
printf("I am process %d.I receive string '%s' from process %d.
",myid,message,source);
}
}
MPI_Finalize();
}
:MPI C
MPI
C
MPI_CHAR
Signed char
MPI_SHORT
Signed short int
MPI_INT
Signed int
MPI_LONG
Signed long int
MPI_UNSIGNED_CHAR
Unsigned char
MPI_UNSIGNED_SHORT
Unsigned short int
MPI_UNSIGNED
Unsigned int
MPI_UNSIGNED_LONG
Unsigned long int
MPI_FLOAT
Float
MPI_DOUBLE
Double
MPI_LONG_DOUBLE
Long double
MPI_BYTE
MPI_PACKED
MPI_LONG_LONG_INT
Long long int