实验操作

  1. 登录集群
1
2
ssh -p 9922 用户名@172.28.9.54
cd data
  1. 创建作业文件
1
2
cat > sparse.cpp
cat > sparse.pbs
  1. 分别粘贴作业代码
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <fstream>
#include <cmath>
#include <pthread.h>
#include <sys/time.h>
#include <cstdlib>

using namespace std;

1
2
3
4
5
6
7
8
#! /bin/bash
#PBS -N sparse
#PBS -l nodes=1:ppn=4
#PBS -j oe

cd $PBS_O_WORKDIR
procs=$(cat $PBS_NODEFILE | wc -l)
./sparse.o matrix.txt vector.txt $procs &> run.log
  1. 编译
1
g++ -pthread -o sparse.o sparse.cpp
  1. 准备输入数据文件(其中的数据可以做替换,此处用的指导书数据)
1
2
3
4
5
6
7
cat > matrix.txt << 'EOF'
3
7
3.0 1.0 1.0 4.0 1.0 1.0 5.0
0 2 5 7
0 1 0 1 2 1 2
EOF
1
2
3
cat > vector.txt << 'EOF'
4.0 6.0 6.0
EOF
  1. 先进行本地测试
1
./sparse.o matrix.txt vector.txt 4

输出类似:

1
2
3
interations: 2
time: 0.004993 s
1 1 1
  1. 提交至作业集群并查看(这次sparse.o*为空)
1
2
3
qsub sparse.pbs
qstat
cat run.log

记录迭代次数和计算时间,重复此过程10遍并取平均值
8. 更改ppn值为1 2 8 16,重复以上步骤并记录

不更改nodes值,因为此实验为多线程并行计算