void task5() { //TODO Task 5 vector float scale_factor = spu_splats(0.5f); print_vector_float(&A, N); printf("\n"); print_vector_float(&B, N); printf("\n"); print_vector_float(&C, N); printf("\n"); // 'transform' scalar arrays A, B, C to vector arrays: a, b, c vector unsigned int *a = (vector unsigned int *) A * (unsigned int) scale_factor; print_vector_uint(&a,N); int i; int n = N/4; // b = a * scale_factor // compare b and c and store the result in cmp_res vector unsigned int cmp_res[n]; // print b,c, cmp_res // modify C such that there is at least one different element between B and C // print cmp_res }
int main (int argc, char **argv) { int i; float prod_scalaire_res = 0; vectf a ; initVf(a); vectf b ; initVf(b); vectf c ; print_vector_float(a); printf("================================================\n"); print_vector_float(b); printf("================================================\n"); __m128 v1, v2, v3 ; __m128i iV1, iV2, iV3 ; for(i=0; i<N; i+=4) { v1 = _mm_load_ps (a+i) ; v2 = _mm_load_ps (b+i) ; v3 = _mm_dp_ps (v1, v2, 0xFF) ; //_mm_store_ps (c+i, v3) ; prod_scalaire_res += v3[0]; } printf("Produit scalaire des deux vecteurs : %f\n", prod_scalaire_res); exit (0) ; }
void task5() { // TODO Task 5 vector float scale_factor = spu_splats(0.5f); // 'transform' scalar arrays A, B, C to vector arrays: a, b, c vector float * a = (vector float *) A; vector float * b = (vector float *) B; vector float * c = (vector float *) C; int i; int n = N/4; // b = a * scale_factor for(i = 0; i < n; i++) b[i] = a[i] * scale_factor; // compare b and c vector unsigned int cmp_res[n]; for(i = 0; i < n; i++) cmp_res[i] = spu_cmpeq(b[i],c[i]); print_vector_uint (cmp_res, n); print_vector_float(b, n); print_vector_float(c, n); }
void sendNewCentroid(int centroidId, int iterationChanges, Centroid *pCentroid, int numDimensions) { unsigned int szMsg = 2*sizeof(int) + sizeof(float)*numDimensions; int *global_centroid = (int *)malloc(szMsg); float *coordinates; int i=0; /*****************DEBUG******************************************/ #ifdef DEBUG FILE *fp_log; char name_of_fp_log[50]; sprintf(name_of_fp_log, "log_%s_%d.txt", ahGetFilterName(), ahGetMyRank()); #endif /********************************************************/ if (numDimensions > 0) { global_centroid[0] = centroidId; global_centroid[1] = iterationChanges; coordinates = (float *) &(global_centroid[2]); for (i=0; i<numDimensions; i++) { coordinates[i] = pCentroid->coordinates[i]; } } /********************************** DEBUG ***********************************/ #ifdef DEBUG fp_log = fopen(name_of_fp_log,"a"); fprintf(fp_log, "\n\t\t----------\t----------\t----------\t----------\t----------\t----------\n\n"); fprintf(fp_log, "Send NewCentroid Msg: \n"); fprintf(fp_log, "Centroid ID = %d ------ IterationChanges = %d\n", global_centroid[0], global_centroid[1]); print_vector_float(coordinates, num_dimensions, fp_log); fprintf(fp_log, "End NewCentroid Msg \n"); fclose(fp_log); #endif /****************************************************************************/ ahWriteBuffer(new_centroidsP, global_centroid, szMsg); free(global_centroid); }