#! /bin/bash if [ "$#" -ne 3 ]; then echo "Usage: $0 " exit 1 fi # Validate if the first argument is a positive integer if ! [[ "$1" =~ ^[1-9][0-9]*$ ]]; then echo "Error: Number of samples must be a positive integer." exit 1 fi #NT=(5 10 15) # Number of Tasks #NDT=(3 4 8) # Number of different periods #NR=(2 3 4) # Number of resources RSF=33 # Resource sharing factor CSR=0 # Critical section ratio GCU=(20 30 40 50 60 70 80 90) # Global CPU usages N=$1 # Number of samples for each set category INPUT_DIR=$2 # Validate if the input directory exists if [ ! -d "$INPUT_DIR" ]; then echo "Error: Input directory '$INPUT_DIR' does not exist." exit 1 fi OUTPUT_DIR=$3; mkdir -p "$OUTPUT_DIR" SCRIPT_DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"; export SCRIPT_DIR parallel_simulation() { # The arrays below are put inside the function since parallel has no access to the outer environment NT=(5 10 15) # Number of Tasks NDT=(3 4 8) # Number of different periods NR=(2 3 4) # Number of resources local nt="${NT[$1]}" ndt="${NDT[$1]}" nr="${NR[$1]}" rsf=$2 csr=$3 gcu=$4 i=$5 proto=$6 indir=$7 outdir=$8 input_file="${indir}/${nt}_${ndt}_${nr}_${rsf}_${csr}_${gcu}_${proto}_${i}.xmlv3" output_file="${outdir}/${nt}_${ndt}_${nr}_${rsf}_${csr}_${gcu}_${proto}_${i}.xmlv3.log" local nit=$(python "${SCRIPT_DIR}/feas_int.py" "${input_file}") echo "FEAS: " $nit # Check if the variable is a valid integer if [[ ! "$nit" =~ ^[0-9]+$ ]]; then echo "Error: Computed feasability interval is not a valid integer." echo "Input file: ${input_file}" exit 1 fi "${SCRIPT_DIR}/../../trunk/src/response_time" -s -i "${input_file}" "${nit}" | grep -A 20 "Task response time computed from simulation" > "${output_file}" # If the file is empty, we put it in a special directory if [ ! -s "${output_file}" ]; then mkdir -p "${outdir}/failed" mv "${output_file}" "${outdir}/failed" fi } # Run the response time simulation: export -f parallel_simulation parallel -j $(nproc) parallel_simulation ::: 0 1 2 ::: "${RSF}" ::: "${CSR}" ::: "${GCU[@]}" ::: $(seq -w 1 "${N}") ::: "PCP" "PPCP" ::: "${INPUT_DIR}" ::: "${OUTPUT_DIR}" # Check if the "failed" directory exists if [ -d "${OUTPUT_DIR}/failed" ]; then echo "#######################################################" echo "# Simulation Result #" echo "# #" echo "# Simulation completed. The 'failed' directory exists #" echo "# Please check for any issues. #" echo "#######################################################" fi