Skip to content

Commit 3ae2935

Browse files
author
jkinsky
authored
Update particle diffusion README.md (#1047)
Updated to match new template. Updated information on Windows. Corrected multiple formatting issues.
1 parent 8a2d908 commit 3ae2935

File tree

1 file changed

+109
-94
lines changed
  • DirectProgramming/DPC++/StructuredGrids/particle-diffusion

1 file changed

+109
-94
lines changed

DirectProgramming/DPC++/StructuredGrids/particle-diffusion/README.md

Lines changed: 109 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,166 @@
1-
# `Water Molecule Diffusion` Sample
1+
# `Particle Diffusion` Sample
2+
The `Particle Diffusion` code sample implements a simple example of a Monte Carlo simulation of water molecule diffusion in tissue. This kind of computational experiment can be used to simulate the acquisition of a diffusion signal for dMRI.
23

3-
This code sample implements a simple example of a Monte Carlo simulation of water molecule diffusion in tissue. This kind of computational experiment can be used to simulate the acquisition of a diffusion signal for dMRI.
4-
5-
For comprehensive information in using oneAPI programming, see the [Intel® oneAPI Programming Guide](https://software.intel.com/en-us/oneapi-programming-guide), and use search or the table of contents to find relevant information.
6-
7-
| Property | Description
8-
|:--- |:---
9-
| What you will learn | How to offload the computation to GPU using the Intel® oneAPI DPC++/C++ Compiler
10-
| Time to complete | 20 minutes
4+
| Area | Description
5+
|:--- |:---
6+
| What you will learn | How to offload complex computation to a GPU
7+
| Time to complete | 20 minutes
118

129
## Purpose
10+
The simulation model consists of water molecules moving through a 2D array of cells in a tissue sample (water molecule diffusion). The sample uses a uniform rectilinear 2D array of digital cells. The cells are spaced regularly along each direction and are represented by circles.
1311

14-
The simulation model consists of water molecules moving through a 2D array of cells in a tissue sample (water molecule diffusion). In this code sample, we use a uniform rectilinear 2D array of digital cells, where cells are spaced regularly along each direction and are represented by circles.
15-
16-
Water molecule diffusion is simulated by defining a number of particles P (simulated water molecules) at random positions in the grid, followed by random walks of these particles in the ensemble of cells in the grid. During the random walks, particles can move randomly inside or outside simulated cells. The positions of these particles at every time step in the simulation, the number of times they go through a cell membrane (in/out), and the time every particle spends inside and outside cells can be recorded. These measurements are a simple example of useful information that can be used to simulate an MR signal.
17-
18-
> **Note**: You can find more information and a walk through for this sample at [Code Sample: Particle Diffusion – An Intel® oneAPI DPC++/C++ Compiler Example](https://www.intel.com/content/www/us/en/developer/articles/code-sample/oneapi-dpcpp-compiler-example-particle-diffusion.html).
12+
The sample code simulates water molecule diffusion by defining a number of particles P (simulated water molecules) at random positions in the grid. The code randomly walks the particles in the ensemble of cells in the grid. During the random walks, particles can move randomly inside or outside simulated cells. The program records the positions of the particles at every time step in the simulation, the number of times they go through a cell membrane (in or out), and the amount of time every particle spends inside and outside cells.
1913

20-
Performance number tabulation, if applicable.
14+
These measurements are a simple example of useful information needed for simulating a magnetic resonance (MR) signal.
2115

22-
| motionsim sample | Performance data
23-
|:--- |:---
24-
| Scalar baseline -O2 | 1.0
25-
| SYCL |
26-
| OpenMP offload |
16+
> **Note**: You can find more information about this sample and a walk-through at [Code Sample: Particle Diffusion – An Intel® oneAPI DPC++/C++ Compiler Example](https://www.intel.com/content/www/us/en/developer/articles/code-sample/oneapi-dpcpp-compiler-example-particle-diffusion.html).
2717
2818
## Prerequisites
2919
| Optimized for | Description
3020
|:--- |:---
3121
| OS | Ubuntu* 18.04 <br>Windows* 10 <br>Windows* Server 2017
3222
| Hardware | Kaby Lake with Gen9 or newer
33-
| Software | Intel&reg; oneAPI DPC++/C++ Compiler
23+
| Software | Intel® oneAPI DPC++/C++ Compiler
3424

3525
## Key Implementation Details
36-
37-
SYCL* implementation explained in this sample includes:
26+
SYCL* concepts explained in this sample include:
3827
- SYCL* queues (including device selectors and exception handlers).
3928
- SYCL buffers and accessors.
4029
- The ability to call a function inside a kernel definition and pass accessor arguments as pointers.
4130
- Optimization using API-based programming and Atomic Functions.
4231

43-
SYCL implementation is explained in further detail in the source code.
32+
The SYCL implementation is explained in the source code.
33+
34+
The sample uses the Intel® Math Kernel Library (Intel® MKL) to generate random numbers on the CPU and device. Precise generators are used within this library to ensure that the numbers generated on the CPU and device are relatively equivalent (relative accuracy 10E-07).
4435

45-
Intel&reg; Math Kernel Library (Intel&reg; MKL) is used to generate random numbers on the CPU and device. Precise generators are used within this library to ensure that the numbers generated on the CPU and device are relatively equivalent (relative accuracy 10E-07).
36+
>**Note**: For comprehensive information about oneAPI programming, see the [Intel® oneAPI Programming Guide](https://software.intel.com/en-us/oneapi-programming-guide). (Use search or the table of contents to find relevant information quickly.)
4637
47-
## Build the `particle-diffusion` Program for CPU and GPU
38+
## Set Environment Variables
39+
When working with the command-line interface (CLI), you should configure the oneAPI toolkits using environment variables. Set up your CLI environment by sourcing the `setvars` script every time you open a new terminal window. This practice ensures that your compiler, libraries, and tools are ready for development.
4840

41+
## Build the `Particle Diffusion` Program for CPU and GPU
4942
> **Note**: If you have not already done so, set up your CLI
50-
> environment by sourcing the `setvars` script located in
51-
> the root of your oneAPI installation.
43+
> environment by sourcing the `setvars` script in the root of your oneAPI installation.
5244
>
53-
> Linux:
45+
> Linux*:
5446
> - For system wide installations: `. /opt/intel/oneapi/setvars.sh`
55-
> - For private installations: `. ~/intel/oneapi/setvars.sh`
47+
> - For private installations: ` . ~/intel/oneapi/setvars.sh`
48+
> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'`
5649
>
57-
> Windows:
50+
> Windows*:
5851
> - `C:\Program Files(x86)\Intel\oneAPI\setvars.bat`
52+
> - Windows PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'`
5953
>
60-
>For more information on environment variables, see Use the setvars Script for [Linux or macOS](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html), or [Windows](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html).
54+
> For more information on configuring environment variables, see [Use the setvars Script with Linux* or macOS*](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html) or [Use the setvars Script with Windows*](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html).
6155
6256
### Include Files
63-
The include folder is located at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your
64-
development system.
57+
The include folder is at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your development system. You might need to use some of the resources from this location to build the sample.
6558

66-
### Use Visual Studio Code* (Optional)
59+
>**Note**: You can get the common resources from the [oneAPI-samples](https://github.com/oneapi-src/oneAPI-samples/tree/master/common) GitHub repository.
6760
68-
You can use Visual Studio Code (VS Code) extensions to set your environment,
61+
### Use Visual Studio Code* (VS Code) (Optional)
62+
You can use Visual Studio Code* (VS Code) extensions to set your environment,
6963
create launch configurations, and browse and download samples.
7064

7165
The basic steps to build and run a sample using VS Code include:
72-
- Download a sample using the extension **Code Sample Browser for Intel&reg; oneAPI Toolkits**.
73-
- Configure the oneAPI environment with the extension **Environment Configurator for Intel&reg; oneAPI Toolkits**.
74-
- Open a Terminal in VS Code (**Terminal>New Terminal**).
75-
- Run the sample in the VS Code terminal using the instructions below.
66+
1. Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**.
67+
2. Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**.
68+
3. Open a terminal in VS Code (**Terminal > New Terminal**).
69+
4. Run the sample in the VS Code terminal using the instructions below.
7670

77-
To learn more about the extensions and how to configure the oneAPI environment, see
78-
[Using Visual Studio Code with Intel&reg; oneAPI Toolkits User Guide](https://software.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).
71+
To learn more about the extensions and how to configure the oneAPI environment, see the
72+
[Using Visual Studio Code with Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html)
7973

80-
## Build the Sample
8174
### On Linux*
75+
1. Change to the sample directory.
76+
2. Build the program.
77+
```
78+
mkdir build
79+
cd build
80+
cmake ..
81+
make
82+
```
8283

83-
1. Change to the particle diffusion directory.
84+
### On Windows*
85+
1. Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native Tools Command Prompt for VS2019" or whatever is appropriate for your Visual Studio* version.
86+
2. Change to the sample directory.
87+
3. Build the program.
88+
```
89+
nmake
90+
```
91+
>**Note**: This will run the program too.
92+
93+
## Run the `Particle Diffusion` Program
94+
### Configurable Application Parameters
95+
The following table describes each command line parameter you can use.
96+
97+
|Flag and Argument |Description |Range of Possible Values |Default
98+
|:--- |:--- |:--- |:---
99+
|`-i num_iterations` | Number of iterations | [1, &#8734;] | 10000
100+
|`-p num_particles` | Number of particles | [1, &#8734;] | 256
101+
|`-g grid_size` | Size of square grid | [1, &#8734;] | 22
102+
|`-r rng_seed` | Random number generator seed | [-&#8734;, &#8734;] | 777
103+
|`-c cpu_flag` | Turns cpu comparison on/off | [1 \| 0] | 0
104+
|`-o output_flag` | Turns grid output on/off | [1 \| 0] | 1
105+
|`-h` | Help message. | |
106+
107+
#### Parameter Rules
108+
- If you do not specify parameters, the program will use the defaults for all parameters.
109+
- If you do not specify a specific parameter, the program will use the default value for that parameter.
110+
- If you specify a `grid_size` greater than **44**, the program will not print the grid even if the grid output flag is on.
111+
- The input flags apply to Linux only. Pass values without flags on Windows.
112+
- Enter `motionsim.exe -h` to display help text and exit the program.
113+
114+
Example usage with default values on Linux:
84115
```
85-
$ cd particle-diffusion
116+
motionsim.exe -i 10000 -p 256 -g 22 -r 777 -c 0 -o 1
86117
```
87-
2. Build the program.
118+
Example usage with default values on Windows:
88119
```
89-
$ mkdir build
90-
$ cd build
91-
$ cmake ..
92-
$ make -s -j
120+
motionsim.exe 10000 256 22 777 0 1
93121
```
94122

95-
### On Windows*
96-
1. Use `nmake` to build the sample.
97-
98-
> **Note**: `nmake clean` removes temporary files.
99-
100-
### Run Samples in Intel&reg; DevCloud
101-
If running a sample in the Intel&reg; DevCloud, you must specify the compute node (CPU, GPU, FPGA) and whether to run in batch or interactive mode. For more information, see the Intel&reg; oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/).
102-
103-
## Run the Sample
123+
### On Linux
124+
1. Run the program.
125+
```
126+
make run
127+
```
128+
Alternatively, specify the input values, and run the program directly.
129+
```
130+
./src/motionsim.exe -i 10000 -p 256 -g 22 -r 777 -c 0 -o 1
131+
```
132+
2. Clean the project files. (Optional)
133+
```
134+
make clean
135+
```
104136

105-
### On Windows*
106-
1. Run the sample.
137+
### On Windows
138+
1. Specify the input values, and run the program.
107139
```
108140
motionsim.exe 10000 256 22 777 0 1
109141
```
142+
2. Clean the projects files. (Optional)
143+
```
144+
nmake clean
145+
```
110146

111-
### On Linux*
112-
1. Run the sample using default parameters.
113-
```
114-
$ make run
115-
```
116-
2. Alternatively, run the sample using custom parameters shown below.
117-
118-
The following table describes each command line parameter (applies to Linux builds only)
119-
120-
| Flag and Argument | Description | Range of Possible Values | Default
121-
|:--- |:--- |:--- |:---
122-
| `-i num_iterations` | Number of iterations | [1, &#8734;] | 10000
123-
| `-p num_particles` | Number of particles | [1, &#8734;] | 256
124-
| `-g grid_size` | Size of square grid | [1, &#8734;] | 22
125-
| `-r rng_seed` | Random number generator seed | [-&#8734;, &#8734;] | 777
126-
| `-c cpu_flag` | Turns cpu comparison on/off | [1 \| 0] | 0
127-
| `-o output_flag` | Turns grid output on/off | [1 \| 0] | 1
128-
| `-h` | Help message. | |
129-
130-
> **Note**:
131-
>
132-
>- If the grid size specified is greater than **44**, the application will not print the grid even if the grid output flag is on.
133-
>- If a particular parameter is not specified, the application will choose the default value for that parameter.
134-
>- Typing `$ ./src/motionsim.exe -h` displays a brief help message and exits the program.
147+
### Build and Run the `Particle Diffusion` Sample in Intel® DevCloud (Optional)
148+
When running a sample in the Intel® DevCloud, you must specify the compute node (CPU, GPU, FPGA) and whether to run in batch or interactive mode. You can specify a GPU node using a single line script.
135149

136-
You can run the program using the above parameters with the application binary:
137-
```
138-
$ ./src/motionsim.exe
139150
```
140-
Example usage:
141-
```
142-
$ ./src/motionsim.exe -i 1000 -p 200 -g 30 -r 777 -c 1 -o 0
151+
qsub -I -l nodes=1:gpu:ppn=2 -d .
143152
```
153+
154+
- `-I` (upper case I) requests an interactive session.
155+
- `-l nodes=1:gpu:ppn=2` (lower case L) assigns one full GPU node.
156+
- `-d .` makes the current folder as the working directory for the task.
157+
158+
For more information on how to specify compute nodes read, [Launch and manage jobs](https://devcloud.intel.com/oneapi/documentation/job-submission/) in the Intel® DevCloud for oneAPI Documentation.
159+
160+
For more information on using Intel® DevCloud, see the Intel® oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/).
161+
144162
## Example Output
145163
```
146-
**Running with default parameters**
147-
148164
Running on: Intel(R) Gen9
149165
Device Max Work Group Size: 256
150166
Device Max EUCount: 24
@@ -240,7 +256,6 @@ $ ./src/motionsim.exe -i 1000 -p 200 -g 30 -r 777 -c 1 -o 0
240256
**********************************************************
241257
242258
Success.
243-
Built target run
244259
```
245260

246261
## License

0 commit comments

Comments
 (0)