Tutorial by Examples: alle

var actions = Enumerable.Range(1, 10).Select(n => new Action(() => { Console.WriteLine("I'm task " + n); if((n & 1) == 0) throw new Exception("Exception from task " + n); })).ToArray(); try { Parallel.Invoke(actions); } catch(AggregateExc...
Instead of this lambda-function that calls the method explicitly: alist = ['wolf', 'sheep', 'duck'] list(filter(lambda x: x.startswith('d'), alist)) # Keep only elements that start with 'd' # Output: ['duck'] one could use a operator-function that does the same: from operator import metho...
import multiprocessing def fib(n): """computing the Fibonacci in an inefficient way was chosen to slow down the CPU.""" if n <= 2: return 1 else: return fib(n-1)+fib(n-2) p = multiprocessing.Pool() print(p.map(fib,[38,37,3...
Note: Before deciding which Stream to use please have a look at ParallelStream vs Sequential Stream behavior. When you want to perform Stream operations concurrently, you could use either of these ways. List<String> data = Arrays.asList("One", "Two", "Three", &q...
The following examples show two main methods for installing Erlang/OTP on Ubuntu. Method 1 - Pre-built Binary Package Simply run this command and it will download and install the latest stable Erlang release from Erlang Solutions. $ sudo apt-get install erlang Method 2 - Build and Install from...
While static constructors are always called before the first usage of a type it's sometimes useful to be able to force them to be called and the RuntimeHelpers class provide an helper for it: using System.Runtime.CompilerServices; // ... RuntimeHelpers.RunClassConstructor(typeof(Foo).TypeHand...
An example that uses Parallel.ForEach loop to ping a given array of website urls. static void Main() { string [] urls = { "www.stackoverflow.com", "www.google.net", "www.facebook.com", "www.twitter.com" ...
An example that uses Parallel.For loop to ping a given array of website urls. static void Main() { string [] urls = { "www.stackoverflow.com", "www.google.net", "www.facebook.com", "www.twitter.com" }; ...
Invoking methods or actions in parallel (Parallel region) static void Main() { string [] urls = { "www.stackoverflow.com", "www.google.net", "www.facebook.com", "www.twitter.com" }; System.Thr...
__CLASS__ magic constant returns the same result as get_class() function called without parameters and they both return the name of the class where it was defined (i.e. where you wrote the function call/constant name ). In contrast, get_class($this) and get_called_class() functions call, will both ...
Statement-level parallel hints are the easiest: SELECT /*+ PARALLEL(8) */ first_name, last_name FROM employee emp; Object-level parallel hints give more control but are more prone to errors; developers often forget to use the alias instead of the object name, or they forget to include some objec...
The foreach package brings the power of parallel processing to R. But before you want to use multi core CPUs you have to assign a multi core cluster. The doSNOW package is one possibility. A simple use of the foreach loop is to calculate the sum of the square root and the square of all numbers from...
The base package parallel allows parallel computation through forking, sockets, and random-number generation. Detect the number of cores present on the localhost: parallel::detectCores(all.tests = FALSE, logical = TRUE) Create a cluster of the cores on the localhost: parallelCluster <- para...
To find some number (more than one) of largest or smallest values of an iterable, you can use the nlargest and nsmallest of the heapq module: import heapq # get 5 largest items from the range heapq.nlargest(5, range(10)) # Output: [9, 8, 7, 6, 5] heapq.nsmallest(5, range(10)) # Output: [...
child.py import time def main(): print "starting work" time.sleep(1) print "work work work work work" time.sleep(1) print "done working" if __name__ == '__main__': main() parent.py import os def main(): for i in range(5):...
To list installed packages: $ pip list # example output docutils (0.9.1) Jinja2 (2.6) Pygments (1.5) Sphinx (1.1.2) To list outdated packages, and show the latest version available: $ pip list --outdated # example output docutils (Current: 0.9.1 Latest: 0.10) Sphinx (Current: 1.1.2 Late...
Caller info attributes can be used to pass down information about the invoker to the invoked method. The declaration looks like this: using System.Runtime.CompilerServices; public void LogException(Exception ex, [CallerMemberName]string callerMemberName = "", ...
Imagine the following XML: <root> <element>hello</element> <another> hello </another> <example>Hello, <nested> I am an example </nested>.</example> </root> The following XPath expression: //*[text() = 'hel...
The installer requires PHP 5.4 or higher. If you still use the legacy PHP 5.3 version, you cannot use the Symfony Installer. Read the Creating Symfony Applications without the Installer section to learn how to proceed. - source: http://symfony.com/doc/current/book/installation.html
To iterate over several generators in parallel, use the zip builtin: for x, y in zip(a,b): print(x,y) Results in: 1 x 2 y 3 z In python 2 you should use itertools.izip instead. Here we can also see that the all the zip functions yield tuples. Note that zip will stop iterating as soon...

Page 1 of 7