С++ MPI Broadcast вектор структуры

У меня есть программа, использующая C++ MPI. У меня есть такая структура Edge:

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <climits>
#include <exception>
#include <string>
#include "mpi.h"
using namespace std;

/** STEP 2: STATE data sructure */
struct Edge {
    int fromPoint;
    int toPoint;
    int cost;
    // constructor
    Edge(int fromPointIn, int toPointIn, int costIn)
    : fromPoint(fromPointIn), toPoint(toPointIn), cost(costIn) {}
};

Во время моего основного я создал вектор ребер:

int main(int argc, char **argv) {

    /* MPI_Init ... get rank, hostname ,... */

    if (rank==0) { 
       int V=0, E=0;
       vector<Edge> adjList;

       ifstream fin(inputFile.c_str());
       fin >> V >> E;
       while (!fin.eof()) {
           int v1, v2, c;
           fin >> v1 >> v2 >> c;
           Edge temp(v1+1,v2+1,c);
           adjList.push_back(temp);

            // THIS IS WHERE I DO NOT HOW TO PASS
            //MPI_Bcast(&adjList,adjList.size()*3,MPI_INT,0,MPI_COMM_WORLD);
       }
    }

Моя цель - передать вектор adjList от процессора 0 всем остальным процессорам. Однако может показаться, что это не работает
MPI_Bcast(&adjList,adjList.size()*3,MPI_INT,0,MPI_COMM_WORLD);
* send data = adjList
* size = adjList.size()* 3 (я думал, что каждое векторное значение имеет 3 int из структуры).
* тип данных = MPI_INT
* отправка из процессора = 0
* MPI_COMM_WORLD

Подводя итог, моя цель - передать вектор adjList от процессора 0 всем остальным процессорам. Буду очень признателен за любое предложение


person NNguyen    schedule 29.02.2016    source источник
comment
Вы должны создать тип данных MPI структуры, а затем использовать MPI_Bcast(&adjList[0], adjList.size(), datatype, ...);.   -  person Hristo Iliev    schedule 29.02.2016
comment
Простым исправлением будет использование adjList.data() вместо &adjList и size=adjList.size()*sizeof(Edge) при условии, что вы правильно инициализировали приемный буфер на всех ядрах.   -  person dee-kay    schedule 29.02.2016