示例#1
0
static u_long 
WriteOutWords (char *file_name, u_long type, int lookback)
{
  FILE *f;
  int i;
  u_long mem_reqd = 0;
  compression_dict_header cdh;
  f = create_file (file_name, TEXT_DICT_SUFFIX, "w+",
		   MAGIC_DICT, MG_ABORT);

  bzero((char *) &cdh, sizeof(cdh));

  cdh.dict_type = type;
  cdh.novel_method = (type == MG_SEED_DICTIONARY) ? novel_method :
    MG_NOVEL_HUFFMAN_CHARS;

  cdh.num_words[1] = keep[1].num_wds;
  cdh.num_words[0] = keep[0].num_wds;
  cdh.num_word_chars[1] = Uncompressed_size (&keep[1]);
  cdh.num_word_chars[0] = Uncompressed_size (&keep[0]);
  cdh.lookback = lookback;
  Write_cdh (f, &cdh);

  for (i = 0; i < 2; i++)
    switch (type)
      {
      case MG_COMPLETE_DICTIONARY:
	{
	  mem_reqd += Write_data (f, &keep[i], lookback);
	}
	break;
      case MG_PARTIAL_DICTIONARY:
	{
	  if (keep[i].num_wds)
	    {
	      int j;
	      WordData esc;
	      esc.freq = 0;
	      esc.word = (u_char *) "";
	      keep[i].wd[keep[i].num_wds++] = &esc;
	      for (j = 0; j < discard[i].num_wds; j++)
		esc.freq += discard[i].wd[j]->freq;
	      if (!esc.freq)
		esc.freq++;
	      mem_reqd += Write_data (f, &keep[i], lookback);
	    }
	  Write_charfreqs (f, &discard[i], i, 1);
	  Write_wordlens (f, &discard[i], 1);
	}
	break;
      case MG_SEED_DICTIONARY:
	{
	  if (keep[i].num_wds)
	    {
	      int j;
	      WordData esc;
	      esc.freq = 0;
	      esc.word = (u_char *) "";
	      keep[i].wd[keep[i].num_wds++] = &esc;
	      for (j = 0; j < all[i].num_wds; j++)
		if (all[i].wd[j]->freq == 1)
		  esc.freq++;
	      if (!esc.freq)
		esc.freq++;
	      mem_reqd += Write_data (f, &keep[i], lookback);
	    }
	  switch (novel_method)
	    {
	    case MG_NOVEL_HUFFMAN_CHARS:
	      Write_charfreqs (f, &all[i], i, 0);
	      Write_wordlens (f, &all[i], 0);
	      break;
	    case MG_NOVEL_BINARY:
	      break;
	    case MG_NOVEL_DELTA:
	      break;
	    case MG_NOVEL_HYBRID:
	      break;
	    case MG_NOVEL_HYBRID_MTF:
	      break;
	    default:
	      FatalError (1, "Bad novel method");
	    }
	}
	break;
      }
  fclose (f);
  return mem_reqd;
}
int main(int argc, char** argv)
{
 int node_count, i;
 int element_count;
 int force_count;
 int constraint_count;
 int material_count;
 long location;
 unsigned minkey[2]={0, 0};
 unsigned maxkey[2]={0, 0};
 int p;

 if(argc != 2) {
   p = 1;
   cout<<"Need to input the number of processors as a command line argument if you want more than 1 processor!"<<endl<<flush;
 }

 Read_no_of_objects(&node_count, &element_count, &force_count, 
		    &constraint_count, &material_count, &location);

 Node* node=new Node[node_count];
 Element* element=new Element[element_count];
 Boundary* boundary=new Boundary[force_count+constraint_count];
 Element** ordering=new Element*[element_count];
 double* lambda = new double[material_count];
 double* mu = new double[material_count];

 Read_node_data(&node_count, node, &location);
 Read_element_data(&element_count, node, element, &location);
 Read_boundary_data(&force_count, &constraint_count, node, boundary, &location);
 Read_material_data(material_count, lambda, mu, &location);

 /* for(int i=0; i<element_count; i++)
    element[i].case5();*/

 double max[2]={0, 0};
 double min[2]={0, 0};

 element[0].create_m_node(max, min);

 min[0]=max[0]=*((*(element[0].get_element_node()))->get_node_coord());
 min[1]=max[1]=*((*(element[0].get_element_node()))->get_node_coord()+1);

 for(i=0; i<element_count; i++)
   element[i].create_m_node(max, min);

 unsigned nkey=2;

 for(i=0; i<element_count; i++)
   element[i].find_boundary(constraint_count, force_count, boundary);

 Determine_neighbors(element_count, element, node_count, node);

 for(i=0; i<node_count; i++)
   node[i].determine_max_min(max, min);

 node[0].determine_the_key(nkey, max, min, maxkey, minkey);
 for(i=0; i<2; i++)
   maxkey[i]=minkey[i]=*(node[0].get_key()+i);

 for(i=1; i<node_count; i++)
   node[i].determine_the_key(nkey, max, min, maxkey, minkey);

 for(i=0; i<element_count; i++)
   (*(element[i].get_element_node()+8))->determine_the_key(nkey, max, min, maxkey, minkey);

 for(i=0;i<element_count;i++)
   ordering[i] = &(element[i]);

 // before doing qsort, switch the first element with the middle element
 Element* EmTemp = ordering[0];
 ordering[0] = ordering[element_count/2];
 ordering[element_count/2] = EmTemp;

 qsort(ordering, element_count, sizeof(Element*), compare_key_fn);
 
/* cout<<"Number of processors: ";
 cin>>p;
 while(p <=0)
   {
     cout<<"Number of processors must be greater than 0\n";
     cout<<"Number of processors: ";
     cin>>p;
   } */
 if(argc == 2)
   p = atoi(argv[1]); // the number of processors -- this parameter is passed in
 
 for(i=0; i<element_count; i++)
  ( ordering[i])->myproc(p, i, element_count);
 
 Write_data(p, node_count, element_count, (force_count+constraint_count), material_count, 
	    node, ordering, boundary, maxkey, minkey, min, max, lambda, mu);
 

 delete []lambda;
 delete []mu;
 delete []node;
 delete []element;
 delete []boundary;
 delete []ordering;
 return(0);
 
}