Example #1
0
int main() {
	int i = 1; int n = 6;
	int k;
	while (true) {
		for (k = 2; k < n; k++) {
			if (!isPerm(i, i * k)) break;
		}
		if (isPerm(i, i * k) && k == n) {
			std::cout << "The solution is " << i << std::endl;
			break;
		}
		i++;
	}
	return 0;
}
Example #2
0
//Given two strings, write a method to decide if one is a permutation of the other
int main(){
	char* a = "hi";
	char* b = "id";
	printf("%s\n",isPerm(a,b)?"same\n":"different\n");


	return 0;
}
Example #3
0
int main()
{
	double best = 50;
	Uint64 bestN = 0;
	
	for (int x=1000;x<6000;x++)
		for (int y=x+1;y<6000;y++)
			if (isPrime(x) && isPrime(y) && x*y<10000000.0 && isPerm(x*y,(x-1)*(y-1)))
			{
				double d = double(x*y) / ((x-1.0)*(y-1.0));
				if (d<best)
					best = d,
					bestN = x*y;
			}
	
	cout<<bestN<<endl;
}
Example #4
0
int main(){
    liste l = creerListe();
    remplissageListe(&(l->end));

    cell p1 = l->deb, p2 = NULL, p3 = NULL, p4 = NULL, p5 = NULL;
    element tab[5];

    while(p1 !=NULL){
	p2 = p1->suiv;
	tab[0] = p1->el;
	while(p2!=NULL){
	    if(isPerm(p1->el, p2->el)){
		tab[1] = p2->el;
		p3 = p2->suiv;
		while(p3!=NULL){
		    if(isPermTab(p3->el, tab, 2)){
			tab[2] = p3->el;
			p4 = p3->suiv;
			while(p4!=NULL){
			    if(isPermTab(p4->el, tab, 3)){
				tab[3] = p4->el;
				p5 = p4->suiv;
				while(p5!=NULL){
				    if(isPermTab(p5->el, tab, 4)){
					printf("%d\n", (p1->el.nbre + p2->el.nbre + p3->el.nbre + p4->el.nbre + p5->el.nbre));
					return 0;
				    }
				    p5 = p5->suiv;
				}
			    }
			    p4 = p4->suiv;
			}
		    }
		    p3 = p3->suiv;
		}
	    }
	    p2 = p2->suiv;
	}
	p1 = p1->suiv;
    }

    return 0;
}
Example #5
0
int main(int argc, char **argv)
{
  if (argc < 2) {
    fprintf(stderr, "Usage: reordering_test matrix_in_matrix_market_format\n");
    return -1;
  }

  CSR *A = new CSR(argv[1], 0, true /* force-symmetric */);
  int nnz = A->getNnz();
  double flops = 2*nnz;
  double bytes = (sizeof(double) + sizeof(int))*nnz + sizeof(double)*(A->m + A->n);

  printf("original bandwidth %d\n", A->getBandwidth());

  double *x = MALLOC(double, A->m);
  double *y = MALLOC(double, A->m);

  // allocate a large buffer to flush out cache
  bufToFlushLlc = (double *)_mm_malloc(LLC_CAPACITY, 64);

  const int REPEAT = 128;
  double times[REPEAT];

  for (int i = 0; i < REPEAT; ++i) {
    flushLlc();

    double t = omp_get_wtime();
    A->multiplyWithVector(y, x);
    times[i] = omp_get_wtime() - t;
  }
  correctnessCheck(A, y);

  printf("SpMV BW");
  printEfficiency(times, REPEAT, flops, bytes);

#ifdef MKL
  for (int i = 0; i < REPEAT; ++i) {
    flushLlc();

    double t = omp_get_wtime();
    mkl_cspblas_dcsrgemv(
      "N", &A->m, A->values, A->rowptr, A->colidx, x, y);
    times[i] = omp_get_wtime() - t;
  }
  correctnessCheck(A, y);

  printf("MKL SpMV BW");
  printEfficiency(times, REPEAT, flops, bytes);
#endif

  int *perm = MALLOC(int, A->m);
  int *inversePerm = MALLOC(int, A->m);

  for (int o = BFS; o <= RCM; ++o) {
    Option option = (Option)o;

    switch (option) {
    case BFS:
      printf("\nBFS reordering\n");
      break;
    case RCM_WO_SOURCE_SELECTION:
      printf("\nRCM reordering w/o source selection heuristic\n");
      break;
    case RCM:
      printf("\nRCM reordering\n");
      break;
    default: assert(false); break;
    }

    double t = -omp_get_wtime();
    switch (option) {
    case BFS:
      A->getBFSPermutation(perm, inversePerm);
      break;
    case RCM_WO_SOURCE_SELECTION:
      A->getRCMPermutation(perm, inversePerm, false);
      break;
    case RCM:
      A->getRCMPermutation(perm, inversePerm);
      break;
    default: assert(false); break;
    }
    t += omp_get_wtime();

    printf(
      "Constructing permutation takes %g (%.2f gbps)\n",
      t, nnz*4/t/1e9);

    isPerm(perm, A->m);
    isPerm(inversePerm, A->m);

    t = -omp_get_wtime();
    CSR *APerm = A->permute(perm, inversePerm);
    t += omp_get_wtime();

    printf("Permute takes %g (%.2f gbps)\n", t, bytes/t/1e9);
    printf("Permuted bandwidth %d\n", APerm->getBandwidth());

    for (int i = 0; i < REPEAT; ++i) {
      flushLlc();

      t = omp_get_wtime();
      APerm->multiplyWithVector(y, x);
      times[i] = omp_get_wtime() - t;
    }
    printf("SpMV BW");
    printEfficiency(times, REPEAT, flops, bytes);

    delete APerm;
  }

  FREE(x);
  FREE(y);

  delete A;
}