Showing posts with label Parallel programming. Show all posts
Showing posts with label Parallel programming. Show all posts

Thursday, 25 July 2019

java async task



.map

jshell> var t1 = CompletableFuture.completedFuture(100)
t1 ==> java.util.concurrent.CompletableFuture@25f38edc[Completed normally]

jshell> var t2 = t1.thenApply(x -> x * 2)
t2 ==> java.util.concurrent.CompletableFuture@1a86f2f1[Completed normally]

jshell> t2.get()
$14 ==> 200

.fmap

jshell> var t1 = CompletableFuture.completedFuture(100)
t1 ==> java.util.concurrent.CompletableFuture@506c589e[Completed normally]

jshell> var t2 = CompletableFuture.completedFuture(200)
t2 ==> java.util.concurrent.CompletableFuture@69d0a921[Completed normally]

jshell> var result = t1.thenCompose($ -> t2)
result ==> java.util.concurrent.CompletableFuture@7aec35a[Completed normally]

jshell> result.get()
$19 ==> 200

javascript equivalent

> var t1 = Promise.resolve(100)
undefined
> var t2 = t1.then(x => x * 2)
undefined
> t2
Promise {
  200,
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }


Friday, 24 June 2016

Parallel application using OpenMP/ MacOS

brew install clang-omp
xcode-select --install

$ clang-omp --version
clang version 3.5.0
Target: x86_64-apple-darwin15.4.0
Thread model: posix

$ xcode-select --version
xcode-select version 2343.

application

#include <omp.h>
#include <stdio.h>

#define n 20                                                                                          

omp_set_num_threads(3);                                                                              
#pragma omp parallel for private(tid) schedule(static,1)                                              

for (i=0; i<n; i++) {                                                                                
 tid = omp_get_thread_num();                                                                          
 printf("Thread %d executing iteration %d\n", tid, i);                                                
}


$ clang-omp -fopenmp parallel.c