summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-09 21:45:03 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-09 21:45:03 +0000
commit02102b75a9664460555ae0947350582293465abd (patch)
tree6afbd835d361722977b9aa8f241fdb175c6c8c6e
parente0f0366f920a4681be3ceb60bb86ecc82d14ce54 (diff)
-running at scale...
-rw-r--r--src/scalarproduct/gnunet-scalarproduct.c19
-rwxr-xr-xsrc/scalarproduct/perf_scalarproduct.sh43
-rw-r--r--src/scalarproduct/scalarproduct_api.c38
-rwxr-xr-xsrc/scalarproduct/test_scalarproduct.sh2
4 files changed, 95 insertions, 7 deletions
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c
index b3b954211..be56a44f0 100644
--- a/src/scalarproduct/gnunet-scalarproduct.c
+++ b/src/scalarproduct/gnunet-scalarproduct.c
@@ -243,13 +243,20 @@ run (void *cls,
input_peer_id);
return;
}
-
+ if ( ('\'' == *begin) &&
+ ('\'' == begin[strlen(begin)-1]) )
+ {
+ begin[strlen(begin)-1] = '\0';
+ if (strlen (begin) > 0)
+ begin++;
+ }
for (end = begin; 0 != *end; end++)
if (*end == ';')
element_count++;
- if (0 == element_count) {
+ if (0 == element_count)
+ {
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Need elements to compute the vectorproduct, got none.\n"));
+ _("Need elements to compute the scalarproduct, got none.\n"));
return;
}
@@ -276,9 +283,8 @@ run (void *cls,
GNUNET_free (elements);
return;
}
-
- /* read the element's key */
*separator = 0;
+ /* read the element's key */
GNUNET_CRYPTO_hash (begin,
strlen (begin),
&element.key);
@@ -316,7 +322,8 @@ run (void *cls,
&responder_callback,
NULL))) ) )
{
- GNUNET_break (0);
+ fprintf (stderr,
+ _("Failed to initiate computation, were all keys unique?\n"));
GNUNET_free (elements);
return;
}
diff --git a/src/scalarproduct/perf_scalarproduct.sh b/src/scalarproduct/perf_scalarproduct.sh
new file mode 100755
index 000000000..35a6d872c
--- /dev/null
+++ b/src/scalarproduct/perf_scalarproduct.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# compute a simple scalar product
+# payload for this test:
+SIZE=1000
+INPUTALICE="-k CCC -e '"
+INPUTBOB="-k CCC -e '"
+for X in `seq 1 $SIZE`
+do
+ INPUTALICE="${INPUTALICE}A${X},$X;"
+ INPUTBOB="${INPUTBOB}A${X},$X;"
+done
+INPUTALICE="${INPUTALICE}BC,-20000;RO,1000;FL,100;LOL,24;'"
+INPUTBOB="${INPUTBOB}AB,10;RO,3;FL,3;LOL,-1;'"
+
+# necessary to make the testing prefix deterministic, so we can access the config files
+PREFIX=/tmp/test-scalarproduct`date +%H%M%S`
+
+# where can we find the peers config files?
+CFGALICE="-c $PREFIX/0/config"
+CFGBOB="-c $PREFIX/1/config"
+
+# launch two peers in line topology non-interactively
+#
+# interactive mode would terminate the test immediately
+# because the rest of the script is already in stdin,
+# thus redirecting stdin does not suffice)
+GNUNET_FORCE_LOG=';;;;ERROR'
+GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 &
+PID=$!
+# sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe
+echo "Waiting for peers to start..."
+sleep 5
+# get Bob's peer ID, necessary for Alice
+PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
+
+echo "Running problem of size $SIZE"
+gnunet-scalarproduct $CFGBOB $INPUTBOB &
+time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB`
+
+echo "Terminating testbed..."
+# terminate the testbed
+kill $PID
+
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index cd63030bd..7c03150a3 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.c
@@ -268,6 +268,40 @@ process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
/**
+ * Check if the keys for all given elements are unique.
+ *
+ * @param elements elements to check
+ * @param element_count size of the @a elements array
+ * @return #GNUNET_OK if all keys are unique
+ */
+static int
+check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements,
+ uint32_t element_count)
+{
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ uint32_t i;
+ int ok;
+
+ ok = GNUNET_OK;
+ map = GNUNET_CONTAINER_multihashmap_create (2 * element_count,
+ GNUNET_YES);
+ for (i=0;i<element_count;i++)
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put (map,
+ &elements[i].key,
+ map,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Keys given to SCALARPRODUCT not unique!\n"));
+ ok = GNUNET_SYSERR;
+ }
+ GNUNET_CONTAINER_multihashmap_destroy (map);
+ return ok;
+}
+
+
+/**
* Used by Bob's client to cooperate with Alice,
*
* @param cfg the gnunet configuration handle
@@ -291,6 +325,8 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
uint32_t size;
uint16_t possible;
+ if (GNUNET_SYSERR == check_unique (elements, element_count))
+ return NULL;
h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle);
h->cont_status = cont;
h->cont_cls = cont_cls;
@@ -433,6 +469,8 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
uint32_t size;
uint32_t possible;
+ if (GNUNET_SYSERR == check_unique (elements, element_count))
+ return NULL;
h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle);
h->client = GNUNET_CLIENT_connect ("scalarproduct-alice", cfg);
if (NULL == h->client)
diff --git a/src/scalarproduct/test_scalarproduct.sh b/src/scalarproduct/test_scalarproduct.sh
index 562a4f68f..dd9bb80a5 100755
--- a/src/scalarproduct/test_scalarproduct.sh
+++ b/src/scalarproduct/test_scalarproduct.sh
@@ -17,7 +17,7 @@ CFGBOB="-c $PREFIX/1/config"
# interactive mode would terminate the test immediately
# because the rest of the script is already in stdin,
# thus redirecting stdin does not suffice)
-GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG'
+# GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG'
GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 &
PID=$!
# sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe