小编sep*_*cmk的帖子

通过MPI发送功能指针

通过MPI传递函数指针作为告诉另一个节点调用函数的方法是否安全?有人可能会说通过MPI传递任何类型的指针都没有意义,但我写了一些代码来验证它.

//test.cpp
#include <cstdio>
#include <iostream>
#include <mpi.h>
#include <cstring>

using namespace std;

int f1(int a){return a + 1;}
int f2(int a){return a + 2;}
int f3(int a){return a + 3;}

using F=int (*)(int);

int main(int argc, char *argv[]){
    MPI_Init(&argc, &argv);
    int rank, size;
    MPI_Status state;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    //test
    char data[10];
    if( 0 == rank ){
        *(reinterpret_cast<F*>(data))=&f2;
        for(int i = 1 ; i < size ; ++i)
            MPI_Send(data, 8, MPI_CHAR, i, 0, MPI_COMM_WORLD);
    }else{
        MPI_Recv(data, 8, MPI_CHAR, 0, …
Run Code Online (Sandbox Code Playgroud)

parallel-processing pointers mpi virtual-address-space c++11

2
推荐指数
1
解决办法
344
查看次数

'$'是haskell中的一个功能吗?

我对haskell的($)感到很困惑.

当我输入

:t ($)
Run Code Online (Sandbox Code Playgroud)

在ghci.我会得到

:($) :: (a -> b) -> a -> b
Run Code Online (Sandbox Code Playgroud)

但是,当我输入

:t ($ 3)
Run Code Online (Sandbox Code Playgroud)

我会得到

($ 3) :: Num a => (a -> b) -> b
Run Code Online (Sandbox Code Playgroud)

那么,为什么($)接受第二个参数没有任何错误?

syntax haskell dollar-sign

0
推荐指数
1
解决办法
151
查看次数