# Communication - async

**PCJ.asyncBroadcast() -** Sends data from one PCJ thraed to all other threads.

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 0 ) {
     a = 5.0;
     PCJ.asyncBroadcast(a, Shared.a);
}
...    
PCJ.waitFor(Shared.a);
System.out.println("a = "+a);
```

**PCJ.asyncPut() -** Sends data from one PCJ thraed to another PCJ threads (PCJ thread 0 sends data to PCJ thread 1)

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 0 ) PCJ.asyncPut(a, 1, Shared.a);
...
if (PCJ.myId() == 1 ) {
   PCJ.waitFor(Shared.a);
   System.out.println("a = "+a);           
}
```

**PCJ.asyncGet() -** Gets data from anether PCJ thraed (form PCJ thread 1)

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
PcjFuture f = null;
double b; 
if (PCJ.myId() == 0) {
   f = PCJ.asyncGet(1, Shared.a);
 }
...
if (PCJ.myId() == 0) {
   b = (double) f.get();
   System.out.println("b = " + b);
}
```

**PCJ.asyncReduce() -** Gathers values from all PCJ threads and performs reduction (eg. sum).

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
PcjFuture f = null;
double s;
if (PCJ.myId() == 0) {
   f = PCJ.asyncReduce(Double::sum, Shared.a);
}
...
if (PCJ.myId() == 0) {
   s = (double) fr.get();
   System.out.println("s = " + s);
}
```

**PCJ.asyncCollect() -** Collects (gathers) values from all PCJ threads

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
 if (PCJ.myId() == 0) {
    PcjFuture<double[]> f = PCJ.asyncCollect(Shared.a);
    double[] w = f.get();
    for (int i = 0; i < PCJ.threadCount(); i++) {
         System.out.println("w " + w[i]);
   }
}
```
