2017-05-02 3 views
1

이 사람이 내 코드에서 다음 오류를 찾는 데 도움이 될 수 있어야합니다 :MPI_Send (109) : 잘못된 순위 값을 가지고 -2 만 부가 아닌 미만 1

"치명적인 오류 MPI_Send에서을 : 잘못된 순위를, 오류 스택 : MPI_Send (190) : 잘못된 순위는 값이 -2이지만 음수가 아니고 더 적어야합니다 () : MPI_Send (buf = 0x1123060, 개수 = 40, MPI_FLOAT, dest = MPI_ANY_SOURCE, tag = 25, MPI_COMM_WORLD) MPI_Send

int main(int argc, char* argv[]) 
{ 
    name = "quick.dat"; 
    n = 40; 
    auto start = std::chrono::high_resolution_clock::now(); 

    int i; 
    double sp; 
    double *ap, *ae, *aw, *aww, *cte; 
    ap = new double[n]; 
    ae = new double[n]; 
    aw = new double[n]; 
    aww = new double[n]; 
    cte = new double[n]; 

    int my_rank, nproc; 
    MPI_Status status; 
    MPI_Init(&argc, &argv); 
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); 
    MPI_Comm_size(MPI_COMM_WORLD, &nproc); 

    if (my_rank == 0) 
    { 
     MPI_Send(&ap[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD); 
     MPI_Send(&ae[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD); 
     MPI_Send(&aw[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD); 
     MPI_Send(&aww[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD); 
     MPI_Send(&cte[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD); 
     for (i = 0; i < (n - 1)/nproc + 1; i++) 
     { 
      if (i == 0) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         1./3.0 * a(i * 1.0/n) * D(i * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = -(8./3. * a(i * 1.0/n) * D(i * 1.0/n) + 
          2.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) + 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       ap[i] = -(ae[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         7./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = 0.25 * a(i * 1.0/n) * u(i * 1.0/n); 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(ae[i] + aw[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == n - 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         1./3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         6.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       sp = 8.0/3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
        a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(aww[i] + aw[i] + sp + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i != 0 && i != 1 && i != n - 1) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         6./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       ap[i] = -(aww[i] + aw[i] + ae[i] - cte[i] + 
          a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
      } 
     } 
     MPI_Recv(&ap[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&ae[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aw[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aww[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&cte[0], n, MPI_FLOAT, MPI_ANY_SOURCE, 25, MPI_COMM_WORLD, &status); 
    } 

    else if (my_rank != 0 && my_rank != nproc - 1) 
    { 
     MPI_Recv(&ap[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&ae[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aw[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aww[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&cte[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     for (i = ((n - 1)/nproc) * my_rank + 1; i < ((n - 1)/nproc) * (my_rank + 1) + 1; i++) 
     { 
      if (i == 0) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         1./3.0 * a(i * 1.0/n) * D(i * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = -(8./3. * a(i * 1.0/n) * D(i * 1.0/n) + 
          2.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) + 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       ap[i] = -(ae[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         7./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = 0.25 * a(i * 1.0/n) * u(i * 1.0/n); 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(ae[i] + aw[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == n - 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         1./3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         6.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       sp = 8.0/3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
        a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(aww[i] + aw[i] + sp + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i != 0 && i != 1 && i != n - 1) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         6./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       ap[i] = -(aww[i] + aw[i] + ae[i] - cte[i] + 
          a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
      } 
     } 
     MPI_Send(&ap[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD); 
     MPI_Send(&ae[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD); 
     MPI_Send(&aw[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD); 
     MPI_Send(&aww[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD); 
     MPI_Send(&cte[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD); 
    } 
    else if (my_rank == nproc - 1 && nproc != 1) 
    { 
     MPI_Recv(&ap[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&ae[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aw[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&aww[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     MPI_Recv(&cte[0], n, MPI_FLOAT, 0, 25, MPI_COMM_WORLD, &status); 
     for (i = ((n - 1)/nproc) * my_rank + 1; i < n; i++) 
     { 

      if (i == 0) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         1./3.0 * a(i * 1.0/n) * D(i * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = -(8./3. * a(i * 1.0/n) * D(i * 1.0/n) + 
          2.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) + 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       ap[i] = -(ae[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         7./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       cte[i] = 0.25 * a(i * 1.0/n) * u(i * 1.0/n); 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(ae[i] + aw[i] - cte[i] + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i == n - 1) 
      { 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         1./3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) + 
         6.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       sp = 8.0/3.0 * a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
        a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       ap[i] = -(aww[i] + aw[i] + sp + a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
       continue; 
      } 
      if (i != 0 && i != 1 && i != n - 1) 
      { 
       ae[i] = a((i + 1) * 1.0/n) * D((i + 1) * 1.0/n) - 
         3.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aw[i] = a(i * 1.0/n) * D(i * 1.0/n) + 
         6./8. * a(i * 1.0/n) * u(i * 1.0/n) + 
         1.0/8.0 * a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n); 
       aww[i] = -1.0/8.0 * a(i * 1.0/n) * u(i * 1.0/n); 
       cte[i] = 0; 
       ap[i] = -(aww[i] + aw[i] + ae[i] - cte[i] + 
          a((i + 1) * 1.0/n) * u((i + 1) * 1.0/n) - 
          a(i * 1.0/n) * u(i * 1.0/n)); 
      } 
     } 
     MPI_Send(&ap[0], n, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD); 
     MPI_Send(&ae[0], n, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD); 
     MPI_Send(&aw[0], n, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD); 
     MPI_Send(&aww[0], n, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD); 
     MPI_Send(&cte[0], n, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD); 
    } 

    // double t22 = MPI_Wtime(); 
    MPI_Finalize(); 

    // printf("[IJK] Compute time [s] : %6.3f \n", t22-t11); 

    iteration(aww, aw, ap, ae, cte); 

    auto end = std::chrono::high_resolution_clock::now(); 
    std::chrono::duration<double> diff = end - start; 
    std::cout << "Time to Execute the FVM code " 
       << " is : " << diff.count() << " s\n"; 

    return 0; 
} 
+0

답변은 귀하의 경우에 분명하지만 실제로 질문을 준비하는 데 더 많은 시간을 투자해야합니다. 질문과 코드를 올바르게 포맷하고, 적절한 태그를 선택하고, 가장 중요한 것은 [mcve]로 코드를 줄입니다. 코드와 오류를 버리는 습관에 빠지지 마십시오! – Zulan

답변

0

혼란 "1 이상 나이는 실제로 다소 명확합니다 : MPI_Send: Invalid rank. MPI_Send의 대상 순위로 MPI_ANY_SOURCE을 지정할 수 없습니다. 지점 간 통신에는 하나의 특정 수신기가 있어야합니다. 당신이 정확히 같은 모든 계급에서 실행해야

MPI_Send(&ap[0], n, MPI_FLOAT, 0, MPI_COMM_WORLD); 

: 예컨대, 집단 MPI_Bcast을 사용할 것으로 보인다.

+0

Zulan에게 도움을 주셔서 감사합니다. Zulan이 말한대로 2 개의 코어로 실행하는 데 다른 오류가 발생했습니다. MPI_Init : 내부 MPI 오류 !, 오류 스택 : MPIR_Init_thread (483) : MPID_Init (363) ....... : 채널 초기화에 실패했습니다. (알 수 없음)() : 내부 MPI 오류! " 아무도 그 문제가 뭔지 압니까? 나는 MPI 초보자입니다. –