如何发送动态矢量? [英] How to send dynamic vector?

查看:73
本文介绍了如何发送动态矢量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Group,


int Msg [size];

MPI_Send(Msg,size,MPI_INT,DEST,TAG,MPI_COMM_WORLD);

这个工作正常。


但是如何发送Msg这样声明:

int * Msg =(int *)malloc(sizeof (int)* size);


它给了我

p4_error:中断SIGSEGV:11

not_send:无法写入fd = 4,errno = 32

谢谢!

Hello Group,

int Msg[size];
MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
this is working fine.

But how to send Msg declared like this:
int *Msg=(int*)malloc(sizeof(int)*size);

It gives me
p4_error: interrupt SIGSEGV: 11
not_send: could not write to fd=4, errno = 32

Thanks!

推荐答案

dopiotr写道:
dopiotr wrote:

Hello Group,

int Msg [size];

MPI_Send(Msg,size, MPI_INT,DEST,TAG,MPI_COMM_WORLD);

这个工作正常。


但是如何发送Msg这样声明:

int * Msg =(int *)malloc(sizeof(int)* size);


它给了我

p4_error:中断SIGSEGV:11

not_send:无法写入fd = 4,errno = 32
Hello Group,

int Msg[size];
MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
this is working fine.

But how to send Msg declared like this:
int *Msg=(int*)malloc(sizeof(int)*size);

It gives me
p4_error: interrupt SIGSEGV: 11
not_send: could not write to fd=4, errno = 32



如果没有进一步的代码我真的不能你的问题是什么。可能

不是C问题,而是MPI函数的错误使用。你可以在一个专门讨论你的MPI实现的论坛中提问




< http://en.wikipedia.org/wiki/Message_Passing_Interface> ;

< http://www.mpi-forum.org/docs/>

< http://www.open-mpi.org/> ;

< http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>

Without further code I can''t really tell what your problem is. It may
not be a C problem but an incorrect use of MPI functions. You might do
better to ask in a forum dedicated to your MPI implementation.

<http://en.wikipedia.org/wiki/Message_Passing_Interface>
<http://www.mpi-forum.org/docs/>
<http://www.open-mpi.org/>
<http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>


10月22日上午12:45,dopiotr< nos ... @nospam.invalidwrote:
On Oct 22, 12:45 am, dopiotr <nos...@nospam.invalidwrote:

Hello Group,

int Msg [size];

MPI_Send(Msg,size,MPI_INT,DEST,TAG,MPI_COMM_WORLD);

这个工作正常。


但是如何发送Msg这样声明:

int * Msg =(int *)malloc(sizeof(int)* size);
Hello Group,

int Msg[size];
MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
this is working fine.

But how to send Msg declared like this:
int *Msg=(int*)malloc(sizeof(int)*size);



你检查了malloc的返回值吗?

由于内存分配失败,它可能是NULL。

Did u check the return value of malloc?
It might be NULL, due to failed memory allocation.


2007年10月21日19:56,santosh写道:
On 21 Oct 2007 at 19:56, santosh wrote:

dopiotr写道:
dopiotr wrote:

> Hello Group,
int msg [size];
MPI_Send (Msg,size,MPI_INT,DEST,TAG,MPI_COMM_WORLD);
这个工作正常。

但是如何发送Msg声明如下:
int * Msg =(int *)malloc(sizeof(int)* size);

它给了我
p4_error:中断SIGSEGV:11
not_send:无法写入fd = 4,errno = 32
>Hello Group,

int Msg[size];
MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
this is working fine.

But how to send Msg declared like this:
int *Msg=(int*)malloc(sizeof(int)*size);

It gives me
p4_error: interrupt SIGSEGV: 11
not_send: could not write to fd=4, errno = 32



如果没有进一步的代码我就不能确定你的问题是什么。可能

不是C问题,而是MPI函数的错误使用。您可以在专门讨论MPI实施的论坛中提出更好的问题。

< http://en.wikipedia.org/wiki/Message_Passing_Interface>
< http://www.mpi-forum.org/docs/>
< http://www.open-mpi.org/>
< http:// www .personal.leeds.ac.uk / ~bgy1mm / MPITutorial / MPIHome.html>


Without further code I can''t really tell what your problem is. It may
not be a C problem but an incorrect use of MPI functions. You might do
better to ask in a forum dedicated to your MPI implementation.

<http://en.wikipedia.org/wiki/Message_Passing_Interface>
<http://www.mpi-forum.org/docs/>
<http://www.open-mpi.org/>
<http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>



工作wersion:

#include" mpi .h"

#include< stdio.h>

#include< stdlib.h>

uint n_sigm;

float * suma_sigm;


void main(int c,char * v [])

{

int size,排名;

int j;

float * s_tmp;

MPI_Init(& c,& v);

MPI_Comm_size(MPI_COMM_WORLD,& size);

MPI_Comm_rank(MPI_COMM_WORLD,& rank);

n_sigm = 1000;


suma_sigm =(float *)malloc(sizeof(float)* n_sigm);

s_tmp =(float *)malloc(sizeof(float)* n_sigm); //差异


if(rank!= 0)

{

for(j = 0; j< n_sigm; j ++)

suma_sigm [j] = rank * 1000 + j;

}

else

{

for(j = 0; j< n_sigm; j ++)

s_tmp [j] = 0;

}

MPI_Reduce(suma_sigm,s_tmp,n_sigm,MPI_FLOAT,MPI_SUM,

0,MPI_COMM_WORLD);

if(rank == 0)

for(j = 0; j< n_sigm; j ++)

printf("%i%f \ n" ,j,s_tmp [j]);

免费(suma_sigm);

免费(s_tmp);

MPI_Finalize();

}


为什么不工作:

#include" mpi.h"

#include< ; stdio.h>

#include< stdlib.h>

uint n_sigm;

float * suma_sigm;

int main(int c,char * v [])

{

int size,rank;

int j;

float * s_tmp;

MPI_Init(& c,& v);

MPI_Comm_size(MPI_COMM_WORLD,& size);

MPI_Comm_rank(MPI_COMM_WORLD,& rank);

n_sigm = 1000;


suma_sigm =(float *)malloc(sizeof(float)* n_sigm);


if(rank!= 0)

{

for(j = 0; j< n_sigm; j ++)

suma_sigm [j] = rank * 1000 + j;

}

else

{

for(j = 0; j< n_sigm; j ++)

s_tmp [j] = 0;

}

s_tmp =(float *)malloc(sizeof(float)* n_sigm); //差异

MPI_Reduce(suma_sigm,s_tmp,n_sigm,MPI_FLOAT ,MPI_SUM,

0,MPI_COMM_WORLD);

if(rank == 0)

for(j = 0; j< n_sigm; j ++ )

printf("%i%f\ n,j,s_tmp [j]);

免费(suma_sigm);

free(s_tmp);

MPI_Finalize();

}


为什么s_tmp [0]&的价值s_tmp [1]不正确(在工作中

版本)。

Working wersion:
#include "mpi.h"
#include<stdio.h>
#include<stdlib.h>
uint n_sigm;
float *suma_sigm;

void main(int c, char *v[])
{
int size,rank;
int j;
float *s_tmp;
MPI_Init(&c,&v);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
n_sigm=1000;

suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference

if(rank != 0)
{
for(j=0;j<n_sigm;j++)
suma_sigm[j]=rank*1000+j;
}
else
{
for(j=0;j<n_sigm;j++)
s_tmp[j]=0;
}
MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
0,MPI_COMM_WORLD);
if( rank == 0 )
for(j=0;j<n_sigm;j++)
printf("%i %f\n",j,s_tmp[j]);
free(suma_sigm);
free(s_tmp);
MPI_Finalize();
}

Why it is not working:
#include "mpi.h"
#include<stdio.h>
#include<stdlib.h>
uint n_sigm;
float *suma_sigm;
int main(int c, char *v[])
{
int size,rank;
int j;
float *s_tmp;
MPI_Init(&c,&v);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
n_sigm=1000;

suma_sigm=(float *)malloc(sizeof(float)*n_sigm);

if(rank != 0)
{
for(j=0;j<n_sigm;j++)
suma_sigm[j]=rank*1000+j;
}
else
{
for(j=0;j<n_sigm;j++)
s_tmp[j]=0;
}
s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference
MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
0,MPI_COMM_WORLD);
if( rank == 0 )
for(j=0;j<n_sigm;j++)
printf("%i %f\n",j,s_tmp[j]);
free(suma_sigm);
free(s_tmp);
MPI_Finalize();
}

And why value of s_tmp[0] & s_tmp[1] is incorrect (in working
version).


这篇关于如何发送动态矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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