/*************************************************************************************************** * CDAC Workshop - hyPACK 2013 * Oct 15 - 18 ,2013 * * FILE : mat-mat-mul-pthreads-multi-mic.c * * INPUT : #Matrix Size * * OUTPUT : Time elapsed and GFLOPS * * DESCRIPTION : To demonstrate how to run the code on multiple mics using Posix threads * * CREATED : August,2013 * * EMAIL : hpcfte@cdac.in * **************************************************************************************************/ #include #include #include #include #include #include #define NUM_DEV 2 struct matInfo { double *a; double *b; double *c; int mic_id; int size; }; double wallTime() { double tsec=0.0; struct timeval mytime; gettimeofday(&mytime,0); tsec=(double)(mytime.tv_sec+mytime.tv_usec*1.0e-6); return tsec; } void fill_Matrix(double *x,int size) { int i; for(i=0;imic_id; double *a=temp->a; double *b=temp->b; double *c=temp->c; long int size=temp->size; printf("In thread %d\n",tid); long int start=(tid*(size/NUM_DEV))*size; long int end = ((size*(tid+1))*size)/NUM_DEV; #pragma offload target(mic:tid) \ in(a:length(size*size) )\ in(b:length(size*size))\ inout(c[start:end-start]) { double sum=0.0; // printf("\ntarget device = %d", _Offload_get_device_number()); // printf("tid = %d\n",tid); #pragma omp parallel for private(i,j,k) reduction(+:sum) for(i=tid*(size/NUM_DEV);i<(size*(tid+1))/NUM_DEV;i++) { for(j=0;j\n"); exit(1); } size=atoi(argv[1]); //printf("size =%d\n",size); matA=(double *)malloc(sizeof(double)*size*size); if(matA==NULL) { perror("malloc error\n"); exit(1); } matB=(double *)malloc(sizeof(double)*size*size); if(matB==NULL) { perror("malloc error\n"); exit(1); } matR=(double *)malloc(sizeof(double)*size*size); if(matR==NULL) { perror("malloc error\n"); exit(1); } fill_Matrix(matA,size); //printf("Matrix A values are\n"); //print_Matrix(matA,size); fill_Matrix(matB,size); //printf("Matrix B values are\n"); //print_Matrix(matB,size); fill_zeroes(matR,size); /* Initialise structure */ for(i=0;i