<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Test Intel MPI Jobs :: Ay Docs</title>
    <link>https://ops.docs.72602.space/csp/zhejianglab/slurm/mpi/test_intel_mpi_job/index.html</link>
    <description>在SLURM集群中使用MPI（Message Passing Interface）进行并行计算，通常需要以下几个步骤：&#xA;1. 安装MPI库 确保你的集群节点已经安装了MPI库，常见的MPI实现包括：&#xA;OpenMPI Intel MPI MPICH 可以通过以下命令检查集群是否安装了MPI： mpicc --version # 检查MPI编译器 mpirun --version # 检查MPI运行时环境 2. 测试MPI性能 mpirun -n 2 IMB-MPI1 pingpong 3. 编译MPI程序 你可以用mpicc（C语言）或mpic++（C++语言）来编译MPI程序。例如：&#xA;以下是一个简单的MPI “Hello, World!” 示例程序，假设文件名为 hello_mpi.c, 还有一个进行矩阵计算的示例程序，文件名为dot_product.c，任意挑选一个即可：&#xA;​ hello_mpi.c dot_product.c #include &lt;stdio.h&gt; #include &lt;mpi.h&gt; int main(int argc, char *argv[]) { int rank, size; // 初始化MPI环境 MPI_Init(&amp;argc, &amp;argv); // 获取当前进程的rank和总进程数 MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank); MPI_Comm_size(MPI_COMM_WORLD, &amp;size); // 输出进程的信息 printf(&#34;Hello, World! I am process %d out of %d processes.\n&#34;, rank, size); // 退出MPI环境 MPI_Finalize(); return 0; } #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;mpi.h&gt; #define N 8 // 向量大小 // 计算向量的局部点积 double compute_local_dot_product(double *A, double *B, int start, int end) { double local_dot = 0.0; for (int i = start; i &lt; end; i++) { local_dot += A[i] * B[i]; } return local_dot; } void print_vector(double *Vector) { for (int i = 0; i &lt; N; i++) { printf(&#34;%f &#34;, Vector[i]); } printf(&#34;\n&#34;); } int main(int argc, char *argv[]) { int rank, size; // 初始化MPI环境 MPI_Init(&amp;argc, &amp;argv); MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank); MPI_Comm_size(MPI_COMM_WORLD, &amp;size); // 向量A和B double A[N], B[N]; // 进程0初始化向量A和B if (rank == 0) { for (int i = 0; i &lt; N; i++) { A[i] = i + 1; // 示例数据 B[i] = (i + 1) * 2; // 示例数据 } } // 广播向量A和B到所有进程 MPI_Bcast(A, N, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(B, N, MPI_DOUBLE, 0, MPI_COMM_WORLD); // 每个进程计算自己负责的部分 int local_n = N / size; // 每个进程处理的元素个数 int start = rank * local_n; int end = (rank + 1) * local_n; // 如果是最后一个进程，确保处理所有剩余的元素（处理N % size） if (rank == size - 1) { end = N; } double local_dot_product = compute_local_dot_product(A, B, start, end); // 使用MPI_Reduce将所有进程的局部点积结果汇总到进程0 double global_dot_product = 0.0; MPI_Reduce(&amp;local_dot_product, &amp;global_dot_product, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); // 进程0输出最终结果 if (rank == 0) { printf(&#34;Vector A is\n&#34;); print_vector(A); printf(&#34;Vector B is\n&#34;); print_vector(B); printf(&#34;Dot Product of A and B: %f\n&#34;, global_dot_product); } // 结束MPI环境 MPI_Finalize(); return 0; } 3. 创建Slurm作业脚本 创建一个SLURM作业脚本来运行该MPI程序。以下是一个基本的SLURM作业脚本，假设文件名为 mpi_test.slurm: ​ hello_mpi.c dot_product.c #!/bin/bash #SBATCH --job-name=mpi_job # Job name #SBATCH --nodes=2 # Number of nodes to use #SBATCH --ntasks-per-node=1 # Number of tasks per node #SBATCH --time=00:10:00 # Time limit #SBATCH --output=mpi_test_output_%j.log # Standard output file #SBATCH --error=mpi_test_output_%j.err # Standard error file # Manually set Intel OneAPI MPI and Compiler environment export I_MPI_PMI=pmi2 export I_MPI_PMI_LIBRARY=/usr/lib/x86_64-linux-gnu/slurm/mpi_pmi2.so export I_MPI_ROOT=/opt/intel/oneapi/mpi/2021.14 export INTEL_COMPILER_ROOT=/opt/intel/oneapi/compiler/2025.0 export PATH=$I_MPI_ROOT/bin:$INTEL_COMPILER_ROOT/bin:$PATH export LD_LIBRARY_PATH=$I_MPI_ROOT/lib:$INTEL_COMPILER_ROOT/lib:$LD_LIBRARY_PATH export MANPATH=$I_MPI_ROOT/man:$INTEL_COMPILER_ROOT/man:$MANPATH # Compile the MPI program icx-cc -I$I_MPI_ROOT/include hello_mpi.c -o hello_mpi -L$I_MPI_ROOT/lib -lmpi # Run the MPI job mpirun -np 2 ./hello_mpi #!/bin/bash #SBATCH --job-name=mpi_job # Job name #SBATCH --nodes=2 # Number of nodes to use #SBATCH --ntasks-per-node=1 # Number of tasks per node #SBATCH --time=00:10:00 # Time limit #SBATCH --output=mpi_test_output_%j.log # Standard output file #SBATCH --error=mpi_test_output_%j.err # Standard error file # Manually set Intel OneAPI MPI and Compiler environment export I_MPI_PMI=pmi2 export I_MPI_PMI_LIBRARY=/usr/lib/x86_64-linux-gnu/slurm/mpi_pmi2.so export I_MPI_ROOT=/opt/intel/oneapi/mpi/2021.14 export INTEL_COMPILER_ROOT=/opt/intel/oneapi/compiler/2025.0 export PATH=$I_MPI_ROOT/bin:$INTEL_COMPILER_ROOT/bin:$PATH export LD_LIBRARY_PATH=$I_MPI_ROOT/lib:$INTEL_COMPILER_ROOT/lib:$LD_LIBRARY_PATH export MANPATH=$I_MPI_ROOT/man:$INTEL_COMPILER_ROOT/man:$MANPATH # Compile the MPI program icx-cc -I$I_MPI_ROOT/include dot_product.c -o dot_product -L$I_MPI_ROOT/lib -lmpi # Run the MPI job mpirun -np 2 ./dot_product</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate></lastBuildDate>
    <atom:link href="https://ops.docs.72602.space/csp/zhejianglab/slurm/mpi/test_intel_mpi_job/index.xml" rel="self" type="application/rss+xml" />
  </channel>
</rss>