Using ipython for parallel computing

from xieweizhong.tk Using ipython for parallel computing Wed 25 December 2013 By Xiewei Zhong

In Python.

Problem

In my work, I meet one problem: the time consuming during computing. My Thought

At first, the GPU programming was occured in my mind. But, aftering trying, I found that the algorithm should be rewrite by myself using CUDA-c, and the helpful functions in scipy module can not be used. Therefore, I get rid of the mind, and begain to looking for the method: CPU-parallel programming. IPython

Before, I only know that the ipython is a wonderful python programming environment. Now, the other powerful function of ipython make me shocked: Using IPython for parallel computing.

Below, the detail solutions are illustrated.

from scipy.optimize import minimize from IPython.parallel import Client # The most important thing import numpy as np

def func(x): "My function for minimize"

def myminimize(x): """My function to wrap the minimize funtion""" ... ... # To determine the x0 res = minimize(func, x0, args=(x,), method='Nelder-Mead', options={'xtol': 1e-5, 'disp': False}) return res.x

if name == 'main': x = list() ... # initialize content of x rc = Client() dview = rc[:] # set the global informations dview['g_1'] = g_1 dview['np'] = np dview['minimize'] = minimize ... result = dview.map_sync(myminimize, x)

In the termial, typeipcluster start -n 16 at first, and then python yourcode.py

转载于:https://my.oschina.net/grassyue/blog/187909

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值