> For the complete documentation index, see [llms.txt](https://pcj.icm.edu.pl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pcj.icm.edu.pl/manual/communication.md).

# Communication

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

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 0 ) PCJ.broadcast(a, Shared.a)
PCJ.waitFor(Shared.a);
```

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

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 0 ) PCJ.put(a, 1, Shared.a);
```

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

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 1 ) PCJ.get(a, 0, Shared.a);
```

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

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
if (PCJ.myId() == 0) {
        double s = PCJ.reduce(Double::sum, Shared.a);
   }
```

**PCJ.collect() -** Gathers values from all PCJ threads

```
@Storage(PcjExample.class)
enum Shared { a }
public double a;
...
double cL[] = new double[PCJ.threadCount()];
if (PCJ.myId() == 0) {
   cL = PCJ.collect(Shared.a);
   for (int i = 0; i<PCJ.threadCount(); i++){
       System.out.println("cl " + cL[i]);
   }
}
```
