00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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 }