Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

tuple_client.c

Go to the documentation of this file.
00001 /*****************************************************************
00002  *
00003  * LinuxTuples - an open-source tuple space for Linux clusters
00004  * Copyright (c) 2003, Will Ware <wware@alum.mit.edu>
00005  * All rights reserved.
00006  * 
00007  *    Redistribution and use in source and binary forms, with or
00008  *    without modification, are permitted provided that the following
00009  *    conditions are met:
00010  * 
00011  *    + Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    + Redistributions in binary form must reproduce the above
00015  *    copyright notice, this list of conditions and the following
00016  *    disclaimer in the documentation and/or other materials provided
00017  *    with the distribution.
00018  *
00019  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
00020  *    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00021  *    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00022  *    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00024  *    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00027  *    USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  *    AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  *    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  *    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00031  *    THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  *****************************************************************/
00034 
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #include <string.h>
00039 #include <time.h>
00040 #include <math.h>
00041 #include <sys/time.h>
00042 #include <sys/types.h>
00043 #include <sys/stat.h>
00044 #include <fcntl.h>
00045 
00046 #include "tuple.h"
00047 
00048 #define PARALLEL 4
00049 
00050 #define N  8 * 1024
00051 
00056 int main(int argc, char *argv[])
00057 {
00058         struct tuple *s, *t, *u;
00059         int i, j, iters = 0;
00060         int r1[PARALLEL], r2[PARALLEL], r3[PARALLEL];
00061         double x[N], y[N], mult;
00062         struct timeval T0, T1;
00063         int rndsock;
00064         struct context ctx;
00065 
00066         if (get_server_portnumber(&ctx)) {
00067                 if (argc < 3) {
00068                         /* help message */
00069                         fprintf(stderr,
00070                                 "Usage: %s <server> <pornumber>\n",
00071                                 argv[0]);
00072                         exit(1);
00073                 }
00074                 strcpy(ctx.servername, argv[1]);
00075                 ctx.portnumber = atoi(argv[2]);
00076         }
00077         
00078         rndsock = open("/dev/urandom", O_RDONLY);
00079         mult = 1.0 / pow(2.0, 31);
00080         for (i = 0; i < N; i++) {
00081                 x[i] = mult * random_int();
00082                 y[i] = mult * random_int();
00083         }
00084 
00085         s = make_tuple("siiis#s#", "fft",
00086                        0, 0, 0,
00087                        x, N * sizeof(double),
00088                        y, N * sizeof(double));
00089 
00090         t = make_tuple("siii??", "fft done", 0, 0, 0);
00091 
00092         gettimeofday(&T0, NULL);
00093 
00094         while (1) {
00095 
00096                 for (j = 0; j < PARALLEL; j++) {
00097                         r1[j] = random_int();
00098                         r2[j] = random_int();
00099                         r3[j] = random_int();
00100                         s->elements[1].data.i = r1[j];
00101                         s->elements[2].data.i = r2[j];
00102                         s->elements[3].data.i = r3[j];
00103                         if (put_tuple(s, &ctx)) {
00104                                 perror("put_tuple failed");
00105                                 exit(1);
00106                         }
00107                 }
00108 
00109                 for (j = 0; j < PARALLEL; j++) {
00110                         t->elements[1].data.i = r1[j];
00111                         t->elements[2].data.i = r2[j];
00112                         t->elements[3].data.i = r3[j];
00113                         u = get_tuple(t, &ctx);
00114                         if (u == NULL) {
00115                                 perror("get_tuple failed");
00116                                 exit(1);
00117                         }
00118                 }
00119 
00120                 gettimeofday(&T1, NULL);
00121                 iters += PARALLEL;
00122                 printf("%f\n", TIMEVAL_DIFF(T0, T1) / iters);
00123         }
00124 
00125         close(rndsock);
00126         destroy_tuple(s);
00127         destroy_tuple(t);
00128         destroy_tuple(u);
00129 
00130         return 0;
00131 }

Generated on Sun Mar 30 23:46:50 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002