hpc-lab-code/lab1/lab1.sh
2026-01-19 22:25:14 +08:00

59 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
echo "Current directory: $PWD"
# Build directory
BUILD_DIR="./build/linux/x86_64/release"
# Programs
MPI_HELLO="$BUILD_DIR/mpi_hello_world"
MPI_PI="$BUILD_DIR/mpi_pi"
SERIAL_PI="$BUILD_DIR/serial_pi"
# Check if programs exist
if [[ ! -f "$MPI_HELLO" ]]; then
echo "Error: $MPI_HELLO not found. Please build first."
exit 1
fi
if [[ ! -f "$MPI_PI" ]]; then
echo "Error: $MPI_PI not found. Please build first."
exit 1
fi
if [[ ! -f "$SERIAL_PI" ]]; then
echo "Error: $SERIAL_PI not found. Please build first."
exit 1
fi
echo "Programs found. Starting tests..."
# Test mpi_hello_world
echo "Testing mpi_hello_world with default settings:"
mpirun "$MPI_HELLO"
echo "mpi_hello_world test completed."
# Terms to test
TERMS=(1000 100000 1000000 10000000 1000000000)
PROCS=(1 2 3 4 5 6)
echo ""
echo "Testing mpi_pi with different terms and processes:"
for procs in "${PROCS[@]}"; do
for terms in "${TERMS[@]}"; do
echo "Running mpi_pi with $procs processes and $terms terms:"
mpirun -np $procs "$MPI_PI" <<< $terms
echo ""
done
done
echo ""
echo "Testing serial_pi with different terms:"
for terms in "${TERMS[@]}"; do
echo "Running serial_pi with $terms terms:"
"$SERIAL_PI" <<< $terms
echo ""
done
echo "All tests completed."