2011-07-27 5 views
2

내부에서 작업하지 : 그것은 내가MPI_Barrier 내가 작동하고 MPI_Barrier와 이상한 결과를 가지고 방법을 이해하기 위해 MPI 기능에 대한 몇 가지 테스트를 실행 한 루프

int main(int argc, char *argv[]) 
{ 
    <some code> 
    MPI_Barrier(MPI_COMM_WORLD); 
    <more code> 
    MPI_Barrier(MPI_COMM_WORLD); 
    <...> 
} 
같은 코드에서 사용하는 경우 모든 사람들이 무엇을 기대하지

하지만 루프 내부에서 호출 할 때 임의의 결과가 표시됩니다.

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

int main(int argc, char *argv[]) 
{ 
    int i, rb, rank, nprocs; 

    MPI_Init(&argc,&argv); 
    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 

    i=0; 
    while(i<5) 
    { 
    rb=MPI_Barrier(MPI_COMM_WORLD); 
    printf("Itartion %d. I am %d of %d. MPIBarrierRes: %d\n", i, rank, nprocs, rb); 
    i++; 
    } 
    MPI_Finalize(); 
    return 0; 
} 

내가 3 작업을 실행할 때 무작위로 얻을 : 구체적으로, 나는 다음과 같은 테스트 코드를 가지고하는 것은

Itartion 0. I am 0 of 3. MPIBarrierRes: 0 
Itartion 0. I am 2 of 3. MPIBarrierRes: 0 
Itartion 0. I am 1 of 3. MPIBarrierRes: 0 
Itartion 1. I am 0 of 3. MPIBarrierRes: 0 
Itartion 1. I am 1 of 3. MPIBarrierRes: 0 
Itartion 1. I am 2 of 3. MPIBarrierRes: 0 
Itartion 2. I am 0 of 3. MPIBarrierRes: 0 
Itartion 2. I am 1 of 3. MPIBarrierRes: 0 
Itartion 2. I am 2 of 3. MPIBarrierRes: 0 
Itartion 3. I am 0 of 3. MPIBarrierRes: 0 
Itartion 3. I am 1 of 3. MPIBarrierRes: 0 
Itartion 3. I am 2 of 3. MPIBarrierRes: 0 
Itartion 4. I am 0 of 3. MPIBarrierRes: 0 
Itartion 4. I am 1 of 3. MPIBarrierRes: 0 
Itartion 4. I am 2 of 3. MPIBarrierRes: 0 

내가 기대, 아니면 그냥 oposite된다 원하든 인 :

Itartion 0. I am 1 of 3. MPIBarrierRes: 0 
Itartion 0. I am 0 of 3. MPIBarrierRes: 0 
Itartion 1. I am 0 of 3. MPIBarrierRes: 0 
Itartion 0. I am 2 of 3. MPIBarrierRes: 0 
Itartion 1. I am 1 of 3. MPIBarrierRes: 0 
Itartion 2. I am 0 of 3. MPIBarrierRes: 0 
Itartion 1. I am 2 of 3. MPIBarrierRes: 0 
Itartion 2. I am 1 of 3. MPIBarrierRes: 0 
Itartion 3. I am 0 of 3. MPIBarrierRes: 0 
Itartion 2. I am 2 of 3. MPIBarrierRes: 0 
Itartion 3. I am 1 of 3. MPIBarrierRes: 0 
Itartion 4. I am 0 of 3. MPIBarrierRes: 0 
Itartion 3. I am 2 of 3. MPIBarrierRes: 0 
Itartion 4. I am 1 of 3. MPIBarrierRes: 0 
Itartion 4. I am 2 of 3. MPIBarrierRes: 0 
,369 같은
Itartion 0. I am 2 of 3. MPIBarrierRes: 0 
Itartion 1. I am 2 of 3. MPIBarrierRes: 0 
Itartion 2. I am 2 of 3. MPIBarrierRes: 0 
Itartion 3. I am 2 of 3. MPIBarrierRes: 0 
Itartion 4. I am 2 of 3. MPIBarrierRes: 0 
Itartion 0. I am 0 of 3. MPIBarrierRes: 0 
Itartion 1. I am 0 of 3. MPIBarrierRes: 0 
Itartion 2. I am 0 of 3. MPIBarrierRes: 0 
Itartion 3. I am 0 of 3. MPIBarrierRes: 0 
Itartion 4. I am 0 of 3. MPIBarrierRes: 0 
Itartion 0. I am 1 of 3. MPIBarrierRes: 0 
Itartion 1. I am 1 of 3. MPIBarrierRes: 0 
Itartion 2. I am 1 of 3. MPIBarrierRes: 0 
Itartion 3. I am 1 of 3. MPIBarrierRes: 0 
Itartion 4. I am 1 of 3. MPIBarrierRes: 0 

나 사이에 뭔가 ,

누군가 MPI_Barrier와 루프 사이에 충돌이 있는지 알려 줄 수 있습니까? (나는 다른 작업에서 다른 크기의 루프를 사용하여 교착 상태를 피하기위한 경고 만 찾았습니다.) 하나가 있다면 루프의 새 반복을 시작하기 전에 작업이 서로를 기다리게하려면 어떻게해야합니까? 없으면이 코드에 어떤 문제가 있습니까?

감사합니다.

+0

다른 MPI_Barrier를 printf 문 아래에 배치하고 문제가 지속되는지 확인할 수 있습니까? – FFox

답변

3

이것은 루프와는 아무런 관련이 없습니다. MPI가 의미하는 IO의 순차 화는 없습니다. 인쇄물이 순서대로 나올 필요가 있다면 명시 적으로 한 랭크로 보내야하고 모든 인쇄물을 인쇄해야합니다.

+0

감사합니다. 메시지가 전송되는 시점에 대한 정보를 추가했는데 순서가 여전히 임의 임에도 불구하고 어떻게 작동하는지 볼 수 있습니다. 나는 다음 시험을 위해 당신이 제안한 것을 시도 할 것입니다. – josh