diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..94f480de94e1d767531580401cbf13844868e82b --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/mpi/mpi_alltoall.c b/mpi/mpi_alltoall.c index 43f74e7dfe7ea287d886992ca6549061c188bd8e..702867951217a3a91dffe9bd89d5d74719671c98 100644 --- a/mpi/mpi_alltoall.c +++ b/mpi/mpi_alltoall.c @@ -28,7 +28,7 @@ int main(int argc, char** argv) { // 检查是否小于1024个进程(本示例仅支持1024进程通信) if (size > 1024) { if (rank == 0) { - printf("Error\n"); + printf("ERROR\n"); } MPI_Finalize(); return 1; @@ -77,9 +77,9 @@ int main(int argc, char** argv) { if (rank == 0) { if(result == 0) { - printf("Success!\n"); + printf("PASSED\n"); } else { - printf("Error!\n"); + printf("ERROR\n"); } } diff --git a/mpi/mpi_gather.c b/mpi/mpi_gather.c index 54596c1de0120f742bdf253fd56476762230129d..07b86ea0ba37d4ee1787eb2ae5d993dd2eba9df6 100644 --- a/mpi/mpi_gather.c +++ b/mpi/mpi_gather.c @@ -28,7 +28,7 @@ int main(int argc, char** argv) { // 检查是否小于1024个进程(本示例仅支持1024进程通信) if (size > 1024) { if (rank == 0) { - printf("Error\n"); + printf("ERROR\n"); } MPI_Finalize(); return 1; @@ -66,9 +66,9 @@ int main(int argc, char** argv) { } if(result == 0) { - printf("Success!\n"); + printf("PASSED\n"); } else { - printf("Error!\n"); + printf("ERROR\n"); } } diff --git a/mpi/mpi_reduce.c b/mpi/mpi_reduce.c index 7296d0403ff211c316a67c34375230fc3429b961..4482758a6606474df7c5628a29db224e1b288911 100644 --- a/mpi/mpi_reduce.c +++ b/mpi/mpi_reduce.c @@ -27,7 +27,7 @@ int main(int argc, char** argv) { // 检查是否小于1024个进程(本示例仅支持1024进程通信) if (size > 1024) { if (rank == 0) { - printf("Error\n"); + printf("ERROR\n"); } MPI_Finalize(); return 1; @@ -55,9 +55,9 @@ int main(int argc, char** argv) { } if(result == global_sum) { - printf("Success!\n"); + printf("PASSED\n"); } else { - printf("Error!\n"); + printf("ERROR\n"); } } diff --git a/mpi/mpi_scatter.c b/mpi/mpi_scatter.c index 9457a5b61c8274c12d271dcb3e23b51e20d5c029..da0377e3ae9d459fdb87a6a0c75b24af6aab7c08 100644 --- a/mpi/mpi_scatter.c +++ b/mpi/mpi_scatter.c @@ -29,7 +29,7 @@ int main(int argc, char** argv) { // 检查是否小于1024个进程(本示例仅支持1024进程通信) if (size > 1024) { if (rank == 0) { - printf("Error\n"); + printf("ERROR\n"); } MPI_Finalize(); return 1; @@ -76,9 +76,9 @@ int main(int argc, char** argv) { if (rank == 0) { if(result == 0) { - printf("Success!\n"); + printf("PASSED\n"); } else { - printf("Error!\n"); + printf("ERROR\n"); } } diff --git a/mpi/mpi_send_recv.c b/mpi/mpi_send_recv.c index 797656d589230b8d8a18dcca8e5eb83aad440d6b..5dac202f0f39855d40b4f2dc45024455e623d767 100644 --- a/mpi/mpi_send_recv.c +++ b/mpi/mpi_send_recv.c @@ -22,7 +22,7 @@ int main(int argc, char** argv) { // 检查是否只有2个进程(本示例仅支持2进程通信) if (size != 2) { if (rank == 0) { - printf("Error\n"); + printf("ERROR\n"); } MPI_Finalize(); return 1; @@ -48,9 +48,9 @@ int main(int argc, char** argv) { MPI_COMM_WORLD, // 通信域 MPI_STATUS_IGNORE); // 忽略状态信息 if (data == random_num) { - printf("Success!\n"); + printf("PASSED\n"); } else { - printf("Error!\n"); + printf("ERROR\n"); } } diff --git a/mpi/run.sh b/mpi/run.sh index f736163a154326df89bcf6c8559c6d5793bb4886..b599b447df1a69dbf125d15cbd7e7b53c3c01afd 100644 --- a/mpi/run.sh +++ b/mpi/run.sh @@ -7,34 +7,39 @@ total_error=0 # 定义测试列表 tests=("-np 2 ./build/mpi_send_recv" "-np 8 ./build/mpi_reduce" "-np 8 ./build/mpi_gather" "-np 8 ./build/mpi_scatter" "-np 8 ./build/mpi_alltoall") +echo "=== 执行 mpi 测试 ===" + # 循环运行每个测试 for test in "${tests[@]}"; do - echo "=== 开始运行测试: $test ===" + # 步骤1:按空格分割字符串为数组(获取所有参数) + IFS=' ' read -ra parts <<< "$test" + + # 步骤2:获取数组最后一个元素(即程序的完整路径) + full_path="${parts[-1]}" + + # 步骤3:从完整路径中提取文件名(去掉目录部分) + test_name=$(basename "$full_path") + + echo "start test $test_name" # 运行测试并捕获输出(保存到临时变量) output=$(mpirun $test 2>&1) # 2>&1 确保错误输出也被捕获 - echo "测试输出:" - echo "$output" - echo "-------------------------" - # 从输出中提取 success 和 error 的数量(支持类似 "success: 3" 或 "2 errors" 等格式) # 匹配 "success" 相关的数字(不区分大小写) - success=$(echo "$output" | grep -oi 'Success' | wc -l) + success=$(echo "$output" | grep -oi 'PASSED' | wc -l) # 匹配 "error" 相关的数字(不区分大小写) - error=$(echo "$output" | grep -oi 'Error' | wc -l) + error=$(echo "$output" | grep -oi 'ERROR' | wc -l) # 累加统计 total_success=$((total_success + success)) total_error=$((total_error + error)) - - # 输出当前测试的统计 - echo "$test 统计: 成功=$success, 失败=$error" - echo "=========================" + if [ $error -eq 0 ] && [ $success -eq 1 ]; then + echo "end test $test_name PASSED" + else + echo "end test $test_name FAILED" + fi done # 输出总统计结果 -echo -e "\n===== 所有测试汇总统计 =====" -echo "总成功数: $total_success" -echo "总失败数: $total_error" -echo "总用例数: $((total_success + total_error))" +echo "$((total_success + total_error)) tests ran, $total_success tests PASSED, $total_error tests FAILED." echo "============================"