Posts

Showing posts with the label parallel-processing

ThreadPool and Pool for parallel processing

Image
Clash Royale CLAN TAG #URR8PPP ThreadPool and Pool for parallel processing Is there a way to use both ThreadPool and Pool in python to parallelise a loop by specifying the number of CPUs and cores you wish to use? For example I would have a loop execute as: from multiprocessing.dummy import Pool as ThreadPool from tqdm import tqdm import numpy as np def my_function(x): return x + 1 pool = ThreadPool(4) my_array = np.arange(0,1e6,1) results = list(tqdm(pool.imap(my_function, my_array),total=len(my_array))) For 4 cores (threads) but it I wanted to spread these out on multiple CPUs as well, is there a simple way to adapt the code? 1 Answer 1 You can just use it with no parameter and let the library decide: from multiprocessing.pool import ThreadPool ... pool = ThreadPool() But that will not share the process across multiple CPUs no? Only cores – user...

Error when accessing an Excel workbook from within a parallel loop

Image
Clash Royale CLAN TAG #URR8PPP Error when accessing an Excel workbook from within a parallel loop I am using MATLAB to write to an Excel file with Macros in them, and then reevaluate the file and extract the Macro results using xlsread . The code works fine with only one worker. However, if I use parfor and use a second worker, MATLAB gives the error message as below. To be rigorous, I have created a second Excel file for the second worker and use t = getCurrentTask(); t.ID; to instruct the workers to work on their arranged excel file. xlsread parfor t = getCurrentTask(); t.ID; Error using xlswrite (line 226) Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: Microsoft Excel cannot access the file 'C:Users-----D0481000'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. Help File: xlmai...

Spark - Why is it necessary to collect() to the driver node before printing an RDD? Can it not be done in parallel?

Image
Clash Royale CLAN TAG #URR8PPP Spark - Why is it necessary to collect() to the driver node before printing an RDD? Can it not be done in parallel? I was reading about how to print RDDs in Spark (I'm using Java), and it seems like most people just collect() (if the RDD is small enough) and use forall(println), or something like that. Is it not possible to print in parallel? Why do we have to collect the data onto the driver node in order to print? collect() I was thinking maybe it's because we can't use System.out in parallel, but I feel like that's not it. And furthermore, I'm not quite sure how one would even distribute the data and print parallelly, in terms of code. One approach I was thinking of was to do a mappartitions that doesn't do anything useful in terms of mapping, but it iterates through the partition and prints its contents. By clicking "Post Your Answer", you acknowledg...

Execute multiple parallel cURL against the same URL?

Image
Clash Royale CLAN TAG #URR8PPP Execute multiple parallel cURL against the same URL? I need to execute 2 requests in parallel using cURL to get a reply from the web service. The problem is that I need to get the encrypted password from the first XML's output and pass it to the second XML to get 100 success response from the API. Currently, I have created 2 cURL to achieve this but the API responds "101 Password Expired" because the encrypted password is valid only for the first request. Here is my code for reference: 1st cURL: $soapUrl = "http://localhost:54934/frmMutualFund.asmx?op=getPassword"; // asmx URL of WSDL // xml post structure $xml_post_string = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ...

Parallel processes: appending outputs to an array in a zsh script

Image
Clash Royale CLAN TAG #URR8PPP Parallel processes: appending outputs to an array in a zsh script I have a for loop in which a function task is called. Each call to the function returns a string that is appended to an array. I would like to parallelise this for loop. I tried using & but it does not seem to work. task & Here is the code not parallelised. task (){ sleep 1;echo "hello $1"; } arr=() for i in {1..3}; do arr+=("$(task $i)") done for i in "${arr[@]}"; do echo "$i x"; done The output is: hello 1 x hello 2 x hello 3 x Great! But now, when I try to parallelise it with [...] for i in {1..3}; do arr+=("$(task $i)")& done wait [...] the output is empty. This question is specifically for zsh , for its bash counterpart please see here. zsh bash 2 Answers 2 I could be wrong, but I'm pretty sure you don't want to do...