| 818 | return np.block(combined.reshape(ext_mesh).tolist()) |
| 819 | |
| 820 | def allreduce_data_norm(self, layout=None, order=2): |
| 821 | # Change layout |
| 822 | if layout is not None: |
| 823 | self.change_layout(layout) |
| 824 | # Compute local data |
| 825 | if self.data.size == 0: |
| 826 | norm = 0 |
| 827 | elif order == np.inf: |
| 828 | norm = np.max(np.abs(self.data)) |
| 829 | else: |
| 830 | norm = np.sum(np.abs(self.data)**order) |
| 831 | # Reduce |
| 832 | if order == np.inf: |
| 833 | if self.dist.comm.size > 1: |
| 834 | norm = self.dist.comm.allreduce(norm, op=MPI.MAX) |
| 835 | else: |
| 836 | if self.dist.comm.size > 1: |
| 837 | norm = self.dist.comm.allreduce(norm, op=MPI.SUM) |
| 838 | norm = norm ** (1 / order) |
| 839 | return norm |
| 840 | |
| 841 | def allreduce_data_max(self, layout=None): |
| 842 | return self.allreduce_data_norm(layout=layout, order=np.inf) |