Chapter 5
P2P
1. P2P
개요
- Message Passing의 가장 단순한 형태
- 한 프로세스가 다른 프로세스로 데이터 전달
- synchronous send / buffered (asynchronous send)
2. blocking communications
개요
- 다른 process가 동작할 때 까지 send/receive 함수가 코드 진행을 멈춤
- 송신 도중에 다른 작업 불가
종류
- synchronous send: receive 호출까지 멈춤
- receive : 메세지 전달이 완료될 때 까지 멈춤
- Blocking Subroutine: operation이 완료될 때에만 호출한 위치로 return
Blocking Send(standard)

MPI_Send(buf, count, datatype, dest, tag, comm)
Blocking Receive(standard)


MPI_Recv(buf, count, datatype, dest, comm, status)
MPI_Get_count(status, datatype, count)
3. non-blocking communications
개요

- 호출 즉시 return
- 현실 세계의 fax와 유사함
4. Communication Mode
MPI call routine

- non-blocking 함수는 "I"가 추가됨
- Standard mode는 send buffer의 크기에 따라 mode를 자동 결정
Precautions for Succesful Communication
- receiver, sender가 서로의 rank를 정확히 알고 있을 것
- 같은 communicator 내에 있을 것
- receiver가 충분한 buffer size를 가져야 함
5.NULL Processes
개요
- 많은 경우, 통신을 위해 'dummy' source 혹은 'dummy' destination을 지정하는 것이 편리
- send-recv 호출에서 non-circular shift의 경우에서 경계를 취급하는 데 필요한 코드를 간단히 해줌
MPI_PROC_NULL
MPI_PROC_NULL
은 source 혹은 destination argument가 필요할 때 rank 대신 사용
MPI_PROC_NULL
를 가진 통신은 아무런 효과가 없음
Example

inext=myrank+1;
if (myrank==3) inext=MPI_PROC_NULL;
MPI_Send(..., inext, ...);
- non-circular shift case
- 3번에서 송신되는 통신은
MPI_PROC_NULL
로 지정
Non-blocking's completion
1. Non-blocking Communication
과정
- 초기화: Posting send or recv -> 바로 호출한 위치로 return (다른 작업 수행 가능)
- 통신 과정: LAN 등에서 통신을 하는 동안 CPU 에서는 다른 작업을 할 수 있음 (중첩)
- 통신 확인: Waiting/Testing
효과
- dead-lock free code를 작성하기 쉬워짐
- communication overhead 감소 (병렬 작업)
2. Functions
Non-blocking send
MPI_Isend(buf, cound, datatype, dest, tag, comm, request)
- request는 통신 확인 시 필요한 인자
Non-blocking receive

MPI_Irecv(buf, cound, datatype, source, tag, comm, request)
MPI_Recv()
의 status 인자 대신 request 사용
3. Waiting / Testing
Waiting
MPI_Wait(request, status);
- 통신 완료까지 process를 blocking
- Non-blocking Comm + waiting = Blocking Comm
Testing
MPI_Test(request, flag, status);
- 통신 완료 여부를 true or false로 return
- flag: 통신 완료 여부를 알려주는 boolean
WaitAll
MPI_Waitall(count, array_of_requests[], array_of_statuses[]);
- List에 있는 모든 완료되지 않은 연산이 완료될 때까지 대기함
4. MPI_Status
MPI_Status
- MPI_Status를 return 하는 함수는 매우 많음
ex. non-blocking 함수는 모두 status return
- 코드 개발 단계를 제외하고 status를 조사할 일은 거의 없음
- status에 값을 채워넣을 필요가 없을 때,
MPI_STATUS_IGNORE
, MPI_STATUSES_IGNORE
사용