Ejemplo n.º 1
0
void
app_init (App * app)
{
  GError *err = NULL;
    
  app->definitions = gtk_builder_new ();
    
  gtk_builder_add_from_file (app->definitions,
			     UI_DEFINITIONS_FILE, &err);
    
  if (err != NULL) {
    g_printerr
      ("Error while loading app definitions file: %s\n",
       err->message);
    g_error_free (err);
    gtk_main_quit ();
  }
    
  gtk_builder_connect_signals (app->definitions, app);
  
  app_init_colors (app);

  app->filename = NULL;
  
  app->display_level = FALSE;
  app->display_weight = FALSE;




   GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
  GET_UI_ELEMENT(GtkComboBox, combobox_from);  
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_from),renderer,FALSE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_from),renderer,
				       "text",0,
				       NULL);
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_from),0);

  GET_UI_ELEMENT(GtkComboBox, combobox_to);  
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_to),renderer,FALSE);
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_to),renderer,
				       "text",0,
				       NULL);
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_to),0);

	
  //init non graphical units
  app->p_graph = malloc(sizeof(graph));

  app->p_matrix = malloc(sizeof(matrix));
  app->p_matrix->i_size = 3;
  matrix_malloc(app->p_matrix);
  matrix_zero(app->p_matrix);
  
  //construct the graph from the matrix
  init_all(app->p_graph, app->p_matrix);
  
}
Ejemplo n.º 2
0
char set_level(matrix *p_matrix, summit *v_summit)
{
  int i;
  int i_level = 0;
  matrix MatriceTemp;
  MatriceTemp.i_size = p_matrix->i_size;
  matrix_malloc(&MatriceTemp);

  if(has_loop(p_matrix)){
    printf("Error : set_level. A matrix which have loop cannot be used to calculate levels");
    return 0;
  }
  else{
    //Initialisation
    matrix_copy(p_matrix, &MatriceTemp);
    for(i=0;i<MatriceTemp.i_size;i++){
      v_summit[i].i_level = -1;
    }

    for(i=0;i<MatriceTemp.i_size;i++){			//Les sommets sans precedents sont de NV 0
      if(has_prev(&MatriceTemp, i)){
	v_summit[i].i_level = i_level;
      }
    }

    for(i=0;i<MatriceTemp.i_size;i++){
      if(v_summit[i].i_level == i_level){
	matrix_zero_at_line(&MatriceTemp, i);
      }
    }
    //Fin init

    while(!all_level_checked(p_matrix, v_summit)){
      i_level++;
      for(i=0;i<MatriceTemp.i_size;i++){
	if(has_prev(&MatriceTemp, i)&&(v_summit[i].i_level==-1)){
	  v_summit[i].i_level = i_level;
	}
      }

      for(i=0;i<MatriceTemp.i_size;i++){
	if(v_summit[i].i_level == i_level){
	  matrix_zero_at_line(&MatriceTemp, i);
	}
      }	//Fin for
    }	//Fin while
  }	//Fin si has_loop
  matrix_free(&MatriceTemp);
  return 1;
}
Ejemplo n.º 3
0
void master(char *a_fname, char *b_fname, char *out_fname) {
    Matrix a = matrix_read(a_fname);
    Matrix b = matrix_read(b_fname);

    if (a.width != a.height || b.width != b.height || a.width != b.width) {
        printf("Invalid inputs. Both matricies must be nxn. A was %dx%d. B was"
               " %dx%d", a.height, a.width, b.height, b.width);
        MPI_Abort(MPI_COMM_WORLD, -1);
    }

    MPI_Bcast(&(a.width), 1, MPI_INT, 0, MPI_COMM_WORLD);

    Matrix result = matrix_malloc(a.width, b.width);
    matrix_init(&result);
    MPI_matrix_multiply(&result, &a, &b, a.width, 0, MPI_COMM_WORLD);
    matrix_write(out_fname, result);

    if (result.width <= 20)
        matrix_print(result);

    free(result.data);
    free(a.data);
    free(b.data);
}
Ejemplo n.º 4
0
void MPI_matrix_multiply(Matrix *result, Matrix *a, Matrix *b, int n, int root,
                         MPI_Comm comm) {
    int rank, total_procs;

    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &total_procs);

    int rows_per_proc    = n / total_procs;
    int total_procs_used = total_procs;

    MPI_Comm gather_comm = comm;
    int      gather_root = root;

    if (rows_per_proc == 0) {
        if (rank == root)
            printf("Warning: multilpying two %dx%d matricies takes %d or fewer"
                   " processes. %d were given.\n", n, n, n, total_procs);

        int color = rank + root - 1;
        int key   = color % total_procs + 1;
        color /= total_procs;
        MPI_Comm_split(comm, color, key, &gather_comm);

        if (rank == root)
            MPI_Comm_rank(gather_comm, &gather_root);

        MPI_Bcast(&gather_root, 1, MPI_INT, root, comm);

        if (color > 0) return;

        rows_per_proc    = 1;
        total_procs_used = n;
    }

    if (n > total_procs && n % total_procs != 0) {
        if (rank == root)
            printf("Number of rows is not evenly divisible by number of processes.\n");

        return;
    }

    int size = rows_per_proc * n;

    // ##################################################
    // Step 0: Distribute A and invert b
    // ##################################################

    Matrix A = matrix_malloc(rows_per_proc, n);
    MPI_Scatter(rank == root ? a->data : NULL, size, MPI_FLOAT, A.data, size,
                MPI_FLOAT, root, comm);

    if (rank == root && b->is_inverted != 1) matrix_invert(b);

    int i;
    int sender = (rank - 1) % total_procs;

    if (sender < 0) sender += total_procs;

    int reciever       = (rank + 1) % total_procs;
    int last_proc_rank = (root + total_procs_used - 1) % total_procs;

    Matrix B = matrix_malloc(n, rows_per_proc);
    B.is_inverted = 1;
    Matrix C = matrix_malloc(rows_per_proc, n);
    C.is_inverted = 1;

    float *c_data = C.data;

    MPI_Status status;

    double start_time = MPI_Wtime();

    for (i = 0; i < total_procs_used; i++) {
        // ##################################################
        // Step 1: Recieve Data
        // ##################################################
        if (rank == root)
            matrix_get_submatrix(&B, *b, 0, i * rows_per_proc);
        else
            MPI_Recv(B.data, rows_per_proc * n, MPI_FLOAT, sender, MPI_ANY_TAG, comm,
                     &status);

        // ##################################################
        // Step 2: Calculate Dot Product
        // ##################################################
        matrix_multiply(&C, A, B);
        C.data += rows_per_proc;

        // ##################################################
        // Step 3: Send Data
        // ##################################################
        if (rank != last_proc_rank)
            MPI_Send(B.data, rows_per_proc * n, MPI_FLOAT, reciever, 0, comm);
    }

    C.data = c_data;

    // ##################################################
    // Step 4: Get time and Gather on root
    // ##################################################

    double end_time = MPI_Wtime();

    if (rank == last_proc_rank)
        MPI_Send(&end_time, 1, MPI_DOUBLE, 0, 0, comm);

    if (rank == root) {
        MPI_Recv(&end_time, 1, MPI_DOUBLE, last_proc_rank, MPI_ANY_TAG, comm, &status);
        printf("Multiplication took %f seconds.\n", end_time - start_time);
    }

    int send_count = C.width * C.height;
    MPI_Gather(C.data, send_count, MPI_FLOAT,
               rank == root ? result->data : NULL, send_count, MPI_FLOAT,
               gather_root, gather_comm);

    free(C.data);
    free(B.data);
    free(A.data);
}