如何使用MPI_Scatter()

如何使用MPI_Scatter(),mpi,openmp,pragma,scatter,Mpi,Openmp,Pragma,Scatter,我试图了解如何调用与我的程序有关的函数。我的程序正在读取文本文件,并将每个单词放入如下数组: // declared outside of main const static int ARRAY_SIZE = 130000; using Lines = char[ARRAY_SIZE][16]; // in main Lines lines; int i = 0; if (processId == 0) { std::ifstream file; file.imbue(std:

我试图了解如何调用与我的程序有关的函数。我的程序正在读取文本文件,并将每个单词放入如下数组:

// declared outside of main
const static int ARRAY_SIZE = 130000;
using Lines = char[ARRAY_SIZE][16];

// in main
Lines lines;
int i = 0;
if (processId == 0) {
    std::ifstream file;
    file.imbue(std::locale(std::locale(), new letter_only())); // letter_only is defined
    file.open(argv[1]);
    std::string workString;
    while (file >> workString) {
        memset(lines[i], '\0', 16);
        memcpy(lines[i++], workString.c_str(), workString.length());
    }
}
然后,我想将这个数组分成若干块,传递给进程,然后将工作分散到这些进程。我是这样做的:

int chunk_size = i/num_processes;  // num_processes has the number of processes
int sum = 0;
int my_count = 0;
std::vector<std::string> my_string_vector;
char my_lines[chunk_size][16];

MPI_Scatter(lines,chunk_size,MPI_CHAR,my_lines,chunk_size,MPI_CHAR,0,MPI_COMM_WORLD);
int chunk\u size=i/num\u进程;//num_processs具有进程数
整数和=0;
int my_count=0;
std::vector my_string_vector;
char my_line[块大小][16];
MPI_分散(行、块大小、MPI_字符、我的行、块大小、MPI_字符、0、MPI_通信世界);
调用MPI_Scatter会导致程序挂起,我不知道为什么。我是否将正确的值传递给MPI_散点?是否有MPI的数据类型字符串


感谢您提供的任何帮助第一步:请确保您正在编写混合分布式/共享内存程序,并且不会混淆
OpenMP
MPI
。如果是前者,几乎可以肯定你需要解释更多,如果是后者,你需要在网上做一些研究。你想让我发布整个代码吗?不,我想让你向我们保证。。。。正如我在之前的评论中所写。如果您正试图编写混合MPI/OpenMP程序,请提供一个比上面的代码片段更好的示例来说明您的问题。哦,通过编辑你的问题来做到这一点,不要在新的评论中发布任何有用的信息。嘿,我用更好的信息编辑了原来的帖子。