发送字符串数组MPI C [英] Sending string array MPI C

查看:90
本文介绍了发送字符串数组MPI C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字符串数组发送到MPI中的从属进程,但是我不知道该怎么做.我有一个很大的字符串数组,我已经从文件中读取了,我需要将此数组的一部分发送给从属服务器.我正在分配一个新数组,其中包含主要数组中的一些元素,并尝试发送此数组.这是代码的发送部分:

i'm trying to send an array of strings to the slaves process in MPI, but i can't figure out how to do it. I have a big array of strings, which i've read from a file, and i need to send parts of this array to the slaves. I'm allocating a new array with some elements from the main one and trying to send this. Here's the send part of the code:

int w = 0;
int division = size / (procs -1);
for(i=1; i<procs; i++){
    //allocating
    char **array1 = (char**) malloc(sizeof(*array1) * division);
    array1[0] = (char*) malloc(sizeof(*array1[0]) * division * buf);
    for(j=1; j<division; j++)
        array1[i] = &(array1[0][i*buf]);

    // filling it up
    for(j=0; j<division; j++)
        array1[j] = array[w++];

    // sending
    MPI_Send(&array1, division[i], MPI_CHAR, i, tag, MPI_COMM_WORLD);

    // clearing memory
    free(array1);
}
printf("%d: All Sent\n", rank);

如果我将send方法更改为这种方式

If i change the send method to something like this

MPI_SEND(&array[0][0] ...)

它可以工作,但是我需要为每个进程发送多个字符串.

it works, but i need to send more than one string per process.

推荐答案

我也正在从事MPI项目,因为没有人回答这个问题,所以我会尽力而为.我认为在您的实现中,您传递了一个指针列表,每个指针指向一个char列表,​​因此MPI_send本质上发出了一个数组地址列表.结果,data_type"char"不匹配,或者它只能在每个数组中找到第一个char.

I am working on a MPI project too, since no one answers this question, I will give my best shot. I think in your implementation, you pass a list of pointers, each pointer pointing a list of char, thus MPI_send essentially sends out a list of addresses of arrays. As a result the data_type "char" won't match or it may only find the first char in each array.

这篇关于发送字符串数组MPI C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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