Esempio n. 1
0
SwitcherMode profile_switcher_dialog ( char **input )
{
    SwitcherMode retv = MODE_EXIT;
    // act as a launcher
    char **cmd_list = get_profile( );

    if ( cmd_list == NULL ) {
        unsigned int retv_index = 0;
        cmd_list = add_elements( cmd_list, "No profiles found", &retv_index );
    }

    int shift=0;
    int selected_line = 0;
    int retvm = menu( cmd_list, input, "profile:", NULL, &shift,token_match, NULL, &selected_line );

    if ( retvm == MENU_NEXT ) {
        retv = NEXT_DIALOG;
    } else if ( retvm == MENU_OK && cmd_list[selected_line] != NULL ) {
        exec_profile( cmd_list[selected_line] );
    }

    for ( int i=0; cmd_list[i] != NULL; i++ ) {
        free( cmd_list[i] );
    }

    free( cmd_list );

    return retv;
}
Esempio n. 2
0
void add_elements(int n)
{
  list_element * le;
  if (n == 0) return;
  add_elements(n-1);
  le = malloc(sizeof(list_element));
  if (le == 0)
    {
      fprintf(stderr, "Out of memory\n");
      exit(2);
    }
  le -> data = n;
  AO_stack_push(&the_list, (AO_t *)le);
}
Esempio n. 3
0
void bi::inverse_gamma_log_densities(const M1 Z, const T1 alpha, const T1 beta,
    V1 p, const bool clear) {
  /* pre-condition */
  BI_ASSERT(Z.size1() == p.size());

  op_elements(vec(Z), vec(Z), inverse_gamma_log_density_functor<T1>(alpha, beta));
  if (clear) {
    sum_columns(Z, p);
  } else {
    typename sim_temp_vector<V1>::type p1(p.size());
    sum_columns(Z, p1);
    add_elements(p, p1, p);
  }
}
UsersGroupsManager::UsersGroupsManager(QSqlDatabase *db, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::UsersGroupsManager)
{   /** CONSTRUCTOR **/

    /// Initialisation of the class properties
    ui->setupUi(this); // GUI
    m_db = db;
    m_listStudents = new QList<qulonglong>();
    m_listGroups = new QList<qulonglong>();
    m_shortcutNotepad = Notepad::shortcut();
    this->addAction(m_shortcutNotepad);

    /// Get the list of the students
    QSqlQuery query(*m_db);
    query.exec("SELECT `id`, `name`, `first_name` FROM `tau_users` ORDER BY UPPER(`name`), UPPER(`first_name`)");
    while (query.next()) {
        Student* stdnt = new Student();
        stdnt->setId(query.value(0).toInt());
        stdnt->setName(query.value(1).toString());
        stdnt->setFirst_name(query.value(2).toString());
        // Add the student in a list
        m_listStudents->append((qulonglong) stdnt);
    }
    /// Get the list of the groups
    query.exec("SELECT `id`, `name` FROM `tau_groups` ORDER BY UPPER(`name`)");
    while (query.next()) {
        Group* grp = new Group();
        grp->setId(query.value(0).toInt());
        grp->setName(query.value(1).toString());
        // Add the group in a list
        m_listGroups->append((qulonglong) grp);
    }

    /// Connect to detect when user click on an item or on a button
    connect(ui->comboBox_browse, SIGNAL(currentIndexChanged(int)), this, SLOT(update_list_browse()));
    connect(ui->list_browse, SIGNAL(itemSelectionChanged()), this, SLOT(update_listsYesNo()));
    connect(ui->pushButton_add, SIGNAL(clicked()), this, SLOT(add_elements()));
    connect(ui->pushButton_remove, SIGNAL(clicked()), this, SLOT(remove_elements()));

    /// Fill the combobox which selects the method to link
    ui->comboBox_browse->addItem("A partir des élèves", BrowseStudents);
    ui->comboBox_browse->addItem("A partir des groupes", BrowseGroups);

    /// Update the lists
    update_list_browse();
}
Esempio n. 5
0
int main(int argc, char **argv)
{
  int nthreads;
  int max_nthreads;
  int exper_n;

  if (1 == argc)
    max_nthreads = 4;
  else if (2 == argc)
    {
      max_nthreads = atoi(argv[1]);
      if (max_nthreads < 1 || max_nthreads > MAX_NTHREADS)
        {
          fprintf(stderr, "Invalid max # of threads argument\n");
          exit(1);
        }
    }
  else
    {
      fprintf(stderr, "Usage: %s [max # of threads]\n", argv[0]);
      exit(1);
    }
  for (exper_n = 0; exper_n < N_EXPERIMENTS; ++ exper_n)
    for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
      {
        int i;
#       ifdef USE_WINTHREADS
          DWORD thread_id;
          HANDLE thread[MAX_NTHREADS];
#       else
          pthread_t thread[MAX_NTHREADS];
#       endif
        int list_length = nthreads*(nthreads+1)/2;
        long long start_time;
        list_element * le;

#       ifdef VERBOSE
          printf("Before add_elements: exper_n=%d, nthreads=%d,"
                 " max_nthreads=%d, list_length=%d\n",
                 exper_n, nthreads, max_nthreads, list_length);
#       endif
        add_elements(list_length);
#       ifdef VERBOSE
          printf("Initial list (nthreads = %d):\n", nthreads);
          print_list();
#       endif
        ops_performed = 0;
        start_time = get_msecs();
        for (i = 1; i < nthreads; ++i) {
          int code;

#         ifdef USE_WINTHREADS
            thread[i] = CreateThread(NULL, 0, run_one_test, (LPVOID)(size_t)i,
                                     0, &thread_id);
            code = thread[i] != NULL ? 0 : (int)GetLastError();
#         else
            code = pthread_create(&thread[i], 0, run_one_test,
                                  (void *)(size_t)i);
#         endif
          if (code != 0) {
            fprintf(stderr, "Thread creation failed %u\n", (unsigned)code);
            exit(3);
          }
        }
        /* We use the main thread to run one test.  This allows gprof   */
        /* profiling to work, for example.                              */
        run_one_test(0);
        for (i = 1; i < nthreads; ++i) {
          int code;

#         ifdef USE_WINTHREADS
            code = WaitForSingleObject(thread[i], INFINITE) == WAIT_OBJECT_0 ?
                        0 : (int)GetLastError();
#         else
            code = pthread_join(thread[i], 0);
#         endif
          if (code != 0) {
            fprintf(stderr, "Thread join failed %u\n", (unsigned)code);
            abort();
          }
        }
        times[nthreads][exper_n] = (unsigned long)(get_msecs() - start_time);
  #     ifdef VERBOSE
          printf("%d %lu\n", nthreads,
                 (unsigned long)(get_msecs() - start_time));
          printf("final list (should be reordered initial list):\n");
          print_list();
  #     endif
        check_list(list_length);
        while ((le = (list_element *)AO_stack_pop(&the_list)) != 0)
          free(le);
      }
    for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
      {
#       ifndef NO_TIMES
          unsigned long sum = 0;
#       endif

        printf("About %d pushes + %d pops in %d threads:",
               LIMIT, LIMIT, nthreads);
#       ifndef NO_TIMES
          for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n) {
#           if defined(VERBOSE)
              printf(" [%lu]", times[nthreads][exper_n]);
#           endif
            sum += times[nthreads][exper_n];
          }
          printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS);
#       else
          printf(" completed\n");
#       endif
      }
  return 0;
}
Esempio n. 6
0
int
main(int argc, char *argv[])
{
	if (initialize_context(&my_context, argc, argv) != 0) {
		usage(argv[0]);
		return 1;
	}

	if (art_tree_map_init(&myds, &my_context) != 0) {
		fprintf(stderr, "failed to initialize memory pool file\n");
		return 1;
	}

	if (my_context.pop == NULL) {
		perror("pool initialization");
		return 1;
	}

	if (art_tree_init(my_context.pop, &my_context.newpool)) {
		perror("pool setup");
		return 1;
	}

	if ((my_context.mode & FILL)) {
		if (add_elements(&my_context)) {
			perror("add elements");
			return 1;
		}
	}

	if ((my_context.mode & INSERT)) {
		if (insert_element(&my_context)) {
			perror("insert elements");
			return 1;
		}
	}

	if ((my_context.mode & SEARCH)) {
		if (search_element(&my_context)) {
			perror("search elements");
			return 1;
		}
	}

	if ((my_context.mode & REMOVE)) {
		if (delete_element(&my_context)) {
			perror("delete elements");
			return 1;
		}
	}

	if (my_context.mode & DUMP) {
		art_iter(my_context.pop, dump_art_leaf_callback, NULL);
	}

	if (my_context.mode & GRAPH) {
		printf("digraph g {\nrankdir=LR;\n");
		art_iter(my_context.pop, dump_art_node_callback, NULL);
		printf("}");
	}

	exit_handler(&my_context);

	return 0;
}
Esempio n. 7
0
int main(int argc, char **argv)
{
  int nthreads;
  int max_nthreads;
  int exper_n;

  if (1 == argc)
    max_nthreads = 4;
  else if (2 == argc)
    {
      max_nthreads = atoi(argv[1]);
      if (max_nthreads < 1 || max_nthreads > MAX_NTHREADS)
        {
          fprintf(stderr, "Invalid max # of threads argument\n");
          exit(1);
        }
    }
  else
    {
      fprintf(stderr, "Usage: %s [max # of threads]\n", argv[0]);
      exit(1);
    }
  for (exper_n = 0; exper_n < N_EXPERIMENTS; ++ exper_n)
    for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
      {
        int i;
        pthread_t thread[MAX_NTHREADS];
        int list_length = nthreads*(nthreads+1)/2;
        long long start_time;
        list_element * le;

        add_elements(list_length);
#       ifdef VERBOSE
          printf("Initial list (nthreads = %d):\n", nthreads);
          print_list();
#       endif
        ops_performed = 0;
        start_time = get_msecs();
        for (i = 1; i < nthreads; ++i) {
          int code;

          if ((code = pthread_create(thread+i, 0, run_one_test,
                                     (void *)(long)i)) != 0) {
            fprintf(stderr, "Thread creation failed %u\n", code);
            exit(3);
          }
        }
        /* We use the main thread to run one test.  This allows gprof   */
        /* profiling to work, for example.                              */
        run_one_test(0);
        for (i = 1; i < nthreads; ++i) {
          int code;
          if ((code = pthread_join(thread[i], 0)) != 0) {
            fprintf(stderr, "Thread join failed %u\n", code);
            abort();
          }
        }
        times[nthreads][exper_n] = (unsigned long)(get_msecs() - start_time);
  #     ifdef VERBOSE
          printf("%d %lu\n", nthreads,
                 (unsigned long)(get_msecs() - start_time));
          printf("final list (should be reordered initial list):\n");
          print_list();
  #     endif
        check_list(list_length);
        while ((le = (list_element *)AO_stack_pop(&the_list)) != 0)
          free(le);
      }
# ifndef NO_TIMES
    for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
      {
        unsigned long sum = 0;

        printf("About %d pushes + %d pops in %d threads:",
               LIMIT, LIMIT, nthreads);
        for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n)
          {
#           if defined(VERBOSE)
              printf("[%lu] ", times[nthreads][exper_n]);
#           endif
            sum += times[nthreads][exper_n];
          }
        printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS);
      }
# endif /* !NO_TIMES */
  return 0;
}