コード例 #1
0
ファイル: matrix.c プロジェクト: 10045125/PhotoProcessing
void saturateMatrix(float matrix[4][4], float* saturation)
{
	float sat = (*saturation);
    float mmatrix[4][4];
    float a, b, c, d, e, f, g, h, i;
    float rwgt, gwgt, bwgt;

    rwgt = RLUM;
    gwgt = GLUM;
    bwgt = BLUM;

    a = (1.0f-sat)*rwgt + sat;
    b = (1.0f-sat)*rwgt;
    c = (1.0f-sat)*rwgt;
    d = (1.0f-sat)*gwgt;
    e = (1.0f-sat)*gwgt + sat;
    f = (1.0f-sat)*gwgt;
    g = (1.0f-sat)*bwgt;
    h = (1.0f-sat)*bwgt;
    i = (1.0f-sat)*bwgt + sat;
    mmatrix[0][0] = a;
    mmatrix[0][1] = b;
    mmatrix[0][2] = c;
    mmatrix[0][3] = 0.0f;

    mmatrix[1][0] = d;
    mmatrix[1][1] = e;
    mmatrix[1][2] = f;
    mmatrix[1][3] = 0.0f;

    mmatrix[2][0] = g;
    mmatrix[2][1] = h;
    mmatrix[2][2] = i;
    mmatrix[2][3] = 0.0f;

    mmatrix[3][0] = 0.0f;
    mmatrix[3][1] = 0.0f;
    mmatrix[3][2] = 0.0f;
    mmatrix[3][3] = 1.0f;
    multiplyMatricies(mmatrix, matrix, matrix);
}
コード例 #2
0
ファイル: pthreads.c プロジェクト: etoestja/inf
int main(int argc, char *argv[], char **envp){
	int *a = NULL, *b = NULL, *c = NULL;
	int num_cores = 0;
	int i = 0, j = 0;
	time_t stime, ftime;
	int size = MATRIX_SIZE;
	struct pthread_info *targs = NULL;
	pthread_t *threads = NULL;

	num_cores = sysconf(_SC_NPROCESSORS_ONLN);
	printf("System Info:\n--------------------\nCPUs: %d\n", num_cores);
	a = (int *)malloc(sizeof(int) * size * size);
	b = (int *)malloc(sizeof(int) * size * size);
	c = (int *)malloc(sizeof(int) * size * size);
	targs = (struct pthread_info *)malloc(sizeof(struct pthread_info) * num_cores);
	threads = (pthread_t *)malloc(sizeof(pthread_t) * num_cores);
	for(i = 0; i < num_cores; i++){
		targs[i].msize = size;
		targs[i].srow = i;
		targs[i].rstep = num_cores;
		targs[i].a = a;
		targs[i].b = b;
		targs[i].c = c;
		targs[i].cpu = 0;
		threads[i] = 0;
	}

	printf("Init Matricies...\n");
	time(&stime);
	initMatricies(a, b, c, size);
	time(&ftime);
	printf("Finish of Initialization.\nTime: %d sec.\n", (ftime - stime));
	printf("Start multiplying...\n");
	time(&stime);
	multiplyMatricies(a, b, c, size);
	time(&ftime);
	printf("Finish Multiplying.\n");
	printf("Finish of Multiplying.\nTime: %d sec.\n", (ftime - stime));
        printf("\n");
        printm(a);
        printf("\n");
        printm(b);
        printf("\n");
        printm(c);
	printf("Now using threads.\n");
	for(j = 1; j <= num_cores; j++){
		printf("Start multiplying %d cores...\n", j);
		time(&stime);
		for(i = 0; i < num_cores; i++){
			targs[i].cpu = i % j;
			pthread_create(&threads[i], NULL, thread_multiplication, &targs[i]);
		}
		for(i = 0; i < num_cores; i++){
			pthread_join(threads[i], NULL);
		}
		time(&ftime);
		printf("Finish Multiplying.\n");
		printf("Finish of Multiplying.\nTime: %d sec.\n", (ftime - stime));
        printf("\n");
        printm(a);
        printf("\n");
        printm(b);
        printf("\n");
        printm(c);
        }
	return 0;
}