Добавил:
ivanov666
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Распараллеливание программ. Учебник
.pdf
171
int MPI_Issend(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Ibsend(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Irsend(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Irecv(void* buf, int count, MPI_Datatype datatype,
int source, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Iprobe(int source, int tag, MPI_Comm comm,
int *flag, MPI_Status *status)
flag
status
int MPI_Test(MPI_Request *request, int *flag,
MPI_Status *status)
flag

172
int MPI_Wait(MPI_Request *request, MPI_Status *status)
request
int MPI_Testany(int count, MPI_Request *array_of_requests,
int *index, int *flag,
MPI_Status *status)
array_of_request
flagindex
array_of_requeststatus
int MPI_Waitany(int count, MPI_Request *array_of_requests,
int *index, MPI_Status *status)
array_of_requests
int MPI_Testall(int count,
MPI_Request *array_of_requests, int *flag,
MPI_Status *array_of_statuses)
все
array_of_requestscount flag
array_of_statuses
int MPI_Waitall(int count, MPI_Request *array_of_requests,
MPI_Status *array_of_statuses)
int MPI_Testsome(int incount,
MPI_Request *array_of_requests, int *outcount,
int *array_of_indices, MPI_Status *array_of_statuses)

173
array_of_requests incount
outcountarray_of_
indicesarray_of_statuses
int MPI_Waitsome(int incount,
MPI_Request *array_of_requests, int *outcount,
int *array_of_indices, MPI_Status *array_of_statuses)
outcountarray_of_
indicesarray_of_statuses
int MPI_Test_cancelled(MPI_Status *status, int *flag)
MPI_CANCEL
int MPI_Cancel(MPI_Request *request)
INIT → (START)* → FREE
MPI_START MPI_
STARTALL
MPI_TEST/MPI_WAIT
MPI_STARTMPI_STARTALL
int MPI_Send_init(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)

174
int MPI_Ssend_init(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Bsend_init(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Rsend_init(void* buf, int count,
MPI_Datatype datatype, int dest, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Recv_init(void* buf, int count,
MPI_Datatype datatype, int source, int tag,
MPI_Comm comm, MPI_Request *request)
int MPI_Start(MPI_Request *request)
int MPI_Startall(int count,
MPI_Request *array_of_requests)

175
π
#include «mpi.h»
#include <stdio.h>
#include <math.h>
int main( int argc, char *argv[] ) {
int n, myid, numprocs, i;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
while (1) {
if (myid == 0) {
printf(“Количество интервалов: (0 выход) “);
scanf(«%d»,&n);
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (n == 0)
break;
else {
h = 1.0 / (double) n;
sum = 0.0;
for (i = myid + 1; i <= n; i += numprocs) {
x = h * ((double)i - 0.5);
sum += (4.0 / (1.0 + x*x));
}
mypi = h * sum;
MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0,
MPI_COMM_WORLD);
if (myid == 0)
printf(«pi %.16f, Ошибка %.16f\n»,
pi, fabs(pi - PI25DT));
}
}
MPI_Finalize();
return 0;
}
Коллективные взаимодействия

176
int MPI_Barrier(MPI_Comm comm)
comm
int MPI_Bcast(void* buffer, int count,
MPI_Datatype datatype, int root,
MPI_Comm comm)
root
comm
bufferroot
buffer
int MPI_Gather(void* sendbuf, int sendcount,
MPI_Datatype sendtype,
void* recvbuf, int recvcount, MPI_Datatype recvtype,
int root, MPI_Comm comm)
root
sendbufroot
recvbufrecvbuf
root
int MPI_Gatherv(void* sendbuf, int sendcount,
MPI_Datatype sendtype,
void* recvbuf, int *recvcounts, int *displs,

177
MPI_Datatype recvtype, int root,
MPI_Comm comm)
MPI_Gather
rooti
recvbufdispls[i]
int MPI_Allgather(void* sendbuf, int sendcount,
MPI_Datatype sendtype,
void* recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)
MPI_Gather
int MPI_Allgatherv(void* sendbuf, int sendcount,
MPI_Datatype sendtype,
void* recvbuf, int *recvcounts, int *displs,
MPI_Datatype recvtype, MPI_Comm comm)
MPI_Gatherv
int MPI_Scatter(void* sendbuf, int sendcount,
MPI_Datatype sendtype,
void* recvbuf, int recvcount, MPI_Datatype recvtype,
int root, MPI_Comm comm)
root
comm
int MPI_Scatterv(void* sendbuf, int *sendcounts,
int *displs, MPI_Datatype sendtype,
void* recvbuf, int recvcount, MPI_Datatype recvtype,
int root, MPI_Comm comm)
int MPI_Alltoall(void* sendbuf, int sendcount,
MPI_Datatype sendtype,

178
void* recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)
jij
i
int MPI_Alltoallv(void* sendbuf, int *sendcounts,
int *sdispls, MPI_Datatype sendtype,
void* recvbuf, int *recvcounts, int *rdispls,
MPI_Datatype recvtype, MPI_Comm comm)
MPI_Alltoall
sdisplsrdispls
int MPI_Reduce(void* sendbuf, void* recvbuf,
int count, MPI_Datatype datatype, MPI_Op op,
int root, MPI_Comm comm)
sendbuf
op
recvbufroot
int MPI_Allreduce(void* sendbuf, void* recvbuf,
int count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm)
MPI_REDUCErecvbuf
int MPI_Reduce_scatter(void* sendbuf, void* recvbuf,
int *recvcounts, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm)

179
sendbuf
recvcounts[i]
int MPI_Scan(void* sendbuf, void* recvbuf,
int count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm)
sendbuf
countrecvbufk
sendbufk
Константа Смысл
MPI_MAX
MPI_MIN
MPI_SUM
MPI_PROD
MPI_LAND
MPI_BAND
MPI_LOR
MPI_BOR
MPI_LXOR
MPI_BXOR
MPI_MAXLOC
MPI_MINLOC
Максимум
Минимум
Сумма
Произведение
Логическое И
Побитовое И
Логическое ИЛИ
Побитовое ИЛИ
Логическое XOR
Побитовое XOR
Позиция максимума
Позиция минимума
int MPI_Op_create(MPI_User_function *function,
int commute, MPI_Op *op)
ALLREDUCE
MPI_REDUCE_SCATTERMPI_SCAN
MPI_REDUCE MPI_
commute

180
commute
typedef void MPI_User_function(void *invec,
void *inoutvec, int *len,
MPI_Datatype *datatype);
invec len datatype
inoutvec
int MPI_op_free( MPI_Op *op)
NULL
MPI_OP_
Коммуникаторы
int MPI_Group_size(MPI_Group group, int *size)
int MPI_Group_rank(MPI_Group group, int *rank)
MPI_UNDEFINED
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]
