parExQHV
Compute Exclusive HyperVolumes using threads
 All Data Structures Files Functions Variables Macros
main.c
1 /*
2  *
3  * Copyright (c) Year(s), 2013, Luis M. S. Russo and Alexandre
4  * P. Francisco / KDBIO / INESC-ID, <qhv@kdbio.inesc-id.pt>
5  *
6  * Any published media that is related with to use of the distributed
7  * software, or derived software, must contain a reference to "Extending
8  * quick hypervolume. Luís M. S. Russo, Alexandre P. Francisco:
9  * J. Heuristics 22(3): 245-271 (2016)".
10  *
11  * Permission to use, copy, modify, and/or distribute this software for
12  * any purpose with or without fee is hereby granted, provided that the
13  * above copyright notice and this permission notice appear in all
14  * copies.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
17  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
19  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
21  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23  * PERFORMANCE OF THIS SOFTWARE.
24  *
25  */
26 
27 #define _GNU_SOURCE
28 #include <stdio.h>
29 #include <stdlib.h>
30 #undef _GNU_SOURCE
31 #include <string.h>
32 #include <assert.h>
33 
34 #include <time.h>
35 /* #include <sys/resource.h> */
36 #include <pthread.h>
37 
38 #include "point.h"
39 #include "quickhvolume.h"
40 #include "splitter.h"
41 #include "subsets.h"
42 #include "unionFilter.h"
43 #include "naiverandom.h"
44 #include "HSO.h"
45 #include "inexclusion.h"
46 #include "tpool.h"
47 
48 double max = 1.0;
49 
57 void* console(void *threadid)
58 {
59  char line[1024];
60  taskData l;
61  jobData jd;
63  int i;
64 
65  i = 0;
66  while(i < NPOINTS)
67  {
68  l.idx[i] = i;
69  i++;
70  }
71 
72  l.z = cZero;
73  l.o = cOne;
74 
75  jd.n = 0;
76  IECinit();
77 
78  while(scanf("%[^\n]\n", line) > 0) /* Simple getline */
79  {
80  if('#' == line[0])
81  {
82  if(jd.n > 0)
83  {
84  memset(jd.r, 0, NPOINTS*sizeof(double)); /* Initial result */
85  l.n = jd.n;
86  postJob(&jd, &l);
87  }
88  jd.n = 0;
89  }
90  else
91  {
92  parsePoint(line, &(jd.PS[jd.n]), max);
93  jd.n++;
94  }
95  }
96 
97  pthread_exit(NULL);
98 }
99 
108 int
109 main(int argc, char** argv)
110 {
111  int t;
113  if(1 == argc)
114  {
115  fprintf(stderr, "usage: qhv <#threads> <#inputfile>\n");
116  exit(0);
117  }
118 
119  t = 4;
120 
121  if (argc > 1) sscanf(argv[1], "%d", &t);
122  if (argc > 2) stdin = fopen(argv[2], "r");
123  if (argc > 3) max = atof(argv[3]);
124 
125  printf("Copyright (c) Year(s), 2013, Luis M. S. Russo and Alexandre \n");
126  printf("P. Francisco / KDBIO / INESC-ID, <qhv@kdbio.inesc-id.pt> \n");
127  printf(" \n");
128  printf("Any published media that is related with to use of the distributed \n");
129  printf("software, or derived software, must contain a reference to \"Luís \n");
130  printf("M. S. Russo, Alexandre P. Francisco: Extending quick hypervolume. \n");
131  printf("J. Heuristics 22(3): 245-271 (2016).\" \n");
132  printf(" \n");
133  printf("Permission to use, copy, modify, and/or distribute this software for \n");
134  printf("any purpose with or without fee is hereby granted, provided that the \n");
135  printf("above copyright notice and this permission notice appear in all \n");
136  printf("copies. \n");
137  printf(" \n");
138  printf("THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL \n");
139  printf("WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED \n");
140  printf("WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE \n");
141  printf("AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL \n");
142  printf("DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR \n");
143  printf("PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER \n");
144  printf("TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR \n");
145  printf("PERFORMANCE OF THIS SOFTWARE. \n");
146 
147  /*
148  struct timeval tv1, tv2;
149  struct rusage ru_before, ru_after;
150  */
151  struct timespec ts_before, ts_after;
152 
153  /* getrusage (RUSAGE_SELF, &ru_before); */
154  clock_gettime(CLOCK_MONOTONIC_RAW, &ts_before);
155 
156  launch(t, console, quickHVolumeS, openBox, closeBox, priority, jobCopy, taskCopy, merge, publish);
157 
158  /* getrusage (RUSAGE_SELF, &ru_after); */
159  clock_gettime(CLOCK_MONOTONIC_RAW, &ts_after);
160 
161  /*
162  tv1 = ru_before.ru_utime;
163  tv2 = ru_after.ru_utime;
164  printf("Time: %f (s)\n", tv2.tv_sec + tv2.tv_usec * 1e-6 - tv1.tv_sec - tv1.tv_usec * 1e-6);
165  */
166  if (argc > 2) fclose(stdin);
167 
168  printf("Time: %f (s)\n", ts_after.tv_sec + ts_after.tv_nsec * 1e-9 - ts_before.tv_sec - ts_before.tv_nsec * 1e-9);
169 
170  exit(0);
171 }
172 
173 /* int main(int argc, char** argv) */
174 /* { */
175 /* int n; /\**< Size of point list *\/ */
176 /* int a; /\**< Amount of alloced memory *\/ */
177 /* point* L; /\**< List of alloced points *\/ */
178 /* point* T; /\**< Temporary pointer *\/ */
179 /* size_t k; /\**< Size of alloced line *\/ */
180 /* char* line; */
181 /* int read; */
182 /* double HV; /\**< The HyperVolume *\/ */
183 
184 /* struct timeval tv1, tv2; */
185 /* struct rusage ru_before, ru_after; */
186 
187 /* double max = 1.0; */
188 
189 /* /\* stdin = fopen("../tests/spherical/8d/DTLZSphereShape.8d.front.240pts.10", "r"); *\/ */
190 /* if (argc > 1) stdin = fopen(argv[1], "r"); */
191 /* if (argc > 2) max = atof(argv[2]); */
192 
193 /* a = 0; */
194 /* n = 0; */
195 /* k = 0; */
196 /* line = NULL; */
197 /* L = NULL; */
198 /* read = 0; */
199 /* /\* resetHSO(); /\\**< Initiate the HSO sub-calculator *\\/ *\/ */
200 /* IECinit(); */
201 /* initSplitter(); */
202 /* /\* printf("N is %d\n", N); *\/ */
203 
204 /* do{ */
205 /* read = getline(&line, &k, stdin); */
206 /* if(read > 0) */
207 /* { */
208 /* switch(line[0]) */
209 /* { */
210 /* case '#': */
211 /* if(n > 0) */
212 /* { */
213 /* getrusage (RUSAGE_SELF, &ru_before); */
214 
215 /* initUnion(n); /\**< TODO: update this *\/ */
216 /* HV = quickHVolume(n, L); */
217 
218 /* printf("%1.10f\n", HV); */
219 
220 /* getrusage (RUSAGE_SELF, &ru_after); */
221 /* tv1 = ru_before.ru_utime; */
222 /* tv2 = ru_after.ru_utime; */
223 /* printf("Time: %f (s)\n", tv2.tv_sec + tv2.tv_usec * 1e-6 - tv1.tv_sec - tv1.tv_usec * 1e-6); */
224 
225 /* } */
226 /* n = 0; */
227 /* break; */
228 /* default: */
229 /* if(n == a) */
230 /* { */
231 /* a++; */
232 /* a*=2; */
233 /* L = (point*) realloc(L, a*sizeof(point)); */
234 /* if(((int)L % 16) != 0) */
235 /* { */
236 /* posix_memalign((void**)&T, 16, a*sizeof(point)); */
237 /* memcpy(T, L, n*sizeof(point)); */
238 /* free(L); */
239 /* L = T; */
240 /* } */
241 /* } */
242 
243 /* parsePoint(line, &L[n], max); */
244 /* n++; */
245 /* break; */
246 /* } */
247 /* } */
248 /* }while(read > 0); */
249 
250 /* free(L); */
251 /* free(line); */
252 /* destroySplitter(); */
253 
254 /* /\* fclose(stdin); *\/ */
255 /* if (argc > 1) fclose(stdin); */
256 
257 /* return 0; */
258 /* } */
point cZero
Definition: point.c:44
This returns iterators for diferent type. WARNING, these objects are singleton, so new overwrites exi...
Simple point interface. Contains simple point manipulation functions.
int idx[NPOINTS]
Definition: tdata.h:85
void IECinit(void)
Definition: inexclusion.c:70
Definition: tdata.h:80
A splitter for storing classified points. The splitter is an array that grows dinamically, when all points are inserted they are separeted into classes by sorting. Preferably count sort or hased count sort.
void parsePoint(char *S, point *p, double max)
Definition: point.c:57
Structure for uniting two sets, without repetition.
double r[NPOINTS]
Definition: tdata.h:76
Inclusion Exclusion Algorithm better than HSO for high d and small n.
Definition: tdata.h:72
Header: copy HSO.
point cOne
Definition: point.c:45
Header: copy naiverandom.