ok so i am making a program that has a master slave process. the master sends out the 2-d array which is 1000 by 1000 to the slaves. then the slaves calculate the sums of the rows sends back to the master who sums it all up. then the time is displays with the total sum. my problem is that i get this warning when i use the make makefile : mast_slave.c(44): (col. 2) remark: LOOP WAS VECTORIZED.
/usr/intel10/lib/libimf.so: warning: warning: feupdateenv is not implemented and will always fail

i dont know what this means. here is my code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "mpi.h"

#define N 1000
#define M 1000

int main(int argc, char* argv[])
{
        int arr[N][M]; // 2-d array
        int myrank, numprocs, i, j;
        int master = 0;
        double start;
        double part_sum, tot_sum;
        double MPI_Wtime(void);
        MPI_Status status;

        MPI_Init(&argc,&argv);
        MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
        MPI_Comm_rank(MPI_COMM_WORLD,&myrank);// gets ranks

        srand(time(NULL));


        /* Master Process */
        if( myrank == 0)
        {
                for( i=0;i < N; i++)
                {       for( j = 0; j < M; j++)
                        {       arr[i][j] = rand();
                        }
                }
        }

        /* Master broadcasts to the slaves */

        MPI_Bcast( arr, N, MPI_DOUBLE,master, MPI_COMM_WORLD);

        part_sum =0;
        start = MPI_Wtime();

        for( i = 0; i <N; i++)
        {       for(j =0; j<M;j++)
                {
                        part_sum = part_sum + arr[i][j];
                }
        }

        printf("\n Sub sum was returned from %f\n", part_sum);

        /* Slave processess send the sum back to master */

        if( myrank !=0 )
        {
                MPI_Send( &part_sum, 1, MPI_DOUBLE, master, 1, MPI_COMM_WORLD);
        }
        else
        {
                tot_sum = part_sum;

                for( i = 1; i < numprocs;i++)
                {
                        MPI_Recv(&part_sum,1,MPI_DOUBLE,MPI_ANY_SOURCE,1,MPI_COMM_WORLD,&status);
                        tot_sum = tot_sum + part_sum;
                }
        }

        if( myrank ==0)
        {
                printf("Total sum is %f\n", tot_sum);
                printf("Time duration was %1.2f\n", (MPI_Wtime() - start));
        }

        MPI_Finalize();
        return 0;
}

ok so i got that problem fixed but all my sums are coming out negative...any advice?

Line 16, try initializing part_sum and tot_sum to 0.

no that didnt help..the sums are still coming out to be negative numbers

On line 32 you're using rand but you haven't seeded it. Include <time.h> and put a srand((unsigned)time(0)); before line 32 and also give a maximum value for rand by modding it with a maximum(so rand() % 10 +1 will give you random number from 1 to 10. I'm not sure that will solve the problem but it should give you a better idea as to where the negative values are coming from.

ok i did that...i even reduced the size of the array to 100 by 100 and one process returns the number positive and the rest are negative this is what it looks like for the output with five processes

Sub sum was returned from -288152290740.000000

Sub sum was returned from -288168767384.000000

Sub sum was returned from -288654112693.000000

Sub sum was returned from -288127294090.000000

Sub sum was returned from 55354.000000

Total sum is -1153102409553.000000

Time duration was 0.00

Unfortunately, I don't have a system to test this out on. It's probably best to see how well the array arr was passed to the nodes. I regret it's been a while since I have done MPI but I remember the BCast being fussy.
It does take a void* but it still asks for the total number of elements and you have only provided it with N for a count. Either try giving it the count of M*N or try the whole thing as a 1D array with MxN elements (that will change your loops around). See if any of that helps. I've tried to do some searches as to passing a 2D array via BCast but didn't turn up anything worth noting. Wish I had more info for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.