From 83e45cbde13aca5f1be11ee50e6f07f5140f213d Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 10 May 2010 16:12:27 +0200 Subject: [PATCH] sn-info: Add tool for displaying information about a network in human readable form. --- src/Makefile.am | 9 ++-- src/sn-info.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 src/sn-info.c diff --git a/src/Makefile.am b/src/Makefile.am index da50c9f..7612c97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,8 +2,8 @@ include_HEADERS = sn_network.h sn_stage.h sn_comparator.h lib_LTLIBRARIES = libsortnetwork.la -bin_PROGRAMS = sn-apply sn-batcher sn-check-bf sn-cut sn-merge sn-normalize \ - sn-oddevenmerge sn-shmoo sn-show sn-tex +bin_PROGRAMS = sn-apply sn-batcher sn-check-bf sn-cut sn-info sn-merge \ + sn-normalize sn-oddevenmerge sn-shmoo sn-show sn-tex libsortnetwork_la_SOURCES = sn_network.c sn_network.h \ sn_stage.c sn_stage.h \ @@ -23,6 +23,9 @@ sn_check_bf_LDADD = libsortnetwork.la sn_cut_SOURCES = sn-cut.c sn_cut_LDADD = libsortnetwork.la +sn_info_SOURCES = sn-info.c +sn_info_LDADD = libsortnetwork.la + sn_merge_SOURCES = sn-merge.c sn_merge_LDADD = libsortnetwork.la @@ -42,7 +45,7 @@ sn_tex_SOURCES = sn-tex.c sn_tex_LDADD = libsortnetwork.la if BUILD_WITH_LIBPOPULATION -bin_PROGRAMS += sn-evolution sn-evolution2.c sn-evolution-cut +bin_PROGRAMS += sn-evolution sn-evolution2 sn-evolution-cut sn_evolution_SOURCES = sn-evolution.c sn_evolution_CPPFLAGS = $(AM_CPPFLAGS) $(LIBPOPULATION_CPPFLAGS) diff --git a/src/sn-info.c b/src/sn-info.c new file mode 100644 index 0000000..7d0b2f6 --- /dev/null +++ b/src/sn-info.c @@ -0,0 +1,124 @@ +/** + * collectd - src/sn-info.c + * Copyright (C) 2010 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + **/ + +#include "config.h" + +#include +#include +#include + +#include "sn_network.h" + +static _Bool is_normalized (sn_network_t *n) /* {{{ */ +{ + int i; + + for (i = 0; i < SN_NETWORK_STAGE_NUM (n); i++) + { + sn_stage_t *s = SN_NETWORK_STAGE_GET (n, i); + int j; + + for (j = 0; j < SN_STAGE_COMP_NUM (s); j++) + { + sn_comparator_t *c = SN_STAGE_COMP_GET (s, j); + + if (c->min > c->max) + return (0); + } + } + + return (1); +} /* }}} _Bool is_normalized */ + +int main (int argc, char **argv) +{ + sn_network_t *n; + + int inputs_num; + int stages_num; + int comparators_num; + _Bool normalized; + _Bool sorts; + + int stages_num_compressed; + + if (argc >= 2) + n = sn_network_read_file (argv[1]); + else + n = sn_network_read (stdin); + if (n == NULL) + { + fprintf (stderr, "Unable to read network.\n"); + exit (EXIT_FAILURE); + } + + inputs_num = SN_NETWORK_INPUT_NUM (n); + stages_num = SN_NETWORK_STAGE_NUM (n); + comparators_num = sn_network_get_comparator_num (n); + + normalized = is_normalized (n); + + if (!normalized) + sn_network_normalize (n); + sn_network_compress (n); + + stages_num_compressed = SN_NETWORK_STAGE_NUM (n); + + if (inputs_num <= 16) + { + if (sn_network_brute_force_check (n) == 0) + sorts = 1; + else + sorts = 0; + } + else + { + sorts = 0; + } + + printf ("%s %s network:\n" + "\n" + " Inputs: %4i\n", + (normalized ? "Standard" : "Non-standard"), + (sorts ? "sorting" : "comparator"), + inputs_num); + + if (stages_num_compressed == stages_num) + printf (" Stages: %4i\n", + stages_num); + else + printf (" Stages: %4i (compressed: %i)\n", + stages_num, stages_num_compressed); + + printf (" Comparators: %4i\n" + " Normalized: %4s\n" + " Sorts: %7s\n" + " Rating: %4i\n" + "\n", + comparators_num, + (normalized ? "yes" : "no"), + ((inputs_num > 16) ? "unknown" : (sorts ? "yes" : "no")), + (stages_num_compressed * inputs_num) + comparators_num); + + exit (EXIT_SUCCESS); +} /* int main */ + +/* vim: set shiftwidth=2 softtabstop=2 : */ -- 2.11.0