|
1 | 1 | # `1D-Heat-Transfer` Sample
|
2 | 2 |
|
3 |
| -This code sample demonstrates the simulation of a one-dimensional heat transfer process using SYCL*. Kernels in this example are implemented as a discretized differential equation with the second derivative in space and the first derivative in time. |
| 3 | +This `1D-Heat-Transfer` sample demonstrates the simulation of a one-dimensional heat transfer process. Kernels in this example are implemented as a discretized differential equation with the second derivative in space and the first derivative in time. |
4 | 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 simulate 1D Heat Transfer using Intel® oneAPI DPC++ Compiler |
10 |
| -| Time to complete | 10 minutes |
| 5 | +| Area | Description |
| 6 | +|:--- |:--- |
| 7 | +| What you will learn | How to simulate 1D Heat Transfer using SYCL* |
| 8 | +| Time to complete | 10 minutes |
11 | 9 |
|
12 | 10 |
|
13 | 11 | ## Purpose
|
| 12 | +This `1D-Heat-Transfer` sample is an application that simulates the heat |
| 13 | +propagation on a one-dimensional isotropic and homogeneous medium. The code sample includes both parallel and serial calculations of heat |
| 14 | +propagation. |
14 | 15 |
|
15 |
| -1D-Heat-Transfer is a SYCL*-compliant application that simulates the heat |
16 |
| -propagation on a one-dimensional isotropic and homogeneous medium. The |
17 |
| -following equation is used in the simulation of heat propagation: |
| 16 | +The following equation is used in the simulation of heat propagation: |
18 | 17 |
|
19 |
| -$dU/dt = k * d^2U/dx^2$ |
| 18 | +$ |
| 19 | +dU/dt = k * d^2U/dx^2 |
| 20 | +$ |
20 | 21 |
|
21 |
| -Where: |
| 22 | +where: |
22 | 23 | - $dU/dt$ is the rate of change of temperature at a point.
|
23 |
| -- $k$ is the thermal diffusivity. |
| 24 | +- k is the thermal diffusivity. |
24 | 25 | - $d^2U/dx^2$ is the second spatial derivative.
|
25 | 26 |
|
26 |
| -or |
| 27 | +or: |
27 | 28 |
|
28 |
| -$U(i) = C * (U(i+1) - 2 * U(i) + U(i-1)) + U(i)$ |
| 29 | +$ |
| 30 | +U(i) = C * (U(i+1) - 2 * U(i) + U(i-1)) + U(i) |
| 31 | +$ |
29 | 32 |
|
30 |
| -Where: |
| 33 | +where: |
31 | 34 | - constant $C = k * dt / (dx * dx)$
|
32 | 35 |
|
33 |
| -The code sample includes both parallel and serial calculations of heat |
34 |
| -propagation. The code sample attempts to execute on an |
35 |
| -available GPU and will fallback to the system CPU if a compatible GPU is |
36 |
| -not detected. The results are stored in a file. |
37 |
| - |
38 | 36 | ## Prerequisites
|
39 |
| - |
40 | 37 | | Optimized for | Description
|
41 | 38 | |:--- |:---
|
42 |
| -| OS | Ubuntu* 18.04 |
| 39 | +| OS | Ubuntu* 18.04 <br> Windows* 10 |
43 | 40 | | Hardware | Skylake with GEN9 or newer
|
44 |
| -| Software | Intel® oneAPI DPC++/C++ Compiler |
| 41 | +| Software | Intel® oneAPI DPC++/C++ Compiler |
45 | 42 |
|
46 | 43 | ## Key Implementation Details
|
47 |
| - |
48 | 44 | The basic SYCL* implementation explained in the code includes a device
|
49 | 45 | selector, buffer, accessor, USM allocation, kernel, and command
|
50 | 46 | groups.
|
51 | 47 |
|
52 |
| -## Build the 1d_HeatTransfer Program for CPU and GPU |
| 48 | +The program attempts to offload the computations to a GPU first. If the program cannot detect a compatible GPU, the program runs on the CPU (host device). |
| 49 | + |
| 50 | +## Set Environment Variables |
| 51 | +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. |
| 52 | + |
| 53 | +>**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.) |
53 | 54 |
|
| 55 | +## Build the `1D-Heat-Transfer` Program for CPU and GPU |
54 | 56 | > **Note**: If you have not already done so, set up your CLI
|
55 |
| -> environment by sourcing the `setvars` script located in |
56 |
| -> the root of your oneAPI installation. |
| 57 | +> environment by sourcing the `setvars` script in the root of your oneAPI installation. |
57 | 58 | >
|
58 |
| -> Linux: |
| 59 | +> Linux*: |
59 | 60 | > - For system wide installations: `. /opt/intel/oneapi/setvars.sh`
|
60 |
| -> - For private installations: `. ~/intel/oneapi/setvars.sh` |
| 61 | +> - For private installations: ` . ~/intel/oneapi/setvars.sh` |
| 62 | +> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'` |
61 | 63 | >
|
62 |
| -> Windows: |
| 64 | +> Windows*: |
63 | 65 | > - `C:\Program Files(x86)\Intel\oneAPI\setvars.bat`
|
| 66 | +> - Windows PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'` |
64 | 67 | >
|
65 |
| ->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). |
66 |
| -
|
| 68 | +> 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). |
67 | 69 |
|
68 | 70 | ### Include Files
|
| 71 | +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. |
69 | 72 |
|
70 |
| -The include folder is located at |
71 |
| -`%ONEAPI_ROOT%\dev-utilities\latest\include` on your development |
72 |
| -system". |
73 |
| - |
| 73 | +>**Note**: You can get the common resources from the [oneAPI-samples](https://github.com/oneapi-src/oneAPI-samples/tree/master/common) GitHub repository. |
74 | 74 |
|
75 |
| -### Use Visual Studio Code* (Optional) |
76 | 75 |
|
77 |
| -You can use Visual Studio Code (VS Code) extensions to set your environment, create launch configurations, and browse and download samples. |
| 76 | +### Use Visual Studio Code* (VS Code) (Optional) |
| 77 | +You can use Visual Studio Code* (VS Code) extensions to set your environment, |
| 78 | +create launch configurations, and browse and download samples. |
78 | 79 |
|
79 | 80 | The basic steps to build and run a sample using VS Code include:
|
80 |
| - - Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**. |
81 |
| - - Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**. |
82 |
| - - Open a Terminal in VS Code (**Terminal>New Terminal**). |
83 |
| - - Run the sample in the VS Code terminal using the instructions below. |
84 |
| - |
85 |
| -To learn more about the extensions and how to configure the oneAPI environment, see |
86 |
| -[Using Visual Studio Code with Intel® oneAPI Toolkits User Guide](https://software.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html). |
| 81 | + 1. Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**. |
| 82 | + 2. Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**. |
| 83 | + 3. Open a terminal in VS Code (**Terminal > New Terminal**). |
| 84 | + 4. Run the sample in the VS Code terminal using the instructions below. |
87 | 85 |
|
| 86 | +To learn more about the extensions and how to configure the oneAPI environment, see the |
| 87 | +[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). |
88 | 88 |
|
89 | 89 | ### On Linux*
|
90 |
| -1. Build the program using the following `cmake` commands. |
91 |
| - ``` |
92 |
| - $ cd 1d_HeatTransfer |
93 |
| - $ mkdir build |
94 |
| - $ cd build |
95 |
| - $ cmake .. |
96 |
| - $ make -j |
97 |
| - ``` |
98 |
| -2. Run the program |
| 90 | +1. Change to the sample directory. |
| 91 | +2. Build the program. |
99 | 92 | ```
|
100 |
| - $ make run |
| 93 | + mkdir build |
| 94 | + cd build |
| 95 | + cmake .. |
| 96 | + make -j |
101 | 97 | ```
|
| 98 | +> **Note**: The `make -j` flag allows multiple jobs simultaneously. |
| 99 | +
|
102 | 100 | If an error occurs, you can get more details by running `make` with
|
103 | 101 | the `VERBOSE=1` argument:
|
104 | 102 | ```
|
105 | 103 | make VERBOSE=1
|
106 | 104 | ```
|
107 |
| -#### Troubleshooting |
108 |
| -If you receive an error message, troubleshoot the problem using the Diagnostics Utility for Intel® oneAPI Toolkits, which provides system checks to find missing |
109 |
| -dependencies and permissions errors. See [Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html). |
110 | 105 |
|
111 |
| -### On Windows* Using Visual Studio* Version 2017 or Newer |
112 |
| -- Build the program using VS2017 or VS2019. |
113 |
| - - Right-click on the solution file and open using either VS2017 or VS2019 IDE. |
114 |
| - - Right-click on the project in Solution Explorer and select Rebuild. |
115 |
| - - From the top menu, select Debug -> Start without Debugging. |
| 106 | +### On Windows* |
| 107 | +**Using Visual Studio*** |
116 | 108 |
|
117 |
| -- Build the program using MSBuild. |
118 |
| - - Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native Tools Command Prompt for VS2019" |
119 |
| - - Run the following command: `MSBuild 1d_HeatTransfer.sln /t:Rebuild /p:Configuration="Release"` |
| 109 | +Build the program using **Visual Studio 2017** or newer. |
| 110 | +1. Change to the sample directory. |
| 111 | +2. Right-click on the solution file and open the solution in the IDE. |
| 112 | +3. Right-click on the project in **Solution Explorer** and select **Rebuild**. |
| 113 | +4. From the top menu, select **Debug** > **Start without Debugging**. (This runs the program.) |
120 | 114 |
|
121 |
| -### Run Samples in Intel® DevCloud |
122 |
| -If 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/). |
| 115 | +**Using MSBuild** |
| 116 | +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. |
| 117 | +2. Change to the sample directory. |
| 118 | +3. Run the following command: `MSBuild 1d_HeatTransfer.sln /t:Rebuild /p:Configuration="Release"` |
123 | 119 |
|
124 |
| -## Run the Sample |
125 |
| -### Application Parameters |
| 120 | +#### Troubleshooting |
| 121 | +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. |
126 | 122 |
|
127 |
| -Usage: `1d_HeatTransfer <n> <i>` |
128 | 123 |
|
129 |
| -Where: |
130 |
| -- `n` is the number of points you want to simulate the heat transfer. |
131 |
| -- `i` is the number of timesteps in the simulation. |
| 124 | +## Run the `1D-Heat-Transfer` Program |
| 125 | +### Application Parameters |
| 126 | +The program requires two inputs. General usage syntax is as follows: |
| 127 | + |
| 128 | +`1d_HeatTransfer <n> <i>` |
132 | 129 |
|
133 |
| - To simulate 100 points for 1000 timesteps: `./1d_HeatTransfer 100 1000` |
| 130 | +| Input | Description |
| 131 | +|:--- |:--- |
| 132 | +| `n` | The number of points you want to simulate the heat transfer. |
| 133 | +| `i` | The number of timesteps in the simulation. |
134 | 134 |
|
135 |
| -The sample performs the computation serially on CPU, using SYCL* buffers and USM. The results are compared against the serial version and saved to `usm_error_diff.txt` and |
136 |
| -`buffer_error_diff.txt`. If the results match, the application will |
| 135 | +The sample performs the computation serially on CPU using buffers and USM. The parallel results are compared to serial version. The output of the comparisons is saved to `usm_error_diff.txt` and |
| 136 | +`buffer_error_diff.txt` in the output directory. If the results match, the application will |
137 | 137 | display a `PASSED!` message.
|
138 | 138 |
|
139 |
| -### Example of Output |
| 139 | +### On Linux |
| 140 | +1. Run the program |
| 141 | + ``` |
| 142 | + $ make run |
| 143 | + ``` |
| 144 | +2. Clean project files. (Optional) |
| 145 | + ``` |
| 146 | + make clean |
| 147 | + ``` |
| 148 | + |
| 149 | +### On Windows |
| 150 | +1. Change to the output directory. |
| 151 | +2. Specify the input values, and run the program. |
| 152 | + ``` |
| 153 | + 1d_HeatTransfer 100 1000 |
| 154 | + ``` |
| 155 | + |
| 156 | +### Build and Run the `1D-Heat-Transfer` Sample in Intel® DevCloud (Optional) |
| 157 | +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. |
| 158 | + |
| 159 | +``` |
| 160 | +qsub -I -l nodes=1:gpu:ppn=2 -d . |
| 161 | +``` |
| 162 | + |
| 163 | +- `-I` (upper case I) requests an interactive session. |
| 164 | +- `-l nodes=1:gpu:ppn=2` (lower case L) assigns one full GPU node. |
| 165 | +- `-d .` makes the current folder as the working directory for the task. |
| 166 | + |
| 167 | +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. |
| 168 | + |
| 169 | +For more information on using Intel® DevCloud, see the Intel® oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/). |
| 170 | + |
| 171 | +## Example Output |
140 | 172 | ```
|
141 |
| -$ make run |
142 |
| -[100%] Built target 1d_HeatTransfer |
143 | 173 | Number of points: 100
|
144 | 174 | Number of iterations: 1000
|
145 | 175 | Using buffers
|
146 |
| - Kernel runs on Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz |
147 |
| - Elapsed time: 0.439238 sec |
| 176 | + Kernel runs on Intel(R) UHD Graphics P630 [0x3e96] |
| 177 | + Elapsed time: 0.506778 sec |
148 | 178 | PASSED!
|
149 | 179 | Using USM
|
150 |
| - Kernel runs on Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz |
151 |
| - Elapsed time: 0.193435 sec |
| 180 | + Kernel runs on Intel(R) UHD Graphics P630 [0x3e96] |
| 181 | + Elapsed time: 0.00926689 sec |
152 | 182 | PASSED!
|
153 |
| -[100%] Built target run |
154 |
| -$ |
155 | 183 | ```
|
| 184 | + |
| 185 | +The parallel to serial comparisons are saved to `usm_error_diff.txt` and `buffer_error_diff.txt` in the output directory. |
| 186 | + |
156 | 187 | ## License
|
157 | 188 | Code samples are licensed under the MIT license. See
|
158 | 189 | [License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.
|
|
0 commit comments