run_tests.sh 2.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash

# Set default parameters
default_grid_size_lat=1
default_grid_size_lon=1
default_run_distributed=false

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -h|--help)

            bold=$(tput bold)
            normal=$(tput sgr0)

            echo "Runs the torch-harmonics test suite."
            echo "${bold}Arguments:${normal}"
            echo "  ${bold}-h   | --help:${normal} Prints this text."
            echo "  ${bold}-d   | --run_distributed:${normal} Run the distributed test suite."
            echo "  ${bold}-lat | --grid_size_lat:${normal} Number of ranks in latitudinal direction for distributed case."
            echo "  ${bold}-lon | --grid_size_lon:${normal} Number of ranks in longitudinal direction for distributed case."

            shift
            exit 0
            ;;
        -lat|--grid_size_lat)
            grid_size_lat="$2"
            shift 2
            ;;
        -lon|--grid_size_lon)
            grid_size_lon="$2"
            shift 2
            ;;
        -d|--run_distributed)
            run_distributed=true
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            exit 1
            ;;
    esac
done

# Use default values if arguments were not provided
grid_size_lat=${grid_size_lat:-$default_grid_size_lat}
grid_size_lon=${grid_size_lon:-$default_grid_size_lon}
run_distributed=${run_distributed:-$default_run_distributed}

echo "Running sequential tests:"
python3 -m pytest tests/test_convolution.py tests/test_sht.py

# Run distributed tests if requested
if [ "$run_distributed" = "true" ]; then

    echo "Running distributed tests with the following parameters:"
    echo "Grid size latitude: $grid_size_lat"
    echo "Grid size longitude: $grid_size_lon"

    ngpu=$(( ${grid_size_lat} * ${grid_size_lon} ))

    mpirun --allow-run-as-root -np ${ngpu} bash -c "
        export CUDA_LAUNCH_BLOCKING=1;
        export WORLD_RANK=\${OMPI_COMM_WORLD_RANK};
        export WORLD_SIZE=\${OMPI_COMM_WORLD_SIZE};
        export RANK=\${OMPI_COMM_WORLD_RANK};
        export MASTER_ADDR=localhost;
        export MASTER_PORT=29501;
        export GRID_H=${grid_size_lat};
        export GRID_W=${grid_size_lon};
        python3 -m pytest tests/test_distributed_sht.py
        python3 -m pytest tests/test_distributed_convolution.py
73
        python3 -m pytest tests/test_distributed_resample.py
74
75
76
77
        "
else
    echo "Skipping distributed tests."
fi