小编Fla*_*hão的帖子

MPI Spawn:根进程不与子进程通信

(初学者问题)我正在尝试使用MPI_Comm_Spawn动态生成进程,然后向子进程广播消息,但程序在从根进程到子进程的广播中停止.我正在关注http://www.mpi-forum.org/docs/docs.html上的文档,但我无法使其正常运行.有人能帮帮我吗?

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[])
{
    MPI_Init(&argc, &argv);
    MPI_Comm parentcomm;

    MPI_Comm_get_parent( &parentcomm );

    if (parentcomm == MPI_COMM_NULL) {
        MPI_Comm intercomm;
        MPI_Status status;
        char msg_rec[1024];
        char msg_send[1024];
        int size, i;

        int np = (argc > 0) ? atoi(argv[1]) : 3;

        printf("Spawner will spawn %d processes\n", np);
        MPI_Comm_spawn( argv[0], MPI_ARGV_NULL, np, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm, MPI_ERRCODES_IGNORE );
        MPI_Comm_size(intercomm, &size);

        sprintf(msg_send, "Hello!");
        printf("Spawner will broadcast '%s'\n", msg_send);
        MPI_Bcast( (void*)msg_send, 1024, MPI_CHAR, 0, intercomm);

        printf("Spawner will receive …
Run Code Online (Sandbox Code Playgroud)

c mpi

8
推荐指数
1
解决办法
2295
查看次数

stringstream-> rdbuf() - > pubsetbuf没有设置缓冲区

我试图修改stringstream对象的stringbuffer而不必复制字符串,使用方法pubsetbuf,但它无法正常工作.我正在关注http://www.cplusplus.com/reference/iostream/streambuf/pubsetbuf/中的文档.这是我的示例代码:

#include <iostream>
#include <sstream>

int main(int argc, char* argv[])
{
    std::stringstream stream("You say goodbye");
    char replace[] = {"And I say hello"};
    std::cout << stream.str() << std::endl; // Checking original contents
    stream.rdbuf()->pubsetbuf(replace, 16); // Should set contents here
    std::cout << stream.str() << std::endl; // But don't :(
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是:

You say goodbye
You say goodbye
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用stream.str(替换),但是这个方法复制'replace'的值,我不想复制.

我错过了什么?

更新:我正在使用VS2010

c++ stl stringstream stringbuffer

8
推荐指数
1
解决办法
2882
查看次数

标签 统计

c ×1

c++ ×1

mpi ×1

stl ×1

stringbuffer ×1

stringstream ×1