# 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]);
   }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pcj.icm.edu.pl/manual/communication-async.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
