由于MPI不提供二进制兼容性,仅提供源兼容性,因此我们被迫将求解器源代码交付给客户,以使他们将求解器与首选版本的MPI一起使用。好了,我们到达了无法再提供源代码的地步。
因此,我正在研究围绕MPI调用创建包装器的方法。我们的想法是为我们提供存根函数的标头,用户将编写实现,从中创建一个动态库,然后我们的求解器将在运行时加载它。
但是解决方案不是“优雅”的,而且容易出错。由于有些实struct参(例如MPI_Request)的struct定义可能因一个MPI实现而异,因此我们需要接受(void*)许多存根实参。另外,如果一个MPI到另一个MPI的参数数量可以不同(我不确定是否可以保证不会发生),那么使用唯一的方法就是使用var_args。
//header (provided by us)
int my_stub_mpi_send(const void buf, int count, void* datatype,
int dest, int tag, void* comm);
//*.c (provided by user)
#include <my_stub_mpi.h>
#include <mpi.h>
int my_stub_mpi_send(const void buf, int count, void* datatype,
int dest, int tag, void* comm)
{
return MPI_Send(buf, count, *((MPI_Datatype) datatype),
dest, tag, ((MPI_Comm) comm));
}
//Notes: (1) Most likely the interface will be C, not C++,
// unless I can make …Run Code Online (Sandbox Code Playgroud) 我是Haskell的新手.我试图解决丢番图方程| x ^ yy ^ x | 对于给定的上界x,y <n,使用Haskell 是素数.
所以,我写了这个Haskell代码:
-- list of primes
listprimesupto :: Integral a => a -> [a]
listprimesupto 1 = []
listprimesupto 2 = [2]
listprimesupto n = let halflstprimes = (listprimesupto (n `div` 2))
in halflstprimes++[i|i<-[((n `div` 2)+1)..n], (length [x|x<-halflstprimes, (i `mod` x) == 0])==0 ]
-- is prime?
is_prime :: Integral a => a -> Bool
is_prime 1 = False
is_prime n = let halflstprimes = (listprimesupto (n …Run Code Online (Sandbox Code Playgroud)