On 19:31 Tue 08 Jan     , Dino Rossegger wrote:
> Hi,
> thanks for the programm, but sadly I can't get it work :(.
> It's the same error as in my programm. I get the following output:
> 0
> 0
> 0
> 10
> 0
> 0
> 11
> 0
> 0
> 
> Which as far as I know can't be correct. 

Oh, my bad. The field pointers had to be corrected for the Gather.
Now the output looks like this:

0
500
1000
10
510
1010
11
511
1011

Is this what you did expect?

BTW: of course you can send multidimensional arrays with scatter and
gather. This is because they're really just one-dimensional in
memory. 

Cheers
-Andreas


-- 
============================================
Andreas Schäfer
Cluster and Metacomputing Working Group
Friedrich-Schiller-Universität Jena, Germany
PGP/GPG key via keyserver
I'm a bright... http://www.the-brights.net
============================================

(\___/)
(+'.'+)
(")_(")
This is Bunny. Copy and paste Bunny into your 
signature to help him gain world domination!
#include <iostream>
#include <mpi.h>

const int ARRAYSIZE = 150;

int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);
    int rank, anzprocs, recvcount, sendcnt;
    MPI_Comm_size(MPI_COMM_WORLD, &anzprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    
    const int WORKING = ARRAYSIZE/anzprocs;

    double stat[ARRAYSIZE][2];
    double stathlp[WORKING][2];
    
    if (rank == 0)
        for (int i = 0; i < ARRAYSIZE; ++i)
            for (int j = 0; j < 2; ++j)
                stat[i][j] = i * 10 + j;

    double stat2[WORKING][5];
    double stat3[anzprocs][WORKING][5];
    if (rank==0) 
        sendcnt=WORKING*2;

    MPI::COMM_WORLD.Scatter(
        stat, 
        sendcnt, 
        MPI::DOUBLE, 
        stathlp, 
        WORKING*2, 
        MPI::DOUBLE, 
        0);

    for(int i=0; i < WORKING; i++){
        stat2[i][0] = stathlp[i][0];
        stat2[i][1] = stathlp[i][1];
        stat2[i][2] = (stat2[i][0]*stat2[i][1]);
        stat2[i][3] = (stat2[i][0]*stat2[i][0]);
        stat2[i][4] = (stat2[i][1]*stat2[i][1]);
    }
    
    if (rank==0) 
        recvcount=WORKING*5;

    MPI_Gather(
        stat2, 
        WORKING*5, 
        MPI_DOUBLE,
        stat3, 
        recvcount,
        MPI_DOUBLE,
        0, 
        MPI_COMM_WORLD);
        
    if (rank==0){
        std::cout << stat3[0][0][0] << std::endl;
        std::cout << stat3[1][0][0] << std::endl;
        std::cout << stat3[2][0][0] << std::endl;

        std::cout << stat3[0][1][0] << std::endl;
        std::cout << stat3[1][1][0] << std::endl;
        std::cout << stat3[2][1][0] << std::endl;

        std::cout << stat3[0][1][1] << std::endl;
        std::cout << stat3[1][1][1] << std::endl;
        std::cout << stat3[2][1][1] << std::endl;
    }
    MPI_Finalize();
 }

Attachment: pgpqCyynmh9De.pgp
Description: PGP signature

Reply via email to