int nb_threads = 1;
int sched_rt_prio = 50;
+int do_clock = 0;
int mode = 0;
/* types */
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
- fprintf (fd, "usage: %s [-c] [-h] [-n int] [-r int] [-v]\n", progname);
+ fprintf (fd, "usage: %s [-a|-m] [-c] [-h] [-n int] [-r int] [-v]\n", progname);
+ fprintf (fd, " -a: load with allocation\n");
fprintf (fd, " -c: estimate clock\n");
fprintf (fd, " -h: help message\n");
+ fprintf (fd, " -m: load with mathematics\n");
fprintf (fd, " -n: number of thread (%d)\n", nb_threads);
fprintf (fd, " -r: real-time priority, -1 to desactivate (%d)\n", sched_rt_prio);
fprintf (fd, " -v: print version\n");
}
}
-void *work (__attribute__((unused)) void *arg)
+void *work_math (__attribute__((unused)) void *arg)
{
while (1) {
matrix_t *matrix = alloc_matrix (N);
pthread_exit (NULL);
}
+void *work_alloc (__attribute__((unused)) void *arg)
+{
+ while (1) {
+ matrix_t *matrix = alloc_matrix (N);
+ //generate_matrix (matrix);
+ free_matrix (matrix);
+ }
+ pthread_exit (NULL);
+}
+
double estimate_tics_clock (void)
{
int n = 4;
}
char c = arg[1];
switch (c) {
+ case 'a':
+ mode = 1;
+ break;
case 'c':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
- mode = (arg == NULL) ? 1 : atoi (arg);
+ do_clock = (arg == NULL) ? 1 : atoi (arg);
+ break;
+ case 'm':
+ mode = 0;
break;
case 'n':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
/* main process */
- if (mode) {
+ if (do_clock) {
cpu_set_t cpu_mask;
CPU_ZERO (&cpu_mask);
CPU_SET (0, &cpu_mask);
fprintf (stderr, "error: sched_setaffinity\n");
return 1;
}
- while (mode--) {
+ while (do_clock--) {
printf ("\r");
printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);
printf ("\t");
pthread_t *tid = (pthread_t *) calloc (nb_threads, sizeof (pthread_t));
assert (tid);
for (int i = 0; i < nb_threads; i++) {
- if (pthread_create (&tid[i], NULL, work, NULL) != 0) {
+ if (pthread_create (&tid[i], NULL, (mode == 1) ? work_alloc : work_math, NULL) != 0) {
fprintf (stderr, "error on pthread_create\n");
return 1;
}