문제

PI를 10 만 명까지 계산하기 위해 Bellard 기능을 실행하는 MPI 프로그램을 만들려고합니다. 프로그램을 컴파일하면 다음 오류가 발생합니다.

오류 : 바이너리 +에 대한 잘못된 피연산자 ( 'float *'및 'float *')

터미널에서 가리키는 선은 다음과 같습니다. pi = pi+tmppi;

누구 든지이 오류를 해결하는 데 도움을 줄 수 있습니까?이 프로그램에 다른 잘못된 것을 발견하면 자유롭게 말씀해주십시오. 도움이 크게 감사하겠습니다.

내 코드 :

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <mpi/mpi.h>

#define PRECISION 10000


float minus_one,one,two,three,four,five,six,seven,eight,nine,ten,   
    thirty_two,sixty_four,two_five_six,one_zero_two_four,
    two_pow_six,recip_two_pow_six;


float *pi;
int rank,size;

void init(){
    minus_one = -1.0;
    one = 1.0;
    two = 2.0;
    three = 3.0;
    four = 4.0;
    five = 5.0;
    six = 6.0;
    seven = 7.0;
    eight = 8.0;
    nine = 9.0;
    ten = 10.0;
    thirty_two = 32.0;
    sixty_four = 64.0;
    two_five_six = 256.0;
    one_zero_two_four = 1024.0;
    two_pow_six = pow(two,6);
    recip_two_pow_six = one/two_pow_six;

    pi = 0;

    return;
}

float *bellard(int start, int end,int rank){
    float *terms,t,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,
        t13,t14,t15,t16,t17,tx,ty,tz;

    int offset = rank;
    int start_k = start, end_k = end;
    start_k = offset * (PRECISION /size);
    end_k = (offset+1) * (PRECISION/size);

    int k = start_k;

    while( (k<PRECISION) && (k<end_k)){
        t1 = k;
        t2 = t1*ten;
        t3 = t2+one;
        t4 = two_five_six/t3;
        t5 = t2+nine;
        t6 = one/t5;
        t7 = t2+three;
        t8 = sixty_four/t7;
        t9 = four*t1;
        t10 = t9+one;
        t11 = thirty_two/t10;
        t12 = t2+five;
        t13 = four/t12;
        t14 = t2+seven;
        t15 = four/t14;
        t16 = t9+three;
        t17 = one+t16;

        t = t4+t6;
        t = t-t8;
        t = t-t11;
        t = t-t13;
        t = t-t15;
        t = t-t17;

        tx = pow(minus_one,k);
        ty = pow(one_zero_two_four,k);
        tz = tx/ty;
        *terms = tz*t;

        //pi = pi+terms;
        k = k+1;
    }
        return terms;
}

int main(int argc, char** argv){


    int i;
    MPI_Status status;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    int elementsCount = 10000/(size-1);

    if(rank == 0){
        float *tmpPi;

        for(i=1; i < size; i++){
            MPI_Recv(tmpPi,elementsCount,MPI_FLOAT,i,1,MPI_COMM_WORLD,&status);
            pi=pi+tmpPi;
        }
    }else{

        //int i;
        float *workerPi;
        int start,end,slice,workers;
        workerPi = malloc(sizeof(int)*elementsCount);
        workers = size-1;
        slice = 10000/workers;
        start = (rank-1)*slice;
        end = start+slice;

        printf("Worker %d processing data %d to %d\n",rank,start,end);

        workerPi = bellard(start,end,rank);

        MPI_Send(workerPi,slice,MPI_FLOAT,0,1,MPI_COMM_WORLD);

    }

    MPI_Finalize();

    return 0;
}
도움이 되었습니까?

해결책

두 개의 포인터를 함께 추가하려고합니다.

대신에

float *pi;
float *tmpPi;
...
pi=pi+tmpPi;

노력하다:

float *pi;
float *tmpPi;
...
*pi = *pi + *tmpPi;

이것은 포인터를 피할 것입니다 pi 그리고 tmpPi, 값을 함께 추가 한 다음 결과를 pi.

다른 팁

PI와 TMPPI는 둘 다 포인터이므로 변경 사항입니다.

pi=pi+tmpPi;

안에:

*pi = *pi + *tmpPi;

pi 그리고 tmpPi 포인터이므로, 당신은 그들을 피해야합니다.

  *pi = *pi + *tmpPi
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top