如何在MPI中使用多维STL向量 [英] How to use multi dimensional STL vector in MPI

查看:206
本文介绍了如何在MPI中使用多维STL向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MPI中将两个矩阵相乘,但是我的两个矩阵都是矢量形式.

I am trying to multiply two matrices in MPI but my both matrices are in vector form.

vector <vector <int> > Mat1;以MxN顺序

vector <vector <int> > Mat2;这是NxL阶

结果也是矢量形式

vector <vector <int> > Mat3;

这是MxL订单.

我正在使用MPI_BCAST将值广播为

I am using MPI_BCAST to broadcast the values as

MPI_Bcast(Mat2.data(), Mat2.size(), MPI_INT, 0, MPI_COMM_WORLD);

并使用分散和收集功能以

and using scatter and gather function to receive the data as

    MPI_Scatterv(Mat1.data(), CNTS, SNTS, MPI_INT, MatPartS.data(), MatPartS.size(), MPI_INT, 0, MPI_COMM_WORLD);


    for (int i = 0; i < myRowsSize; ++i)
    {
            for (int j = 0; j < L; ++j)
            {
                    ResultMatPart[i][j]=0;
                    for (int k = 0; k < N; ++k)
                    {
                             ResultMatPart[i][j] += MatPartS[i][k] * Mat2[k][j];
                    }
            }
    }               


    MPI_Gatherv(ResultMatPart.data(), ResultMatPart.size(), MPI_INT, ResultMat.data(), RCNTS, SCNTS, MPI_INT, 0, MPI_COMM_WORLD);  

Blockquote

Blockquote

我可以编译程序,但是它会崩溃并且不会产生任何输出.

I can compile the program but it crashes and doesn't produce any output.

它打印的消息是:

Fatal error in PMPI_Scatterv: Message truncated, error stack:
PMPI_Scatterv(376).....: MPI_Scatterv(sbuf=0x108fe00, scnts=0x108fef0, displs=0x108ffc0, MPI_INT, rbuf=0x1090270, rcount=4, MPI_INT, root=0, MPI_COMM_WORLD) failed
MPIR_Scatterv_impl(187): 
MPIR_Scatterv(106).....: 
MPIR_Localcopy(340)....: Message truncated; 64 bytes received but buffer size is 16

有什么帮助如何在MPI中传递多维STL向量?

Any help how to pass a multidimensional STL vector in MPI?

非常感谢

S

推荐答案

那些MPI函数期望一维数组.您将需要将2D向量收集到单个向量中.这只是使用向量表示矩阵吮吸的原因之一.

Those MPI functions are expecting a one-dimensional array. You will need to collect your 2D vectors into a single vector. This is just one of the reasons why using vector-of-vector to represent a matrix sucks.

看看这个答案,我给出了别人的向量困境.它使用单个向量提供了一个简单的矩阵类:

Have a look at this answer I gave for someone else's vector-of-vector dilemmas. It provides a simple matrix class using a single vector:

获取由向量的向量表示的矩阵的第一列

这篇关于如何在MPI中使用多维STL向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆