void PrpFromPrfFixed::computeBlock(const vector<byte> & inBytes, int inOff, int inLen, vector<byte>& outBytes, int outOff, int outLen) { if (!isKeySet()) throw IllegalStateException("secret key isn't set"); if ((inOff > inBytes.size()) || (inOff + inLen > inBytes.size())) throw out_of_range("wrong offset for the given input buffer"); if ((outOff > outBytes.size()) || (outOff + outLen > outBytes.size())) throw out_of_range("wrong offset for the given output buffer"); // if the input and output length are equal to the blockSize, call the computeBlock that doesn't take length arguments. if (inLen == outLen && inLen == getBlockSize()) computeBlock(inBytes, inOff, outBytes, outOff); else throw out_of_range("input and output lengths should be equal to Block size"); }
void PrpFromPrfVarying::computeBlock(const vector<byte> & inBytes, int inOff, int inLen, vector<byte>& outBytes, int outOff, int outLen) { if (!isKeySet()) throw new IllegalStateException("secret key isn't set"); // checks that the offsets and lengths are correct if ((inOff > inBytes.size()) || (inOff + inLen > inBytes.size())) throw out_of_range("wrong offset for the given input buffer"); if ((outOff > outBytes.size()) || (outOff + outLen > outBytes.size())) throw out_of_range("wrong offset for the given output buffer"); //if the input and output lengths are equal, call the computeBlock which takes just one length argument if (inLen == outLen) computeBlock(inBytes, inOff, inLen, outBytes, outOff); else throw out_of_range("input and output lengths should be equal"); }
void *th_electric_field(void *argthinfo) { Thinfo *thinfo = (Thinfo *) argthinfo; float * charge = thinfo->charge; float * coord1 = thinfo->coord1; float * coord2 = thinfo->coord2; float * coord3 = thinfo->coord3; float grid_span = thinfo->grid_span; int grid_size = thinfo->grid_size; int totalElements = thinfo->totalElements; int block_size = thinfo->block_size; int x_start = thinfo->x_start; int x_end = thinfo->x_end; int num_threads = thinfo->num_threads; fftw_real *grid = thinfo->grid; float phi; int block_ini, block_fin; float x_centre, y_centre, z_centre; int x, y, z, i, k; __m128 _phi_tmp; __m128 _phiSet; float *phiSet = (float *) &_phiSet; float * distance; float * epsilon; if ((posix_memalign((void**)&distance, 16, 4*sizeof(float))!=0)) { printf("No memory.\n"); exit(-1); } if ((posix_memalign((void**)&epsilon, 16, 4*sizeof(float))!=0)) { printf("No memory.\n"); exit(-1); } for (block_ini = 0; block_ini < totalElements-(block_size-1); block_ini += block_size) { block_fin = block_ini + block_size; for (x = x_start; x < x_end; x++) { x_centre = gcentre(x ,grid_span, grid_size ) ; for (y = 0; y < grid_size; y++) { y_centre = gcentre(y ,grid_span ,grid_size ) ; for (z = 0; z < grid_size; z++) { z_centre = gcentre( z , grid_span , grid_size ) ; phi = 0 ; computeBlock(block_ini, block_fin); grid[gaddress(x,y,z,grid_size)] += (fftw_real)phi; } } } //Changing block. Must wait for others threads to finish. pthread_mutex_lock(&mut); ready_threads++; if (ready_threads==num_threads) { ready_threads=0; pthread_cond_broadcast(&cond); } else { pthread_cond_wait(&cond, &mut); } pthread_mutex_unlock(&mut); } //Last block is not a multiple of block_size if (block_ini != totalElements) { for (x = x_start; x < x_end; x++ ) { x_centre = gcentre(x, grid_span, grid_size) ; for (y = 0; y < grid_size; y++) { y_centre = gcentre(y, grid_span, grid_size) ; for (z = 0; z < grid_size; z++) { z_centre = gcentre(z, grid_span, grid_size) ; phi = 0 ; computeEndBlock(block_ini, totalElements); grid[gaddress(x,y,z,grid_size)] += (fftw_real)phi ; } } } } pthread_exit(NULL); return ; }