Skip to content

Commit ed63718

Browse files
authored
Updated Nbody readme.md file (oneapi-src#1027)
Restructured to match new template. Corrected MS Build information. Updated formatting and branding.
1 parent e81eb64 commit ed63718

File tree

1 file changed

+155
-197
lines changed
  • DirectProgramming/DPC++/N-BodyMethods/Nbody

1 file changed

+155
-197
lines changed

DirectProgramming/DPC++/N-BodyMethods/Nbody/README.md

Lines changed: 155 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,225 +1,193 @@
11
# `Nbody` sample
2-
An N-body simulation is a simulation of a dynamical system of particles, usually under the influence of physical forces, such as gravity. This nbody sample code is written to SYCL standards for Intel® CPUs and GPUs.
2+
An N-body simulation is a simulation of a dynamical system of particles, usually under the influence of physical forces, such as gravity. This `Nbody` sample code uses SYCL* standards for CPUs and GPUs.
33

4-
| Property | Description
5-
|:--- |:---
6-
| What you will learn | How to offload the computation to GPU using Intel® oneAPI DPC++ Compiler
7-
| Time to complete | 15 minutes
4+
| Property | Description
5+
|:--- |:---
6+
| What you will learn | How to offload complex computations to GPU
7+
| Time to complete | 15 minutes
88

99
## Purpose
10-
Nbody sample code simulates 16000 particles and for ten integration steps. Each particle's position, velocity and acceleration parameters are dependent on other (N-1) particles. This algorithm is highly data parallel and a perfect candidate to offload to GPU. The code demonstrates how to deal with multiple device kernels, which can be enqueued into a DPC++ queue for execution and how to handle parallel reductions.
10+
By default, the `Nbody` sample code simulates 16,000 particles over ten integration steps. The position, velocity, and acceleration parameters of each particle are dependent on other (N-1) particles.
1111

12-
## Prerequisites
13-
14-
| Optimized for | Description
15-
|:--- |:---
16-
| OS | Linux* Ubuntu* 18.04 <br>Windows* 10
17-
| Hardware | Skylake with GEN9 or newer
18-
| Software | Intel&reg; oneAPI DPC++ Compiler;
12+
This algorithm is highly data parallel, so the code a good candidate to offload to GPU. The code demonstrates how to deal with multiple device kernels, which can be enqueued into a SYCL queue for execution, and the code demonstrates how to handle parallel reductions.
1913

14+
## Prerequisites
15+
| Optimized for | Description
16+
|:--- |:---
17+
| OS | Ubuntu* 18.04 <br> Windows* 10
18+
| Hardware | Skylake with GEN9 or newer
19+
| Software | Intel® oneAPI DPC++ Compiler
2020

2121
## Key Implementation Details
2222
The basic SYCL* compliant implementation explained in the code includes device selector, buffer, accessor, kernel, and command groups.
2323

24-
## Building the Program for CPU and GPU
24+
## Set Environment Variables
25+
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.
2526

27+
## Build the `Nbody` Program for CPU and GPU
2628
> **Note**: If you have not already done so, set up your CLI
27-
> environment by sourcing the `setvars` script located in
28-
> the root of your oneAPI installation.
29+
> environment by sourcing the `setvars` script in the root of your oneAPI installation.
2930
>
30-
> Linux:
31+
> Linux*:
3132
> - For system wide installations: `. /opt/intel/oneapi/setvars.sh`
32-
> - For private installations: `. ~/intel/oneapi/setvars.sh`
33+
> - For private installations: ` . ~/intel/oneapi/setvars.sh`
34+
> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'`
3335
>
34-
> Windows:
36+
> Windows*:
3537
> - `C:\Program Files(x86)\Intel\oneAPI\setvars.bat`
38+
> - Windows PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'`
3639
>
37-
>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).
38-
39-
### Running Samples in Intel&reg; DevCloud
40-
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/), and see [Run the Nbody sample on the Intel&reg; DevCloud](#run-nbody-on-devcloud) below.
40+
> 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).
4141
42+
### Include Files
43+
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.
4244

43-
### Using Visual Studio Code* (Optional)
44-
45-
You can use Visual Studio Code (VS Code) extensions to set your environment, create launch configurations,
46-
and browse and download samples.
45+
### Use Visual Studio Code* (VS Code) (Optional)
46+
You can use Visual Studio Code* (VS Code) extensions to set your environment,
47+
create launch configurations, and browse and download samples.
4748

4849
The basic steps to build and run a sample using VS Code include:
49-
- Download a sample using the extension **Code Sample Browser for Intel&reg; oneAPI Toolkits**.
50-
- Configure the oneAPI environment with the extension **Environment Configurator for Intel oneAPI Toolkits**.
51-
- Open a Terminal in VS Code (**Terminal>New Terminal**).
52-
- Run the sample in the VS Code terminal using the instructions below.
50+
1. Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**.
51+
2. Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**.
52+
3. Open a terminal in VS Code (**Terminal > New Terminal**).
53+
4. Run the sample in the VS Code terminal using the instructions below.
5354

54-
To learn more about the extensions and how to configure the oneAPI environment, see
55-
[Using Visual Studio Code with Intel&reg; oneAPI Toolkits](https://software.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).
56-
57-
After learning how to use the extensions for Intel oneAPI Toolkits, return to this readme for instructions on how to build and run a sample.
58-
59-
### Include Files
60-
The include folder is located at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your development system.
55+
To learn more about the extensions and how to configure the oneAPI environment, see the
56+
[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).
6157

6258
### On Linux*
63-
Perform the following steps:
64-
1. Build the program using the following `cmake` commands.
65-
```
66-
$ mkdir build
67-
$ cd build
68-
$ cmake ..
69-
$ make
70-
```
71-
72-
2. Run the program
73-
```
74-
make run
75-
```
76-
77-
3. Clean the program
78-
```
79-
make clean
80-
```
81-
59+
1. Build the program.
60+
```
61+
mkdir build
62+
cd build
63+
cmake ..
64+
make
65+
```
8266
If an error occurs, you can get more details by running `make` with
8367
the `VERBOSE=1` argument:
8468
```
8569
make VERBOSE=1
8670
```
87-
### Troubleshooting
88-
If you receive an error message, troubleshoot the problem using the Diagnostics Utility for Intel&reg; oneAPI Toolkits, which provides system checks to find missing
89-
dependencies and permissions errors. See [Diagnostics Utility for Intel&reg; oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html).
90-
91-
### On Windows* Using Visual Studio* Version 2017 or Newer
92-
- Build the program using VS2017 or VS2019.
93-
- Right-click on the solution file and open using either VS2017 or VS2019 IDE.
94-
- Right-click on the project in Solution Explorer and select Rebuild.
95-
- From the top menu, select Debug -> Start without Debugging.
96-
97-
- Build the program using MSBuild
98-
- Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native Tools Command Prompt for VS2019"
99-
- Run the following command: `MSBuild Hello_World_GPU.sln /t:Rebuild /p:Configuration="Release"`
10071

72+
### On Windows*
73+
**Using Visual Studio**
74+
75+
Build the program using **Visual Studio 2017** or newer.
76+
1. Change to the sample directory.
77+
2. Right-click on the solution file and open the solution in the IDE.
78+
3. From the top menu, select **Debug** > **Start without Debugging**.
79+
80+
**Using MSBuild**
81+
82+
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.
83+
2. Change to the sample directory.
84+
3. Run the following command: `MSBuild Nbody.sln /t:Rebuild /p:Configuration="Release"`
85+
86+
#### Troubleshooting
87+
If you receive an error message, troubleshoot the problem using the **Diagnostics Utility for Intel® oneAPI Toolkits**. The diagnostic utility provides configuration and system checks to help find missing dependencies, permissions errors, and other issues. See the [Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html) for more information on using the utility.
88+
89+
## Run the `Nbody` Program
90+
### On Linux
91+
1. Run the program.
92+
```
93+
make run
94+
```
95+
2. Clean the program. (Optional)
96+
```
97+
make clean
98+
```
99+
### On Windows
100+
1. Change to the output directory.
101+
2. Run the executable.
102+
```
103+
Nbody.exe
104+
```
105+
106+
### Run 'Nbody' Sample in Intel® DevCloud (Optional)
107+
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. For more information, see the Intel® oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/).
108+
109+
#### Build and Run Samples in Batch Mode (Optional)
110+
You can submit build and run jobs through a Portable Bash Script (PBS). A job is a script that submitted to PBS through the `qsub` utility. By default, the `qsub` utility does not inherit the current environment variables or your current working directory, so you might need to submit jobs to configure the environment variables. To indicate the correct working directory, you can use either absolute paths or pass the `-d \<dir\>` option to `qsub`.
111+
112+
If you choose to use scripts, jobs terminate with writing a couple of files to the disk:
113+
- `<script_name>.sh.eXXXX` is the job stderr
114+
- `<script_name>.sh.oXXXX` is the job stdout
115+
116+
Here `XXXX` is the job ID, which gets printed to the screen after each `qsub` command.
117+
118+
You can inspect output of the sample.
119+
```
120+
cat run.sh.oXXXX
121+
```
122+
#### Build and Run on Intel® DevCloud
123+
1. Open a terminal on a Linux* system.
124+
2. Log in to the Intel® DevCloud.
125+
```
126+
ssh devcloud
127+
```
128+
3. Download the samples from GitHub.
129+
```
130+
git clone https://github.com/oneapi-src/oneAPI-samples.git
131+
```
132+
4. Change to the sample directory.
133+
5. Configure the sample for a GPU node. (This is a single line script.)
134+
```
135+
qsub -I -l nodes=1:gpu:ppn=2 -d .
136+
```
137+
- `-I` (upper case I) requests an interactive session.
138+
- `-l nodes=1:gpu:ppn=2` (lower case L) assigns one full GPU node.
139+
- `-d .` makes the current folder as the working directory for the task.
140+
141+
> **Note**: To inspect job progress, use the qstat utility.
142+
> ```
143+
> watch -n 1 qstat -n -1
144+
> ```
145+
> The command displays the results every second. The job is complete when no new results display.
146+
147+
6. Perform build steps you would on Linux. (Including optionally cleaning the project.)
148+
7. Run the sample.
149+
8. Disconnect from the Intel® DevCloud.
150+
```
151+
exit
152+
```
153+
154+
## Example Output
101155
### Application Parameters
102-
You can modify the NBody simulation parameters from within `GSimulation.cpp`. The configurable parameters include:
103-
- `set_npart(__);`
104-
- `set_nsteps(__);`
105-
- `set_tstep(__);`
106-
- `set_sfreq(__);`
107-
108-
Below are the default parameters:
109-
110-
* Number of particles (npart) is 16000
111-
* Number of integration steps (nsteps) is 10
112-
* Time delta (tstep) is 0.1s
113-
* Sample frequency (sfreq) is 1
114-
115-
## Example of Output
116-
===============================
117-
Initialize Gravity Simulation
118-
Target Device: Intel(R) Gen9
119-
nPart = 16000; nSteps = 10; dt = 0.1
120-
------------------------------------------------
121-
s dt kenergy time (s) GFLOPS
122-
------------------------------------------------
123-
1 0.1 26.405 0.28029 26.488
124-
2 0.2 313.77 0.066867 111.03
125-
3 0.3 926.56 0.065832 112.78
126-
4 0.4 1866.4 0.066153 112.23
127-
5 0.5 3135.6 0.065607 113.16
128-
6 0.6 4737.6 0.066544 111.57
129-
7 0.7 6676.6 0.066403 111.81
130-
8 0.8 8957.7 0.066365 111.87
131-
9 0.9 11587 0.066617 111.45
132-
10 1 14572 0.06637 111.86
133-
134-
# Total Time (s) : 0.87714
135-
# Average Performance : 112.09 +- 0.56002
136-
===============================
137-
Built target run
138-
139-
### Running the Nbody sample in the Intel&reg; DevCloud<a name="run-nbody-on-devcloud"></a>
140-
1. Open a terminal on your Linux system.
141-
2. Log in to Intel&reg; DevCloud.
142-
```
143-
ssh devcloud
144-
```
145-
3. Download the samples.
146-
```
147-
git clone https://github.com/oneapi-src/oneAPI-samples.git
148-
```
149-
150-
4. Change directories to the Nbody sample directory.
151-
```
152-
cd ~/oneAPI-samples/DirectProgramming/DPC++/N-bodyMethods/Nbody
153-
```
154-
#### Build and run the sample in batch mode
155-
The following describes the process of submitting build and run jobs to PBS.
156-
A job is a script that is submitted to PBS through the qsub utility. By default, the qsub utility does not inherit the current environment variables or your current working directory. For this reason, it is necessary to submit jobs as scripts that handle the setup of the environment variables. In order to address the working directory issue, you can either use absolute paths or pass the `-d \<dir\>` option to qsub to set the working directory.
157-
158-
#### Create the Job Scripts
159-
1. Create a build.sh script with your preferred text editor:
160-
161-
```
162-
nano build.sh
163-
```
164-
2. Add this text into the build.sh file:
165-
166-
```
167-
source /opt/intel/inteloneapi/setvars.sh > /dev/null 2>&1
168-
mkdir build
169-
cd build
170-
cmake ..
171-
make
172-
```
173-
3. Save and close the build.sh file.
174-
175-
4. Create a run.sh script with with your preferred text editor:
176-
```
177-
nano run.sh
178-
```
179-
180-
5. Add this text into the run.sh file:
181-
```
182-
source /opt/intel/inteloneapi/setvars.sh > /dev/null 2>&1
183-
cd build
184-
make run
185-
```
186-
6. Save and close the run.sh file.
187-
188-
#### Build and run
189-
Jobs submitted in batch mode are placed in a queue waiting for the necessary resources (compute nodes) to become available. The jobs will be executed on a first come basis on the first available node(s) having the requested property or label.
190-
1. Build the sample on a gpu node.
191-
192-
```
193-
qsub -l nodes=1:gpu:ppn=2 -d . build.sh
194-
```
156+
You can modify the `NBody` sample simulation parameters in `GSimulation.cpp`. Configurable parameters include:
195157
196-
Note: -l nodes=1:gpu:ppn=2 (lower case L) is used to assign one full GPU node to the job.
197-
Note: The -d . is used to configure the current folder as the working directory for the task.
158+
|Parameter | Defaults
159+
|:--- |:---
160+
|`set_npart` | Default number of particles is **16000**
161+
|`set_nsteps` | Default number of integration steps is **10**
162+
|`set_tstep` | Default time delta is **0.1**
163+
|`set_sfreq` | Default sample frequency is **1**
198164
199-
2. In order to inspect the job progress, use the qstat utility.
165+
### Example Output on Linux
200166
```
201-
watch -n 1 qstat -n -1
202-
```
203-
Note: The watch -n 1 command is used to run qstat -n -1 and display its results every second. If no results are displayed, the job has completed.
204-
205-
3. After the build job completes successfully, run the sample on a gpu node:
206-
```
207-
qsub -l nodes=1:gpu:ppn=2 -d . run.sh
208-
```
209-
4. When a job terminates, a couple of files are written to the disk:
210-
211-
`<script_name>.sh.eXXXX`, which is the job stderr
212-
213-
`<script_name>.sh.oXXXX`, which is the job stdout
214-
215-
Here XXXX is the job ID, which gets printed to the screen after each qsub command.
216-
217-
5. Inspect the output of the sample.
218-
```
219-
cat run.sh.oXXXX
167+
===============================
168+
Initialize Gravity Simulation
169+
Target Device: Intel(R) Gen9
170+
nPart = 16000; nSteps = 10; dt = 0.1
171+
------------------------------------------------
172+
s dt kenergy time (s) GFLOPS
173+
------------------------------------------------
174+
1 0.1 26.405 0.28029 26.488
175+
2 0.2 313.77 0.066867 111.03
176+
3 0.3 926.56 0.065832 112.78
177+
4 0.4 1866.4 0.066153 112.23
178+
5 0.5 3135.6 0.065607 113.16
179+
6 0.6 4737.6 0.066544 111.57
180+
7 0.7 6676.6 0.066403 111.81
181+
8 0.8 8957.7 0.066365 111.87
182+
9 0.9 11587 0.066617 111.45
183+
10 1 14572 0.06637 111.86
184+
185+
# Total Time (s) : 0.87714
186+
# Average Performance : 112.09 +- 0.56002
187+
===============================
188+
Built target run
220189
```
221-
You should see output similar to this:
222-
190+
### Example Output on Intel® DevCloud
223191
```
224192
Scanning dependencies of target run
225193
===============================
@@ -244,16 +212,6 @@ Scanning dependencies of target run
244212
===============================
245213
Built target run
246214
```
247-
248-
6. Remove the stdout and stderr files, and clean-up the project files.
249-
```
250-
rm build.sh.*; rm run.sh.*; make clean
251-
```
252-
7. Disconnect from the Intel DevCloud.
253-
```
254-
exit
255-
```
256-
257215
## License
258216
Code samples are licensed under the MIT license. See
259217
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.

0 commit comments

Comments
 (0)