Tutorial by Examples: alle

private static void Main(string[] args) { var a = new A(); var b = new B(); //implicit task parallelism Parallel.Invoke( () => a.DoSomeWork(), () => b.DoSomeOtherWork() ); }
If you have a foreach loop that you want to speed up and you don't mind what order the output is in, you can convert it to a parallel foreach loop by doing the following: using System; using System.Threading; using System.Threading.Tasks; public class MainClass { public static void Main...
If you are optimizing all images manually, disable APT Cruncher for a smaller APK file size. android { aaptOptions { cruncherEnabled = false } }
Multiple FOR clauses are allowed in a LOOP. The loop finishes when the first of these clauses finishes: (loop for a in '(1 2 3 4 5) for b in '(a b c) collect (list a b)) ;; Evaluates to: ((1 a) (2 b) (3 c)) Other clauses that determine if the loop should continue can be combined: ...
The degree of parallelism is the maximum number of concurrently executing tasks that will be used to process the query. var sequence = Enumerable.Range(1, 10000); var evenNumbers = sequence.AsParallel() .WithDegreeOfParallelism(4) .Where(x =&gt...
From command line: cpan -l From a Perl script: use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); my @modules = $inst->modules();
To create a parallel collection from a sequential collection, call the par method. To create a sequential collection from a parallel collection, call the seq method. This example shows how you turn a regular Vector into a ParVector, and then back again: scala> val vect = (1 to 5).toVector vect:...
PyPar is a library that uses the message passing interface (MPI) to provide parallelism in Python. A simple example in PyPar (as seen at https://github.com/daleroberts/pypar) looks like this: import pypar as pp ncpus = pp.size() rank = pp.rank() node = pp.get_processor_name() print 'I am r...
When using async queries, you can execute multiple queries at the same time, but not on the same context. If the execution time of one query is 10s, the time for the bad example will be 20s, while the time for the good example will be 10s. Bad Example IEnumerable<TResult1> result1; IEnumera...
async.parallel(tasks, afterTasksCallback) will execute a set of tasks in parallel and wait the end of all tasks (reported by the call of callback function). When tasks are finished, async call the main callback with all errors and all results of tasks. function shortTimeFunction(callback) { set...
To check if a required gem is installed, from within your code, you can use the following (using nokogiri as an example): begin found_gem = Gem::Specification.find_by_name('nokogiri') require 'nokogiri' .... <the rest of your code> rescue Gem::LoadError end However, this can ...
using System; using System.Threading; using System.Threading.Tasks; class Program { static void Main( string[] args ) { object sync = new object(); int sum = 0; Parallel.For( 1, 1000, ( i ) => { lock( sync ) sum = sum + i; // lock is necessa...
<svg width="400px" height="200px"> <text x="1em, 2em, 3em, 4em, 5em" y="3em, 4em, 5em"> Individually Spaced Text </text> </svg> The Text element supports individual placement of letters by accepting an array of values for...
When an object is exposed to the template context, its arguments-less methods are available. This is useful when these functions are "getters". But it can be hazardeous if these methods alter some data or have some side effects. Eventhough you likely trust the template writer, he may not b...
In some situations, one might want to return from a function before finishing an entire loop. The return statement can be used for this. function primefactor(n) for i in 2:n if n % i == 0 return i end end @assert false # unreachable end Usage: jul...
Julia provides macros to simplify distributing computation across multiple machines or workers. For instance, the following computes the sum of some number of squares, possibly in parallel. function sumofsquares(A) @parallel (+) for i in A i ^ 2 end end Usage: julia> sumo...
You can use parfor to execute the iterations of a loop in parallel: Example: poolobj = parpool(2); % Open a parallel pool with 2 workers s = 0; % Performing some parallel Computations parfor i=0:9 s = s + 1; end disp(s) % Outputs '10' d...
For Each row As DataRow In FooDataTable.Rows Me.RowsToProcess.Add(row) Next Dim myOptions As ParallelOptions = New ParallelOptions() myOptions.MaxDegreeOfParallelism = environment.processorcount Parallel.ForEach(RowsToProcess, myOptions, Sub(currentRow, state) ...
Gradle will only run one task at a time by default, regardless of the project structure. By using the --parallel switch, you can force Gradle to execute independent subprojects - those that have no implicit or explicit project dependencies between one another - in parallel, allowing it to run multip...
@parallel can be used to parallellize a loop, dividing steps of the loop up over different workers. As a very simple example: addprocs(3) a = collect(1:10) for idx = 1:10 println(a[idx]) end For a slightly more complex example, consider: @time begin @sync begin @paral...

Page 3 of 7