void task3(int size, int tid, int ctid) { { std::stringstream ss; ss << "task 3 with tid " << tid << " and ctid " << ctid << " started" << std::endl; std::cout << ss.str(); } vector w, x; matrix ms, mz; w = generateVector(size); x = generateVector(size); ms = generateMatrix(size); mz = generateMatrix(size); vector result = func3(ms, mz, w, x); if (size < 8) { std::stringstream ss; ss << "task 3 result: "; ss << '['; for (int i = 0; i < result.size(); ++i) { ss << result[i] << " "; } ss << ']'; ss << std::endl; std::cout << ss.str(); } { std::stringstream ss; ss << "task 3 with tid " << tid << " and ctid " << ctid << " finished" << std::endl; std::cout << ss.str(); } }
void task1(int size, int tid, int ctid) { { std::stringstream ss; ss << "task 1 with tid " << tid << " and ctid " << ctid << " started" << std::endl; std::cout << ss.str(); } vector a, b; matrix ma, md; a = generateVector(size); b = generateVector(size); ma = generateMatrix(size); md = generateMatrix(size); vector result = func1(a, b, ma, md); if (size < 8) { std::stringstream ss; ss << "task 1 result: "; ss << '['; for (int i = 0; i < result.size(); ++i) { ss << result[i] << " "; } ss << ']'; ss << std::endl; std::cout << ss.str(); } { std::stringstream ss; ss << "task 1 with tid " << tid << " and ctid " << ctid << " finished" << std::endl; std::cout << ss.str(); } }
int main() { clock_t t1, t2, t3, t4, t5, t6; char a[50], b[50], c[50]; printf("Hi, v1.7\n"); printf("Running algorithm for task: "); printf((task)?"4+\n":"1-3\n"); printf("Dividing result by 1024 is: "); printf((div_1024)?"ON\n":"OFF\n"); //////////////// //test case 1 // //////////////// printf("gen vector 1, "); generateVector(x1, N1, S1); printf("sum vector 1\n"); float y1=0.0; if (task) {t1 = times(NULL); y1 = sumVector_cos_custom(x1, N1); t2 = times(NULL);} else {t1 = times(NULL); y1 = sumVector(x1, N1); t2 = times(NULL);} gcvt(t2-t1, 10, a); alt_putstr("Time = "); alt_putstr(a); alt_putstr("; "); printf("Result = %f\n", ((div_1024)?y1/1024:y1)); //////////////// //test case 2 // //////////////// printf("gen vector 2, "); generateVector(x2, N2, S2); printf("sum vector 2\n"); float y2=0.0; if (task) {t3 = times(NULL); y2 = sumVector_cos_custom(x2, N2); t4 = times(NULL);} else {t3 = times(NULL); y2 = sumVector(x2, N2); t4 = times(NULL);} gcvt(t4-t3, 10, b); alt_putstr("Time = "); alt_putstr(b); alt_putstr("; "); printf("Result = %f\n", ((div_1024)?y2/1024:y2)); //////////////// //test case 3 // //////////////// printf("gen vector 3, "); generateVector(x3, N3, S3); printf("sum vector 3\n"); float y3=0.0; if (task) {t5 = times(NULL); y3 = sumVector_cos_custom(x3, N3); t6 = times(NULL);} else {t5 = times(NULL); y3 = sumVector(x3, N3); t6 = times(NULL);} gcvt(t6-t5, 10, c); alt_putstr("Time = "); alt_putstr(c); alt_putstr("; "); printf("Result = %f\n", ((div_1024)?y3/1024:y3)); return 0; }
int main() { printf("Task 2! \n"); float x[N]; float y; generateVector(x); // timing char buf[50]; clock_t exec_t1, exec_t2; exec_t1 = times(NULL); // get system time before starting the process // code START y = sumVector (x, N); //code END exec_t2 = times(NULL); // get system time after finishing the process gcvt((exec_t2 - exec_t1), 10, buf); // gcvt convert a number to a string with decimal including a point, gcvt(value,number of digits,buffer) // buffer 8,9 character longer than number, this is the memory block that stores the number alt_putstr("proc time = "); alt_putstr(buf); alt_putstr("ticks\n"); //printf could be used if memory is enough int i; for (i=0; i<10; i++) y = y/2.0; gcvt((int)y, 10, buf); alt_putstr("Result (divided by 1014) = "); alt_putstr(buf); return 0; }
std::vector<std::vector<double> > generateMatrix(int rows, int cols, double from, double to) { std::vector<std::vector<double> > result(rows); #pragma omp parallel for for (int i = 0; i < result.size(); i++) { result[i] = generateVector(cols, from, to); } return result; }
PetscErrorCode generateVectorRandom(int size, Vec * v){ PetscErrorCode ierr; ierr=PetscPrintf(PETSC_COMM_WORLD,"Generating Vector \n");CHKERRQ(ierr); ierr=generateVector(size,v);CHKERRQ(ierr); ierr=VecSetRandom(*v,PETSC_NULL);CHKERRQ(ierr); PetscPrintf(PETSC_COMM_WORLD,"Generated Random Vector of size : %d\n",size); return 0; }
int main(int argc, char** argv) { float *A=NULL, *B=NULL; long long k=0; struct timeval fin,ini; float sum=0; unsigned long long num; unsigned long thr; thr=atoi(argv[1]); num=atoi(argv[2]); omp_set_num_threads(thr); A = generateVector(num); B = generateVector(num); if ( !A || !B ) { printf("Error when allocationg matrix\n"); freeVector(A); freeVector(B); return -1; } gettimeofday(&ini,NULL); /* Bloque de computo */ sum = 0; #pragma omp parallel for for(k=0;k<num;k++) { sum = sum + A[k]*B[k]; } /* Fin del computo */ gettimeofday(&fin,NULL); printf("Resultado: %f\n",sum); printf("Tiempo: %f\n", ((fin.tv_sec*1000000+fin.tv_usec)-(ini.tv_sec*1000000+ini.tv_usec))*1.0/1000000.0); freeVector(A); freeVector(B); return 0; }
PetscErrorCode generateVectorNorm(int size, Vec * v){ PetscScalar scal; PetscErrorCode ierr; ierr=PetscPrintf(PETSC_COMM_WORLD,"Generating Vector \n");CHKERRQ(ierr); ierr=generateVector(size,v);CHKERRQ(ierr); scal=1.0/size; ierr=VecSet(*v,scal);CHKERRQ(ierr); PetscPrintf(PETSC_COMM_WORLD,"Generated Norm Vector of size : %d\n",size); return 0; }
int main(int argc, char **argv) { int num_threads, size, num_tries; float *A = NULL, *B = NULL; long long k = 0; struct timeval fin, ini; float sum = 0; parse_args(argc, argv, &num_threads, &size, &num_tries); omp_set_num_threads(num_threads); A = generateVector(size); B = generateVector(size); if ( !A || !B ) { printf("Error when allocationg matrix\n"); freeVector(A); freeVector(B); return -1; } gettimeofday(&ini, NULL); /* Bloque de computo */ sum = 0; #pragma omp parallel for for (k = 0; k < size; k++) { sum = sum + A[k] * B[k]; } /* Fin del computo */ gettimeofday(&fin, NULL); printf("Resultado: %f\n", sum); printf("Tiempo: %f\n", ((fin.tv_sec * 1000000 + fin.tv_usec) - (ini.tv_sec * 1000000 + ini.tv_usec)) * 1.0 / 1000000.0); freeVector(A); freeVector(B); return 0; }
int main() { IntVector vect_int = generateVector(); printVector(vect_int); findLongestRun(vect_int); std::sort(vect_int.begin(), vect_int.end()); findLongestRun(vect_int); std::sort(vect_int.begin(), vect_int.end(), std::greater<unsigned>()); findLongestRun(vect_int); return 0; }
Teuchos::RCP<const LOCA::Extended::Vector> LOCA::Extended::MultiVector::getVector(int i) const { // Verify index is valid checkIndex("LOCA::Extended::MultiVector::vector()", i); // Create extended vector view if necessary if (extendedVectorPtrs[i] == Teuchos::null) { extendedVectorPtrs[i] = generateVector(numMultiVecRows, numScalarRows); for (int k=0; k<numMultiVecRows; k++) extendedVectorPtrs[i]->setVectorView( k, Teuchos::rcp(&(*multiVectorPtrs[k])[i], false)); if (numScalarRows > 0) extendedVectorPtrs[i]->setScalarArray((*scalarsPtr)[i]); } return extendedVectorPtrs[i]; }
void ParticleEmitter::emitOnce(unsigned int particleCount) { GP_ASSERT(_node); GP_ASSERT(_particles); // Limit particleCount so as not to go over _particleCountMax. if (particleCount + _particleCount > _particleCountMax) { particleCount = _particleCountMax - _particleCount; } Vector3 translation; Matrix world = _node->getWorldMatrix(); world.getTranslation(&translation); // Take translation out of world matrix so it can be used to rotate orbiting properties. world.m[12] = 0.0f; world.m[13] = 0.0f; world.m[14] = 0.0f; // Emit the new particles. for (unsigned int i = 0; i < particleCount; i++) { Particle* p = &_particles[_particleCount]; p->_visible = true; generateColor(_colorStart, _colorStartVar, &p->_colorStart); generateColor(_colorEnd, _colorEndVar, &p->_colorEnd); p->_color.set(p->_colorStart); p->_energy = p->_energyStart = generateScalar(_energyMin, _energyMax); p->_size = p->_sizeStart = generateScalar(_sizeStartMin, _sizeStartMax); p->_sizeEnd = generateScalar(_sizeEndMin, _sizeEndMax); p->_rotationPerParticleSpeed = generateScalar(_rotationPerParticleSpeedMin, _rotationPerParticleSpeedMax); p->_angle = generateScalar(0.0f, p->_rotationPerParticleSpeed); p->_rotationSpeed = generateScalar(_rotationSpeedMin, _rotationSpeedMax); // Only initial position can be generated within an ellipsoidal domain. generateVector(_position, _positionVar, &p->_position, _ellipsoid); generateVector(_velocity, _velocityVar, &p->_velocity, false); generateVector(_acceleration, _accelerationVar, &p->_acceleration, false); generateVector(_rotationAxis, _rotationAxisVar, &p->_rotationAxis, false); // Initial position, velocity and acceleration can all be relative to the emitter's transform. // Rotate specified properties by the node's rotation. if (_orbitPosition) { world.transformPoint(p->_position, &p->_position); } if (_orbitVelocity) { world.transformPoint(p->_velocity, &p->_velocity); } if (_orbitAcceleration) { world.transformPoint(p->_acceleration, &p->_acceleration); } // The rotation axis always orbits the node. if (p->_rotationSpeed != 0.0f && !p->_rotationAxis.isZero()) { world.transformPoint(p->_rotationAxis, &p->_rotationAxis); } // Translate position relative to the node's world space. p->_position.add(translation); // Initial sprite frame. if (_spriteFrameRandomOffset > 0) { p->_frame = rand() % _spriteFrameRandomOffset; } else { p->_frame = 0; } p->_timeOnCurrentFrame = 0.0f; ++_particleCount; } }