示例#1
0
文件: primes.c 项目: edunham/cs311
int main(int argc, char **argv){
//----------------SETUP--------------------------------------------------------
    if(argc < 4){
        printf("primes.c by Emily Dunham. Usage:\n");
        printf("\tFirst argument is number up to which we shall find primes\n");
        printf("\tSecond argument is the number of threads or processes\n");
        printf("\tThird argument is t for threads or p for processes\n");
        return 0;
    }
    int max = atoi(argv[1]);
    int rows = atoi(argv[2]);
    int use_threads = 0;
    if (argv[3][0] == 't' || argv[3][0] == 'T'){
        use_threads = 1;
    }
    #ifdef DBG
    printf("DBG: max is %d and rows is %d and threads is %d\n", 
           max, rows, use_threads);
    #endif
//----------------MAKE BITMAP---------------------------------------------------
    //Yes, I know this isn't a proper bitmap. But if one put appropriate
    //headers and stuff, it could become a bitmap. However, considering the
    //fact that it's currently 8:30pm the night it's due, you may just have to
    //dock me some points and be content with a char[][]...
    int cols = max / rows;
    if (max % rows != 0)
        cols++;
    #ifdef DBG
    printf("DBG: cols is %d :) \n", cols);
    #endif
    char **data;
    data = malloc(rows * sizeof(char*));
    int i=0;
    int j=0;
    for(i; i < rows; i++){
        data[i] = (char*)malloc(cols * sizeof(char));
        for(j; j < cols; j++){
            data[i][j] = PRIME;
        }
        j=0;
    }
//---------------MAKE THREADS OR PROCESSES--------------------------------------
    //first serially to make sure it works
    int total_found = 0;
    int c = 0;
    for(c; c < rows; c++){
        #ifdef DBG
        printf("c is %d, calc_block gets %d %d\n", c,(c*cols),cols);
        #endif
        total_found += calc_block((c * cols), cols, data[c]);
    }

//--------------PRINT NUMBER OF PRIMES FOUND------------------------------------
    printf("found %i primes\n", total_found);

    return 0;
}
示例#2
0
文件: subfield.c 项目: BENGMN/soen490
/* subfields of degree d */
static GEN
subfields_of_given_degree(blockdata *B)
{
  pari_sp av = avma;
  GEN L;

  if (DEBUGLEVEL) fprintferr("\n* Look for subfields of degree %ld\n\n", B->d);
  B->DATA = NULL; compute_data(B);
  L = calc_block(B, B->S->Z, cgetg(1,t_VEC), NULL);
  if (DEBUGLEVEL) fprintferr("\nSubfields of degree %ld: %Z\n", B->d, L);
  if (isclone(B->DATA)) gunclone(B->DATA);
  avma = av; return L;
}
示例#3
0
文件: subfield.c 项目: BENGMN/soen490
/* Computation of potential block systems of given size d associated to a
 * rational prime p: give a row vector of row vectors containing the
 * potential block systems of imprimitivity; a potential block system is a
 * vector of row vectors (enumeration of the roots). */
static GEN
calc_block(blockdata *B, GEN Z, GEN Y, GEN SB)
{
  long r = lg(Z), lK, i, j, t, tp, T, u, nn, lnon, lY;
  GEN K, n, non, pn, pnon, e, Yp, Zp, Zpp;
  pari_sp av0 = avma;

  if (DEBUGLEVEL>3)
  {
    fprintferr("lg(Z) = %ld, lg(Y) = %ld\n", r,lg(Y));
    if (DEBUGLEVEL > 5)
    {
      fprintferr("Z = %Z\n",Z);
      fprintferr("Y = %Z\n",Y);
    }
  }
  lnon = min(BIL, r);
  e    = new_chunk(BIL);
  n    = new_chunk(r);
  non  = new_chunk(lnon);
  pnon = new_chunk(lnon);
  pn   = new_chunk(lnon);

  Zp   = cgetg(lnon,t_VEC);
  Zpp  = cgetg(lnon,t_VEC); nn = 0;
  for (i=1; i<r; i++) { n[i] = lg(Z[i])-1; nn += n[i]; }
  lY = lg(Y); Yp = cgetg(lY+1,t_VEC);
  for (j=1; j<lY; j++) Yp[j] = Y[j];

  {
    pari_sp av = avma;
    long k = nn / B->size;
    for (j = 1; j < r; j++) 
      if (n[j] % k) break;
    if (j == r)
    {
      gel(Yp,lY) = Z;
      SB = print_block_system(B, Yp, SB);
      avma = av;
    }
  }
  gel(Yp,lY) = Zp;

  K = divisors(utoipos(n[1])); lK = lg(K);
  for (i=1; i<lK; i++)
  {
    long ngcd = n[1], k = itos(gel(K,i)), dk = B->size*k, lpn = 0;
    for (j=2; j<r; j++)
      if (n[j]%k == 0)
      {
        if (++lpn >= BIL) pari_err(talker,"overflow in calc_block");
        pn[lpn] = n[j]; pnon[lpn] = j;
        ngcd = cgcd(ngcd, n[j]);
      }
    if (dk % ngcd) continue;
    T = 1<<lpn;
    if (lpn == r-2)
    {
      T--; /* done already above --> print_block_system */
      if (!T) continue;
    }

    if (dk == n[1])
    { /* empty subset, t = 0. Split out for clarity */
      Zp[1] = Z[1]; setlg(Zp, 2);
      for (u=1,j=2; j<r; j++) Zpp[u++] = Z[j];
      setlg(Zpp, u);
      SB = calc_block(B, Zpp, Yp, SB);
    }

    for (t = 1; t < T; t++)
    { /* loop through all non-empty subsets of [1..lpn] */
      for (nn=n[1],tp=t, u=1; u<=lpn; u++,tp>>=1)
      {
        if (tp&1) { nn += pn[u]; e[u] = 1; } else e[u] = 0;
      }
      if (dk != nn) continue;

      for (j=1; j<r; j++) non[j]=0;
      Zp[1] = Z[1];
      for (u=2,j=1; j<=lpn; j++)
        if (e[j]) { Zp[u] = Z[pnon[j]]; non[pnon[j]] = 1; u++; }
      setlg(Zp, u);
      for (u=1,j=2; j<r; j++)
        if (!non[j]) Zpp[u++] = Z[j];
      setlg(Zpp, u);
      SB = calc_block(B, Zpp, Yp, SB);
    }
  }
  avma = av0; return SB;
}