Hi Dino,

On 18:05 Tue 08 Jan     , Dino Rossegger wrote:
> In fact it is initialized, as I stated in my first mail I only left out 
> the code where it gets initialized, since it reads the data from a file 
> and that works (I have tested it).

(you should have provided a self contained excerpt)

I have reworked your program to check what's running wrong. In fact it
seems to work as expected, although you might want to double check
your array sizes, they're named a bit confusingly.

Maybe it didn't work because there was no MPI_Finalize() at the
end. But then again I might not understand your problem. The other
machines do no output, so how can their output be wrong? If you expect
the other processors to have the same data in stat3 as rank 0 does,
then you should rather use MPI_Allgather than MPI_Gather, as
MPI_Gather will only concentrate the data on the root node, which is 0
in your case. Thus, the other nodes cannot produce the same output as
node 0.

I've attached my reworked version (including some initialization
code for clarity). If you want me again to debug a program of yours,
send a floppy along with a pizza Hawai (cartwheel size) to:

Andreas Schäfer
Cluster and Metacomputing Working Group
Friedrich-Schiller-Universität Jena
Ernst-Abbe-Platz 2
07743 Jena
Germany

Seriously, that would be cool :P

HTH
-Andi


-- 
============================================
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][ARRAYSIZE][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: pgpCWR31YicVT.pgp
Description: PGP signature

Reply via email to