我正在努力学习如何使用该Control.Parallel模块,但我认为我做得不对.
我正在尝试运行以下代码(fibs.hs).
import Control.Parallel
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = p `par` (q `pseq` (p + q))
where
p = fib (n-1)
q = fib (n-2)
main = print $ fib 30
Run Code Online (Sandbox Code Playgroud)
我编译了这个:
ghc -O2 --make -threaded fibs.hs
Run Code Online (Sandbox Code Playgroud)
然后我得到以下执行该程序的结果(输出每个程序100次的Python脚本并返回执行时间的平均值和标准差):
./fibs +RTS -N1 -> avg= 0.060203 s, deviation = 0.004112 s
./fibs +RTS -N2 -> avg= 0.052335 s, deviation = 0.006713 s
./fibs +RTS -N3 -> avg= …Run Code Online (Sandbox Code Playgroud) LLVM的哪些属性使其成为(并行,并发,分布式)语言的实现的良好选择,是什么让它变得糟糕?
compiler-construction parallel-processing llvm distributed-programming
我有一个方法,我用不同的参数调用8次.我用
AvailableYears.AsParallel()
.Select<Int32,DateUsedByThread>(x => GetDataForYearWorker(x,CIF))
.ToList();
Run Code Online (Sandbox Code Playgroud)
GetDataForYearWorker同步从Web服务获取响应.它在我的asp.net应用程序上使用非常少的计算能力,但是每个webservice响应都需要3-5秒.因为对web服务的调用是彼此独立的,所以我想同时进行所有操作.但看起来只有2个线程可以同时运行.为什么这样,我怎么能有8个线程同时工作?
我正在开发一个需要进行重线性代数计算的程序.
现在我正在使用LAPACK/BLAS例程,但我需要利用我的机器(24核Xeon X5690).
我发现像pblas和scalapack这样的项目,但它们似乎都专注于分布式计算和使用MPI.
我没有可用的集群,所有计算都将在一台服务器上完成,并且使用MPI看起来像是一种过度杀伤力.
有人对此有任何建议吗?
我有一个10米行的大桌子.我需要为每一行获得一些统计值.例如,我有生成此值的函数GetStatistic(uuid).这个函数运行速度很慢,结果值不经常更改,所以我Statistic在表中创建了列,每天执行一次这样的查询:
UPDATE MyTable SET Statistic = GetStatistic(ID);
Run Code Online (Sandbox Code Playgroud)
在选择查询中,我使用列Statistic而不调用GetStatistic函数.
问题是,我的生产服务器有64个CPU和大量内存,因此几乎所有数据库都可以缓存到RAM,但是这个查询只使用一个CPU,需要2或3个小时才能执行.
GetStatistic函数使用表,在所有UPDATE查询执行期间都是常量.我可以修改查询以获得postgre,使用所有可用的CPU同时计算不同行的并行中的GetStatistic吗?
我正在尝试使用Cython来并行化一个昂贵的操作,这涉及生成中间多维数组.
以下非常简化的代码说明了我正在尝试做的事情:
import numpy as np
cimport cython
cimport numpy as np
from cython.parallel cimport prange
from libc.stdlib cimport malloc, free
@cython.boundscheck(False)
@cython.wraparound(False)
def embarrasingly_parallel_example(char[:, :] A):
cdef unsigned int m = A.shape[0]
cdef unsigned int n = A.shape[1]
cdef np.ndarray[np.float64_t, ndim = 2] out = np.empty((m, m), np.float64)
cdef unsigned int ii, jj
cdef double[:, :] tmp
for ii in prange(m, nogil=True):
for jj in range(m):
# allocate a temporary array to hold the result of
# expensive_function_1
tmp_carray …Run Code Online (Sandbox Code Playgroud) python parallel-processing numpy cython thread-local-storage
我正在编写一个函数来组合和组织数据,然后使用基数R中的并行函数并行运行MCMC链.我的函数如下.
dm100zip <- function(y, n.burn = 1, n.it = 3000, n.thin = 1) {
y <- array(c(as.matrix(y[,2:9]), as.matrix(y[ ,10:17])), c(length(y$Plot), 8, 2))
nplots <- nrow(y)
ncap1 <- apply(y[,1:8, 1],1,sum)
ncap2 <- apply(y[,1:8, 2],1,sum)
ncap <- as.matrix(cbind(ncap1, ncap2))
ymax1 <- apply(y[,1:8, 1],1,sum)
ymax2 <- apply(y[,1:8, 2],1,sum)
# Bundle data for JAGS/BUGS
jdata100 <- list(y=y, nplots=nplots, ncap=ncap)
# Set initial values for Gibbs sampler
inits100 <- function(){
list(p0=runif(1, 1.1, 2),
p.precip=runif(1, 0, 0.1),
p.day = runif(1, -.5, 0.1))
}
# Set parameters …Run Code Online (Sandbox Code Playgroud) 我最近偶然发现了一种通过在java项目的pom.xml文件中指定以下内容来通过jUnit并行执行测试的简单方法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>classes</parallel>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我发现有两个测试类(让我们称之为"badtestclass1"和"badtestclass2")由于编写测试的方式而不断受到并行执行的惩罚.理想情况下,我会重构那些测试类以表现得更好,但在此期间,我想知道是否有一种漂亮的方法来"排除"这些特定类并行执行.基本上,是否有一种方法可以并行执行其他所有操作,然后按顺序执行其他操作(或其他顺序,无关紧要).会有类似下面的工作吗?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>classes</parallel>
<excludes>
<excludesFile>badtestclass1</excludesFile>
<excludesFile>badtestclass2</excludesFile>
</excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我试图平行化在许多独立数据集上运行的蒙特卡罗模拟.我发现numba的并行guvectorize实现比numba jit实现快了不到30-40%.
我发现这些(1,2#2)相媲美的话题,但他们没有真正回答我的问题.在第一种情况下,实现通过回退到对象模式而减慢,而在第二种情况下,原始海报没有正确使用guvectorize - 这些问题都不适用于我的代码.
为了确保我的代码没有问题,我创建了这个非常简单的代码来比较jit和guvectorize:
import timeit
import numpy as np
from numba import jit, guvectorize
#both functions take an (m x n) array as input, compute the row sum, and return the row sums in a (m x 1) array
@guvectorize(["void(float64[:], float64[:])"], "(n) -> ()", target="parallel", nopython=True)
def row_sum_gu(input, output) :
output[0] = np.sum(input)
@jit(nopython=True)
def row_sum_jit(input_array, output_array) :
m, n = input_array.shape
for i in range(m) :
output_array[i] = np.sum(input_array[i,:])
rows = int(64) …Run Code Online (Sandbox Code Playgroud) 我有一种算法可以对给定长度的列表进行并行排序:
import Control.Parallel (par, pseq)
import Data.Time.Clock (diffUTCTime, getCurrentTime)
import System.Environment (getArgs)
import System.Random (StdGen, getStdGen, randoms)
parSort :: (Ord a) => [a] -> [a]
parSort (x:xs) = force greater `par` (force lesser `pseq`
(lesser ++ x:greater))
where lesser = parSort [y | y <- xs, y < x]
greater = parSort [y | y <- xs, y >= x]
parSort _ = []
sort :: (Ord a) => [a] -> [a]
sort (x:xs) = lesser ++ x:greater
where lesser …Run Code Online (Sandbox Code Playgroud) haskell ×2
numpy ×2
python ×2
asp.net ×1
c# ×1
cython ×1
function ×1
java ×1
junit4 ×1
lapack ×1
llvm ×1
maven ×1
multicore ×1
numba ×1
optimization ×1
performance ×1
postgresql ×1
quicksort ×1
r ×1
sql-update ×1