コード例 #1
0
CPropagation *cpropagation_create(const Problem *_problem)
{
	CPropagation *cp = new CPropagation;
	const double *colLb = problem_vars_lower_bound(_problem);
    const double *colUb = problem_vars_upper_bound(_problem);

    cp->problem = (Problem*)_problem;
    fillMatrices(cp);
	assert(cp->matrixByRow.size() == cp->rhs.size());

    cp->numCols = problem_num_cols(cp->problem);
	cp->numRows = (int)cp->matrixByRow.size();
    cp->varIsBinary = new char[cp->numCols];
    cp->isToFix = new char[cp->numCols];
    cp->binaryVars = 0;
    cp->varsToFix = 0;

    int numThreads = omp_get_max_threads();
    int chunk = max(1, cp->numCols/numThreads);
    #pragma omp parallel for shared(cp, colLb, colUb) num_threads(numThreads) schedule(static, chunk)
        for(int i = 0; i < cp->numCols; i++)
        {
            cp->isToFix[i] = UNFIXED;

            if(problem_var_is_binary(cp->problem, i))
            {
                cp->varIsBinary[i] = 1;
                #pragma omp atomic
                	cp->binaryVars++;
            }
            else cp->varIsBinary[i] = 0;
        }

	return cp;
}
コード例 #2
0
renderer::AssemblyInstance* createAssemblyInstance(const MayaObject* obj)
{
    MayaObject* assemblyObject = getAssemblyMayaObject(obj);
    boost::shared_ptr<AppleseedRenderer> appleRenderer = boost::static_pointer_cast<AppleseedRenderer>(getWorldPtr()->mRenderer);
    renderer::Assembly* ass = getAssembly(obj);
    renderer::Assembly* master = getMasterAssemblyFromProject(appleRenderer->getProjectPtr());
    MString assemblyInstanceName = getAssemblyInstanceName(assemblyObject);
    foundation::auto_release_ptr<renderer::AssemblyInstance> assemblyInstance = renderer::AssemblyInstanceFactory::create(assemblyInstanceName.asChar(), renderer::ParamArray(), ass->get_name());
    fillMatrices(obj, assemblyInstance->transform_sequence());
    renderer::AssemblyInstance* assInst = assemblyInstance.get();
    master->assembly_instances().insert(assemblyInstance);
    return assInst;
}
コード例 #3
0
ファイル: ContactDynamics.cpp プロジェクト: jmainpri/dart
        void ContactDynamics::applyContactForces() {
            if (getNumTotalDofs() == 0)
                return;
            mCollisionChecker->clearAllContacts();
            mCollisionChecker->checkCollision(true, true);

            for (int i = 0; i < getNumSkels(); i++)
                mConstrForces[i].setZero();

            if (mCollisionChecker->getNumContact() == 0)
                return;
            fillMatrices();
            solve();
            applySolution();
        }
コード例 #4
0
ファイル: ConstraintDynamics.cpp プロジェクト: ehuang3/dart
        void ConstraintDynamics::computeConstraintForces() {
            //            static Timer t1("t1");

            if (getTotalNumDofs() == 0)
                return;
            mCollisionChecker->clearAllContacts();
            mCollisionChecker->checkCollision(true, true);

            //            t1.startTimer();
            mLimitingDofIndex.clear();
            
            for (int i = 0; i < mSkels.size(); i++) {
                if (mSkels[i]->getImmobileState() || !mSkels[i]->getJointLimitState())
                    continue;
                for (int j = 0; j < mSkels[i]->getNumDofs(); j++) {
                    double val = mSkels[i]->getDof(j)->getValue();
                    double ub = mSkels[i]->getDof(j)->getMax();
                    double lb = mSkels[i]->getDof(j)->getMin();
                    if (val >= ub){
                        mLimitingDofIndex.push_back(mIndices[i] + j + 1);
                        //        cout << "Skeleton " << i << " Dof " << j << " hits upper bound" << endl;
                    }
                    if (val <= lb){
                        mLimitingDofIndex.push_back(-(mIndices[i] + j + 1));
                        //      cout << "Skeleton " << i << " Dof " << j << " hits lower bound" << endl;
                    }
                }
            }
            
            
            if (mCollisionChecker->getNumContacts() == 0 && mLimitingDofIndex.size() == 0) {
                for (int i = 0; i < mSkels.size(); i++)
                    mContactForces[i].setZero();
                if (mConstraints.size() == 0) {
                    for (int i = 0; i < mSkels.size(); i++)
                        mTotalConstrForces[i].setZero();
                } else {
                    computeConstraintWithoutContact();
                }
            } else {
                fillMatrices();
                solve();
                applySolution();
            }
            //            t1.stopTimer();
            //            t1.printScreen();
        }
コード例 #5
0
MatrixSelector::MatrixSelector(QWidget *parent, ObjectStore *store)
  : QWidget(parent), _store(store) {

  setupUi(this);

  int size = style()->pixelMetric(QStyle::PM_SmallIconSize);

  _newMatrix->setIcon(QPixmap(":kst_matrixnew.png"));
  _editMatrix->setIcon(QPixmap(":kst_matrixedit.png"));

  _newMatrix->setFixedSize(size + 8, size + 8);
  _editMatrix->setFixedSize(size + 8, size + 8);

  fillMatrices();

  connect(_newMatrix, SIGNAL(pressed()), this, SLOT(newMatrix()));
  connect(_editMatrix, SIGNAL(pressed()), this, SLOT(editMatrix()));

  connect(_matrix, SIGNAL(currentIndexChanged(int)), this, SLOT(matrixSelected(int)));
}
コード例 #6
0
ファイル: matrixMultiply.c プロジェクト: nachirau/compArch
int main (int argc, char* argv[]) {

	N = atoi(argv[1]);
	int i = 0;


	pthread_t *thread;
	thread = malloc(sizeof(pthread_t) * N);

	int *threadArgs;
	threadArgs = malloc(sizeof(int) * N);

	setUpMatrices();
	fillMatrices();
	//printInputMatrices();
		
	for (i=0; i<N; i++) {

		threadArgs[i] = i;
		pthread_create (&thread[i], NULL, multiplier, &threadArgs[i]); 


	}

	for (i=0; i<N; i++) {

		pthread_join (thread[i], NULL);
	}


	free(thread);
	free(threadArgs);
	//printResultMatrix();
	cleanUp();

	return 0;

}
コード例 #7
0
twoD_diffusion_ME::
twoD_diffusion_ME(
  const Teuchos::RCP<const Epetra_Comm>& comm, int n, int d,
  double s, double mu,
  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& basis_,
  bool log_normal_,
  bool eliminate_bcs_,
  const Teuchos::RCP<Teuchos::ParameterList>& precParams_) :
  mesh(n*n),
  basis(basis_),
  log_normal(log_normal_),
  eliminate_bcs(eliminate_bcs_),
  precParams(precParams_)
{
  //////////////////////////////////////////////////////////////////////////////
  // Construct the mesh.
  // The mesh is uniform and the nodes are numbered
  // LEFT to RIGHT, DOWN to UP.
  //
  // 5-6-7-8-9
  // | | | | |
  // 0-1-2-3-4
  /////////////////////////////////////////////////////////////////////////////
  double xyLeft = -.5;
  double xyRight = .5;
  h = (xyRight - xyLeft)/((double)(n-1));
  Teuchos::Array<int> global_dof_indices;
  for (int j=0; j<n; j++) {
    double y = xyLeft + j*h;
    for (int i=0; i<n; i++) {
      double x = xyLeft + i*h;
      int idx = j*n+i;
      mesh[idx].x = x;
      mesh[idx].y = y;
      if (i == 0 || i == n-1 || j == 0 || j == n-1)
        mesh[idx].boundary = true;
      if (i != 0)
        mesh[idx].left = idx-1;
      if (i != n-1)
        mesh[idx].right = idx+1;
      if (j != 0)
        mesh[idx].down = idx-n;
      if (j != n-1)
        mesh[idx].up = idx+n;
      if (!(eliminate_bcs && mesh[idx].boundary))
        global_dof_indices.push_back(idx);
    }
  }

  // Solution vector map
  int n_global_dof = global_dof_indices.size();
  int n_proc = comm->NumProc();
  int proc_id = comm->MyPID();
  int n_my_dof = n_global_dof / n_proc;
  if (proc_id == n_proc-1)
    n_my_dof += n_global_dof % n_proc;
  int *my_dof = global_dof_indices.getRawPtr() + proc_id*(n_global_dof / n_proc);
  x_map =
    Teuchos::rcp(new Epetra_Map(n_global_dof, n_my_dof, my_dof, 0, *comm));

  // Initial guess, initialized to 0.0
  x_init = Teuchos::rcp(new Epetra_Vector(*x_map));
  x_init->PutScalar(0.0);

  // Parameter vector map
  p_map = Teuchos::rcp(new Epetra_LocalMap(d, 0, *comm));

  // Response vector map
  g_map = Teuchos::rcp(new Epetra_LocalMap(1, 0, *comm));

  // Initial parameters
  p_init = Teuchos::rcp(new Epetra_Vector(*p_map));
  p_init->PutScalar(0.0);

  // Parameter names
  p_names = Teuchos::rcp(new Teuchos::Array<std::string>(d));
  for (int i=0;i<d;i++) {
    std::stringstream ss;
    ss << "KL Random Variable " << i+1;
    (*p_names)[i] = ss.str();
  }

  // Build Jacobian graph
  int NumMyElements = x_map->NumMyElements();
  int *MyGlobalElements = x_map->MyGlobalElements();
  graph = Teuchos::rcp(new Epetra_CrsGraph(Copy, *x_map, 5));
  for (int i=0; i<NumMyElements; ++i ) {

    // Center
    int global_idx = MyGlobalElements[i];
    graph->InsertGlobalIndices(global_idx, 1, &global_idx);

    if (!mesh[global_idx].boundary) {
      // Down
      if (!(eliminate_bcs && mesh[mesh[global_idx].down].boundary))
        graph->InsertGlobalIndices(global_idx, 1, &mesh[global_idx].down);

      // Left
      if (!(eliminate_bcs && mesh[mesh[global_idx].left].boundary))
        graph->InsertGlobalIndices(global_idx, 1, &mesh[global_idx].left);

      // Right
      if (!(eliminate_bcs && mesh[mesh[global_idx].right].boundary))
        graph->InsertGlobalIndices(global_idx, 1, &mesh[global_idx].right);

      // Up
      if (!(eliminate_bcs && mesh[mesh[global_idx].up].boundary))
        graph->InsertGlobalIndices(global_idx, 1, &mesh[global_idx].up);
    }
  }
  graph->FillComplete();
  graph->OptimizeStorage();

  KL_Diffusion_Func klFunc(xyLeft, xyRight, mu, s, 1.0, d);
  if (!log_normal) {
    // Fill coefficients of KL expansion of operator
    if (basis == Teuchos::null) {
      fillMatrices(klFunc, d+1);
    }
    else {
      Normalized_KL_Diffusion_Func<KL_Diffusion_Func> nklFunc(klFunc, *basis);
      fillMatrices(nklFunc, d+1);
    }
  }
  else {
    // Fill coefficients of PC expansion of operator
    int sz = basis->size();
    Teuchos::RCP<const Stokhos::ProductBasis<int, double> > prodbasis =
      Teuchos::rcp_dynamic_cast<const Stokhos::ProductBasis<int, double> >(
        basis, true);
    LogNormal_Diffusion_Func<KL_Diffusion_Func> lnFunc(mu, klFunc, prodbasis);
    fillMatrices(lnFunc, sz);
  }

  // Construct deterministic operator
  A = Teuchos::rcp(new Epetra_CrsMatrix(Copy, *graph));

  // Construct the RHS vector.
  b = Teuchos::rcp(new Epetra_Vector(*x_map));
  for( int i=0 ; i<NumMyElements; ++i ) {
    int global_idx = MyGlobalElements[i];
    if (mesh[global_idx].boundary)
      (*b)[i] = 0;
    else
      (*b)[i] = 1;
  }

  if (basis != Teuchos::null) {
    point.resize(d);
    basis_vals.resize(basis->size());
  }

  if (precParams != Teuchos::null) {
    std::string name = precParams->get("Preconditioner Type", "Ifpack");
    Teuchos::RCP<Teuchos::ParameterList> p =
      Teuchos::rcp(&(precParams->sublist("Preconditioner Parameters")), false);
    precFactory =
      Teuchos::rcp(new Stokhos::PreconditionerFactory(name, p));
  }
}
コード例 #8
0
void MatrixSelector::setObjectStore(ObjectStore *store) {
  _store = store;
  fillMatrices();;
}
コード例 #9
0
ファイル: project3.c プロジェクト: dmcarr92/OS-Concepts-C
int main(int argc, char *argv[]) {
	
	FILE* ifp;
// create a place where all the pieces will be concatenated
	char *fullfilepath_in = (char *)malloc(30);
// allow for different names per project
	char *thisprojectfile_in = (char *)malloc(13);
	strcpy(thisprojectfile_in, "project3_in.txt");
/* All students will have to use the SAME names & paths for thisprojectfile_in & thisprojectfile_out.
	"filebase" (defined in time_functions.h) is the path to your data, minus the file name.
	On Windows it is: c:\oscourse on Linux it is /root/oscourse
	The code in "time_functions.h will detect Windows/Linux for you */
	
	strcpy(fullfilepath_in, filebase);
	strcat(fullfilepath_in, thisprojectfile_in);
	printf("fullpath=[%s] \n", fullfilepath_in); // for debugging your filename
	ifp = fopen(fullfilepath_in, "r");
	if (ifp == NULL)
	{
		printf("cannot open file_in");
		system("PAUSE");
		exit(4);
	}

	FILE* ofp;
// create a place where all the pieces will be concatenated
	char *fullfilepath_out = (char *)malloc(30);
// allow for different names per project
	char *thisprojectfile_out = (char *)malloc(14);
	strcpy(thisprojectfile_out, "project3_out.txt");

	strcpy(fullfilepath_out, filebase);
	strcat(fullfilepath_out, thisprojectfile_out);
	printf("fullpath=[%s] \n", fullfilepath_out); // for debugging your filename
	ofp = fopen(fullfilepath_out, "w");
	if (ofp == NULL)
	{
		printf("cannot open file_out");
		system("PAUSE");
		exit(4);
	}

/* gathering and organization of input data */
	A = createMatrix();
	B = createMatrix();
	C = createMatrix();
	getInputDimensions(ifp);
	fillMatrices(ifp);
	fclose(ifp);

/* generation of auxiliary data, allocate memory for matrix C data */
	int countA = A->rows * A->columns;
	int countB = B->rows * B->columns;
	C->rows = A->rows; // characterize matrix C
	C->columns = B->columns;
	int countC = C->rows * C->columns;
	int thread_count = A->rows * countB;
	element *tempC = malloc(sizeof(element) * countC);
	C->matrix = tempC;
	int z = 0;
	for(z; z < countC; z++) { // initialize all data within matrix C to 0

		C->matrix[z].c.row = 0;
		C->matrix[z].c.column = 0;
		C->matrix[z].value = 0;
	}
	mutex_array = malloc(sizeof(sem_t) * countC); // allocate memory for semaphore array
	pthread_t *thread_handles = malloc(sizeof(pthread_t) * thread_count); // allocate memory for threads
	int i = 0;
	int j = 0;
	int k = 0;
	int l = 0;
	for(i; i < countC; i++) {

		sem_init(&mutex_array[i], 0, 1); // initialize semaphores with int value 1, shared by threads
	}

/* print matrix A */
	i = 0;
	printf("\nMatrix A\n");
	while(i < countA) {

		printf("%d  ", A->matrix[i].value);
		i++;
		if(i % A->columns == 0) printf("\n");
	};

/* print matrix B */
	i = 0;
	printf("\nMatrix B\n");
	while(i < countB) {

		printf("%d  ", B->matrix[i].value);
		i++;
		if(i % B->columns == 0) printf("\n");
	}
	printf("\n");

//	initialize a data packet pointer to hold data for EACH THREAD
//	embed for() loops to create and join a thread for each multiplication operation to be performed
//	(# threads) = (# mult operations) = (# rows in A) * (# elements in B)
	i = 0;
	packet *p = malloc(sizeof(packet));
	p->a = 0;
	p->b = 0;
	p->c.row = 0;
	p->c.column = 0;
printf("A->rows = %d	A->columns = %d\nB->rows = %d	B->columns = %d\nC->rows = %d	C->columns = %d\n", A->rows, A->columns, B->rows, B->columns, C->rows, C->columns);
	for(k; k < C->rows; k++) {

		j = 0;
		for(j; j < C->columns; j++) {

			l = 0;
			p->c.row = k;
			p->c.column = j;
			for(l; l < A->columns; l++) {

				p->a = A->matrix[(p->c.row * A->columns) + l].value;
				p->b = B->matrix[(p->c.column) + (l * B->columns)].value;
				pthread_create(&thread_handles[i], NULL, getProduct, (void *)p);
				pthread_join(thread_handles[i], NULL);
				i++;
			}
		}
	}

/* print matrix C */
	i = 0;	
	printf("\nMatrix C\n");
	while(i < countC) {

		fprintf(ofp, "%d", C->matrix[i].value);
		printf("%d  ", C->matrix[i].value);
		i++;
		if (i % C->columns == 0) {

			fprintf(ofp, "\n");
		} else {

			fprintf(ofp, " ");
		}
		if(i % C->columns == 0) printf("\n");
	}
	printf("\n");
	fclose(ofp);
	system("PAUSE");

	return 0;
}
コード例 #10
0
int main (int argc, char *argv[]){

	int size = atoi (argv[1]);

	/*PAPI time measurement*/
	long_long start_us, stop_us;

	/*matrixes*/
	float **mat_a, **mat_b, **mat_c;
	mat_a = (float**) malloc (size * sizeof(float*));
	mat_b = (float**) malloc (size * sizeof(float*));
	mat_c = (float**) malloc (size * sizeof(float*));

	for (unsigned i = 0; i < size; ++i) {
		mat_a[i] = (float*) malloc (size * sizeof(float)); 
		mat_b[i] = (float*) malloc (size * sizeof(float)); 
		mat_c[i] = (float*) malloc (size * sizeof(float)); 
	}

	//Fill Matrices
	fillMatrices(mat_a, mat_b, mat_c, size );
	clearCache();

	/* PAPI VARIABLES */
	int events[NUM_EVENTS];
	long long counts[NUM_EVENTS];

	/* FLOATING POINT OPERATIONS */
	events[0]=PAPI_VEC_SP;	
	events[1]=PAPI_SP_OPS;

	/**/
	events[2]=PAPI_FP_OPS;
	events[3]=PAPI_DP_OPS;
	events[4]=PAPI_VEC_DP;

	counts[0] = 0;
	counts[1] = 0;
	counts[2] = 0;
	counts[3] = 0;
	counts[4] = 0;

	PAPI_library_init(PAPI_VER_CURRENT);

	PAPI_start_counters(events,2);
	start_us = PAPI_get_real_usec();


	matrix_mult_ikj ( mat_a, mat_b, mat_c, size);	


	stop_us = PAPI_get_real_usec();
	PAPI_stop_counters(counts,2);

	long_long duration_us = stop_us - start_us;

	FILE *file;
	file = fopen(argv[2],"a");

	fprintf(file, "%lld,", duration_us );
	printf("%lld,", duration_us );	
	fprintf(file,"%lld,", counts[0]);	
	printf("%lld,", counts[0]);	
	fprintf(file,"%lld\n", counts[1]);	
	printf("%lld\n", counts[1]);	

	fclose(file);
	return 0;
}