在此示例中,如何使mpi4py与R配合使用?

时间:2018-07-17 12:36:44

标签: python r parallel-processing mpi mpi4py

我有一个运行mpi4py的python脚本和一个调用python脚本功能的R脚本。想法是让python函数进行多个处理,计算其有效负载,然后将计算结果返回给R。

Python脚本:

from mpi4py import MPI
import numpy
import os
import pickle
import subprocess as s
comm = MPI.COMM_WORLD
sendbuf=[]
root=0
v = comm.rank
rank = v
def mpi_func_test():
    if rank == 1:
        vv = v*2
    elif rank == 2:
        vv = v * 3
    elif rank == 3:
        vv = v * 4
    elif rank > 3 :
        vv = "Rank Greater than 3 impossible"
    elif rank == 0:
        vv = 90
    recvbuf=comm.gather(vv,root)
    if rank == 0:
        f = open('temp','wb')
        pickle.dump(recvbuf, f)
        #f.write(str(recvbuf))
        f.close()
        return recvbuf

R脚本:

rm(list = ls())
library(reticulate)
library(rPython)
# source_python("multiprocessing_play_with4.py")
source_python("mpi_play_with4.py")
mpi_run_results <- run_in_mpi_mode()
# mpi_run_results <- parallelize()
cat(mpi_run_results)

要运行,我启动R并输入:

source(my_r_script.R)

0 个答案:

没有答案