Islams
Islams

Reputation: 67

Scatter array of structures in C MPI

I have a struct called Department, and array of struct Department called Departments. I want to scatter this array for the specific number of processes, so that every process has a struct called Current containing one element(struct)(Department) from the Departments array.

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

struct Department{
    int position;
    int Department_Destinations[100];
};

struct Department Current,Departments[100];

int main(int argc, char** argv){
    int rank, nprocess;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocess);

    if(rank==0){
    for(i=0;i<n;i++){
        Departments[i].position=i+1;
        for(j=0;j<c1;j++){
            Departments[i].Department_Destinations[j]=0;
        }
    }

    MPI_Scatter(Departments, sizeof(Current), MPI_BYTE, Current ,sizeof(Current), MPI_BYTE, 0,MPI_COMM_WORLD);

    MPI_Finalize();
    return 0;
}

Suppose the number of processes is equal to the number of Departments elements (Department).

When compile and run this code it gives me this error: "incompatible type for argument 4 of ‘MPI_Scatter’"

Why do I get this error and how to scatter array of structure (Departments) in MPI?

Upvotes: 1

Views: 874

Answers (1)

francis
francis

Reputation: 9817

MPI_Scatter() needs a pointer to buffer to scatter and a pointer to the buffer that will receive the message.

If struct Department Current,Departments[100];, could you try:

MPI_Scatter(Departments, sizeof(Current), MPI_BYTE, &Current ,sizeof(Current), MPI_BYTE, 0,MPI_COMM_WORLD);

Upvotes: 1

Related Questions