|
71 | 71 | "name": "stderr", |
72 | 72 | "output_type": "stream", |
73 | 73 | "text": [ |
74 | | - "NUMA domain count autodetection failed, assuming 1\n", |
75 | 74 | "Operator `Kernel` ran in 0.01 s\n" |
76 | 75 | ] |
77 | 76 | }, |
|
159 | 158 | "output_type": "stream", |
160 | 159 | "text": [ |
161 | 160 | "\n", |
162 | | - "Symbol defining a non-convex iteration sub-space derived from a ``parent``\n", |
163 | | - "Dimension, implemented by the compiler generating conditional \"if-then\" code\n", |
164 | | - "within the parent Dimension's iteration space.\n", |
| 161 | + " Symbol defining a non-convex iteration sub-space derived from a ``parent``\n", |
| 162 | + " Dimension, implemented by the compiler generating conditional \"if-then\" code\n", |
| 163 | + " within the parent Dimension's iteration space.\n", |
165 | 164 | "\n", |
166 | | - "Parameters\n", |
167 | | - "----------\n", |
168 | | - "name : str\n", |
169 | | - " Name of the dimension.\n", |
170 | | - "parent : Dimension\n", |
171 | | - " The parent Dimension.\n", |
172 | | - "factor : int, optional, default=None\n", |
173 | | - " The number of iterations between two executions of the if-branch. If None\n", |
174 | | - " (default), ``condition`` must be provided.\n", |
175 | | - "condition : expr-like, optional, default=None\n", |
176 | | - " An arbitrary SymPy expression, typically involving the ``parent``\n", |
177 | | - " Dimension. When it evaluates to True, the if-branch is executed. If None\n", |
178 | | - " (default), ``factor`` must be provided.\n", |
179 | | - "indirect : bool, optional, default=False\n", |
180 | | - " If True, use `self`, rather than the parent Dimension, to\n", |
181 | | - " index into arrays. A typical use case is when arrays are accessed\n", |
182 | | - " indirectly via the ``condition`` expression.\n", |
183 | | - "relation: Or/And, default=And\n", |
184 | | - " How this ConditionalDimension will be combined with other ones.\n", |
| 165 | + " Parameters\n", |
| 166 | + " ----------\n", |
| 167 | + " name : str\n", |
| 168 | + " Name of the dimension.\n", |
| 169 | + " parent : Dimension\n", |
| 170 | + " The parent Dimension.\n", |
| 171 | + " factor : int, optional, default=None\n", |
| 172 | + " The number of iterations between two executions of the if-branch. If None\n", |
| 173 | + " (default), ``condition`` must be provided.\n", |
| 174 | + " condition : expr-like, optional, default=None\n", |
| 175 | + " An arbitrary SymPy expression, typically involving the ``parent``\n", |
| 176 | + " Dimension. When it evaluates to True, the if-branch is executed. If None\n", |
| 177 | + " (default), ``factor`` must be provided.\n", |
| 178 | + " indirect : bool, optional, default=False\n", |
| 179 | + " If True, use `self`, rather than the parent Dimension, to\n", |
| 180 | + " index into arrays. A typical use case is when arrays are accessed\n", |
| 181 | + " indirectly via the ``condition`` expression.\n", |
| 182 | + " relation: Or/And, default=And\n", |
| 183 | + " How this ConditionalDimension will be combined with other ones.\n", |
185 | 184 | "\n", |
186 | | - "Examples\n", |
187 | | - "--------\n", |
188 | | - "Among the other things, ConditionalDimensions are indicated to implement\n", |
189 | | - "Function subsampling. In the following example, an Operator evaluates the\n", |
190 | | - "Function ``g`` and saves its content into ``f`` every ``factor=4`` iterations.\n", |
| 185 | + " Examples\n", |
| 186 | + " --------\n", |
| 187 | + " Among the other things, ConditionalDimensions are indicated to implement\n", |
| 188 | + " Function subsampling. In the following example, an Operator evaluates the\n", |
| 189 | + " Function ``g`` and saves its content into ``f`` every ``factor=4`` iterations.\n", |
191 | 190 | "\n", |
192 | | - ">>> from devito import Dimension, ConditionalDimension, Function, Eq, Operator\n", |
193 | | - ">>> size, factor = 16, 4\n", |
194 | | - ">>> i = Dimension(name='i')\n", |
195 | | - ">>> ci = ConditionalDimension(name='ci', parent=i, factor=factor)\n", |
196 | | - ">>> g = Function(name='g', shape=(size,), dimensions=(i,))\n", |
197 | | - ">>> f = Function(name='f', shape=(int(size/factor),), dimensions=(ci,))\n", |
198 | | - ">>> op = Operator([Eq(g, 1), Eq(f, g)])\n", |
| 191 | + " >>> from devito import Dimension, ConditionalDimension, Function, Eq, Operator\n", |
| 192 | + " >>> size, factor = 16, 4\n", |
| 193 | + " >>> i = Dimension(name='i')\n", |
| 194 | + " >>> ci = ConditionalDimension(name='ci', parent=i, factor=factor)\n", |
| 195 | + " >>> g = Function(name='g', shape=(size,), dimensions=(i,))\n", |
| 196 | + " >>> f = Function(name='f', shape=(int(size/factor),), dimensions=(ci,))\n", |
| 197 | + " >>> op = Operator([Eq(g, 1), Eq(f, g)])\n", |
199 | 198 | "\n", |
200 | | - "The Operator generates the following for-loop (pseudocode)\n", |
| 199 | + " The Operator generates the following for-loop (pseudocode)\n", |
201 | 200 | "\n", |
202 | | - ".. code-block:: C\n", |
| 201 | + " .. code-block:: C\n", |
203 | 202 | "\n", |
204 | | - " for (int i = i_m; i <= i_M; i += 1) {\n", |
205 | | - " g[i] = 1;\n", |
206 | | - " if (i%4 == 0) {\n", |
207 | | - " f[i / 4] = g[i];\n", |
208 | | - " }\n", |
209 | | - " }\n", |
| 203 | + " for (int i = i_m; i <= i_M; i += 1) {\n", |
| 204 | + " g[i] = 1;\n", |
| 205 | + " if (i%4 == 0) {\n", |
| 206 | + " f[i / 4] = g[i];\n", |
| 207 | + " }\n", |
| 208 | + " }\n", |
210 | 209 | "\n", |
211 | | - "Another typical use case is when one needs to constrain the execution of\n", |
212 | | - "loop iterations so that certain conditions are honoured. The following\n", |
213 | | - "artificial example uses ConditionalDimension to guard against out-of-bounds\n", |
214 | | - "accesses in indirectly accessed arrays.\n", |
| 210 | + " Another typical use case is when one needs to constrain the execution of\n", |
| 211 | + " loop iterations so that certain conditions are honoured. The following\n", |
| 212 | + " artificial example uses ConditionalDimension to guard against out-of-bounds\n", |
| 213 | + " accesses in indirectly accessed arrays.\n", |
215 | 214 | "\n", |
216 | | - ">>> from sympy import And\n", |
217 | | - ">>> ci = ConditionalDimension(name='ci', parent=i,\n", |
218 | | - "... condition=And(g[i] > 0, g[i] < 4, evaluate=False))\n", |
219 | | - ">>> f = Function(name='f', shape=(int(size/factor),), dimensions=(ci,))\n", |
220 | | - ">>> op = Operator(Eq(f[g[i]], f[g[i]] + 1))\n", |
| 215 | + " >>> from sympy import And\n", |
| 216 | + " >>> ci = ConditionalDimension(name='ci', parent=i,\n", |
| 217 | + " ... condition=And(g[i] > 0, g[i] < 4, evaluate=False))\n", |
| 218 | + " >>> f = Function(name='f', shape=(int(size/factor),), dimensions=(ci,))\n", |
| 219 | + " >>> op = Operator(Eq(f[g[i]], f[g[i]] + 1))\n", |
221 | 220 | "\n", |
222 | | - "The Operator generates the following for-loop (pseudocode)\n", |
| 221 | + " The Operator generates the following for-loop (pseudocode)\n", |
223 | 222 | "\n", |
224 | | - ".. code-block:: C\n", |
| 223 | + " .. code-block:: C\n", |
225 | 224 | "\n", |
226 | | - " for (int i = i_m; i <= i_M; i += 1) {\n", |
227 | | - " if (g[i] > 0 && g[i] < 4) {\n", |
228 | | - " f[g[i]] = f[g[i]] + 1;\n", |
229 | | - " }\n", |
230 | | - " }\n", |
| 225 | + " for (int i = i_m; i <= i_M; i += 1) {\n", |
| 226 | + " if (g[i] > 0 && g[i] < 4) {\n", |
| 227 | + " f[g[i]] = f[g[i]] + 1;\n", |
| 228 | + " }\n", |
| 229 | + " }\n", |
231 | 230 | "\n", |
232 | | - "\n" |
| 231 | + " \n" |
233 | 232 | ] |
234 | 233 | } |
235 | 234 | ], |
|
322 | 321 | "output_type": "stream", |
323 | 322 | "text": [ |
324 | 323 | "START(section0)\n", |
325 | | - "#pragma omp parallel num_threads(nthreads)\n", |
| 324 | + "for (int x = x_m; x <= x_M; x += 1)\n", |
326 | 325 | "{\n", |
327 | | - " #pragma omp for schedule(static,1)\n", |
328 | | - " for (int x = x_m; x <= x_M; x += 1)\n", |
| 326 | + " #pragma omp simd aligned(f:64)\n", |
| 327 | + " for (int y = y_m; y <= y_M; y += 1)\n", |
329 | 328 | " {\n", |
330 | | - " #pragma omp simd aligned(f:16)\n", |
331 | | - " for (int y = y_m; y <= y_M; y += 1)\n", |
| 329 | + " if (f[x + 1][y + 1] > 0)\n", |
332 | 330 | " {\n", |
333 | | - " if (f[x + 1][y + 1] > 0)\n", |
334 | | - " {\n", |
335 | | - " f[x + 1][y + 1] = f[x + 1][y + 1] + 1;\n", |
336 | | - " }\n", |
| 331 | + " f[x + 1][y + 1] = f[x + 1][y + 1] + 1;\n", |
337 | 332 | " }\n", |
338 | 333 | " }\n", |
339 | 334 | "}\n", |
|
402 | 397 | "output_type": "stream", |
403 | 398 | "text": [ |
404 | 399 | "START(section0)\n", |
405 | | - "#pragma omp parallel num_threads(nthreads)\n", |
| 400 | + "for (int x = x_m; x <= x_M; x += 1)\n", |
406 | 401 | "{\n", |
407 | | - " #pragma omp for schedule(static,1)\n", |
408 | | - " for (int x = x_m; x <= x_M; x += 1)\n", |
| 402 | + " #pragma omp simd aligned(f,g:64)\n", |
| 403 | + " for (int y = y_m; y <= y_M; y += 1)\n", |
409 | 404 | " {\n", |
410 | | - " #pragma omp simd aligned(f,g:16)\n", |
411 | | - " for (int y = y_m; y <= y_M; y += 1)\n", |
| 405 | + " if (y < 5 && g[x + 1][y + 1] != 0)\n", |
412 | 406 | " {\n", |
413 | | - " if (y < 5 && g[x + 1][y + 1] != 0)\n", |
414 | | - " {\n", |
415 | | - " f[x + 1][y + 1] = f[x + 1][y + 1] + g[x + 1][y + 1];\n", |
416 | | - " }\n", |
| 407 | + " f[x + 1][y + 1] = f[x + 1][y + 1] + g[x + 1][y + 1];\n", |
417 | 408 | " }\n", |
418 | 409 | " }\n", |
419 | 410 | "}\n", |
|
498 | 489 | "output_type": "stream", |
499 | 490 | "text": [ |
500 | 491 | "START(section0)\n", |
501 | | - "#pragma omp parallel num_threads(nthreads)\n", |
| 492 | + "for (int x = x_m; x <= x_M; x += 1)\n", |
502 | 493 | "{\n", |
503 | | - " #pragma omp for schedule(static,1)\n", |
504 | | - " for (int x = x_m; x <= x_M; x += 1)\n", |
| 494 | + " for (int y = y_m; y <= y_M; y += 1)\n", |
505 | 495 | " {\n", |
506 | | - " for (int y = y_m; y <= y_M; y += 1)\n", |
| 496 | + " if (y < 5 && g[x + 1][y + 1] != 0)\n", |
507 | 497 | " {\n", |
508 | | - " if (y < 5 && g[x + 1][y + 1] != 0)\n", |
509 | | - " {\n", |
510 | | - " h[x + 1][y + 1] = g[x + 1][y + 1] + h[x + 1][y + 1];\n", |
511 | | - " }\n", |
| 498 | + " h[x + 1][y + 1] = g[x + 1][y + 1] + h[x + 1][y + 1];\n", |
512 | 499 | " }\n", |
513 | 500 | " }\n", |
514 | 501 | "}\n", |
|
564 | 551 | "execution_count": 9, |
565 | 552 | "metadata": {}, |
566 | 553 | "outputs": [ |
| 554 | + { |
| 555 | + "name": "stdout", |
| 556 | + "output_type": "stream", |
| 557 | + "text": [ |
| 558 | + "START(section0)\n", |
| 559 | + "for (int i = i_m; i <= i_M; i += 1)\n", |
| 560 | + "{\n", |
| 561 | + " if ((i)%(cif) == 0)\n", |
| 562 | + " {\n", |
| 563 | + " f[i / cif] = g[i];\n", |
| 564 | + " }\n", |
| 565 | + "}\n", |
| 566 | + "STOP(section0,timers)\n" |
| 567 | + ] |
| 568 | + }, |
567 | 569 | { |
568 | 570 | "name": "stderr", |
569 | 571 | "output_type": "stream", |
|
575 | 577 | "name": "stdout", |
576 | 578 | "output_type": "stream", |
577 | 579 | "text": [ |
578 | | - "START(section0)\n", |
579 | | - "#pragma omp parallel num_threads(nthreads)\n", |
580 | | - "{\n", |
581 | | - " #pragma omp for schedule(static,1)\n", |
582 | | - " for (int i = i_m; i <= i_M; i += 1)\n", |
583 | | - " {\n", |
584 | | - " if ((i)%(cif) == 0)\n", |
585 | | - " {\n", |
586 | | - " f[i / cif] = g[i];\n", |
587 | | - " }\n", |
588 | | - " }\n", |
589 | | - "}\n", |
590 | | - "STOP(section0,timers)\n", |
591 | 580 | "\n", |
592 | 581 | " Data in g \n", |
593 | 582 | " [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.]\n", |
|
695 | 684 | "output_type": "stream", |
696 | 685 | "text": [ |
697 | 686 | "START(section0)\n", |
698 | | - "#pragma omp parallel num_threads(nthreads)\n", |
| 687 | + "for (int x = x_m; x <= x_M; x += 1)\n", |
699 | 688 | "{\n", |
700 | | - " #pragma omp for collapse(2) schedule(static,1) reduction(+:g[1])\n", |
701 | | - " for (int x = x_m; x <= x_M; x += 1)\n", |
| 689 | + " for (int y = y_m; y <= y_M; y += 1)\n", |
702 | 690 | " {\n", |
703 | | - " for (int y = y_m; y <= y_M; y += 1)\n", |
| 691 | + " if (f[x][y] != 0)\n", |
704 | 692 | " {\n", |
705 | | - " if (f[x][y] != 0)\n", |
706 | | - " {\n", |
707 | | - " g[1] += 1;\n", |
708 | | - " }\n", |
| 693 | + " g[1] += 1;\n", |
709 | 694 | " }\n", |
710 | 695 | " }\n", |
711 | 696 | "}\n", |
|
715 | 700 | { |
716 | 701 | "data": { |
717 | 702 | "text/plain": [ |
718 | | - "np.int32(10)" |
| 703 | + "10" |
719 | 704 | ] |
720 | 705 | }, |
721 | 706 | "execution_count": 11, |
|
852 | 837 | "name": "python", |
853 | 838 | "nbconvert_exporter": "python", |
854 | 839 | "pygments_lexer": "ipython3", |
855 | | - "version": "3.13.11" |
| 840 | + "version": "3.11.0rc1" |
856 | 841 | } |
857 | 842 | }, |
858 | 843 | "nbformat": 4, |
|
0 commit comments