<div style="text-align: right; background-color: #f5f5f5; padding: 4px 12px; border-radius: 5px; display: inline-block; float: right; font-size: 1.4rem;">
Last Updated:2025/07/01
</div>
# Intel oneAPI
[TOC]
<br>
在創進一號中,透過 Intel oneAPI 工具,完成 MPI 程式的編譯與執行流程,包括環境載入、程式撰寫、Slurm 作業提交與輸出檢視。
## 1. 載入 Intel 編譯器環境
```
[user@ilgn01 ~]$ ml load intel/2024_01_46
[user@ilgn01 ~]$ ml list
Currently Loaded Modules:
1) intel/2024_01_46
```
<br>
## 2. 確認載入的編譯器路徑
```
[user@ilgn01 ~]$ whereis mpicc
mpicc: /pkg/compiler/intel/2024/mpi/2021.11/bin/mpicc
```
<br>
## 3. 撰寫 MPI 程式(以 hello.c 為例)
```
[user@ilgn01 ~]$ vi hello.c
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
MPI_Init(NULL, NULL);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
MPI_Finalize();
}
```
<br>
## 4. 使用 `mpicc` 編譯 hello.c
```
[user@ilgn01 ~]$ mpicc -o hello ./hello.c
```
<br>
## 5. 撰寫 Slurm Job Script(以 job.sh 為例)
```
[user@ilgn01 ~]$ vi job.sh
#!/bin/bash
#SBATCH --account=GOVXXXXX # Project Name
#SBATCH -J test # Job name
#SBATCH -N 2 # Total number of nodes requested
#SBATCH -n 224 # Total number of mpi tasks requested
#SBATCH -t 01:30:00 # Run time (hh:mm:ss) - 1.5 hours
#SBATCH --partition=XXXX # Partition Name
#SBATCH -o job.%j.log # (-o) Path to the standard output file
#SBATCH -e job.%j.err # (-e) Path to the standard error file
#SBATCH --mail-type=END,FAIL # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=user@example.com # Where to send mail. Set this to your email address
module purge
module load intel/2024_01_46
mpiexec ./hello
```
<br>
## 6. 提交 Slurm Job
```
[user@ilgn01 ~]$ sbatch job.sh
Submitted batch job 14098
```
<br>
## 7. 查看執行輸出的結果
```
[user@ilgn01 ~]$ cat job.14098.out
Hello world from processor icpnp302, rank 118 out of 150 processors
Hello world from processor icpnp302, rank 119 out of 150 processors
Hello world from processor icpnp302, rank 120 out of 150 processors
Hello world from processor icpnp301, rank 0 out of 150 processors
Hello world from processor icpnp301, rank 1 out of 150 processors
Hello world from processor icpnp301, rank 107 out of 150 processors
Hello world from processor icpnp301, rank 108 out of 150 processors
Hello world from processor icpnp301, rank 109 out of 150 processors
Hello world from processor icpnp301, rank 110 out of 150 processors
...
```
<div style="border: 1.5px solid #B7B7B7; padding: 1rem 1rem; border-radius: 5px; color: #333;">
🔗 <strong>如何撰寫 Slurm 作業腳本,詳細教學請參閱</strong>
<a href="https://man.twcc.ai/@f1-manual/slurm_job_example" target="_blank" style="color: #007ACC;">
Job 提交與管理範例
</a>
</div>