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