Example #1
0
/* test functions */
void test1()
{
    av = 10.0;
    bv = 10.0;
    cv = 10.0;
    lx = ly = lz = 0.0;

    view_transform();
    persp_transform();
    win_transform();

    float point[4] = {2.0, 5.0, 1.0, 1.0};

    float vV[4] = {0, 0, 0, 0};
    multiply2(point, V, vV);
    printf("(2, 5, 1)V = [%f, %f, %f, %f]\n", vV[0], vV[1], vV[2], vV[3]);
    float vVP[4] = {0, 0, 0, 0};
    multiply2(vV, P, vVP);
    printf("(2, 5, 1)VP = [%f, %f, %f, %f]\n", vVP[0], vVP[1], vVP[2], vVP[3]);
    float prod1[4] = {0, 0, 0, 0};
    multiply2(vVP, W, prod1);

    printf("(2, 5, 1)VPW = [%f, %f, %f, %f]\n", prod1[0], prod1[1], prod1[2], prod1[3]);
    // homogenize result of <p1>*VPW
    int i;
    for (i = 0; i < 4; i++) {
        prod1[i] /= prod1[3];
    }

    printf("(2, 5, 1)VPW<homogenize> = [%f, %f, %f, %f]\n", prod1[0], prod1[1], prod1[2], prod1[3]);
}
Example #2
0
void checktest(test tc){
		if(tc->result==multiply(tc->x,tc->y,0))
			printf("Scuccess\t");
		else
			printf("Fail\t\t");
		
		if(tc->result==multiply2(tc->x,tc->y,0))
			printf("Scuccess\n");
		else
			printf("Fail\n");
}
Example #3
0
/* draws a line from specified workd coordinates */
void drawline(float *p1, float *p2)
{
    // compute the screen coordinate for p1
    float vV[4] = {0, 0, 0, 0};
    multiply2(p1, V, vV);
    float vVP[4] = {0, 0, 0, 0};
    multiply2(vV, P, vVP);
    float prod1[4] = {0, 0, 0, 0};
    multiply2(vVP, W, prod1);
    // homogenize result of <p1>*VPW
    int i;
    for (i = 0; i < 4; i++) {
        prod1[i] /= prod1[3];
    }

    // compute the screen coordinate for p2
    float vV2[4] = {0, 0, 0, 0};
    multiply2(p2, V, vV2);
    float vVP2[4] = {0, 0, 0, 0};
    multiply2(vV2, P, vVP2);
    float prod2[4] = {0, 0, 0, 0};
    multiply2(vVP2, W, prod2);
    // homogenize result of <p2>*VPW
    for (i = 0; i < 4; i++) {
        prod2[i] /= prod2[3];
    }

    // clip
    if(!clip(prod1, prod2)) {
        glBegin(GL_LINES);
        glVertex2f(prod1[0], prod1[1]);
        glVertex2f(prod2[0], prod2[1]);
        glEnd();
    }
}
Example #4
0
void XAXt2(double **X, int p, double **A, double ***Res, int k){

	double **Res1, **Res2;

	MAKE_MATRIX(Res1, p, p);	
	MAKE_MATRIX(Res2, p, p);

	tA(X, p, p, Res2);

	multiply(X, p, p, A, p, p, Res1);
	multiply2(Res1, p, p, Res2, p, p, Res, k);

	FREE_MATRIX(Res1);
 	FREE_MATRIX(Res2);

}
Example #5
0
/*
void multiplyrest(int *restrict A[SIZE][SIZE], int *restrict B[SIZE][SIZE], void* thr){
	int s = (int)thr;   
  	int from = (s * SIZE)/num_thrd; 
  	int to = ((s+1) * SIZE)/num_thrd; 
  	int i,j,k;
	
 	
  	printf("computing THread part %d (from row %d to %d)\n", s, from, to-1);
  	for (i = from; i < to; i++)
  		{  
    		for (j = 0; j < SIZE; j++)
    		{
      			C[i][j] = 0;
      		for ( k = 0; k < SIZE; k++)
 			C[i][j] += (int)((*A)+j)*(int)((*B)+k);
    			}
  		}
  		printf("finished Thread part %d\n", s);
  	
}
	*/	
int main(int argc, char* argv[])
{
  
 
  num_thrd = 1;
  init_matrix(A);
  init_matrix(B);

  int **ptrA = &A;
  int **ptrB = &B;
 
  int i, j, val = 0;
  
  
  multiply(0);
  	
  printf("\nCalculation is Complete\n");
  
  printf("\n");

  
  multiply2(&A,&B,0);
  
  	
  printf("\nCalculation2 is complete\n");
  
  printf("\n");
  
  
  /*multiplyrest(&A,&B,0);*/
  	
  printf("\nCalculation3 is Complete\n");
  
  printf("\n");

  return 0;
 
}
Example #6
0
int main(void) {
	benchmark(400,1,multiply2);
	int i,j;
	FILE* in  = fopen("input.txt","r");
	// reading matrix a
	fscanf(in,"%d %d",&m,&p);
	a = read_matrix(in,m,p);

	// reading matrix b
	fscanf(in,"%d %d",&q,&n);
	b = read_matrix(in,q,n);

	if (p!=q){
		printf("incompatible matrices --not supported\n");
		return 0;
	}

	//initializing matrix c
	c = (int**) malloc(sizeof(int *)*m);
	for (i = 0; i < m; ++i){
		c[i] = (int *) malloc(sizeof(int)*n);
		for (j = 0; j < n; ++j)
			c[i][j] = 0;
	}

	long long t1,t2;
	FILE* out = fopen("output.txt","w");

//	multiply(a,b,c);
//	multiply(a,b,c);
//	multiply(a,b,c);

	for (i = 0; i < m; ++i)
		for (j = 0; j < n; ++j)
			c[i][j] = 0;


	fprintf(out,"result of non-threaded multiplication\n");
	t1 = curTime();
	multiply(a,b,c);
	t2 = curTime();
	writeMat(c,m,n,out);
	fprintf(out,"elapsed time = %lld usec\n\n",t2-t1);

	for (i = 0; i < m; ++i)
		for (j = 0; j < n; ++j)
			c[i][j] = 0;

	fprintf(out,"result of multiplication1 (thread for each cell)\n");
	t1 = curTime();
	multiply1();
	t2 = curTime();
	writeMat(c,m,n,out);
	fprintf(out,"elapsed time = %lld usec\n\n",t2-t1);
	for (i = 0; i < m; ++i)
		for (j = 0; j < n; ++j)
			c[i][j] = 0;


	fprintf(out,"result of multiplication2 (thread for each row)\n");
	t1 = curTime();
	multiply2();
	t2 = curTime();
	writeMat(c,m,n,out);
	fprintf(out,"elapsed time = %lld usec\n\n",t2-t1);

	fclose(out);
	print(c,m,n);
	return 0;
}