Ejemplo n.º 1
0
void WinHugsStatistics(int Reductions, int Cells, int Gcs)
{
    if (DefaultMessage != NULL)
	free(DefaultMessage);

    if (Reductions == -1) {
	DefaultMessage = NULL;
	TickCount = GetTickCount();
    } else {
	DWORD Time = GetTickCount() - TickCount;

	DefaultMessage = malloc(150);
	wsprintf(DefaultMessage, "Computation finished: %d.%.2d seconds, ",
	    Time / 1000, (Time / 10) % 100);
	AddStat("reduction",Reductions);
	strcat(DefaultMessage, ", ");
	AddStat("cell",Cells);
	if (Gcs > 0) {
	    strcat(DefaultMessage, ", ");
	    AddStat("garbage collection",Gcs);
	}
    }

    SetStatusBar(NULL);
}
Ejemplo n.º 2
0
	//pTypeName: 统计名称
	//iNameID:对应的业务分类
	//szRecordAtMax: 最多延时产生时记录的数据<64bytes
	//iStatCount统计个数
	//iSumVal 累加的值,记录流量等
	int AddStat(const char* szTypeName,
				int iResultID=0, 
				struct timeval *pstBegin=NULL, 
				struct timeval *pstEnd=NULL,
				char* szRecordAtMax=NULL,
				int iSumVal=0,
				unsigned int unStatCount=1, const TypeInfo* pTypeInfoIncr = NULL)
	{return AddStat(szTypeName,-1,iResultID,pstBegin,pstEnd,szRecordAtMax,
				(unsigned long long)iSumVal,(unsigned long long)unStatCount,pTypeInfoIncr);}
namespace MaterialMeshCookStats
{
	static int32 ShadersCompiled = 0;
	static FCookStatsManager::FAutoRegisterCallback RegisterCookStats([](FCookStatsManager::AddStatFuncRef AddStat)
	{
		AddStat(TEXT("MeshMaterial.Misc"), FCookStatsManager::CreateKeyValueArray(
			TEXT("ShadersCompiled"), ShadersCompiled
			));
	});
}
Ejemplo n.º 4
0
stat_record_t process_data(char *wfile, int element_stat, int flow_stat, int sort_flows,
	printer_t print_header, printer_t print_record, time_t twin_start, time_t twin_end, 
	uint64_t limitflows, int tag, int compress, int do_xstat) {
common_record_t 	*flow_record;
master_record_t		*master_record;
nffile_t			*nffile_w, *nffile_r;
xstat_t				*xstat;
stat_record_t 		stat_record;
int 				done, write_file;

#ifdef COMPAT15
int	v1_map_done = 0;
#endif
	
	// time window of all matched flows
	memset((void *)&stat_record, 0, sizeof(stat_record_t));
	stat_record.first_seen = 0x7fffffff;
	stat_record.msec_first = 999;

	// Do the logic first

	// do not print flows when doing any stats are sorting
	if ( sort_flows || flow_stat || element_stat ) {
		print_record = NULL;
	}

	// do not write flows to file, when doing any stats
	// -w may apply for flow_stats later
	write_file = !(sort_flows || flow_stat || element_stat) && wfile;
	nffile_r = NULL;
	nffile_w = NULL;
	xstat  	 = NULL;

	// Get the first file handle
	nffile_r = GetNextFile(NULL, twin_start, twin_end);
	if ( !nffile_r ) {
		LogError("GetNextFile() error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) );
		return stat_record;
	}
	if ( nffile_r == EMPTY_LIST ) {
		LogError("Empty file list. No files to process\n");
		return stat_record;
	}

	// preset time window of all processed flows to the stat record in first flow file
	t_first_flow = nffile_r->stat_record->first_seen;
	t_last_flow  = nffile_r->stat_record->last_seen;

	// store infos away for later use
	// although multiple files may be processed, it is assumed that all 
	// have the same settings
	is_anonymized = IP_ANONYMIZED(nffile_r);
	strncpy(Ident, nffile_r->file_header->ident, IDENTLEN);
	Ident[IDENTLEN-1] = '\0';

	// prepare output file if requested
	if ( write_file ) {
		nffile_w = OpenNewFile(wfile, NULL, compress, IP_ANONYMIZED(nffile_r), NULL );
		if ( !nffile_w ) {
			if ( nffile_r ) {
				CloseFile(nffile_r);
				DisposeFile(nffile_r);
			}
			return stat_record;
		}
		if ( do_xstat ) {
			xstat = InitXStat(nffile_w);
			if ( !xstat ) {
				if ( nffile_r ) {
					CloseFile(nffile_r);
					DisposeFile(nffile_r);
				}
				return stat_record;
			}
		}
	}

	// setup Filter Engine to point to master_record, as any record read from file
	// is expanded into this record
	// Engine->nfrecord = (uint64_t *)master_record;

	done = 0;
	while ( !done ) {
	int i, ret;

		// get next data block from file
		ret = ReadBlock(nffile_r);

		switch (ret) {
			case NF_CORRUPT:
			case NF_ERROR:
				if ( ret == NF_CORRUPT ) 
					LogError("Skip corrupt data file '%s'\n",GetCurrentFilename());
				else 
					LogError("Read error in file '%s': %s\n",GetCurrentFilename(), strerror(errno) );
				// fall through - get next file in chain
			case NF_EOF: {
				nffile_t *next = GetNextFile(nffile_r, twin_start, twin_end);
				if ( next == EMPTY_LIST ) {
					done = 1;
				} else if ( next == NULL ) {
					done = 1;
					LogError("Unexpected end of file list\n");
				} else {
					// Update global time span window
					if ( next->stat_record->first_seen < t_first_flow )
						t_first_flow = next->stat_record->first_seen;
					if ( next->stat_record->last_seen > t_last_flow ) 
						t_last_flow = next->stat_record->last_seen;
					// continue with next file
				}
				continue;

				} break; // not really needed
			default:
				// successfully read block
				total_bytes += ret;
		}


#ifdef COMPAT15
		if ( nffile_r->block_header->id == DATA_BLOCK_TYPE_1 ) {
			common_record_v1_t *v1_record = (common_record_v1_t *)nffile_r->buff_ptr;
			// create an extension map for v1 blocks
			if ( v1_map_done == 0 ) {
				extension_map_t *map = malloc(sizeof(extension_map_t) + 2 * sizeof(uint16_t) );
				if ( ! map ) {
					LogError("malloc() allocation error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) );
					exit(255);
				}
				map->type 	= ExtensionMapType;
				map->size 	= sizeof(extension_map_t) + 2 * sizeof(uint16_t);
				if (( map->size & 0x3 ) != 0 ) {
					map->size += 4 - ( map->size & 0x3 );
				}

				map->map_id = INIT_ID;

				map->ex_id[0]  = EX_IO_SNMP_2;
				map->ex_id[1]  = EX_AS_2;
				map->ex_id[2]  = 0;
				
				map->extension_size  = 0;
				map->extension_size += extension_descriptor[EX_IO_SNMP_2].size;
				map->extension_size += extension_descriptor[EX_AS_2].size;

				if ( Insert_Extension_Map(extension_map_list,map) && write_file ) {
					// flush new map
					AppendToBuffer(nffile_w, (void *)map, map->size);
				} // else map already known and flushed

				v1_map_done = 1;
			}

			// convert the records to v2
			for ( i=0; i < nffile_r->block_header->NumRecords; i++ ) {
				common_record_t *v2_record = (common_record_t *)v1_record;
				Convert_v1_to_v2((void *)v1_record);
				// now we have a v2 record -> use size of v2_record->size
				v1_record = (common_record_v1_t *)((pointer_addr_t)v1_record + v2_record->size);
			}
			nffile_r->block_header->id = DATA_BLOCK_TYPE_2;
		}
#endif

		if ( nffile_r->block_header->id == Large_BLOCK_Type ) {
			// skip
			printf("Xstat block skipped ...\n");
			continue;
		}

		if ( nffile_r->block_header->id != DATA_BLOCK_TYPE_2 ) {
			if ( nffile_r->block_header->id == DATA_BLOCK_TYPE_1 ) {
				LogError("Can't process nfdump 1.5.x block type 1. Add --enable-compat15 to compile compatibility code. Skip block.\n");
			} else {
				LogError("Can't process block type %u. Skip block.\n", nffile_r->block_header->id);
			}
			skipped_blocks++;
			continue;
		}

		flow_record = nffile_r->buff_ptr;
		for ( i=0; i < nffile_r->block_header->NumRecords; i++ ) {

			switch ( flow_record->type ) {
				case CommonRecordV0Type:
				case CommonRecordType:  {
					int match;
					uint32_t map_id = flow_record->ext_map;
					generic_exporter_t *exp_info = exporter_list[flow_record->exporter_sysid];
					if ( map_id >= MAX_EXTENSION_MAPS ) {
						LogError("Corrupt data file. Extension map id %u too big.\n", flow_record->ext_map);
						exit(255);
					}
					if ( extension_map_list->slot[map_id] == NULL ) {
						LogError("Corrupt data file. Missing extension map %u. Skip record.\n", flow_record->ext_map);
						flow_record = (common_record_t *)((pointer_addr_t)flow_record + flow_record->size);	
						continue;
					} 

					total_flows++;
					master_record = &(extension_map_list->slot[map_id]->master_record);
					Engine->nfrecord = (uint64_t *)master_record;
					ExpandRecord_v2( flow_record, extension_map_list->slot[map_id], 
						exp_info ? &(exp_info->info) : NULL, master_record);

					// Time based filter
					// if no time filter is given, the result is always true
					match  = twin_start && (master_record->first < twin_start || master_record->last > twin_end) ? 0 : 1;
					match &= limitflows ? stat_record.numflows < limitflows : 1;

					// filter netflow record with user supplied filter
					if ( match ) 
						match = (*Engine->FilterEngine)(Engine);
	
					if ( match == 0 ) { // record failed to pass all filters
						// increment pointer by number of bytes for netflow record
						flow_record = (common_record_t *)((pointer_addr_t)flow_record + flow_record->size);	
						// go to next record
						continue;
					}

					// Records passed filter -> continue record processing
					// Update statistics
					UpdateStat(&stat_record, master_record);

					// update number of flows matching a given map
					extension_map_list->slot[map_id]->ref_count++;
	
					if ( flow_stat ) {
						AddFlow(flow_record, master_record, extension_map_list->slot[map_id]);
						if ( element_stat ) {
							AddStat(flow_record, master_record);
						} 
					} else if ( element_stat ) {
						AddStat(flow_record, master_record);
					} else if ( sort_flows ) {
						InsertFlow(flow_record, master_record, extension_map_list->slot[map_id]);
					} else {
						if ( write_file ) {
							AppendToBuffer(nffile_w, (void *)flow_record, flow_record->size);
							if ( xstat ) 
								UpdateXStat(xstat, master_record);
						} else if ( print_record ) {
							char *string;
							// if we need to print out this record
							print_record(master_record, &string, tag);
							if ( string ) {
								if ( limitflows ) {
									if ( (stat_record.numflows <= limitflows) )
										printf("%s\n", string);
								} else 
									printf("%s\n", string);
							}
						} else { 
							// mutually exclusive conditions should prevent executing this code
							// this is buggy!
							printf("Bug! - this code should never get executed in file %s line %d\n", __FILE__, __LINE__);
						}
					} // sort_flows - else
					} break; 
				case ExtensionMapType: {
					extension_map_t *map = (extension_map_t *)flow_record;
	
					if ( Insert_Extension_Map(extension_map_list, map) && write_file ) {
						// flush new map
						AppendToBuffer(nffile_w, (void *)map, map->size);
					} // else map already known and flushed
					} break;
				case ExporterRecordType:
				case SamplerRecordype:
						// Silently skip exporter records
					break;
				case ExporterInfoRecordType: {
					int ret = AddExporterInfo((exporter_info_record_t *)flow_record);
					if ( ret != 0 ) {
						if ( write_file && ret == 1 ) 
							AppendToBuffer(nffile_w, (void *)flow_record, flow_record->size);
					} else {
						LogError("Failed to add Exporter Record\n");
					}
					} break;
				case ExporterStatRecordType:
					AddExporterStat((exporter_stats_record_t *)flow_record);
					break;
				case SamplerInfoRecordype: {
					int ret = AddSamplerInfo((sampler_info_record_t *)flow_record);
					if ( ret != 0 ) {
						if ( write_file && ret == 1 ) 
							AppendToBuffer(nffile_w, (void *)flow_record, flow_record->size);
					} else {
						LogError("Failed to add Sampler Record\n");
					}
					} break;
				default: {
					LogError("Skip unknown record type %i\n", flow_record->type);
				}
			}

		// Advance pointer by number of bytes for netflow record
		flow_record = (common_record_t *)((pointer_addr_t)flow_record + flow_record->size);	


		} // for all records

		// check if we are done, due to -c option 
		if ( limitflows ) 
			done = stat_record.numflows >= limitflows;

	} // while

	CloseFile(nffile_r);

	// flush output file
	if ( write_file ) {
		// flush current buffer to disc
		if ( nffile_w->block_header->NumRecords ) {
			if ( WriteBlock(nffile_w) <= 0 ) {
				LogError("Failed to write output buffer to disk: '%s'" , strerror(errno));
			} 
		}

		if ( xstat ) {
			if ( WriteExtraBlock(nffile_w, xstat->block_header ) <= 0 ) {
				LogError("Failed to write xstat buffer to disk: '%s'" , strerror(errno));
			} 
		}

		/* Stat info */
		if ( write_file ) {
			/* Copy stat info and close file */
			memcpy((void *)nffile_w->stat_record, (void *)&stat_record, sizeof(stat_record_t));
			CloseUpdateFile(nffile_w, nffile_r->file_header->ident );
			nffile_w = DisposeFile(nffile_w);
		} // else stdout
	}	 

	PackExtensionMapList(extension_map_list);

	DisposeFile(nffile_r);
	return stat_record;

} // End of process_data
Ejemplo n.º 5
0
Archivo: client.c Proyecto: spchamp/ilu
int
main(int ac, char **av)
{
  char            hostname[1000], sid[1000];
  timeit_p        handle;
  ilu_CString     retstr;
  ilu_CString	  teststring = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  double          tfactor;
  timeit_recseq	  rs;
  CORBA_unsigned_long    i, outerCount = 10, k, innerCount = 10, j, recseqlen = 1000;
  CORBA_unsigned_long    pagecount = 50, pagesize = 5000;
  timeit_pageSeq *doc;
  ILU_C_ENVIRONMENT e;
  struct tms      beginning, ending;
  struct timeval  timebegin, timeend;
  StatSums        tsums = {0}, usums = {0}, ssums = {0};
  timeit_img20x20x20	val;
  ilu_boolean mt = ilu_FALSE;
  enum tests { no_Test, cardinal_Test, real_Test, string_Test, doc_Test, image_Test, record_Test };
  enum tests testtype = no_Test;

  progname = av[0];
  gethostname(hostname, sizeof(hostname));
  for (i = 1;  i < ac;  i++) {
    if (strcmp(av[i], "-test") == 0) {
      if (++i < ac) {
	if ((strcmp(av[i], "cardinal") == 0) || (strcmp(av[i], "ping1") == 0))
	  testtype = cardinal_Test;
	else if ((strcmp(av[i], "real") == 0) || (strcmp(av[i], "ping2") == 0))
	  testtype = real_Test;
	else if ((strcmp(av[i], "string") == 0) || (strcmp(av[i], "ping3") == 0))
	  testtype = string_Test;
	else if (strcmp(av[i], "doctest") == 0)
	  testtype = doc_Test;
	else if (strcmp(av[i], "imgtest") == 0)
	  testtype = image_Test;
	else if (strcmp(av[i], "rectest") == 0)
	  testtype = record_Test;
	else
	  Usage();
      } else {
	Usage();
      }
    } else if (strcmp(av[i], "-mt") == 0) {
      mt = ilu_TRUE;
    } else if (strcmp(av[i], "-st") == 0) {
      mt = ilu_FALSE;
    } else if (strcmp(av[i], "-hostname") == 0) {
      if (++i < ac) {
	strcpy (hostname, av[i]);
      } else {
	Usage();
      }
    } else if (strcmp(av[i], "-string") == 0) {
      if (++i < ac) {
	teststring = av[i];
      } else {
	Usage();
      }
    } else if (strcmp(av[i], "-innercount") == 0) {
      if ((++i < ac) && ((innerCount = atoi(av[i])) > 0))
	continue;
      else
	Usage();
    } else if (strcmp(av[i], "-outercount") == 0) {
      if ((++i < ac) && ((outerCount = atoi(av[i])) > 0))
	continue;
      else
	Usage();
    } else if (strcmp(av[i], "-pagecount") == 0) {
      if ((++i < ac) && ((pagecount = atoi(av[i])) > 0))
	continue;
      else
	Usage();
    } else if (strcmp(av[i], "-pagesize") == 0) {
      if ((++i < ac) && ((pagecount = atoi(av[i])) > 0))
	continue;
      else
	Usage();
    } else if (strcmp(av[i], "-recseqlen") == 0) {
      if ((++i < ac) && ((recseqlen = atoi(av[i])) > 0))
	continue;
      else
	Usage();
    } else {
      Usage();
    }
  };
  if (testtype == no_Test)
    Usage();

  if (mt) {
#if (defined(ILU_OS_THREADED))
    ILU_C_USE_OS_THREADS;
#else
    fprintf (stderr, "OS-supplied thread support not configured into ILU!\n");
    exit(-1);
#endif				/* (defined(ILU_OS_THREADED)) */
  }

  timeit__Initialize();
  sprintf(sid, "TimingTest.%s.%s", hostname, ILU_TEST_DOMAIN);
  handle = ILU_C_LookupObject(sid, "0", timeit_p__MSType);
  if (handle == NULL) {
    fprintf(stderr, "error:  Can't obtain object <%s>\n", sid);
    exit(1);
  }
  tfactor = 1000.0 / (innerCount * 60.0);
  if (testtype == image_Test) {
    pagecount = 1;
    for (i = 0;  i < 20;  i++)
      for (j = 0;  j < 20;  j++)
	for (k = 0;  k < 20;  k++)
	  val[i][j][k] = (CORBA_double) (pagecount++);
  };
  if (testtype == record_Test) {
    timeit_recseq_Init(&rs, recseqlen, NULL);
    rs._length = recseqlen;
  }
    
#ifdef ILU_C_TIMING_STATISTICS
  /* clear stats counter, and enable statistics gathering */
  ILU_C_SetCallStats (ilu_TRUE, ilu_TRUE);
#endif /* def ILU_C_TIMING_STATISTICS */
  
  switch (testtype) {
  case cardinal_Test:

    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      for (k = 0; k < innerCount; k++) {
	j = timeit_p_ping1(handle, i, &e);
	if (e.returnCode != NULL) {
	  fprintf(stderr, "Failure <%s> in call (%lu,%lu) to ping1\n",
		  e.returnCode, i, k);
	  exit(2);
	}
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  case real_Test:

    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      for (k = 0; k < innerCount; k++) {
	CORBA_double          x = i, y;
	y = timeit_p_ping2(handle, x, &e);
	if (e.returnCode != NULL) {
	  fprintf(stderr, "Failure <%s> in call (%lu,%lu) to ping2\n",
		  e.returnCode, i, k);
	  exit(2);
	}
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  case string_Test:

    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      for (k = 0; k < innerCount; k++) {
	retstr = timeit_p_ping3(handle, teststring, &e);
	if (e.returnCode != NULL) {
	  fprintf(stderr, "Failure <%s> in call (%lu,%lu) to ping3\n",
		  e.returnCode, i, k);
	  exit(2);
	}
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  case doc_Test:

    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      doc = timeit_p_doctest(handle,
			     "some document, possibly with search criteria",
			     pagecount, pagesize, &e);
      if (e.returnCode != NULL) {
	fprintf(stderr, "Failure <%s> in call %lu to doctest\n",
		e.returnCode, i);
	exit(2);
      } else {
	timeit_pageSeq__Free(doc);
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  case image_Test:

    val[0][0][0] = 1.1;
    val[0][0][1] = 2.2;
    val[0][0][2] = 3.3;
    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      for (k = 0; k < innerCount; k++) {
	timeit_p_imgtest(handle, val, &e);
	if (e.returnCode != NULL) {
	  fprintf(stderr, "Failure <%s> in call (%lu,%lu) to imgtest\n",
		  e.returnCode, i, k);
	  exit(2);
	}
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  case record_Test:

    if (recseqlen > 0) {
      strcpy(rs._buffer[0].name, "Initial");
      rs._buffer[0].dirty = ilu_TRUE;
      rs._buffer[0].create_time = 1;
      if (recseqlen > 1) {
	strcpy(rs._buffer[recseqlen-1].name, "Last");
	rs._buffer[recseqlen-1].dirty = ilu_FALSE;
	rs._buffer[recseqlen-1].create_time = recseqlen;
      }
    }
    for (i = 0; i < outerCount; i++) {
      gettimeofday(&timebegin, NULL);
      times(&beginning);
      for (k = 0; k < innerCount; k++) {
	timeit_p_rectest(handle, &rs, &e);
	if (e.returnCode != NULL) {
	  fprintf(stderr, "Failure <%s> in call (%lu,%lu) to rectest\n",
		  e.returnCode, i, k);
	  exit(2);
	}
      }
      times(&ending);
      gettimeofday(&timeend, NULL);
      AddStat(&tsums,
	      (((timeend.tv_sec * 1.0E6 + timeend.tv_usec)
		- (timebegin.tv_sec * 1.0E6 + timebegin.tv_usec))
	       / (innerCount * 1000.0)));
      AddStat(&usums,
	      (ending.tms_utime - beginning.tms_utime) * tfactor);
      AddStat(&ssums,
	      (ending.tms_stime - beginning.tms_stime) * tfactor);
    }
    break;

  }

  switch (testtype) {
  case cardinal_Test:
  case real_Test:
  case string_Test:
  case image_Test:
    printf("test \"%s\", outerCount %lu, innerCount %lu:\n",
	   tests[testtype - 1], outerCount, innerCount);
    break;
  case doc_Test:
    printf("test \"%s\", outerCount %lu, innerCount %lu, pagesize %lu, pagecount %lu:\n",
	   tests[testtype - 1], outerCount, innerCount, pagesize, pagecount);
    break;
  case record_Test:
    printf("test \"%s\", outerCount %lu, innerCount %lu, recseqlen %lu:\n",
	   tests[testtype - 1], outerCount, innerCount, recseqlen);
    break;
  default:
    break;
  }
  printf("   category:    min /    avg +-  stdev /    max milliseconds/call\n");
  printf(" total time: %s\n", FmtStats(&tsums));
  printf("  user time: %s\n", FmtStats(&usums));
  printf("system time: %s\n", FmtStats(&ssums));

#if defined(ILU_C_TIMING_STATISTICS)
  {
    ILU_C_CallStats total, latency;
    ilu_cardinal nsync, nasync;
    char buf[FMTSTATSBUFSIZE];
    ILU_C_GetCallStats (&nsync, &nasync, &total, &latency);
    printf("Timing stats using getrusage() (ms/call, %lu synch, %lu asynch):\n",
	   (unsigned long) nsync, (unsigned long) nasync);
    printf("                     min /        avg +-      stdev /        max\n");
    FmtStats2 (buf, &total.total, total.ncalls);
    printf(" total time:  %s\n", buf);
    FmtStats2 (buf, &total.user, total.ncalls);
    printf("  user time:  %s\n", buf);
    FmtStats2 (buf, &total.system, total.ncalls);
    printf("system time:  %s\n", buf);
    FmtStats2 (buf, &latency.total, latency.ncalls);
    printf("    latency:  %s\n", buf);
  }
#endif /* defined(ILU_C_TIMING_STATISTICS) */

  return 0;
}
Ejemplo n.º 6
0
void CalculateEntropies()
{
  long nx, ny, nz, part, i, j, k, idx, ptr;
  double xmin, xmax, ymin, ymax, zmin, zmax, x, y, z, wgt, totw, totp;
  double *spt, *swg, entrp, entrw, sump, sumw;

  /* Check if entropies are calculated */

  if ((long)RDB[DATA_OPTI_ENTROPY_CALC] == NO)
    return;
  
  /* Get mesh size */

  nx = (long)RDB[DATA_ENTROPY_NX];
  ny = (long)RDB[DATA_ENTROPY_NY];
  nz = (long)RDB[DATA_ENTROPY_NZ];

  /* Check values */

  CheckValue(FUNCTION_NAME, "nx", "", nx, 1, 500);
  CheckValue(FUNCTION_NAME, "ny", "", ny, 1, 500);
  CheckValue(FUNCTION_NAME, "nz", "", nz, 1, 500);

  /* Get boundaries */

  xmin = RDB[DATA_ENTROPY_XMIN];
  xmax = RDB[DATA_ENTROPY_XMAX];
  ymin = RDB[DATA_ENTROPY_YMIN];
  ymax = RDB[DATA_ENTROPY_YMAX];
  zmin = RDB[DATA_ENTROPY_ZMIN];
  zmax = RDB[DATA_ENTROPY_ZMAX];

  /* Check values */

  CheckValue(FUNCTION_NAME, "xmin", "", xmin, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "xmax", "", xmax, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "ymin", "", ymin, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "ymax", "", ymax, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "zmin", "", zmin, -INFTY, INFTY);
  CheckValue(FUNCTION_NAME, "zmax", "", zmax, -INFTY, INFTY);

  /* Check order */

  if (xmin > xmax)
    Die(FUNCTION_NAME, "Error in boundaries");

  if (ymin > ymax)
    Die(FUNCTION_NAME, "Error in boundaries");

  if (zmin > zmax)
    Die(FUNCTION_NAME, "Error in boundaries");

  /* Allocate memory for temporary arrays  */

  spt = (double *)Mem(MEM_ALLOC, nx*ny*nz, sizeof(double));
  swg = (double *)Mem(MEM_ALLOC, nx*ny*nz, sizeof(double));

  /* Reset data */

  memset(spt, 0.0, nx*ny*nz*sizeof(double));
  memset(swg, 0.0, nx*ny*nz*sizeof(double));
  
  /* Reset totals */

  totw = 0.0;
  totp = 0.0;

  /* Pointer to first item after dummy */

  part = (long)RDB[DATA_PART_PTR_SOURCE];
  part = NextItem(part);

  /* Loop over source and collect points */

  while(part > VALID_PTR)
    {
      /* Get coordinates and weight */

      x = RDB[part + PARTICLE_X];
      y = RDB[part + PARTICLE_Y];
      z = RDB[part + PARTICLE_Z];

      wgt = RDB[part + PARTICLE_WGT];

      /* Get local normalised co-ordinates */
      
      if (xmin != xmax)
	x = (x - xmin)/(xmax - xmin);
      else
	x = 0.0;
      
      if (ymin != ymax)
	y = (y - ymin)/(ymax - ymin);
      else
	y = 0.0;

      if (zmin != zmax)
	z = (z - zmin)/(zmax - zmin);
      else
	z = 0.0;

      /* Check */

      if ((x >= 0.0) && (x < 1.0) && (y >= 0.0) && (y < 1.0) &&
	  (z >= 0.0) && (z < 1.0))
	{
	  /* Calculate indexes */
      
	  i = (long)(x*nx);
	  j = (long)(y*ny);
	  k = (long)(z*nz);

	  /* Calculate index */

	  idx = i + nx*j + nx*ny*k;

	  /* Add points and weight */

	  spt[idx] = spt[idx] + 1.0;
	  swg[idx] = swg[idx] + wgt;
	  
	  /* Add to totals */

	  totp = totp + 1.0;
	  totw = totw + wgt;
	}

      /* Next particle */

      part = NextItem(part);
    }

  /* X-component of entropy */
  
  entrp = 0.0;
  entrw = 0.0;

  for (i = 0; i < nx; i++)
    {
      /* Sum over values */
      
      sump = 0.0;
      sumw = 0.0;
      
      for (j = 0; j < ny; j++)
	for (k = 0; k < nz; k++)
	  {
	    /* Calculate index */
	    
	    idx = i + nx*j + nx*ny*k;
	  
	    /* Add to sums */

	    sump = sump + spt[idx]/totp;
	    sumw = sumw + swg[idx]/totw;
	  }

      /* Add to entropies */

      if ((sump > 0.0) && (sump < 1.0))
	entrp = entrp - sump*log2(sump);

      if ((sumw > 0.0) && (sumw < 1.0))
	entrw = entrw - sumw*log2(sumw);
    }
  
  /* Divide by uniform source entropy */
  
  if (nx > 1)
    {
      entrp = entrp/log2(nx);
      entrw = entrw/log2(nx);
    }

  /* Add to statistics */

  ptr = (long)RDB[DATA_ENTROPY_PTR_SPT_STAT];  
  AddStat(entrp, ptr, 1);

  ptr = (long)RDB[DATA_ENTROPY_PTR_SWG_STAT];  
  AddStat(entrw, ptr, 1);

  /* Y-component of entropy */
  
  entrp = 0.0;
  entrw = 0.0;

  for (j = 0; j < ny; j++)
    {
      /* Sum over values */
      
      sump = 0.0;
      sumw = 0.0;

      for (i = 0; i < nx; i++)
	for (k = 0; k < nz; k++)
	  {
	    /* Calculate index */
	    
	    idx = i + nx*j + nx*ny*k;
	  
	    /* Add to sums */

	    sump = sump + spt[idx]/totp;
	    sumw = sumw + swg[idx]/totw;
	  }

      /* Add to entropies */

      if ((sump > 0.0) && (sump < 1.0))
	entrp = entrp - sump*log2(sump);

      if ((sumw > 0.0) && (sumw < 1.0))
	entrw = entrw - sumw*log2(sumw);
    }
  
  /* Divide by uniform source entropy */
  
  if (ny > 1)
    {
      entrp = entrp/log2(ny);
      entrw = entrw/log2(ny);
    }

  /* Add to statistics */

  ptr = (long)RDB[DATA_ENTROPY_PTR_SPT_STAT];  
  AddStat(entrp, ptr, 2);

  ptr = (long)RDB[DATA_ENTROPY_PTR_SWG_STAT];  
  AddStat(entrw, ptr, 2);

  /* Z-component of entropy */
  
  entrp = 0.0;
  entrw = 0.0;

  for (k = 0; k < nz; k++)
    {
      /* Sum over values */
      
      sump = 0.0;
      sumw = 0.0;

      for (i = 0; i < nx; i++)
	for (j = 0; j < ny; j++)
	  {
	    /* Calculate index */
	    
	    idx = i + nx*j + nx*ny*k;
	  
	    /* Add to sums */

	    sump = sump + spt[idx]/totp;
	    sumw = sumw + swg[idx]/totw;
	  }

      /* Add to entropies */

      if ((sump > 0.0) && (sump < 1.0))
	entrp = entrp - sump*log2(sump);

      if ((sumw > 0.0) && (sumw < 1.0))
	entrw = entrw - sumw*log2(sumw);
    }
  
  /* Divide by uniform source entropy */
  
  if (nz > 1)
    {
      entrp = entrp/log2(nz);
      entrw = entrw/log2(nz);
    }

  /* Add to statistics */

  ptr = (long)RDB[DATA_ENTROPY_PTR_SPT_STAT];  
  AddStat(entrp, ptr, 3);

  ptr = (long)RDB[DATA_ENTROPY_PTR_SWG_STAT];  
  AddStat(entrw, ptr, 3);

  /* Total entropy */
  
  entrp = 0.0;
  entrw = 0.0;

  /* Loop over values */
      
  for (i = 0; i < nx; i++)
    for (j = 0; j < ny; j++)
      for (k = 0; k < nz; k++)
	{
	  /* Calculate index */
	  
	  idx = i + nx*j + nx*ny*k;
	  
	  /* Get value */

	    sump = spt[idx]/totp;
	    sumw = swg[idx]/totw;
	    
	    /* Add to entropies */

	    if ((sump > 0.0) && (sump < 1.0))
	      entrp = entrp - sump*log2(sump);
	    
	    if ((sumw > 0.0) && (sumw < 1.0))
	      entrw = entrw - sumw*log2(sumw);
	}
  
  /* Divide by uniform source entropy */
  
  if (nx*ny*nz > 1)
    {
      entrp = entrp/log2(nx*ny*nz);
      entrw = entrw/log2(nx*ny*nz);
    }

  /* Add to statistics */

  ptr = (long)RDB[DATA_ENTROPY_PTR_SPT_STAT];  
  AddStat(entrp, ptr, 0);

  ptr = (long)RDB[DATA_ENTROPY_PTR_SWG_STAT];  
  AddStat(entrw, ptr, 0);

  /* Free temporary arrays */

  Mem(MEM_FREE, spt);
  Mem(MEM_FREE, swg);
}
Ejemplo n.º 7
0
void IterateKeff()
{
  long ptr, mode, skip, ncyc, idx, fix;
  double nsf, fiss, capt, nuxn, leak, L0, L1, val, f, keff, val0;
  
  /* Check mode */

  if ((mode = (long)RDB[DATA_ITER_MODE]) == ITER_MODE_NONE)
    return;

  /* Get fix mode */

  fix = (long)RDB[DATA_ITER_FIX];

  /* Number of cycles and actual number of skip cycles (setoptimization.c) */

  ncyc = (long)RDB[DATA_ITER_NCYC];
  idx = (long)RDB[DATA_CYCLE_IDX];

  if (fix == YES)
    skip = (long)((RDB[DATA_CRIT_SKIP] - RDB[DATA_ITER_NCYC])/2.0);
  else
    skip = (long)(RDB[DATA_CRIT_SKIP] - RDB[DATA_ITER_NCYC]);

  /* Check cycles */

  if ((idx < skip) || ((fix == YES) && (idx > skip + ncyc)))
    return;

  /* Reduce scoring buffer */

  ReduceBuffer();

  /* Collect MPI parallel data */

  CollectBuf();

  /* Check mode */

  if (mode == ITER_MODE_ALBEDO)
    {
      /***********************************************************************/

      /***** Albedo iteration ************************************************/

      /* Get k-eff */

      keff = RDB[DATA_ITER_KEFF];
      CheckValue(FUNCTION_NAME, "keff", "", keff, 0.1, 2.5);

      /* Fission nubar */
      
      ptr = (long)RDB[RES_TOT_NSF];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      nsf = BufVal(ptr, 0);
      
      /* Fission term */
      
      ptr = (long)RDB[RES_TOT_FISSRATE];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      fiss = BufVal(ptr, 0);
      
      /* Total capture rate */
      
      ptr = (long)RDB[RES_TOT_CAPTRATE];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      capt = BufVal(ptr, 0);
      
      /* Scattering production rate */
      
      ptr = (long)RDB[RES_TOT_INLPRODRATE];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      nuxn = BufVal(ptr, 0);

      /* Physical leakage rate */

      ptr = (long)RDB[RES_TOT_NEUTRON_LEAKRATE];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      leak = BufVal(ptr, 0);

      /* Get previous albedo leakage rate */
      
      ptr = (long)RDB[RES_ALB_NEUTRON_LEAKRATE];
      CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
      L0 = BufVal(ptr, 0);
     
      /* Calculate estimate for new albedo leakage rate */
      
      L1 = nsf/keff - capt - fiss - leak + nuxn;

      /* Avoid compiler warning */

      val = -1.0;

      /* Get previous value */

      if ((val0 = RDB[DATA_ITER_VAL]) < 0.0)
	{
	  /* Not set, use initial guess */

	  ptr = (long)RDB[RES_ANA_KEFF];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);

	  if (Mean(ptr, 0) > 1.0)
	    val = 0.999;
	  else
	    val = 1.001;
	}
      else if (L0 != 0.0)
	{
	  /* Calculate new */

	  val = (val0 - 1.0)*L1/L0 + 1.0;

	  /* Add to statistics */

	  ptr = (long)RDB[RES_ITER_VAL];
	  CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr);
	  AddStat(val, ptr, 0);
	  
	  /* Fix value for last iteration */
	  
	  if ((fix == YES) && (idx > skip + ncyc))
	    val = Mean(ptr, 0);
	}    
      else
	Die(FUNCTION_NAME, "L0 == 0");

      /* Put value */

      WDB[DATA_ITER_VAL] = val;

      /* Put albedos */

      if ((f = RDB[DATA_ITER_ALB_F1]) > 0.0)
	WDB[DATA_GEOM_ALBEDO1] = val*f;

      if ((f = RDB[DATA_ITER_ALB_F2]) > 0.0)
	WDB[DATA_GEOM_ALBEDO2] = val*f;
      
      if ((f = RDB[DATA_ITER_ALB_F3]) > 0.0)
	WDB[DATA_GEOM_ALBEDO3] = val*f;
      
      /***********************************************************************/
    }
  else
    Die(FUNCTION_NAME, "Invalid iteration mode");
}