예제 #1
0
    void StringFunction::evalFunctions(MDArray& inp, double time_value_optional)
    {
      EXCEPTWATCH;
      std::map<Function *, std::vector<double> >::iterator it = m_func_to_value.begin();
      const std::map<Function *, std::vector<double> >::iterator it_end = m_func_to_value.end();

      //Evaluate the function and store the answer in its bound location
      for(; it != it_end; ++it)
        {
          Function& func = *it->first;

          PRINTQ(func.getName());

          // check to avoid infinite recursion
          if (&func == this)
            {
              std::ostringstream msg;
              msg << "StringFunction::evalFunctions: infinite recursion by self-referential string function, name= " << m_name;
              VERIFY_1(msg.str());
            }

          VERIFY_OP(func.getNewDomain().rank(), ==, 1, "StringFunction::evalFunctions: functions must be defined with domain/codomain of rank 1 for now");
          VERIFY_OP(func.getNewCodomain().rank(), ==, 1, "StringFunction::evalFunctions: functions must be defined with domain/codomain of rank 1 for now");
          int numCells = 1;

          MDArray f_inp = MDArray(numCells, func.getNewDomain().dimension(0));
          MDArray f_out = MDArray(numCells, func.getNewCodomain().dimension(0));

          int nInDim = last_dimension(f_inp);
          // FIXME - do we really need the extra array?
          for (int iDim = 0; iDim < nInDim; iDim++)
            {
              f_inp(0, iDim) = inp( iDim);
            }

          if (m_have_element)
            {
              func(f_inp, f_out, *m_element, m_parametric_coordinates, time_value_optional); 
            }
          else
            {
              func(f_inp, f_out); 
            }

          int nOutDim = last_dimension(f_out);

          for (int iDim = 0; iDim < nOutDim; iDim++)
            {
              (it->second)[iDim] = f_out(0, iDim);
            }

        }
    }
예제 #2
0
파일: init.c 프로젝트: norayr/wmlaptop
void init_battery ( )
{
	if( args_useApmAcpi == USEAPMACPI_APM || args_useApmAcpi == USEAPMACPI_ONLYAPM )
	{
		if( APM_init() == ERROR )
		{
			PRINTQ( stderr, "Cannot support APM (the file %s don't exists)\n", APM_ACCESS_TEST );
			
			if( args_useApmAcpi == USEAPMACPI_ONLYAPM ) {
				if( args_beQuiet )
					fprintf( stderr, "Cannot support APM (the file %s don't exists)\n", APM_ACCESS_TEST );
				free_and_exit( ERROR );
			}
			
			PRINTQ( stderr, "Switching to ACPI..\n");
			if( ACPI_init() == ERROR )
			{
				if( args_beQuiet )
					fprintf( stderr, "Cannot support APM (the file %s don't exists)\n", APM_ACCESS_TEST );
				fprintf( stderr, "Cannot support ACPI (the file %s don't exists)\n", ACPI_ACCESS_TEST );
				PRINTQ( stderr, ".. and now ?.. i must die\n" );
				free_and_exit( ERROR );
			}
		}
	}
	
	if( args_useApmAcpi == USEAPMACPI_ACPI || args_useApmAcpi == USEAPMACPI_ONLYACPI )
	{
		if( ACPI_init() == ERROR )
		{
			PRINTQ( stderr, "Cannot support ACPI (the file %s don't exists)\n", ACPI_ACCESS_TEST );
			
			if( args_useApmAcpi == USEAPMACPI_ONLYACPI ) {
				if( args_beQuiet )
					fprintf( stderr, "Cannot support ACPI (the file %s don't exists)\n", ACPI_ACCESS_TEST );
				free_and_exit( ERROR );
			}
			
			PRINTQ( stderr, "Switching to APM..\n");
			if( APM_init() == ERROR )
			{
				if( args_beQuiet )
					fprintf( stderr, "Cannot support ACPI (the file %s don't exists)\n", ACPI_ACCESS_TEST );
				fprintf( stderr, "Cannot support APM (the file %s don't exists)\n", APM_ACCESS_TEST );
				PRINTQ( stderr, ".. and now ?.. i must die\n" );
				free_and_exit( ERROR );
			}
		}
	}
	
}
예제 #3
0
파일: init.c 프로젝트: norayr/wmlaptop
/* riempe la struttura cpuState tenendo anche conto
 * degli argomenti passati da linea di comando */
void init_cpuState ( )
{
#ifndef LONGRUN
	FILE *  fp;
	char red[10];
	char * paths[4][3] =
	          { /* sys     proc    user */
	/* min */   { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq",
	              "/proc/sys/cpu/0/speed-min",
	              args_useFileMin },
	/* max */   { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq",
	              "/proc/sys/cpu/0/speed-max",
	              args_useFileMax },
	/* set */   { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed",
	              "/proc/sys/cpu/0/speed",
			      args_useFileSet },
   /* read */  { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
             "/proc/sys/cpu/0/speed",
             args_useFileSet }
	          };
	u_int8 idx[3] = {   /* the second index */
	     args_useFileMin ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ),
	     args_useFileMax ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ),
	     args_useFileSet ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 )
	};
	
	
	/* auto_freq_state */
	cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON );

    /* will be checked later */
    cpuState.userspace = false;
	
	/* min freq */
	if( (fp = fopen( paths[0][idx[0]], "r" )) == NULL ) {
		fprintf( stderr, "Error reading the info file (%s):\n%s\n", paths[0][idx[0]], strerror(errno) );
		free_and_exit( ERROR );
	}
	
	fgets ( red, 10, fp );
	cpuState.minFreq = atoi ( red );
	
	fclose ( fp );
	
	/* max freq */	
	if( (fp = fopen( paths[1][idx[1]], "r" )) == NULL ) {
		fprintf( stderr, "Error reading the info file (%s):\n%s\n", paths[1][idx[1]], strerror(errno) );
		free_and_exit( ERROR );
	}
	
	fgets ( red, 10, fp );
	cpuState.maxFreq = atoi ( red );
	
	fclose ( fp );
	
	/* set freq file */
	cpuState.setFreqFile = paths[2][idx[2]];
    /* read freq file */
    cpuState.readFreqFile = paths[3][idx[2]];
        /* if we have to use the SYS's way to set cpufreq, then ensure that in
         * scaling_governor there has been put 'userspace'; otherwise let's try
         * to put it by ourself */
        if( idx[2] == 0 )
            scalingGovernorHelper( );

	
        cpuReadFreq( );
	
	
        /* set freq */
        cpuState.setFreq = cpuState.actualFreq;


        /* step freq */
        cpuState.stepFreq = args_incrementalStep;
	
#else
        /* init and get first actual frequency */
        /* PENDING: get these files from config */
        longrun_init("/dev/cpu/0/cpuid","/dev/cpu/0/msr");
        cpuReadFreq( );
        cpuState.setLevelIdx = cpuState.actualLevelIdx;
	cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON );
        cpuState.stepLevelIdx = 1;
        /* did user set a valid value here? */
        if (args_incrementalStep < 10 && args_incrementalStep > 0)
            cpuState.stepLevelIdx = args_incrementalStep;
#endif

    /* ok, if we are in ttyMode we don't need to modify values.. we just want to read them */
    if( args_ttyMode )
        return;

#ifndef LONGRUN	
	/* other options */
	if( args_maxFreq != ARGSDEF_LEAVE ) {
		if( args_maxFreq > cpuState.maxFreq ) {
			PRINTQ( stderr, "Error: args_maxFreq > maxFreq possible (using %d as max)\n", cpuState.maxFreq );
			args_maxFreq = cpuState.maxFreq;
		}
		cpuState.maxFreq = args_maxFreq;
	}
	
	if( args_minFreq != ARGSDEF_LEAVE ) {
		if( args_minFreq < cpuState.minFreq ) {
			PRINTQ( stderr, "Error: args_minFreq < minFreq possible (using %d as min)\n", cpuState.minFreq );
			args_minFreq = cpuState.minFreq;
		}
		cpuState.minFreq = args_minFreq;
	}
	
	/* little control.. */
	if( cpuState.minFreq > cpuState.maxFreq ) {
		fprintf( stderr, "Error: minFreq > maxFreq\n" );
		free_and_exit( ERROR );
	}
#endif
	switch( args_startingFreq )
	{
		case STARTINGFREQ_MIN:
#ifndef LONGRUN	
			/* frequence at min */
			while( cpuState.actualFreq != cpuState.minFreq )
				cpuSetFreq( FREQ_DECREMENT, FREQ_NEXT );
#else
                        cpuState.setLevelIdx = 0;
#endif
			break;
		case STARTINGFREQ_MAX:
			/* frequence at max */
#ifndef LONGRUN	
			while( cpuState.actualFreq != cpuState.maxFreq )
				cpuSetFreq( FREQ_INCREMENT, FREQ_NEXT );
#else
                        cpuState.setLevelIdx = cpuState.nLongRunLevels-1;
#endif
	}
	
#ifndef LONGRUN	
#ifdef DEBUG
	fprintf ( stderr, "min freq: %d\nmax freq: %d\nactual freq: %d\n", cpuState.minFreq, cpuState.maxFreq, cpuState.actualFreq );
#endif
#else
	fprintf ( stderr, "LongRun CPU starts at %d, with autoadjust = %d\n\n", cpuState.setLevelIdx, cpuState.auto_freq_state );
        cpuEchoFreq();  /* set initial range */
#endif
	return;
}
예제 #4
0
파일: init.c 프로젝트: norayr/wmlaptop
/* this chech for the string 'userspace' is in scaling_governor file under /sys/.. dir
 * (only in case we are going to use SYS's way to set cpufreq). If 'userspace' is not set
 * then we try to set it by ourself */
void scalingGovernorHelper( )
{
    char * scaling_governor_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor";
    char * scaling_governor_av_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors";
    char * error_msg = "Unable to read <%s>\n";
    char * error_msg_w = "Unable to write <%s>\n";
    FILE * sysfp;
    FILE * sysavfp;
    char   littleBuffer[128];
    
    bool   printIt = false;
    int    i;

    if( ( sysfp = fopen( scaling_governor_path, "r" ) ) == NULL ) {
        PRINTQ( stderr, error_msg, scaling_governor_path, strerror(errno) );
        return;
    }

    fgets( littleBuffer, 127, sysfp );
    fclose( sysfp );
    
    if( !strcmp( littleBuffer, "userspace\n" ) )
       {
   cpuState.userspace = true;
        return;
       }
    if( ( sysavfp = fopen( scaling_governor_av_path, "r" ) ) == NULL ) {
        PRINTQ( stderr, error_msg, scaling_governor_av_path, strerror(errno) );
        return;
    }
    
    fgets( littleBuffer, 127, sysavfp );
    fclose( sysavfp );
    
    for( i = 0; i < strlen( littleBuffer ) - 9 ; i++ )
        if( !strncmp( littleBuffer, "userspace", 9 ) )
        {
            /* ok, module is loaded */
            printIt = true;
			cpuState.userspace = true;
            break;
        }


    if( printIt == false ) {
        int s;
        PRINTQ( stderr, "It seems that 'userspace' governor is not set\n");
        PRINTQ( stderr, "wmlaptop may not control CPU frequency\n");       
  cpuState.userspace = false;
    }
    
    /* All ok here */
    if( ( sysfp = fopen( scaling_governor_path, "w" )) == NULL ) 
	    PRINTQ( stderr, error_msg_w, scaling_governor_path, strerror(errno));
    else
    {
        PRINTQ( stderr, "echoing 'userspace' > '%s'\n", scaling_governor_path );
        fprintf( sysfp, "userspace" );
		cpuState.userspace = true;
        fclose( sysfp );
    }

    return;
}
예제 #5
0
파일: init.c 프로젝트: norayr/wmlaptop
void init_display(  )
{
	XClassHint       classHint;
	XTextProperty    name;
	XGCValues        gcv;
	unsigned long    gcm;
	int              dummy=0;
	char           * progname = PROGNAME;
	
	Pixel            back_pix;
	Pixel            fore_pix;

	display = XOpenDisplay( args_XDisplayName );
	
	if( display == NULL )
	{
		fprintf(stderr, "Can't open display\n" );
		free_and_exit( ERROR );
	}
	
	screen  = DefaultScreen(display);
	Root    = RootWindow(display, screen);
	d_depth = DefaultDepth(display, screen);
	x_fd    = XConnectionNumber(display);

	
	init_image ( );
	
	/* Create a window to hold the stuff */
	mysizehints.flags = USSize | USPosition;
	mysizehints.x = 0;
	mysizehints.y = 0;
	

	back_pix = WhitePixel( display, screen);
	fore_pix = BlackPixel( display, screen);

	XWMGeometry(display, screen, NULL, NULL, 1, &mysizehints, \
	            &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
	
	mysizehints.width = 64;
	mysizehints.height = 64;
		
	win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, \
	                          mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);
	
	iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, \
	                              mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);

	/* Activate hints */
	XSetWMNormalHints(display, win, &mysizehints);
	classHint.res_name = progname;
	classHint.res_class = progname;
	XSetClassHint(display, win, &classHint);

	XSelectInput(display, win, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );
	XSelectInput(display, iconwin, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );

	if (XStringListToTextProperty(&progname, 1, &name) == 0)
		PRINTQ(stderr, "%s: can't allocate window name\n", PROGNAME);
	

	XSetWMName(display, win, &name);
	
	/* Create GC for drawing */
	
	gcm = GCForeground | GCBackground | GCGraphicsExposures;
	gcv.foreground = fore_pix;
	gcv.background = back_pix;
	gcv.graphics_exposures = 0;
	NormalGC = XCreateGC(display, Root, gcm, &gcv);

	/* ONLYSHAPE ON */
	
	pixmask = XCreateBitmapFromData(display, win, wmlaptop_mask_bits, wmlaptop_mask_width, wmlaptop_mask_height);

	XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
	
	/* ONLYSHAPE OFF */

	mywmhints.initial_state = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);
	
	XMapWindow(display, win);
	
	
}