我想在R可以调用的子例程中编写一些并行的Fortran代码(我想从R中读取数据并将其发送到并行的Fortran MPI)。但是,我注意到,当我将以下程序作为子例程运行(即用“子例程”代替“程序”)时,代码不再编译(当它是程序时确实会编译)。我编译使用的代码mpif90从MPICH的Linux操作系统。
是否可以在Fortran的子例程中初始化和完成MPI?如果不是,是否仍然可以通过R调用并行的Fortran MPI?如果不是在Fortran中,可以在C中完成吗?
这是代码:
module global
integer numnodes,myid,mpi_err
integer, parameter :: my_root=0
end module global
module fmpi
include 'mpif.h'
end module fmpi
subroutine init
use fmpi
use global
implicit none
call MPI_INIT( mpi_err )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numnodes, mpi_err )
call MPI_Comm_rank(MPI_COMM_WORLD, myid, mpi_err)
end subroutine init
program test
use global
use fmpi
implicit none
real*8:: dat(10)
integer*4:: i
call init
if(myid == my_root) then
do i=1,10
dat(i) = i
enddo
print *,dat(1)
endif
call …Run Code Online (Sandbox Code Playgroud) 我希望并行运行三个任务.我希望检查完成的第一个任务的结果,并检查以确定结果是否良好.如果是,我取消所有其他任务并返回此结果,如果没有,我将等待下一个完成的任务并检查是否良好,如果是,则执行相同操作.(想想是良好的OutputDataType成员对一些简单的检查).
我继续这个,直到我获得一个结果很好的完成任务,或者所有任务返回的结果都不好,在这种情况下我会返回null.
先感谢您.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace myNamespace
{
class Program
{
static void Main()
{
InputDataType data = getMyData();
OutputDataType x = Foo(data);
}
static OutputDataType Foo(InputDataType data)
{
Task<OutputDataType> task1 = null, task2 = null, taks3 = null;
Task<OutPutDataType>[] TaskArray = { task1, task2, task3 };
task1 = Task<SolutionInterpreters>.Factory.StartNew(() => RunFunc1(data));
task2 = Task<SolutionInterpreters>.Factory.StartNew(() => RunFunc2(data));
task3 = Task<SolutionInterpreters>.Factory.StartNew(() => RunFunc3(data));
/*
. …Run Code Online (Sandbox Code Playgroud) 在bash脚本中需要帮助.目标是: - 并行运行多个命令 - 如果任何命令返回非零退出状态,则退出1
即
使用middle命令运行有错误:
$ ./parallel_commands "echo 1" "_echo 2" "echo 3" && echo "OK"
1
3
./parallel_commands: line 4: _echo: command not found
OK <- Incorrect
Run Code Online (Sandbox Code Playgroud)
使用所有命令运行都有错误:
$ ./parallel_commands "_echo 1" "_echo 2" "_echo 3" && echo "OK"
./parallel_commands: line 4: _echo: command not found
./parallel_commands: line 4: _echo: command not found
./parallel_commands: line 4: _echo: command not found
-> Result is fail -> Correct
Run Code Online (Sandbox Code Playgroud)
Bash脚本:
#!/bin/bash
for cmd in "$@"; do {
$cmd & pid=$! …Run Code Online (Sandbox Code Playgroud) 我有一个MPI_Reduce()用于某些通信的分布式应用程序.在精度方面,我们使用16位浮点数(半精度)获得完全准确的结果.
为了加速通信(减少数据移动量),有没有办法调用MPI_Reduce()16位浮点数?
(我查看了MPI文档,但没有看到有关16位浮点数的任何信息.)
我有一个这样的数据框:
Open High Low Close Volume
1998-09-08 10:32:00 106.44 106.44 106.44 106.44 1
1998-09-08 10:33:00 106.42 106.42 106.35 106.35 628225
1998-09-08 10:34:00 106.31 106.38 106.31 106.38 135840
1998-09-08 10:35:00 106.35 106.35 106.32 106.34 170010
1998-09-08 10:36:00 106.35 106.36 106.35 106.36 309560
1998-09-08 10:37:00 106.44 106.50 106.44 106.50 115540
1998-09-08 10:38:00 106.49 106.53 106.49 106.52 427620
1998-09-08 10:39:00 106.53 106.54 106.52 106.53 321350
1998-09-08 10:40:00 106.55 106.60 106.54 106.54 317647
1998-09-08 10:41:00 106.56 106.63 106.56 106.63 233901
Run Code Online (Sandbox Code Playgroud)
我需要改变Open并行处理.我写了一个这样的函数:
parTest …Run Code Online (Sandbox Code Playgroud) 这是一个后续问题:Python:如何并行运行python函数?
最小工作范例:
'''
Created on 06.05.2015
https://stackoverflow.com/questions/7207309/python-how-can-i-run-python-functions-in-parallel
'''
from multiprocessing import Process
import time
def runInParallel(*fns):
proc = []
for fn in fns:
p = Process(target=fn)
p.start()
proc.append(p)
for p in proc:
p.join()
def func1():
s=time.time()
print 'func1: starting', s
for i in xrange(1000000000):
if i==i:
pass
e = time.time()
print 'func1: finishing', e
print 'duration', e-s
if __name__ == '__main__':
s =time.time()
runInParallel(func1, func1, func1, func1, func1)
print time.time()-s
Run Code Online (Sandbox Code Playgroud)
哪个利用了(这正是我想要的):
func1:从1430920678.09开始
func1:起始于1430920678.53
func1:从1430920679.02开始
func1:起始于1430920679.57
func1:从1430920680.55开始
func1:完成1430920729.68
持续时间51.1449999809
func1:完成1430920729.78 …
我开始尝试向Windows窗体添加进度条,以更新在Parallel.Foreach循环中运行的代码的进度.为此,UI线程必须可用于更新进度条.我使用Task来运行Parallel.Foreach循环以允许UI线程更新进度条.
在Parallel.Foreach循环中完成的工作相当密集.在使用Task运行程序的可执行文件(不在visual studio中调试)之后,程序没有响应.如果我在没有Task的情况下运行程序,情况就不是这样.我在两个实例之间注意到的关键区别是,在没有Task的情况下运行时程序需要大约80%的cpu,在使用Task运行时大约需要5%.
private void btnGenerate_Click(object sender, EventArgs e)
{
var list = GenerateList();
int value = 0;
var progressLock = new object ();
progressBar1.Maximum = list.Count();
Task t = new Task(() => Parallel.ForEach (list, item =>
{
DoWork ();
lock (progressLock)
{
value += 1;
}
}));
t.Start();
while (!t.IsCompleted)
{
progressBar1.Value = value;
Thread.Sleep (100);
}
}
Run Code Online (Sandbox Code Playgroud)
旁注:我知道
Interlocked.Increment(ref int___);
Run Code Online (Sandbox Code Playgroud)
用来代替锁.它被认为更有效吗?
我的问题有三个方面:
1.)当负载少得多时,为什么带有Task的程序会无响应?
2.)使用Task运行Parallel.Foreach是否将Parallel.Foreach的线程池限制为只运行任务的线程?
3.)有没有办法让UI线程响应而不是在没有使用取消令牌的情况下休眠.1秒的持续时间?
我很感激任何帮助或想法,我花了很多时间研究这个.如果我违反任何发布格式或规则,我也会道歉.我试图坚持他们,但可能错过了一些东西.
我刚开始阅读Haskell中的并行和并发编程.
我写了两个程序,我相信这两个程序总结了一个列表:
rpar (force (sum list))这是代码:
import Control.Parallel.Strategies
import Control.DeepSeq
import System.Environment
main :: IO ()
main = do
[n] <- getArgs
[single, faster] !! (read n - 1)
single :: IO ()
single = print . runEval $ rpar (sum list)
faster :: IO ()
faster = print . runEval $ do
let (as, bs) = splitAt ((length list) `div` 2) list
res1 <- rpar (sum as)
res2 <- rpar (sum bs)
return (res1 + res2) …Run Code Online (Sandbox Code Playgroud) 想象一下,我为一个有很多属性的学生提供了以下课程,让我们简化它:
public class Student{
public Int64 id { get; set; }
public String name { get; set; }
public Int64 Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后在主线程上我有以下列表:
List<Student> allStudents = new List<Student>();
Run Code Online (Sandbox Code Playgroud)
假设我在Excel文件中有500名学生,我想收集它们并将它们插入列表中.我可以做如下的事情:
for(int i = startRow; i < endRow; i++){
Student s = new Student();
//Perform a lot of actions to gather all the information standing on the row//
allStudents.Add(s);
}
Run Code Online (Sandbox Code Playgroud)
现在因为在Excel中收集信息非常慢,因为必须执行许多操作.所以我想使用Parallel.For,我可以想象做以下事情:
Parallel.For(startRow, endRow, i => {
Student s = new Student();
//Perform a lot of actions to gather …Run Code Online (Sandbox Code Playgroud) 我正在使用boot函数R来实现bootstrap.我的问题是如何设置boot利用其并行选项.考虑以下估算中位数的具体示例.
med_est <- function(dat, indices){
.dat <- dat[indices]
median(.dat)
}
dat <- rnorm(200)
system.time(boot(dat, med_est, R = 10000))
system.time(boot(dat, med_est, R = 10000, parallel = "multicore"))
Run Code Online (Sandbox Code Playgroud)
我不知道如何parallel在boot函数中使用该选项.让我们parallel = "multicore"不提高速度.我尝试过更复杂的估算问题.但我没有看到差异.所以我想我没有boot正确使用.我的机器是双核Mac.