#include "mpi.h"
#include <stdio.h>
#include <math.h>

int main(int argc, char **argv) {
    // Variables used per process
    int myid, numprocs;
    int myresult = 0;
    
    // Global variables
    int DATA_SIZE = argc;
    int data[DATA_SIZE], result;
    
    // Chunk control variables
    int i, low, high, size;
    
    //-------------------------------------------
    // INIT
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);

    //-------------------------------------------
    // PROCESS 0 GETS THE DATA
    if (myid == 0) {
        // Get data from args
        for (i = 0; i < argc; ++i) {
          data[i] = argv[i];
        }
    }

    // Distribute the Data
    MPI_Bcast(data, MAXSIZE, MPI_INT, 0, MPI_COMM_WORLD);
    
    //-------------------------------------------
    // EACH PROCESS COMPUTES ITS PART
    size = DATA_SIZE/numprocs;
    low = myid * size;
    high = low + size;
    for (i = low; i < high; ++i) {
        myresult += data[i];
    }
    //printf("I got %d from %d\n", myresult, myid);

    //-------------------------------------------
    // COMPUTE GLOBAL SUM
    MPI_Reduce(&myresult, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);

    //-------------------------------------------
    // PROCESS 0 PRINTS THE RESULT
    if (myid == 0) {
        printf("%d\n", result);
    }

    //-------------------------------------------
    // FINISH
    MPI_Finalize();
}
Add mpiCC source for MPI test
Add mpiCC source for MPI test

git-svn-id: 6cb0c57df7a4a7d32342646683f5f1b5f4d88845@2381 9ab3861e-6c05-4e1b-b5ef-99af60850597
