Click here to Skip to main content
15,881,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C
#include <stdio.h>
#include <mpi.h>
#include 
#include <time.h>
#include <math.h>
#define size 1000
float a[size][size];
float sum[size];

void norm(int istart, int iend)
{
int i,j;
    for ( i = istart; i <= iend; ++i) {
        for (j = 0; j < size; ++j) {
           sum[i]=sum[i]+a[i][j];
        }
    }
}

int main(int argc, char* argv[])
{
    int rank, nproc,i,j;
    int istart, iend;
float t_1;
clock_t c_1,c_2;
c_1=time(NULL); // time measure: start mm
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == 0) {
        // Initialize buffers.
        for ( i = 0; i < size; ++i) {
            for (j = 0; j < size; ++j) {
                a[i][j] = (float)i + j;
            }
 sum[i]=0;
        }
    }
    MPI_Bcast(a, size*size, MPI_FLOAT, 0,MPI_COMM_WORLD);
    istart = (size / nproc) * rank;
    iend = (size / nproc) * (rank + 1) - 1;
    norm(istart, iend);
    MPI_Gather(sum+ (size/nproc*rank),
               size*size/nproc,
               MPI_FLOAT,
               sum + (size/nproc*rank),
               size*size/nproc,
               MPI_FLOAT,
               0,
               MPI_COMM_WORLD);

    if (rank == 0) {
        if (size % nproc > 0) {
            norm((size/nproc)*nproc, size-1);
        }
    }
    MPI_Finalize();
c_2=time(NULL); 
t_1 = (float)(c_2-c_1); 
printf("Execution time: %f \n",t_1);
    return 0;
}


What I have tried:

Fatal error in PMPI_Gather: Invalid buffer pointer, error stack:
PMPI_Gather(856): MPI_Gather(sbuf=0x6010a0, scount=1000000, MPI_FLOAT, rbuf=0x6010a0, rcount=1000000, MPI_FLOAT, root=0, MPI_COMM_WORLD) failed
PMPI_Gather(797): Buffers must not be aliased

it program to compute norm1 and infinite norm in mathmatical
it run ....
but when it get run show me this error
what means of this error
please help
Posted
Updated 28-Jun-16 21:00pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Jun-16 22:41pm    
Could you first format your code? Did you even look at it after you posted it? It starts with some "#include"...
This is just HTML...
—SA
Member 12606956 28-Jun-16 23:46pm    
Sorry ...be relax... sure i see it before...
If you mean #include without anything ... i know the librarys ...when i post the code ... hide the library ... but it exect in orginal code

1 solution

The error
Quote:
Buffers must not be aliased
tells you that you have used the same buffer for sending and receiving which is not allowed when the receive buffer must be supplied. You must use separate buffers or the MPI_IN_PLACE option.

See also MPI_Gather(3) man page (version 1.8.8)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900