Пример #1
0
int main() {
  double dr = 1.0 / (double) R;
  double dt = 0.0001;
  double mu = 0.5 * dt / (dr*dr);
  int i = 0;
  
  double U[(R+1)*(R+1)];
  double b[(R+1)*(R+1)];

  double du[R];
  double dc[R+1];
  double dl[R];

  printf("mu = %.5lf\n", mu);
  
  setInitialCondition(U, (R+1), (R+1), dr);
  setA(du, dc, dl, (R+1), (R+1), mu);
  dumpMatrix(U, (R+1), (R+1), dr, 0);

  while (i++ < 5) {
    diffuse(U, b, (R+1), (R+1), du, dc, dl, mu);
    dumpMatrix(U, (R+1), (R+1), dr, i);
  }
  
}
int LinearAffineEq::buildLookupTableAndCheck(mat_GF2 & Ta, bsetElem cst, smap & mapA){
	for(unsigned int i=0; i<size; i++){
		mat_GF2 e = colVector(i);
		mat_GF2 v = Ta * e;
		GF2X res = colVector_GF2X(v, 0);
		bsetElem resE = getLong(res) + cst;

		// check mapping, if it is correct (consistent table data with new computed data)
		if (mapA.count(i)>0){
			if (mapA[i] != resE) {
				if (verbosity){
					cout << "Mapping inconsistent for i=" << i
						<< "; mapA[i] = " << mapA[i]
						<< "; resE = " << resE << endl;
					cout << "colVector: " << endl;
					dumpMatrix(e);
					cout << " Ta*e " << endl;
					dumpMatrix(v);
					cout << "res: " << res << endl;
				}
				return -4;
			}
		} else {
			mapA.insert(smapElem(i, resE));
		}
	}

	return 0;
}
Пример #3
0
void AliasingManager::dumpAll() {
	typedef map<VarDecl*, int>::iterator it_p;
	typedef map<MatrixKind, boolean_matrix>::iterator it_m;

	// Output all pointers within map
	for (it_p b = m_indexesMap.begin(), e = m_indexesMap.end(); b != e; ++b) {
		outs() << "\t" << b->second<< " => "<< b->first->getNameAsString()<< "\n";
	}

	// Output aliases matrix
	for (it_m b = m_matricesMap.begin(), e = m_matricesMap.end(); b != e; ++b) {
		// Switch matrix' kind
		switch (b->first) {
			case MK_PointsToMatrix:
				outs() << "# Points-to & Pointed-by Matrix:\n";
				break;
			case MK_SymetricalMatrix:
				outs() << "# Symetrical Matrix:\n";
				break;
			case MK_ClosedMatrix:
				outs() << "# Aliases Matrix:\n";
				break;
		}

		dumpMatrix(b->second);

		outs() << "----------------------------------------\n";
	}
}
Пример #4
0
static void record_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
{
    internal_t*i = (internal_t*)dev->internal;
    msg("<trace> record: %08x FILLGRADIENT %08x\n", dev, gradient);
    writer_writeU8(&i->w, OP_FILLGRADIENT);
    writer_writeU8(&i->w, type);
    dumpGradient(&i->w, &i->state, gradient);
    dumpMatrix(&i->w, &i->state, matrix);
    dumpLine(&i->w, &i->state, line);
}
Пример #5
0
static void record_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
{
    internal_t*i = (internal_t*)dev->internal;
    msg("<trace> record: %08x FILLBITMAP\n", dev);
    writer_writeU8(&i->w, OP_FILLBITMAP);
    dumpImage(&i->w, &i->state, img);
    dumpMatrix(&i->w, &i->state, matrix);
    dumpLine(&i->w, &i->state, line);
    dumpCXForm(&i->w, &i->state, cxform);
}
Пример #6
0
static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
{
    internal_t*i = (internal_t*)dev->internal;
    if(font && !gfxfontlist_hasfont(i->fontlist, font)) {
	record_addfont(dev, font);
    }

    msg("<trace> record: %08x DRAWCHAR %d\n", glyphnr, dev);
    const char*font_id = (font&&font->id)?font->id:"*NULL*";
    
    gfxmatrix_t*l = &i->state.last_matrix[OP_DRAWCHAR];

    U8 flags = 0;
    if(!font)
	flags |= FLAG_ZERO_FONT;

    char same_font = i->state.last_string[OP_DRAWCHAR] && !strcmp(i->state.last_string[OP_DRAWCHAR], font_id);
    char same_matrix = (l->m00 == matrix->m00) && (l->m01 == matrix->m01) && (l->m10 == matrix->m10) && (l->m11 == matrix->m11);
    char same_color = !memcmp(color, &i->state.last_color[OP_DRAWCHAR], sizeof(gfxcolor_t));

    /* FIXME
    if(same_font && same_matrix && same_color)
	flags |= FLAG_SAME_AS_LAST;
    */

    writer_writeU8(&i->w, OP_DRAWCHAR|flags);
    writer_writeU32(&i->w, glyphnr);
#ifdef STATS
    i->state.size_chars += 5;
#endif

    if(!(flags&FLAG_SAME_AS_LAST)) {
	if(!(flags&FLAG_ZERO_FONT))
	    writer_writeString(&i->w, font_id);
	dumpColor(&i->w, &i->state, color);
	dumpMatrix(&i->w, &i->state, matrix);

	if(i->state.last_string[OP_DRAWCHAR])
	    free(i->state.last_string[OP_DRAWCHAR]);
	i->state.last_string[OP_DRAWCHAR] = strdup(font_id);

	i->state.last_color[OP_DRAWCHAR] = *color;
	i->state.last_matrix[OP_DRAWCHAR] = *matrix;
    } else {
	dumpXY(&i->w, &i->state, matrix);
    }
}
Пример #7
0
osg::Matrix OSGConverter::requestToModelPose(const SendRequest& req) {
	double pitch = 0;
	double roll = 0;
	double yaw = 0;
	double x = 0;
	double y = 0;
	double z = 0;
	CAST_PARAM(req.params, pitch, "pitch", double);
	CAST_PARAM(req.params, roll, "roll", double);
	CAST_PARAM(req.params, yaw, "yaw", double);
	CAST_PARAM(req.params, x, "x", double);
	CAST_PARAM(req.params, y, "y", double);
	CAST_PARAM(req.params, z, "z", double);

	osg::Matrix m = eulerToMatrix(pitch, roll, yaw) * osg::Matrix::translate(-1 * x, -1 * y, -1 * z);
#if 0
	dumpMatrix(m);
#endif
	return m;
}
int TxMatrixOptimizationDataCU::ingestLocalMatrix(SparseMatrix& A) {
  std::vector<local_int_t> i(A.localNumberOfRows + 1, 0);
  // Slight overallocation for these arrays
  std::vector<local_int_t> j;
  j.reserve(A.localNumberOfNonzeros);
  std::vector<double> a;
  a.reserve(A.localNumberOfNonzeros);
  scatterFromHalo.setNumRows(A.localNumberOfRows);
  scatterFromHalo.setNumCols(A.localNumberOfColumns);
  scatterFromHalo.clear();
  // We're splitting the matrix into diagonal and off-diagonal block to
  // enable overlapping of computation and communication.
  i[0] = 0;
  for (local_int_t m = 0; m < A.localNumberOfRows; ++m) {
    local_int_t nonzerosInRow = 0;
    for (local_int_t n = 0; n < A.nonzerosInRow[m]; ++n) {
      local_int_t col = A.mtxIndL[m][n];
      if (col < A.localNumberOfRows) {
        j.push_back(col);
        a.push_back(A.matrixValues[m][n]);
        ++nonzerosInRow;
      } else {
        scatterFromHalo.addEntry(m, col, A.matrixValues[m][n]);
      }
    }
    i[m + 1] = i[m] + nonzerosInRow;
  }

  // Setup SpMV data on Device
  cudaError_t err = cudaSuccess;
  int* i_d;
  err = cudaMalloc((void**)&i_d, i.size() * sizeof(i[0]));
  CHKCUDAERR(err);
  err = cudaMemcpy(i_d, &i[0], i.size() * sizeof(i[0]), cudaMemcpyHostToDevice);
  CHKCUDAERR(err);
  int* j_d;
  err = cudaMalloc((void**)&j_d, j.size() * sizeof(j[0]));
  CHKCUDAERR(err);
  err = cudaMemcpy(j_d, &j[0], j.size() * sizeof(j[0]), cudaMemcpyHostToDevice);
  CHKCUDAERR(err);
  double* a_d;
  err = cudaMalloc((void**)&a_d, a.size() * sizeof(a[0]));
  CHKCUDAERR(err);
  err = cudaMemcpy(a_d, &a[0], a.size() * sizeof(a[0]), cudaMemcpyHostToDevice);
  CHKCUDAERR(err);
  cusparseStatus_t cerr = CUSPARSE_STATUS_SUCCESS;
  cerr = cusparseCreateMatDescr(&matDescr);
  CHKCUSPARSEERR(cerr);
  cerr = cusparseSetMatIndexBase(matDescr, CUSPARSE_INDEX_BASE_ZERO);
  CHKCUSPARSEERR(cerr);
  cerr = cusparseSetMatType(matDescr, CUSPARSE_MATRIX_TYPE_GENERAL);
  CHKCUSPARSEERR(cerr);
  cerr = cusparseCreateHybMat(&localMatrix);
  CHKCUSPARSEERR(cerr);
  cerr = cusparseDcsr2hyb(handle, A.localNumberOfRows, A.localNumberOfColumns,
                          matDescr, a_d, i_d, j_d, localMatrix, 27,
                          CUSPARSE_HYB_PARTITION_USER);
  CHKCUSPARSEERR(cerr);

#ifndef HPCG_NOMPI
  err = cudaMalloc((void**)&elementsToSend,
                   A.totalToBeSent * sizeof(*elementsToSend));
  CHKCUDAERR(err);
  err = cudaMemcpy(elementsToSend, A.elementsToSend,
                   A.totalToBeSent * sizeof(*elementsToSend),
                   cudaMemcpyHostToDevice);
  CHKCUDAERR(err);
  err = cudaMalloc((void**)&sendBuffer_d, A.totalToBeSent * sizeof(double));
  CHKCUDAERR(err);
#endif

  // Set up the GS data.
  gelusStatus_t gerr = GELUS_STATUS_SUCCESS;
  gelusSolveDescription_t solveDescr;
  gerr = gelusCreateSolveDescr(&solveDescr);
  CHKGELUSERR(gerr);
  gerr = gelusSetSolveOperation(solveDescr, GELUS_OPERATION_NON_TRANSPOSE);
  CHKGELUSERR(gerr);
  gerr = gelusSetSolveFillMode(solveDescr, GELUS_FILL_MODE_FULL);
  CHKGELUSERR(gerr);
  gerr = gelusSetSolveStorageFormat(solveDescr, GELUS_STORAGE_FORMAT_HYB);
  CHKGELUSERR(gerr);
  gerr = gelusSetOptimizationLevel(solveDescr, GELUS_OPTIMIZATION_LEVEL_THREE);
  CHKGELUSERR(gerr);

  gerr = cugelusCreateSorIterationData(&gsContext);
  CHKGELUSERR(gerr);

#ifdef HPCG_DEBUG
  std::cout << A.localNumberOfRows << std::endl;
  std::cout << A.localNumberOfColumns << std::endl;
  std::cout << A.localNumberOfNonzeros << std::endl;
  int myrank;
  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
  if (myrank == 0) {
    dumpMatrix(std::cout, i, j, a);
  }
#endif

  gerr = cugelusDcsrsor_iteration_analysis(
      A.localNumberOfRows, solveDescr, GELUS_SOR_SYMMETRIC, 1.0,
      &i[0], &j[0], &a[0], gsContext);
  gerr = gelusDestroySolveDescr(solveDescr);
  CHKGELUSERR(gerr);

  if (A.mgData) {
    err =
      cudaMalloc((void**)&f2c, A.mgData->rc->localLength * sizeof(local_int_t));
    CHKCUDAERR(err);
    err = cudaMemcpy(f2c, A.mgData->f2cOperator,
        A.mgData->rc->localLength * sizeof(local_int_t),
        cudaMemcpyHostToDevice);
    CHKCUDAERR(err);
  }

  err = cudaMalloc((void**)&workvector, A.localNumberOfRows * sizeof(double));
  CHKCUDAERR(err);

  return (int)cerr | (int)gerr | (int)err;
}
int LinearAffineEq::checkInvertibleLinear(const bset & Ua,   const bset & Ub,
							  	  	  	  smap & mapA,       smap & mapB,
							  	  	  	  bsetElem * S1,     bsetElem * S1inv,
							  	  	  	  bsetElem * S2,     bsetElem * S2inv,
							  	  	  	  mat_GF2 & Ta, 	 mat_GF2 & Tb,
							  	  	  	  mat_GF2 & Tbinv,   smap & mapBinv,
							  	  	  	  bool AisA){
	// Extract linearly independent vectors, to determine mapping.
	// We need matrix consisting of Avect to be invertible in order to determine
	// matrix representation of transformation.
	bset Avect = extractLinearlyIndependent(mapA);
	if (verbosity) {
		cout << "Size of linearly independent vectors: " << Avect.size() << endl;
		LinearAffineEq::dumpSet(Avect);
	}

	// Derive matrix representation of transformation, if possible
	//
	// Ta * Ainp = Aout => Ta = Aout * Ainp^{-1}
	mat_GF2 Ainp = LinearAffineEq::vectorSet2GF2matrix(Avect, 8), AinpInv;
	mat_GF2 Aout = LinearAffineEq::values2GF2matrix(Avect, mapA, 8);
	mat_GF2 TAinv;
	GF2 det;

	// Dimension check, each matrix has to have exactly 8 rows (dimension) and at least 8 columns
	// (number of equations, sample points)
	if (       Ainp.NumCols() < dim || Ainp.NumRows() != dim
			|| Aout.NumCols() < dim || Aout.NumRows() != dim){
		if (verbosity) cout << "Dimension mismatch for Ainp || Aout matrices " << endl;
		return -1;
	}

	if (verbosity){
		cout << "Input matrix: " << endl;
		dumpMatrix(Ainp);
		cout << "Output matrix: " << endl;
		dumpMatrix(Aout);
	}

	// invertible?
	inv(det, AinpInv, Ainp);
	if (det == 0) {
		if (verbosity) cout << "A Matrix is not invertible! " << endl;
		return -2;
	}

	if (verbosity){
		cout << "Inverse matrix: " << endl;
		dumpMatrix(AinpInv);
	}

	// obtain linear transformation
	Ta = Aout * AinpInv;
	if (verbosity) {
		cout << "Ta matrix: " << endl;
		dumpMatrix(Ta);
	}

	// invertible?
	inv(det, TAinv, Ta);
	if (det==0){
		if (verbosity) cout << "Transformation is not linear & invertible!" << endl;
		return -3;
	}

	if (verbosity){
		cout << "Transformation matrix repr. obtained!!!" << endl;
		dumpMatrix(Ta);
	}

	//
	// A is known (matrix representation), build lookup table
	//
	if (buildLookupTableAndCheck(Ta, 0, mapA)<0){
		return -4;
	}

	//
	// Deriving mapping B from mapping A that is complete now and in matrix form.
	//
	// B * S2 = S1 * A
	// B(x) = S1 * A * S2^{-1} (x)
	// From this we derive mapping for B for basis vectors directly.
	//
	// Or B and A are swapped here and we want to compute values for A(x)
	// knowing mapping for B(x) (AisA==false)
	//
	// A(x) = S1inv * B * S2 (x)
	//
	Tb.SetDims(dim,dim);
	for(unsigned int i=0; i<dim; i++){
		bsetElem base = 1 << i;
		bsetElem res = AisA ? S1[mapA[S2inv[base]]] : S1inv[mapA[S2[base]]];
		for(unsigned int j=0; j<dim; j++){
			Tb.put(j, i, (res & (1<<j)) > 0 ? 1 : 0);
		}
	}

	if (verbosity){
		cout << "Mapping B derived" << endl;
		dumpMatrix(Tb);
	}

	// Transformation B invertibility test.
	// Inversion is needed for final test for relations properties with S-boxes.
	// If AisA==false, it does not mind, both relations has to be invertible.
	inv(det, Tbinv, Tb);
	if (det==0){
		if (verbosity) cout << "B is not linear invertible transformation, cannot create inversion." << endl;
		return -4;
	}

	// build lookup table for B and check already precomputed values
	if (buildLookupTableAndCheck(Tb, 0, mapB)<0){
		return -4;
	}

	// Whole range test for holding desired properties with Sboxes for which
	// they were designed.
	// For this we also need B^{-1} transformation.
	//
	// We apply this equation here:
	// B^{-1} * S1 * A = S2
	//
	// If AisA==false, we have to reverse mapping here, Ta, Tb, Tainv, Tbinv are swapped,
	// but relations works only according to equations. We need to return mapBinv for
	// real B mapping (B^{-1} is needed to verify relations).
	if (AisA){
		buildLookupTableAndCheck(Tbinv, 0, mapBinv);
	} else {
		mapBinv.clear();
		buildLookupTableAndCheck(TAinv, 0, mapBinv);
		Tbinv = TAinv;
	}

	//
	// Again take swapping A and B into account.
	//
	if (verbosity) cout << "Testing matrix representation with |Ua| = " << Ua.size() << " and |Ub| = " << Ub.size() << endl;
	for(bsetElem iter = 0; iter < size; iter++){
		bsetElem desiredResult = S2[iter];
		bsetElem myResult = AisA ? mapBinv[S1[mapA[iter]]] : mapBinv[S1[mapB[iter]]];
		if (desiredResult!=myResult){
			if (verbosity){
				cout << "Problem with relations, it does not work for: " << iter << endl;
				cout << "S2["<<iter<<"]=           " << desiredResult << endl;
				cout << "B^{-1}[S1[A["<<iter<<"]]]=" << myResult << endl;
			}

			return -5;
		}
	}

	return 0;
}