Пример #1
0
void qsort2(long int **V, long int l, long int r)
{
	if (r <= l)
		return;
	long int p = partition(V, l, r);
	qsort2(V, l, p - 1);
	qsort2(V, p + 1, r);
}
Пример #2
0
// 改进版快速排序,随机选取枢纽元
static void qsort2(int data[], int left, int right) {
	if (left < right) {
//		int pos = rand() % (right - left + 1) + left;
//		swap2(data, left, pos);
		int i = partition2(data, left, right);
		qsort2(data, left, i - 1);
		qsort2(data, i + 1, right);
	}
}
Пример #3
0
void matrix_sort_rows_with_sat(pk_internal_t* pk,
                               matrix_t* mat, satmat_t* sat)
{
    size_t i;
    qsort_t* qsort_tab;
    qsort_man_t qsort_man;

    if (!mat->_sorted) {
        qsort_man.pk = pk;
        qsort_man.size = mat->nbcolumns;
        qsort_tab = (qsort_t*)malloc(mat->nbrows * sizeof(qsort_t));
        for (i=0; i<mat->nbrows; i++) {
            qsort_tab[i].p = mat->p[i];
            qsort_tab[i].satp = sat->p[i];
        }
        qsort2(qsort_tab,
               mat->nbrows, sizeof(qsort_t),
               qsort_rows_with_sat_compar,
               &qsort_man);
        for (i=0; i<mat->nbrows; i++) {
            mat->p[i] = qsort_tab[i].p;
            sat->p[i] = qsort_tab[i].satp;
        }
        free(qsort_tab);
        mat->_sorted = true;
    }
}
Пример #4
0
Файл: sort.c Проект: bnjzer/c
int main(int argc, char *argv[]){
  char numeric = 0;
  char reverse = 0;
  char caseInsensitive = 0;

  int nlines;
  char lines[MAXLINES*MAXLEN];
  int arg = 1;

  while(arg < argc){
    if(strcmp(argv[arg], "-n") == 0){
      numeric = 1;
    } else if(strcmp(argv[arg], "-r") == 0){
      reverse = 1;
    } else if(strcmp(argv[arg], "-f") == 0){
      caseInsensitive = 1;
    }
    arg++;
  }

  if((nlines = readlines(linesptr, lines, MAXLINES)) >= 0){
    qsort2((void **) linesptr, 0, nlines-1, (numeric ? numcmp : caseInsensitive ? strcasecmp : strcmp));
    writelines(linesptr, nlines, reverse);
    return 0;
  } else {
    printf("input too big to sort\n");
    return 1;
  }
}
Пример #5
0
signed short
median (signed short *a, int n)
{				/* a: pointer to start of array      */
  qsort2 (a, n);		/* n: # elements in array            */

  return a[((n + 1) / 2) - 1];	/* (10+1)/2 = 5   (11+1)/2 = 6       */
}
Пример #6
0
Файл: sort.c Проект: bnjzer/c
void qsort2(void *linesptr[], int left, int right, int (*comp)(const char *, const char *)){
  int i,indPivot;

  if(left >= right)
    return;

  indPivot=left;

  for(i=indPivot+1; i<=right; i++){
    if((*comp)(linesptr[i], linesptr[indPivot]) < 0){
      swap(linesptr, indPivot, i);
    }
    qsort2(linesptr,left,indPivot-1, comp);
    qsort2(linesptr, indPivot+1,right, comp);
  }
}
Пример #7
0
void qsort(void *base, 
           long n, 
           long size, 
           int (*cmp)(const void *,const void *))
{ 
   qsort2(base, 0, n-1, size, cmp); 
}
Пример #8
0
Файл: sort.c Проект: folde01/kr2
/* qsort2: sort v[left]...v[right] into increasing order */
void qsort2(char *v[], int left, int right)
{
	int i, last;
	void swap(char *v[], int i, int j);
	if (left >= right) /* do nothing if array contains */
	  return;
	/* fewer than two elements */
	swap(v, left, (left + right)/2);
	last = left;
	for (i = left+1; i <= right; i++)
	  if (strcmp(v[i], v[left]) < 0)
	    swap(v, ++last, i);
	swap(v, left, last);
	qsort2(v, left, last-1);
	qsort2(v, last+1, right);
}
Пример #9
0
/* qsort: sort v[left]...v[right] into increasing order */
void qsort2(struct employee * v[], int left, int right)
{
    int i, last;
    void swap(struct employee * v[], int i, int j);
    
    if (left >= right) /* do nothing if array contains */
        return;        /* fewer than two elements */
    swap(v, left, (left + right)/2); /* move partition elem */
    last = left; /* to v[0] */
    for (i = left + 1; i <= right; i++) /* partition */
        if (strncmp(v[i]->name, v[left]->name, 4) < 0)
            swap(v, ++last, i);
    swap(v, left, last);    /* restore partition elem */
    qsort2(v, left, last-1);
    qsort2(v, last+1, right);
}
Пример #10
0
void
qsort2 (register int l, register int r, char *a[], off_t * siz,MPEG_HEAD * inf)
{
    register int i, j;

    char *w;
    char x[256];

    off_t s;
    MPEG_HEAD mh;

    strncpy (x, a[(l + r) / 2], 254);
    i = l;
    j = r;

    while (i <= j) {

        while (my_strcmp (a[i], x) < 0)
            i++;
        while (my_strcmp (a[j], x) > 0)
            j--;

        if (i <= j) {
            w = a[i];
            a[i] = a[j];
            a[j] = w;

            s = siz[i];
            siz[i] = siz[j];
            siz[j] = s;

            if (inf) {
                mh = inf[i];
                inf[i] = inf[j];
                inf[j] = mh;
            }
            i++;
            j--;
        }
    }
    if (l < j)
        qsort2 (l, j, a, siz, inf);
    if (i < r)
        qsort2 (i, r, a, siz, inf);
} //qsort2
Пример #11
0
        template < typename RandomAccessIterator, typename Predicate > inline static
        void qsort2(RandomAccessIterator left, RandomAccessIterator right, const int min_size, const Predicate pred)
        {
            if (left >= right) return;

            auto pivot = left + std::distance(left, right) / 2;
            auto store = partition(left, right, pivot, pred);

            if (std::distance(left, store - 1) <= min_size) {
                insertion_sort(left, store, pred);
            } else {
                qsort2(left, store - 1, min_size, pred);
            }
            if (std::distance(store + 1, right) <= min_size) {
                insertion_sort(store + 1, right + 1, pred);
            } else {
                qsort2(store + 1, right, min_size, pred);
            }
        }
Пример #12
0
//Modified from K&R
static void qsort2(void *base, long left, long right, long size,
      int (*cmp)(const void *,const void *))
{
   int i, last;
   char *base2=(char*)base, *pivot;
   if(left >= right) 
      return;
   QsortSwap(base2, left, (left + right)/2, size);
   last = left;
   pivot = &base2[left*size];
   for(i = left + 1; i <= right; ++i) 
   {
      if(cmp(&base2[i*size], pivot) < 0) 
         QsortSwap(base2, ++last, i, size);
   }
   QsortSwap(base2, left, last, size);
   qsort2(base, left, last-1, size, cmp);
   qsort2(base, last+1, right, size, cmp);
}
Пример #13
0
void qsort2(void *v[], int left, int right, int (*comp)(void *, void *))
{
	int i, last;

	if(left >= right)
		return;

	swap(v, left, (left+right)/2);
	last = left;
	for(i = left + 1; i <= right; ++i){
		if((*comp)(v[i], v[left]) < 0)
			swap(v, ++last, i);
	}
	swap(v, left, last);
	qsort2(v, left, last - 1, comp);
	qsort2(v, last + 1, right, comp);

	return;
}
Пример #14
0
void
qsort2 (signed short *a, int n)	/* a: pointer to start of array      */
{				/* n: # elements in array            */
  int i, j;
  signed short x, w;

  do
    {
      i = 0;
      j = n - 1;
      x = a[j / 2];
      do
	{
	  while (a[i] < x)
	    i++;
	  while (a[j] > x)
	    j--;
	  if (i > j)
	    break;
	  w = a[i];
	  a[i] = a[j];
	  a[j] = w;
	}
      while (++i <= --j);
      if (j + 1 < n - i)
	{
	  if (j > 0)
	    qsort2 (a, j + 1);
	  a += i;
	  n -= i;
	}
      else
	{
	  if (i < n - 1)
	    qsort2 (a + i, n - i);
	  n = j + 1;
	}
    }
  while (n > 1);
}
Пример #15
0
Файл: sort.c Проект: folde01/kr2
/* sort input lines */
int main()
{
  int nlines;
  /* number of input lines read */
  if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
    qsort2(lineptr, 0, nlines-1);
    writelines(lineptr, nlines);
    return 0;
  } else {
    printf("error: input too big to sort\n");
    return 1;
  }
}
Пример #16
0
int main() {
	int a[] = {3,1,3,2,5,2};
	int b[] = {3,1,3,2,5,2};
	qsort(a, sizeof(a)/sizeof(a[0]));
	qsort2(b, sizeof(b)/sizeof(b[0]));
	for(int i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
		printf("%d\t", a[i]);
	printf("\n");
	for(int i = 0; i < sizeof(b)/sizeof(b[0]); ++i)
		printf("%d\t", b[i]);
	printf("\n");
	return 0;
}
Пример #17
0
void matrix_sort_rows(pk_internal_t* pk,
                      matrix_t* mat)
{
    qsort_man_t qsort_man;

    if (!mat->_sorted) {
        qsort_man.pk = pk;
        qsort_man.size = mat->nbcolumns;
        qsort2(mat->p, mat->nbrows, sizeof(numint_t*),
               qsort_rows_compar,
               &qsort_man);
        mat->_sorted = true;
    }
}
Пример #18
0
void sort(int argc, char *argv[])
{
	int nlines = 0;
	int numberic = 0;
	char *pargv;
	int i;

	if(argc >= 2){
		for(i = 1; i < argc; ++i){
			pargv = argv[i];
			if(strcmp(pargv, "-n") == 0)
				numberic = 1;
			else if(strcmp(pargv, "-d") == 0)
				g_directory_sort = 1;
			else if(strcmp(pargv, "-r") == 0)
				g_reverse_flag = 1;
			else if(strcmp(pargv, "-f") == 0)
				g_ignore_case = 1;
			else if(strncmp(pargv, "-F", 2) == 0){
				g_field_sort = atof(pargv+2);
			}
			else if(strncmp(pargv, "-df", 2) == 0){
				g_directory_sort = 1;
				g_ignore_case = 1;
			}
			else
				;
		}
	}
printf("numberic:%d, g_directory_sort:%d, g_reverse_flag:%d, g_ignore_case:%d, g_field_sort:%d\n", numberic, g_directory_sort,g_reverse_flag,g_ignore_case,g_field_sort);

	if((nlines = readlines2(lineptr, MAXLINES)) > 0){
		qsort2(lineptr, 0, nlines - 1, (int (*)(void *, void *))(numberic ? numcmp :  strcmp2));
		writelines(lineptr, nlines);
	}else{
		printf("input too big to sort!\n");
	}

	return;
}
Пример #19
0
int write_nemesis(std::string &nemI_out_file,
                  Machine_Description* machine,
                  Problem_Description* problem,
                  Mesh_Description<INT>* mesh,
                  LB_Description<INT>* lb,
                  Sphere_Info* sphere)
{
  int     exoid;
  char    title[MAX_LINE_LENGTH+1], method1[MAX_LINE_LENGTH+1];
  char    method2[MAX_LINE_LENGTH+1];

  int cpu_ws = sizeof(float);
  int io_ws  = sizeof(float);

  printf("Outputting load balance to file %s\n", nemI_out_file.c_str());

  /* Create the load balance file */
  /* Attempt to create a netcdf4-format file; if it fails, then assume
     that the netcdf library does not support that mode and fall back
     to classic netcdf3 format.  If that fails, issue an error and
     return failure.
  */
  int mode3 = EX_CLOBBER;
  int mode4 = mode3|EX_NETCDF4|EX_NOCLASSIC|problem->int64db|problem->int64api;

  ex_opts(EX_DEFAULT); // Eliminate misleading error if the first ex_create fails, but the second succeeds.
  if((exoid=ex_create(nemI_out_file.c_str(), mode4, &cpu_ws, &io_ws)) < 0) {
    /* If int64api or int64db non-zero, then netcdf-4 format is required, so
       fail now...
    */
    if (problem->int64db|problem->int64api) {
      Gen_Error(0, "fatal: failed to create Nemesis netcdf-4 file");
      return 0;
    }
    if((exoid=ex_create(nemI_out_file.c_str(), mode3, &cpu_ws, &io_ws)) < 0) {
      Gen_Error(0, "fatal: failed to create Nemesis file");
      return 0;
    }
  }
  ON_BLOCK_EXIT(ex_close, exoid);
  
  /* Set the error reporting value */
  if (error_lev > 1)
    ex_opts(EX_VERBOSE | EX_DEBUG);
  else
    ex_opts(EX_VERBOSE);

  /* Enable compression (if netcdf-4) */
  ex_set_option(exoid, EX_OPT_COMPRESSION_LEVEL, 1);
  ex_set_option(exoid, EX_OPT_COMPRESSION_SHUFFLE, 1);

  /* Create the title */
  if(problem->type == NODAL)
    strcpy(method1, "nodal");
  else
    strcpy(method1, "elemental");

  sprintf(title, "nem_slice %s load balance file", method1);

  strcpy(method1, "method1: ");
  strcpy(method2, "method2: ");

  switch(lb->type)
    {
    case MULTIKL:
      strcat(method1, "Multilevel-KL decomposition");
      strcat(method2, "With Kernighan-Lin refinement");
      break;
    case SPECTRAL:
      strcat(method1, "Spectral decomposition");
      break;
    case INERTIAL:
      strcat(method1, "Inertial decomposition");
      break;
    case ZPINCH:
      strcat(method1, "ZPINCH decomposition");
      break;
    case BRICK:
      strcat(method1, "BRICK decomposition");
      break;
    case ZOLTAN_RCB:
      strcat(method1, "RCB decomposition");
      break;
    case ZOLTAN_RIB:
      strcat(method1, "RIB decomposition");
      break;
    case ZOLTAN_HSFC:
      strcat(method1, "HSFC decomposition");
      break;
    case LINEAR:
      strcat(method1, "Linear decomposition");
      break;
    case RANDOM:
      strcat(method1, "Random decomposition");
      break;
    case SCATTERED:
      strcat(method1, "Scattered decomposition");
      break;
    }

  if(lb->refine == KL_REFINE && lb->type != MULTIKL)
    strcat(method2, "with Kernighan-Lin refinement");
  else if(lb->type != MULTIKL)
    strcat(method2, "no refinement");

  switch(lb->num_sects)
    {
    case 1:
      strcat(method1, " via bisection");
      break;
    case 2:
      strcat(method1, " via quadrasection");
      break;
    case 3:
      strcat(method1, " via octasection");
      break;
    }

  /* Do some sorting */
  for(int proc=0; proc < machine->num_procs; proc++) {

    /* Sort node maps */
    gds_qsort(TOPTR(lb->int_nodes[proc]), lb->int_nodes[proc].size());
    if(problem->type == NODAL) {
      sort2(lb->ext_nodes[proc].size(), TOPTR(lb->ext_nodes[proc]),
	    TOPTR(lb->ext_procs[proc]));
    }

    /* Sort element maps */
    gds_qsort(TOPTR(lb->int_elems[proc]), lb->int_elems[proc].size());
  }

  /* Output the info records */
  char *info[3];
  info[0] = title;
  info[1] = method1;
  info[2] = method2;

  if(ex_put_info(exoid, 3, info) < 0)
    Gen_Error(0, "warning: output of info records failed");

  /* Generate a QA record for the utility */
  time_t time_val = time(nullptr);
  char *ct_ptr   = asctime(localtime(&time_val));
  char tm_date[30];
  strcpy(tm_date, ct_ptr);

  /* Break string with null characters */
  tm_date[3]  = '\0';
  tm_date[7]  = '\0';
  tm_date[10] = '\0';
  tm_date[19] = '\0';

  char    qa_date[15], qa_time[10], qa_name[MAX_STR_LENGTH];
  char    qa_vers[10];

  sprintf(qa_date, "%s %s %s", &tm_date[8], &tm_date[4], &tm_date[20]);
  sprintf(qa_time, "%s", &tm_date[11]);
  strcpy(qa_name, UTIL_NAME);
  strcpy(qa_vers, ELB_VERSION);

  if(qa_date[strlen(qa_date)-1] == '\n')
    qa_date[strlen(qa_date)-1] = '\0';

  char **lqa_record = (char **)array_alloc(1, 4, sizeof(char *));
  for(int i2=0; i2 < 4; i2++)
    lqa_record[i2] = (char *)array_alloc(1, MAX_STR_LENGTH+1, sizeof(char));

  strcpy(lqa_record[0], qa_name);
  strcpy(lqa_record[1], qa_vers);
  strcpy(lqa_record[2], qa_date);
  strcpy(lqa_record[3], qa_time);

  printf("QA Record:\n");
  for(int i2=0; i2 < 4; i2++) {
    printf("\t%s\n", lqa_record[i2]);
  }

  if(ex_put_qa(exoid, 1, (char *(*)[4]) &lqa_record[0]) < 0) {
    Gen_Error(0, "fatal: unable to output QA records");
    return 0;
  }

  /* free up memory */
  for(int i2=0; i2 < 4; i2++)
    free(lqa_record[i2]);

  free(lqa_record);

  /* Output the the initial Nemesis global information */
  if(ex_put_init_global(exoid, mesh->num_nodes, mesh->num_elems,
                        mesh->num_el_blks, 0, 0) < 0) {
    Gen_Error(0, "fatal: failed to output initial Nemesis parameters");
    return 0;
  }
  
  /* Set up dummy arrays for ouput */
  std::vector<INT> num_nmap_cnts(machine->num_procs);
  std::vector<INT> num_emap_cnts(machine->num_procs);
  
  if(problem->type == NODAL) {
    /* need to check and make sure that there really are comm maps */
    for(int cnt=0; cnt < machine->num_procs; cnt++) {
      if (!lb->bor_nodes[cnt].empty())
	num_nmap_cnts[cnt] = 1;
    }
  }
  else {	/* Elemental load balance */
    if(((problem->num_vertices)-(sphere->num)) > 0) {
      /* need to check and make sure that there really are comm maps */
      for(int cnt=0; cnt < machine->num_procs; cnt++) {
        if (!lb->bor_nodes[cnt].empty()) num_nmap_cnts[cnt] = 1;
      }
      for(int cnt=0; cnt < machine->num_procs; cnt++) {
        if (!lb->bor_elems[cnt].empty()) num_emap_cnts[cnt] = 1;
      }
    }
  }

  if(ex_put_init_info(exoid, machine->num_procs, machine->num_procs, (char*)"s") < 0) {
    Gen_Error(0, "fatal: unable to output init info");
    return 0;
  }

  // Need to create 5 arrays with the sizes of lb->int_nodes[i].size()...
  {
    std::vector<INT> ins(machine->num_procs);
    std::vector<INT> bns(machine->num_procs);
    std::vector<INT> ens(machine->num_procs);
    std::vector<INT> ies(machine->num_procs);
    std::vector<INT> bes(machine->num_procs);

    for (int iproc = 0; iproc < machine->num_procs; iproc++) {
      ins[iproc] = lb->int_nodes[iproc].size();
      bns[iproc] = lb->bor_nodes[iproc].size();
      ens[iproc] = lb->ext_nodes[iproc].size();
      ies[iproc] = lb->int_elems[iproc].size();
      bes[iproc] = lb->bor_elems[iproc].size();
    }

    if(ex_put_loadbal_param_cc(exoid,
			       TOPTR(ins), TOPTR(bns), TOPTR(ens),
			       TOPTR(ies), TOPTR(bes), TOPTR(num_nmap_cnts),
			       TOPTR(num_emap_cnts)) < 0)
      {
	Gen_Error(0, "fatal: unable to output load-balance parameters");
	return 0;
      }
  }

  if(problem->type == NODAL)		/* Nodal load balance output */
    {
      /* Set up for the concatenated communication map parameters */
      std::vector<INT> node_proc_ptr(machine->num_procs+1);
      std::vector<INT> node_cmap_ids_cc(machine->num_procs);
      std::vector<INT> node_cmap_cnts_cc(machine->num_procs);

      node_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	node_proc_ptr[proc+1]   = node_proc_ptr[proc] + 1;
	node_cmap_cnts_cc[proc] = lb->ext_nodes[proc].size();
	node_cmap_ids_cc[proc]  = 1;
      }

      /* Output the communication map parameters */
      if(ex_put_cmap_params_cc(exoid, TOPTR(node_cmap_ids_cc),
			       TOPTR(node_cmap_cnts_cc),
			       TOPTR(node_proc_ptr), nullptr, nullptr, nullptr) < 0)
	{
	  Gen_Error(0, "fatal: unable to output communication map parameters");
	  return 0;
	}

      /* Output the node and element maps */
      for(int proc=0; proc < machine->num_procs; proc++) {
	/* Output the nodal map */
	if(ex_put_processor_node_maps(exoid,
				      TOPTR(lb->int_nodes[proc]),
				      TOPTR(lb->bor_nodes[proc]),
				      TOPTR(lb->ext_nodes[proc]), proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output node map");
	    return 0;
	  }

	/* Output the elemental map */
	if(ex_put_processor_elem_maps(exoid, TOPTR(lb->int_elems[proc]), nullptr, proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output element map");
	    return 0;
	  }

	/*
	 * Reorder the nodal communication maps so that they are ordered
	 * by processor and then by global ID.
	 */

	/* This is a 2-key sort */
	qsort2(TOPTR(lb->ext_procs[proc]), TOPTR(lb->ext_nodes[proc]), lb->ext_nodes[proc].size());

	/* Output the nodal communication map */
	if(ex_put_node_cmap(exoid, 1,
			    TOPTR(lb->ext_nodes[proc]),
			    TOPTR(lb->ext_procs[proc]), proc) < 0)
	  {
	    Gen_Error(0, "fatal: failed to output nodal communication map");
	    return 0;
	  }

      } /* End "for(proc=0; proc < machine->num_procs; proc++)" */
    }
  else if(problem->type == ELEMENTAL)	/* Elemental load balance output */
    {
      std::vector<INT> node_proc_ptr(machine->num_procs+1);
      std::vector<INT> node_cmap_ids_cc(machine->num_procs);
      std::vector<INT> node_cmap_cnts_cc(machine->num_procs);

      node_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	node_proc_ptr[proc+1]   = node_proc_ptr[proc] + 1;

	node_cmap_cnts_cc[proc] = 0;
	for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++)
	  node_cmap_cnts_cc[proc] += lb->born_procs[proc][cnt].size();

	node_cmap_ids_cc[proc]  = 1;
      }

      std::vector<INT> elem_proc_ptr(machine->num_procs+1);
      std::vector<INT> elem_cmap_ids_cc(machine->num_procs);
      std::vector<INT> elem_cmap_cnts_cc(machine->num_procs);

      elem_proc_ptr[0] = 0;
      for(int proc=0; proc < machine->num_procs; proc++) {
	elem_proc_ptr[proc+1]   = elem_proc_ptr[proc] + 1;
	elem_cmap_cnts_cc[proc] = lb->e_cmap_elems[proc].size();
	elem_cmap_ids_cc[proc]  = 1;
      }

      /* Output the communication map parameters */
      if(ex_put_cmap_params_cc(exoid, TOPTR(node_cmap_ids_cc), TOPTR(node_cmap_cnts_cc),
			       TOPTR(node_proc_ptr), TOPTR(elem_cmap_ids_cc),
			       TOPTR(elem_cmap_cnts_cc), TOPTR(elem_proc_ptr)) < 0)
	{
	  Gen_Error(0, "fatal: unable to output communication map parameters");
	  return 0;
	}

      /* Output the node and element maps */
      for(int proc=0; proc < machine->num_procs; proc++)
	{
	  /* Output the nodal map */
	  if(ex_put_processor_node_maps(exoid,
					TOPTR(lb->int_nodes[proc]),
					TOPTR(lb->bor_nodes[proc]),
					nullptr, proc) < 0)
	    {
	      Gen_Error(0, "fatal: failed to output node map");
	      return 0;
	    }

	  /* Output the elemental map */
	  if(ex_put_processor_elem_maps(exoid,
					TOPTR(lb->int_elems[proc]),
					TOPTR(lb->bor_elems[proc]),
					proc) < 0)
	    {
	      Gen_Error(0, "fatal: failed to output element map");
	      return 0;
	    }

	  /*
	   * Build a nodal communication map from the list of border nodes
	   * and their associated processors and side IDs.
	   */
	  size_t nsize = 0;
	  for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++)
	    nsize += lb->born_procs[proc][cnt].size();

	  if (nsize > 0) {
	    std::vector<INT> n_cmap_nodes(nsize);
	    std::vector<INT> n_cmap_procs(nsize);

	    size_t cnt3 = 0;
	    for(size_t cnt=0; cnt < lb->bor_nodes[proc].size(); cnt++) {
	      for(size_t cnt2=0; cnt2 < lb->born_procs[proc][cnt].size(); cnt2++) {
		n_cmap_nodes[cnt3]   = lb->bor_nodes[proc][cnt];
		n_cmap_procs[cnt3++] = lb->born_procs[proc][cnt][cnt2];
	      }
	    }

	    /*
	     * Reorder the nodal communication maps so that they are ordered
	     * by processor and then by global ID.
	     */
	    /* This is a 2-key sort */
	    qsort2(TOPTR(n_cmap_procs), TOPTR(n_cmap_nodes), cnt3);

	    /* Output the nodal communication map */
	    if(ex_put_node_cmap(exoid, 1, TOPTR(n_cmap_nodes), TOPTR(n_cmap_procs), proc) < 0) {
	      Gen_Error(0, "fatal: unable to output nodal communication map");
	      return 0;
	    }
	  } /* End "if (nsize > 0)" */

	    /* Output the elemental communication map */
	  if(!lb->e_cmap_elems[proc].empty()) {
	    if(ex_put_elem_cmap(exoid, 1,
				TOPTR(lb->e_cmap_elems[proc]),
				TOPTR(lb->e_cmap_sides[proc]),
				TOPTR(lb->e_cmap_procs[proc]), proc) < 0)
	      {
		Gen_Error(0, "fatal: unable to output elemental communication map");
		return 0;
	      }
	  }

	} /* End "for(proc=0; proc < machine->num_procs; proc++)" */

    }
  return 1;
} /*------------------------End write_nemesis()------------------------------*/
Пример #20
0
void quicksort2(int *data, int n) {
	qsort2(data, 0, n - 1);
}
Пример #21
0
void quicksort(long int **V, long int n)
{
	qsort2(V, 0, n - 1); 
}
Пример #22
0
void sort_tab_name()
{
    qsort2(tab_pt, 0, maxst - 1);
    
}
Пример #23
0
int main(int argc,char **argv)
{
  struct dirent *dp;
  struct stat stp;
  DIR *dirp;

  char dir[512];
  char argdir[512];
  char buf[1024];
  char str[128];
  char *files[2048],*dirs[2048];
  long ffsize=0,ddsize=0, i;
  off_t fsize[2048];
  MPEG_HEAD finfo[2048];
  int audioenc=0,fd=0;

  strcpy(argdir,".");

  if (argc==2)
    strcpy(argdir,argv[1]);
  
  dirp = opendir (argdir);
  if (dirp == 0) {
      fprintf (stderr,"opendir \"%s\": %s\n", argdir, strerror (errno));
      exit (errno);
  }


  ffsize=0;


  /* Read directory contents and mp3 file infos*/
  while ((dp = readdir (dirp)) != NULL) {
      strcpy (dir, argdir);
      strcat (dir, "/");
      strcat (dir, dp->d_name);

      if (strstr (dir, ".mp3"))
	  audioenc = 1;
      else if (strstr (dir, ".ogg"))
	  audioenc = 2;
      else
	  audioenc = 0;

      //printf("DIR:%s\n",dir);
      lstat (dir, &stp);
      finfo[ffsize].fmode = stp.st_mode;
      if (S_ISLNK (finfo[ffsize].fmode)) {
	  stat (dir, &stp);
	  if (S_ISDIR (stp.st_mode))
	      finfo[ffsize].fmode = stp.st_mode;
      }

      if (!S_ISDIR (stp.st_mode)) {
	  files[ffsize] =
	      (char *) realloc ((char *) files[ffsize],
				strlen (dp->d_name) + 2);
	  strcpy (files[ffsize], dp->d_name);
	  fsize[ffsize] = stp.st_size;

	  if (audioenc==1) { //mp3
	      if (!S_ISREG (stp.st_mode)) {
		  finfo[ffsize].valid = 0;
		  fd = -1;
	      }
	      else
		  fd = open (dir, O_RDONLY);
	      if (fd < 0) {
		  finfo[ffsize].valid = 0;
	      }
	      else if (S_ISREG (stp.st_mode)) {
		  get_mp3header (&finfo[ffsize], stp.st_size, fd);
		  close (fd);
	      }
	  }
	  if (audioenc==2) { //ogg
	      if (!S_ISREG (stp.st_mode)) {
		  finfo[ffsize].valid = 0;
		  fd = -1;
	      }
	      else
		  fd = open (dir, O_RDONLY);
	      if (fd < 0) {
		  finfo[ffsize].valid = 0;
	      }
	      else if (S_ISREG (stp.st_mode)) {
		  oggnfo (&finfo[ffsize], stp.st_size, fd);
		  finfo[ffsize].valid = 1;
		  finfo[ffsize].enctype = 2; //ogg
		  close (fd);
	      }
	  }
	  else if (audioenc==0) // non-audio file
	      finfo[ffsize].valid = 0;
	  ffsize++;
      }
      else {
	  dirs[ddsize] =
	      (char *) realloc ((char *) dirs[ddsize],
				strlen (dp->d_name) + 2);
	  strcpy (dirs[ddsize], dp->d_name);
	  ddsize++;
      }
  }
  closedir (dirp);

  /*Sort dirs */
  if ((ddsize - 1) > 1)
      qsort1 (0, ddsize - 1, dirs);

  /*Sort files */
  if ((ffsize - 1) > 0) {
      qsort2 (0, ffsize - 1, files, fsize, finfo);
  }


  //print dirs
  for (i = 0; i < ddsize; i++) {
      printf ("d//////%s\n",dirs[i]);
  }

  //print files
  for (i = 0; i < ffsize; i++) {
    if (strstr (files[i], ".mp3")) {
      if (finfo[i].vbr) {
	strcpy(str,"VBR");
	//printf("I:%ld\n",i);
	if ((finfo[i].mins+finfo[i].secs))
	  finfo[i].bitrate=fsize[i]*8/(60*finfo[i].mins+finfo[i].secs)/1000;
	else
	  finfo[i].bitrate=0;
      }
      else
	strcpy(str,"Kbps");
      sprintf (buf,"fmp3/%08ld/%02d/%02d/%03d/%3s/%s\n",
	   fsize[i],finfo[i].mins,finfo[i].secs, finfo[i].bitrate,str,files[i]);
    }
    else if (strstr (files[i], ".ogg")) {
      //sprintf(buf,"%s\n",files[i]);
	strcpy(str,"VBR");
      sprintf (buf,"fmp3/%08ld/%02d/%02d/%03d/%3s/%s\n",
	   fsize[i],finfo[i].mins,finfo[i].secs, finfo[i].bitrate,str,files[i]);
    }
    else
      sprintf (buf,"f/%ld/////%s\n",fsize[i],files[i]);

    printf("%s",buf);
  }

  return 0;
}