Example #1
0
int main() {

	int num_rows = 0; //initialize number of rows
	int num_cols = 0; //initialize number of columns

	int** matrix_A = NULL; //first matrix whose dimensions are initialized by the max size
	int** matrix_B = NULL; //second matrix
	int** matrix_C = NULL;


	printf("Please enter the number of rows: "); //ask the user how many rows are in the matrix
	scanf("%d", &num_rows);
	
	printf("Please enter the number of columns: "); //ask the user how many columns are in the matrix
	scanf("%d", &num_cols);
	
	matrix_A= get_size(num_rows, num_cols);
	matrix_B = get_size(num_rows, num_cols);
	matrix_C = get_size( num_rows, num_cols);

	printf("Enter Matrix A\n");
	get_matrix(num_rows, num_cols, matrix_A); //call the function that stores the values in matrix A, passed as an argument

	printf("Enter Matrix B\n");
	get_matrix(num_rows, num_cols, matrix_B); //call the function that stores the values in matrix B, passed in the argument

	printf("A + B =\n"); //resulting matrix
	add_matrices(num_rows, num_cols, matrix_A, matrix_B, matrix_C); //call the function that adds them together


	


	return 0;
}
Example #2
0
void load_gs(void){

	get_matrix("Operation","B",&gs->B);
	get_matrix("Operation","A",&gs->A);

	get_int("Task","Priority",&gs->task_prio);
}
Example #3
0
void TargetCamera::set_camera(long time)
{
	set_view_matrix(get_matrix());
	set_unistate("st_view_matrix3",Matrix3x3(get_matrix()));

    //DEBUG
    Matrix4x4 view = get_matrix();
    glMatrixMode(GL_MODELVIEW);
    glLoadTransposeMatrixf(view[0]);
}
Example #4
0
	void sprite_instance::get_bound(rect* bound)
	{
		int i, n = m_display_list.size();
		if (n == 0)
		{
			return;
		}

		bound->m_x_min = FLT_MAX;
		bound->m_x_max = - FLT_MAX;
		bound->m_y_min = FLT_MAX;
		bound->m_y_max = - FLT_MAX;

		matrix m = get_matrix();
		for (i = 0; i < n; i++)
		{
			character* ch = m_display_list.get_character(i);
			if (ch != NULL)
			{
				rect ch_bound;
				ch->get_bound(&ch_bound);

				m.transform(&ch_bound);

				bound->expand_to_rect(ch_bound);
			}
		}
	}
void solve_triangle_eq_omp()
{
	char *results_file = "solve_triangle_eq_omp.txt";
	FILE *res;
	if((res=fopen(results_file, "w"))==NULL)
	{
		printf("Can't open file %s.\n", results_file);
		exit(1);
	}
	for(int i = 10; i < ROW; i*=10)
	{
		double **A = get_matrix(i,i);
		double 	*X = get_vector(i,i);
		double start = omp_get_wtime();
		#pragma omp parallel for collapse(2)
		for (int s=i-1; s>=0; s--) 
		{
			X[s] = A[s][i]/A[s][s];
			for (int k=s-1;k>=0; k--)
			    A[k][i] -= A[k][s] * X[s];
		}
		double end = omp_get_wtime();
		fprintf(res, "%lf\n", end-start);
		free(X);
		for(int s = 0; s < i; s++)
			free(A[s]);
		free(A);
	}
	fclose(res);
}
Example #6
0
int main(int argc, char const *argv[]) {
  if(argc!=2){
    printf("USAGE: %s FILE\n", argv[0]);
    return EXIT_FAILURE;
  }
  FILE* f = fopen(argv[1], "r");
  if(!f){
    perror("Failed to open file: ");
    return EXIT_FAILURE;
  }
  atexit(clean_matrix);
  yyin = f;
  yyparse();
  fclose(f);
  yylex_destroy();
  build_starts();
  link_matrix();
  struct MATRIX *matrix = get_matrix();
  int result = forkx(matrix);
  free(matrix);
  if(!result){
    wait_for_children();
  }
  return EXIT_SUCCESS;
}
Example #7
0
void zpr_init(void) {
  get_matrix();

  glutReshapeFunc(zpr_reshape);
  glutMouseFunc(zpr_mouse);
  glutMotionFunc(zpr_motion);
  zpr_reset();
}
bool
RendererServices::get_inverse_matrix (Matrix44 &result, ustring to)
{
    bool ok = get_matrix (result, to);
    if (ok)
        result.invert ();
    return ok;
}
bool
RendererServices::get_inverse_matrix (Matrix44 &result, TransformationPtr xform)
{
    bool ok = get_matrix (result, xform);
    if (ok)
        result.invert ();
    return ok;
}
Example #10
0
void BillBoard::set_vectors()
{
	// Take vectors from inverse matrix
	// (for orthogonal matrices, transpose equals inverse)	

	Matrix4 m(get_matrix(GL_MODELVIEW_MATRIX));
	bbimp.init(Vector(m[0][0],m[1][0],m[2][0]),Vector(m[0][1],m[1][1],m[2][1]));
}
Example #11
0
	bool sprite_instance::get_topmost_mouse_entity ( character * &top_ent, float x, float y )
	// Return the topmost entity that the given point
	// covers that can receive mouse events.  NULL if
	// none.  Coords are in parent's frame.
	{
		if ( get_visible() == false )
		{
			return NULL;
		}

		matrix	m = get_matrix();
		point	p;
		m.transform_by_inverse ( &p, point ( x, y ) );
		character	*top_te = NULL;
		bool this_has_focus = false;
		int i, n = m_display_list.size();
		top_ent = NULL;

		// Go backwards, to check higher objects first.
		for ( i = n - 1; i >= 0; i-- )
		{
			character *ch = m_display_list.get_character ( i );
			character *te = NULL;

			if ( ch != NULL && ch->get_visible() )
			{
				if ( ch->get_topmost_mouse_entity ( te, p.m_x, p.m_y ) )
				{
					this_has_focus = true;

					// The containing entity that 1) is closest to root and 2) can
					// handle mouse events takes precedence.
					if ( te && te->can_handle_mouse_event() )
					{
						top_te = te;
						break;
					}
				}
			}
		}

		//  THIS is closest to root
		if ( this_has_focus && can_handle_mouse_event() )
		{
			top_ent = this;
		}

		else

			// else character which has event is closest to root
			if ( top_te )
			{
				top_ent = top_te;
			}

		// else if we have focus then return not NULL
		return this_has_focus;
	}
Example #12
0
File: main.c Project: rdragos/work
void sum(int n1, int m1, int n2, int m2) {
    

    if (n1 != n2 || m1 != m2) {
        printf("Impossimatrix to add");
        return ;
    }
    new_matrix(n1, m1, ptr_out3);
    int N = n1, M = m1;

    for (int i = 0; i < n1; ++i) {
        for (int j = 0; j < m1; ++j) {
            double x = get_matrix(n1, m1, i, j, ptr_out1);
            x += get_matrix(n2, m2, i, j, ptr_out2);
            set_matrix(N, M, i, j, x);
        }
    }
}
Example #13
0
int pairalign_seq(int istart, int iend, int jstart, int jend)
{
   int i, n, m, si, sj;
   int len1, len2, maxres;
   double gg, mm_score;
   int    *mat_xref, *matptr;

   matptr   = gon250mt;
   mat_xref = def_aa_xref;
   maxres = get_matrix(matptr, mat_xref, 10);
   if (maxres == 0) return(-1);

   for (si = 0; si < nseqs; si++) {
      if ((n = seqlen_array[si+1]) != 0){
         for (i = 1, len1 = 0; i <= n; i++) {
            char c = seq_array[si+1][i];
            if ((c != gap_pos1) && (c != gap_pos2)) len1++;
         }

         for (sj = si + 1; sj < nseqs; sj++) {
            if ((m = seqlen_array[sj+1]) != 0){
               int se1, se2, sb1, sb2, maxscore, seq1, seq2, g, gh;
               int displ[2*MAX_ALN_LENGTH+1];
               int print_ptr, last_print;

               for (i = 1, len2 = 0; i <= m; i++) {
                  char c = seq_array[sj+1][i];
                  if ((c != gap_pos1) && (c != gap_pos2)) len2++;
               }

               gh = 10 * pw_ge_penalty;
               gg = pw_go_penalty + log((double) MIN(n, m));
               g  = (mat_avscore <= 0) ? 20 * gg : 2 * mat_avscore * gg;

               seq1 = si + 1;
               seq2 = sj + 1;

               forward_pass(&seq_array[seq1][0], &seq_array[seq2][0], n, m, &se1, &se2, &maxscore, g, gh);
               reverse_pass(&seq_array[seq1][0], &seq_array[seq2][0], se1, se2, &sb1, &sb2, maxscore, g, gh);

               print_ptr  = 1;
               last_print = 0;

               diff(sb1-1, sb2-1, se1-sb1+1, se2-sb2+1, 0, 0, &print_ptr, &last_print, displ, seq1, seq2, g, gh);
               mm_score = tracepath(sb1, sb2, &print_ptr, &last_print, displ, seq1, seq2);

               if (len1 == 0 || len2 == 0) mm_score  = 0.0;
               else                        mm_score /= (double) MIN(len1,len2);

               seq_output[si*nseqs+sj] = mm_score;
            }
         }
      }
   }
   return 0;
}
Example #14
0
File: main.c Project: rdragos/work
void prod(int n1, int m1, int n2, int m2) {
    if (n2 != m1) {
        printf("Impossimatrix to multiply");
        return ;
    }
    new_matrix(n1, m2, ptr_out3);
    int N = n1;
    int M = m2;
    //c[i][j] = a[i][k] * b[k][j]
    for (int i = 0; i < n1; ++i) {
        for (int j = 0; j < m2; ++j) {
            double x = 0;
            for (int k = 0; k < m1; ++k) {
                x += get_matrix(n1, m1, i, k, ptr_out1) * get_matrix(n2, m2, k, j, ptr_out2) ;
            }
            set_matrix(N, M, i, j, x);
        }
    }
}
Example #15
0
void load_gs(void){

	/*
	 * Change this code.
	 */
	get_string("Operation","aString",gs->aString);
	get_int("Operation","anInt",&gs->anInt);
	get_double("Operation","aDouble",&gs->aDouble);
	get_matrix("Operation","aMatrix",&gs->aMatrix);

	get_int("Task","Priority",&gs->task_prio);
}
Example #16
0
void sphere_t::render(GLuint shdr_prog) {
  assert(glIsProgram(shdr_prog) && "Invalid program handle!");
  glUseProgram(shdr_prog);

  glm::mat4 mvp = cam.get_proj() * cam.get_matrix() * get_matrix();
  GLint location = glGetUniformLocation(shdr_prog, "u_mvp");
  glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(mvp));

  glm::mat3 normal = glm::transpose(glm::inverse(glm::mat3(get_matrix())));
  location = glGetUniformLocation(shdr_prog, "u_norm_mtrx");
  glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(normal));

  glBindVertexArray(gfx_def.vao);
  glEnableVertexAttribArray(vtx_attr.pos);
  // glEnableVertexAttribArray(gdef_t::vattr::norm);

  glDrawArrays(GL_LINE_LOOP, 0, mesh.vtx_data.size());

  glDisableVertexAttribArray(vtx_attr.pos);
  // glDisableVertexAttribArray(gdef_t::vattr::norm);
  glBindVertexArray(0);
  glUseProgram(0);
}
Example #17
0
void aln_score(void)
{
  static short  *mat_xref, *matptr;
  static sint maxres;
  static sint  s1,s2,c1,c2;
  static sint    ngaps;
  static sint    i,l1,l2;
  static lint    score;
  static sint   matrix[NUMRES][NUMRES];

/* calculate an overall score for the alignment by summing the
scores for each pairwise alignment */

  matptr = blosum45mt;
  mat_xref = def_aa_xref;
  maxres = get_matrix(matptr, mat_xref, matrix, TRUE, 100);
  if (maxres == 0)
    {
       fprintf(stdout,"Error: matrix blosum30 not found\n");
       return;
    }

  score=0;
  for (s1=1;s1<=nseqs;s1++)
   {
    for (s2=1;s2<s1;s2++)
      {

        l1 = seqlen_array[s1];
        l2 = seqlen_array[s2];
        for (i=1;i<l1 && i<l2;i++)
          {
            c1 = seq_array[s1][i];
            c2 = seq_array[s2][i];
            if ((c1>=0) && (c1<=max_aa) && (c2>=0) && (c2<=max_aa))
                score += matrix[c1][c2];
          }

        ngaps = count_gaps(s1, s2, l1);

        score -= 100 * gap_open * ngaps;

      }
   }

  score /= 100;

  info("Alignment Score %d", (pint)score);

}
Example #18
0
std::shared_ptr<const VectorXd>
convert_to_eigen(const VectorDImpl & ten)
{
    // does the TensorImpl contain an eigen matrix?
    auto test = dynamic_cast<const EigenVectorImpl*>(&ten);
    if(test)
        return test->get_matrix();

    // otherwise, convert elementwize
    auto ret = std::make_shared<VectorXd>();

    auto sizes = ten.sizes();
    for(size_t i = 0; i < sizes[0]; i++)
        (*ret)(i) = ten.get_value({i});
    return ret;
}
Example #19
0
	static void drawcylinder(coord a, coord b, double width)
	{
		double matrix[16];
		if (cylqs == NULL)
		{
			cylqs = gluNewQuadric();
			gluQuadricNormals(cylqs, GLU_SMOOTH);
			gluQuadricOrientation(cylqs, GLU_OUTSIDE);
			gluQuadricDrawStyle(cylqs, GLU_FILL);//GLU_SILHOUETTE
		}
		glPushMatrix();
		glTranslated(a[0], a[1], a[2]);
		get_matrix(a, b, matrix);
		glMultMatrixd(matrix);
		gluCylinder(cylqs, width, width, sqrt((b - a) ^ (b - a)), 4, 2);
		glPopMatrix();
	}
Example #20
0
File: test1.c Project: blabos/Comp
int main(int argc, char** argv) {
    int i, j, count;
    
    
    
    args_t args;
    args.num_states = 3;
    args.num_symbols = 4;
    
    char symbols[4] = { 'a', 'b', 'c', 'd' };
    char* states[3] = { "e0", "e1", "e2" };
    
    args.symbols = symbols;
    args.states = states;
    args.transitions = get_matrix();
    
    printf("int main(int argc, char** argv) {\n");
    printf("    int curr  = -1;\n");
    printf("    char* str = argv[1];\n\n");
    printf("    if (argc != 2) goto error;\n");
    
    for (i = 0; i < args.num_states; i++) {
        printf("\n    %s:\n         curr++;\n", states[i]);
        count = 0;
        for (j = 0; j < args.num_symbols; j++) {
            if (args.transitions[i + j * args.num_states] != -1) {
                if (count > 0)
                    printf("    else ");
                else
                    printf("         ");
                count++;
                printf("if(str[curr] == '%c') goto %s;\n", symbols[j],
                        states[args.transitions[i + j * args.num_states]]);
            }
        }
        if (count > 0) printf("    else ");
        else printf("    ");
        printf("goto error;\n");
    }
    printf("\n    error:\n        return -1;\n");
    printf("\n    success:\n        return 0;\n}\n");

    return EXIT_SUCCESS;
}
Example #21
0
/*
*******************************************************************************
*                     Parse_Pic_BMP
*
* Description:
*    以路径名来解析图片, 并且把解析处理的图片拷贝到指定的地址,
* 如果指定的地址为NULL, 则可以存放在任何地址。
*
* Parameters:
*    Path           :  input.  图片路径
*    PictureInfo    :  output. 图片解析后的信息
*    Addr			:  input.  存放解析后的图片, 
*
* Return value:
*    void
*
* note:
*    void
*
*******************************************************************************
*/
__s32 Parse_Pic_BMP_ByPath(char *Path, Picture_t *PictureInfo, __u32 Addr)
{
    HBMP_i_t hbmp_buf;
    HBMP  hbmp = NULL;
    
    eLIBs_memset(&hbmp_buf, 0, sizeof(HBMP_i_t));
    hbmp = open_bmp(Path, &hbmp_buf);
    if(hbmp == NULL){
        __wrn("ERR: open_bmp failed\n");
        return -1;
    }

    PictureInfo->BitCount = get_bitcount(hbmp);
	PictureInfo->Width    = get_width(hbmp);
	PictureInfo->Height	  = get_height(hbmp);
	PictureInfo->RowSize  = get_rowsize(hbmp);

	PictureInfo->BufferSize = PictureInfo->RowSize * PictureInfo->Height;
	if(Addr){
		PictureInfo->Buffer = (void *)Addr;
	}else{
		PictureInfo->Buffer = (void *)esMEMS_Balloc(PictureInfo->BufferSize);
	}
	if(PictureInfo->Buffer == NULL){
		__wrn("ERR: wboot_malloc failed\n");
        goto error;
	}

	eLIBs_memset(PictureInfo->Buffer, 0, PictureInfo->BufferSize);

	get_matrix(hbmp, PictureInfo->Buffer);

	close_bmp(hbmp);
	hbmp = NULL;

    return 0;

error:
	close_bmp(hbmp);
	
	return -1;
}
Example #22
0
unsigned int remove_not_factorized(
	unsigned int** exponents,
	mpz_t* reduced_q_a,
	mpz_t* q_a,
	unsigned int howmany,
	unsigned int primes_num
	) {

	unsigned int i;
	unsigned int j;
	unsigned int k = 0;

	for(i = 0; i < howmany; ++i) {
		if(mpz_cmp_ui(reduced_q_a[i], 1) == 0) {
		  mpz_set(q_a[k], q_a[i]);
		  for(j = 0; j < primes_num; ++j)
		  	set_matrix(exponents, k, j, get_matrix(exponents, i, j));
		  ++k;
		}
	}

	return k;
}
Example #23
0
int client(int argc, char const *argv[])
{
    int ips = 0;
    double result = 0;
    struct in_addr* ips_array = NULL;
    matrix current = {};
    
    if (scan(&ips, &ips_array) == -1) {
        print_error(CT_SCAN_FAIL);
        goto fail;
    }
    fprintf(stderr, "Network scan completed.\n");

    if (get_matrix(argv[2], &current) == -1) {
        print_error(CT_MATR_READ_FAIL);
        goto fail;
    }
    fprintf(stderr, "Matrix has been read");

    if (get_det(&current, &result, ips, ips_array) == -1) {
        print_error(CT_DET_CALC_FAIL);
        goto fail;
    }   

    fprintf(stderr, "Determinant is %lg\n", result); 

    free(ips_array);
    matrix_kill(&current);
    return 0;

fail:
    
    free(ips_array);
    matrix_kill(&current);
    return -1;
}
Example #24
0
		virtual bool get_topmost_mouse_entity( character * &te, float x, float y)
		// Return the topmost entity that the given point covers.  NULL if none.
		// I.e. check against ourself.
		{
			if (get_visible() == false || is_enabled() == false)
			{
				return false;
			}

			point	p;
			get_matrix().transform_by_inverse(&p, point(x, y));

			for (int i = 0; i < m_def->m_button_records.size(); i++)
			{
				button_record&	rec = m_def->m_button_records[i];
				if (rec.m_character_id < 0 || rec.m_hit_test == false)
				{
					continue;
				}

				// Find the mouse position in button-record space.
				point	sub_p;
				rec.m_button_matrix.transform_by_inverse(&sub_p, p);

				if (rec.m_character_def->point_test_local(sub_p.m_x, sub_p.m_y))
				{
					// The mouse is inside the shape.
					te = this;
					return true;
					// @@ Are there any circumstances where this is correct:
					//return m_record_character[i].get_ptr();
				}
			}

			return false;
		}
Example #25
0
bool
SimpleRenderer::get_matrix (Matrix44 &result, ustring from, float time)
{
    return get_matrix(result, from);
}
Example #26
0
static void zpr_motion(int x, int y) {
  bool changed = false;

  const int dx = x - _mousex;
  const int dy = y - _mousey;

  GLint viewport[4];
  glGetIntegerv(GL_VIEWPORT, viewport);

  if(dx == 0 && dy == 0) return;

  if(_mouse_middle || _mouse_right) {
    double s = exp((double)dy * 0.01);

    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2] );
    glscale *= s;
    glScalef(s, s, s);
    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);

    changed = true;
  }
  else if(_mouse_left) {
    double ax, ay, az;
    double bx, by, bz;
    double angle;

    ax = dy;
    ay = dx;
    az = 0.0;
    angle = vlen(az, ay, az) / (double)(viewport[2]+1)*180.0;

    // Use inverse matrix to determine axis of rotation.
    bx = _matrix_inverse[0] * ax + _matrix_inverse[4] * ay + _matrix_inverse[8]   * az;
    by = _matrix_inverse[1] * ax + _matrix_inverse[5] * ay + _matrix_inverse[9]   * az;
    bz = _matrix_inverse[2] * ax + _matrix_inverse[6] * ay + _matrix_inverse[10]  * az;

    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);
    glRotatef(angle, bx, by, bz);
    glTranslatef(zpr_reference_point[0], zpr_reference_point[1], zpr_reference_point[2]);

    changed = true;
  }
  else if(0 && _mouse_right) {
    double px, py, pz;

    pos(&px, &py, &pz, x, y, viewport);

    glLoadIdentity();
    glTranslatef(px - _drag_posx, py - _drag_posy, pz - _drag_posz);
    glMultMatrixd(_matrix);

    _drag_posx = px;
    _drag_posy = py;
    _drag_posz = pz;

    changed = true;
  }
  _mousex = x;
  _mousey = y;

  if(changed) {
    reset_orientation = 0;
    get_matrix();
    glutPostRedisplay();
  }
}
Example #27
0
unsigned int sieve(
	mpz_t n,
	unsigned int* factor_base,
	unsigned int base_dim,
	pair* solutions,
	unsigned int** exponents,
	mpz_t* As,
	unsigned int poly_val_num,
	unsigned int max_fact,
	unsigned int intervals
	) {

	unsigned int i;

	unsigned int** expo2;
	init_matrix(&expo2, intervals, base_dim);
	word** is_used_expo2;
	init_matrix_l(&is_used_expo2, 1, (intervals / N_BITS) + 1);
	for(i = 0; i < ((intervals / N_BITS) + 1); ++i) {
		set_matrix_l(is_used_expo2, 0, i, 0);
	}

	mpz_t n_root;
	mpz_t intermed;
	mpz_init(n_root);
	mpz_init(intermed);
	mpz_sqrt(n_root, n);

	unsigned char go_on = 1;

	unsigned int fact_count = 0;
	unsigned int j, k;
	mpz_t* evaluated_poly;

	init_vector_mpz(&evaluated_poly, poly_val_num);

	word** is_used;
	init_matrix_l(&is_used, 1, (poly_val_num / N_BITS) + 1);
	for(i = 0; i < ((poly_val_num / N_BITS) + 1); ++i) {
		set_matrix_l(is_used, 0, i, 0);
	}

	max_fact += base_dim;

	// Trovo poly_val_num valori del polinomio (A + s)^2 - n, variando A
	for(i = 0; i < poly_val_num; ++i) {
		mpz_add_ui(intermed, n_root, i);
		mpz_mul(intermed, intermed, intermed);
		mpz_sub(evaluated_poly[i], intermed, n);
		
		mpz_add_ui(As[i], n_root, i);
	}

	// Per ogni primo nella base di fattori
	for(i = 0; i < base_dim && go_on; ++i) {

		// Provo tutte le possibili fattorizzazioni nella base di fattori
		for(j = solutions[i].sol1; j < poly_val_num && go_on; j += factor_base[i]) {

			// Divido e salvo l'esponente va bene
			while(mpz_divisible_ui_p(evaluated_poly[j], factor_base[i])) {
				
				// Se non sono mai stati usati gli esponenti
				if(get_k_i(is_used, 0, j) == 0) {
					for(k = 0; k < base_dim; ++k)
						set_matrix(exponents, j, k, 0);
					set_k_i(is_used, 0, j, 1);
				}
				
				set_matrix(exponents, j, i, get_matrix(exponents, j, i) + 1); // ++exponents[j][i];
				mpz_divexact_ui(evaluated_poly[j], evaluated_poly[j], factor_base[i]);	
			}
			
			if(mpz_cmp_ui(evaluated_poly[j], 1) == 0) {
				++fact_count;
				if(fact_count >= max_fact) {
					go_on = 0;
				}
			}
		}

		// Faccio la stessa cosa con entrambe le soluzioni, a meno che non stia usando 2
		if(factor_base[i] != 2) {
			for(j = solutions[i].sol2; j < poly_val_num && go_on; j += factor_base[i]) {

				while(mpz_divisible_ui_p(evaluated_poly[j], factor_base[i])) {
					
					// Se non sono mai stati usati gli esponenti
					if(get_k_i(is_used, 0, j) == 0) {
						for(k = 0; k < base_dim; ++k)
							set_matrix(exponents, j, k, 0);
						set_k_i(is_used, 0, j, 1);
					}

					set_matrix(exponents, j, i, get_matrix(exponents, j, i) + 1); // ++exponents[j][i];
					mpz_divexact_ui(evaluated_poly[j], evaluated_poly[j], factor_base[i]);
				}

				if(mpz_cmp_ui(evaluated_poly[j], 1) == 0) {
					++fact_count;
					if(fact_count >= max_fact) {
						go_on = 0;
					}
				}
			}
		}
	}

	mpz_clear(n_root);
	mpz_clear(intermed);

	remove_not_factorized(exponents, evaluated_poly, As, poly_val_num, base_dim);

	// finalize_vector_mpz(&evaluated_poly, poly_val_num);
	// Si noti che questa istruzione apparentemente innocua porta all'uscita di demoni dal naso del programmatore

	return fact_count;
}
Example #28
0
int main(int argc, char **argv) 
{
  int i, j;
  int width;          /* width of the matrix           */
  int matsize;        /* total matrix values           */
  int *input_matrix;  /* the matrix read in            */
  int *result_matrix; /* threads will put results here */
  thread_info *threads;
  pthread_t *thread_id;
  
  if (argc < 2)
  {
    printf("Insufficient parameters supplied\n");
    return -1;
  }
  
    /* Reading the input matrix from a file into it's memory. */
  input_matrix = get_matrix(argv[1], &width);
  
    /* record square of matrix */
  matsize = width * width;
  
    /* array of structs to fill in data for threads */
  threads = malloc(sizeof(thread_info) * matsize);
  
    /* array to hold thread ids */
  thread_id = malloc(sizeof(pthread_t) * matsize);
  
    /* Printing the input matrix. */
  print_matrix(input_matrix, width);
  
    /* allocate memory for result matrix */
  result_matrix = malloc(sizeof(int) * width * width);
  
  
    /* Creating all of the other threads and supplying them with */
    /* their parameters                                          */ 
  for (i = 0; i < width; i++)
  {
    for(j = 0; j < width; j++)
    {
        /* fill in paramters of struct to use in specific thread */
      threads[i * width + j].row = i;
      threads[i * width + j].column = j;
      threads[i * width + j].width = width;
      threads[i * width + j].matrix = input_matrix;
      threads[i * width + j].result_matrix = result_matrix;
      pthread_create(&thread_id[i * width + j], NULL, 
                     matrix_multiply, &threads[i * width + j]);
    }
  }

    /* Waiting for all of the threads to finish. */
  for(i = 0; i < matsize; i++)
  {
    pthread_join(thread_id[i], NULL);
  }
    
    /* Printing the resulting squared matrix. */
  print_matrix(result_matrix, width);
  
    /* Cleaning up any memory or resources the main thread created. */
  free(input_matrix);
  free(result_matrix);
  free(thread_id);
  free(threads);
  
  return 0;
}
Example #29
0
File: main.c Project: alexmavr/pps
int main(int argc, char **argv)
{
    int k;
    int N;
    int i;
    int rank;
    int max_rank;
    int workload;
    int ret = 0;
    int bcaster = 0;
    double sec;
    double *A = NULL;
    double **A2D = NULL;
    double *Ap = NULL;
    double **Ap2D = NULL;
    double *Ak = NULL;
    FILE *fp = NULL;
    void (*propagate) (void*, int, MPI_Datatype, int, MPI_Comm);
    time_struct ts;

    usage(argc, argv);
    propagate = get_propagation(argc, argv);

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &max_rank);

    /* Root gets the matrix */
    if (rank == 0){
        Matrix *mat = get_matrix(argv[1], max_rank, CONTINUOUS);
        N = mat->N;
        A = mat->A;
        A2D = appoint_2D(A, N, N);
    }
    /* And broadcasts N */
    MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);

    workload = (N / max_rank) + 1; // Max number of rows for each thread

#if main_DEBUG
    if (rank == 0){
        debug("A: \n");
        print_matrix_2d(N, N, A);
    }
#endif

    /* Allocations */
    Ak = malloc(N * sizeof(double));
    Ap = malloc(workload * N * sizeof(double));

    /* Scatter the table to each thread's Ap */
    MPI_Scatter(A, workload * N, MPI_DOUBLE, \
            Ap, workload * N, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    
    Ap2D = appoint_2D(Ap, workload, N);

    /* Init Communication Timer */
    time_struct_init(&ts);

    /* Start Total Timer */
    MPI_Barrier(MPI_COMM_WORLD);
    if(rank == 0) {
        sec = timer();
    }

    for (k = 0; k < N - 1 ; k++) {
        /* Find who owns the k-th row */
        bcaster = k / workload; 
            
        /* The broadcaster puts his k-th row in the Ak buffer */
        if (rank == bcaster) {
            i = k % workload;
            memcpy(&Ak[k], &Ap2D[i][k], (N-k) * sizeof(double));
        }

        /* Everyone receives the k-th row */
        time_struct_set_timestamp(&ts);
        (*propagate) (&Ak[k], N-k, MPI_DOUBLE, bcaster, MPI_COMM_WORLD);
        time_struct_add_timestamp(&ts);

        /* And off you go to work. */
        process_rows(k, rank, N, workload, Ap2D, Ak);
    }

    /* Stop Timing */
    MPI_Barrier(MPI_COMM_WORLD);
    if(rank == 0) {
        sec = timer();
        printf("Calc Time: %lf\n", sec);
    }

    printf("Rank: %d Comm Time: %lf\n", rank, get_seconds(&ts));

    /* Gather the table from each thread's Ap */
    MPI_Gather(Ap, workload * N, MPI_DOUBLE, \
            A, workload * N, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    ret = MPI_Finalize();
    if(ret == 0) {
        debug("%d FINALIZED!!! with code: %d\n", rank, ret);
    }
    else {
        debug("%d NOT FINALIZED!!! with code: %d\n", rank, ret);
    }

    /* Format and output solved matrix */
    if(rank == 0) {
        upper_triangularize(N, A2D);
        fp = fopen(argv[2], "w");
        fprint_matrix_2d(fp, N, N, A);
        fclose(fp);
        free(A);
        free(A2D);
    }
    free(Ap);
    free(Ap2D);
    free(Ak);

    return 0;
}
Example #30
0
sint pairalign(sint istart, sint iend, sint jstart, sint jend)
{
  short	 *mat_xref;
  static sint    si, sj, i;
  static sint    n,m,len1,len2;
  static sint    maxres;
  static short    *matptr;
  static char   c;
  static float gscale,ghscale;

  displ = (sint *)ckalloc((2*max_aln_length+1) * sizeof(sint));
  HH = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  DD = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  RR = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
  SS = (pwint *)ckalloc((max_aln_length) * sizeof(pwint));
		
#ifdef MAC
  int_scale = 10;
#else
  int_scale = 100;
#endif
  gscale=ghscale=1.0;
  if (dnaflag)
    {
      if (debug>1) fprintf(stdout,"matrix %s\n",pw_dnamtrxname);
      if (strcmp(pw_dnamtrxname, "iub") == 0)
	{ 
	  matptr = swgapdnamt;
	  mat_xref = def_dna_xref;
	}
      else if (strcmp(pw_dnamtrxname, "clustalw") == 0)
	{ 
	  matptr = clustalvdnamt;
	  mat_xref = def_dna_xref;
	  gscale=0.6667;
	  ghscale=0.751;
	}
      else
	{
	  matptr = pw_userdnamat;
	  mat_xref = pw_dna_xref;
	}
      maxres = get_matrix(matptr, mat_xref, matrix, TRUE, int_scale);
      if (maxres == 0) return((sint)-1);

      matrix[0][4]=transition_weight*matrix[0][0];
      matrix[4][0]=transition_weight*matrix[0][0];
      matrix[2][11]=transition_weight*matrix[0][0];
      matrix[11][2]=transition_weight*matrix[0][0];
      matrix[2][12]=transition_weight*matrix[0][0];
      matrix[12][2]=transition_weight*matrix[0][0];
    }
  else
    {
      if (debug>1) fprintf(stdout,"matrix %s\n",pw_mtrxname);
      if (strcmp(pw_mtrxname, "blosum") == 0)
	{
	  matptr = blosum30mt;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "pam") == 0)
	{
	  matptr = pam350mt;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "gonnet") == 0)
	{
	  matptr = gon250mt;
	  int_scale /= 10;
	  mat_xref = def_aa_xref;
	}
      else if (strcmp(pw_mtrxname, "id") == 0)
	{
	  matptr = idmat;
	  mat_xref = def_aa_xref;
	}
      else
	{
	  matptr = pw_usermat;
	  mat_xref = pw_aa_xref;
	}

      maxres = get_matrix(matptr, mat_xref, matrix, TRUE, int_scale);
      if (maxres == 0) return((sint)-1);
    }


  for (si=MAX(0,istart);si<nseqs && si<iend;si++)
    {
      n = seqlen_array[si+1];
      len1 = 0;
      for (i=1;i<=n;i++) {
	c = seq_array[si+1][i];
	if ((c!=gap_pos1) && (c != gap_pos2)) len1++;
      }

      for (sj=MAX(si+1,jstart+1);sj<nseqs && sj<jend;sj++)
	{
	  m = seqlen_array[sj+1];
	  if(n==0 || m==0) {
	    tmat[si+1][sj+1]=1.0;
	    tmat[sj+1][si+1]=1.0;
	    continue;
	  }
	  len2 = 0;
	  for (i=1;i<=m;i++) {
	    c = seq_array[sj+1][i];
	    if ((c!=gap_pos1) && (c != gap_pos2)) len2++;
	  }

	  if (dnaflag) {
	    g = 2 * (float)pw_go_penalty * int_scale*gscale;
	    gh = pw_ge_penalty * int_scale*ghscale;
	  }
	  else {
	    if (mat_avscore <= 0)
              g = 2 * (float)(pw_go_penalty + log((double)(MIN(n,m))))*int_scale;
	    else
              g = 2 * mat_avscore * (float)(pw_go_penalty +
					    log((double)(MIN(n,m))))*gscale;
	    gh = pw_ge_penalty * int_scale;
	  }

	  if (debug>1) fprintf(stdout,"go %d ge %d\n",(pint)g,(pint)gh);

	  /*
	    align the sequences
	  */
	  seq1 = si+1;
        seq2 = sj+1;

        forward_pass(&seq_array[seq1][0], &seq_array[seq2][0],
           n, m);

        reverse_pass(&seq_array[seq1][0], &seq_array[seq2][0]);

        last_print = 0;
	print_ptr = 1;
/*
        sb1 = sb2 = 1;
        se1 = n-1;
        se2 = m-1;
*/

/* use Myers and Miller to align two sequences */

        maxscore = diff(sb1-1, sb2-1, se1-sb1+1, se2-sb2+1, 
        (sint)0, (sint)0);
 
/* calculate percentage residue identity */

        mm_score = tracepath(sb1,sb2);

		if(len1==0 || len2==0) mm_score=0;
		else
			mm_score /= (float)MIN(len1,len2);

        tmat[si+1][sj+1] = ((float)100.0 - mm_score)/(float)100.0;
        tmat[sj+1][si+1] = ((float)100.0 - mm_score)/(float)100.0;

if (debug>1)
{
        fprintf(stdout,"Sequences (%d:%d) Aligned. Score: %d CompScore:  %d\n",
                           (pint)si+1,(pint)sj+1, 
                           (pint)mm_score, 
                           (pint)maxscore/(MIN(len1,len2)*100));
}
else
{
        info("Sequences (%d:%d) Aligned. Score:  %d",
                                      (pint)si+1,(pint)sj+1, 
                                      (pint)mm_score);
}

   }
  }
   displ=ckfree((void *)displ);
   HH=ckfree((void *)HH);
   DD=ckfree((void *)DD);
   RR=ckfree((void *)RR);
   SS=ckfree((void *)SS);


  return((sint)1);
}