From e4580f054afd2023741e3f1620a465ab9f8810e5 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 25 Feb 2011 10:23:35 +0100 Subject: [PATCH 1/1] Add new_loba.sh to help adding a new algorithm. --- README | 1 + new_loba.sh | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 new_loba.sh diff --git a/README b/README index 2d9059c..b0c0f36 100644 --- a/README +++ b/README @@ -137,6 +137,7 @@ Pour ajouter un nouvel algorithme d'équilibrage pneigh[i]->get_load() ; - définit la charge à envoyer avec send(pneigh[i], quantité) ; + NB: le script new_loba.sh peut servir à créer les fichiers. 2. Ajouter l'algorithme dans la liste des options. Dans options.cpp : - faire le #include adéquat ; diff --git a/new_loba.sh b/new_loba.sh new file mode 100755 index 0000000..f564a5c --- /dev/null +++ b/new_loba.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +if [ "$1" = "-n" ]; then + echo "# Dry run mode!" >&2 + create_files=0 + shift +else + create_files=1 +fi + +if [ $# -ne 1 ]; then + echo "Usage: $0 name" >&2 + echo " Create files loba_name.h and loba_name.cpp." + exit 1 +fi + +name=$(echo $1 | tr A-Z a-z) +if ! echo "$name" | grep -q '^[a-z][a-z0-9_]*$' \ + || ! [ $(echo "$name" | wc -l) = 1 ]; then + echo "ERROR: invalid name -- \"$name\"" >&2 + exit 1 +fi + +uname=$(echo $name | tr a-z A-Z) +h_file=$(printf "loba_%s.h" $name) +cpp_file=$(printf "loba_%s.cpp" $name) + +if [ -e "$h_file" -o -e "$cpp_file" ]; then + echo "ERROR: file $h_file or $cpp_file already exists!" >&2 + exit 1 +fi + +echo "# Creating files for algorithm $name ($uname)..." +echo "# Creating file $h_file... " +if [ "$create_files" = "1" ]; then + cat > "$h_file" < "$cpp_file" < + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba); + +#include "loba_${name}.h" + +void loba_${name}::load_balance() +{ + // write code here... + xbt_die("Load-balancing algorithm ${name} not implemented!"); +} + +// Local variables: +// mode: c++ +// End: +EOF +fi + +cat >&2 <