Author Topic: Number of CPUs as variable in project  (Read 480 times)

claus_stovgaard

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
Number of CPUs as variable in project
« on: February 06, 2019, 09:56:57 am »
Have a number of project where it would be nice to have "number of cpus" as a variable.

E.g. So I can write for the Command Line: "make -j number_of_cpus+1 -f <makefile>"

Do SlickEdit have any feature for specifying -j argument based on number of cpus on the machine?

Graeme

  • Senior Community Member
  • Posts: 2388
  • Hero Points: 314
Re: Number of CPUs as variable in project
« Reply #1 on: February 06, 2019, 10:52:21 am »
Not sure if this is what you want but you can use an environment variable like this
make -j %(NUMBER_OF_PROCESSORS) -f makefile

For Windows, NUMBER_OF_PROCESSORS is a system environment variable.
See this post for how to set environment variables for a workspace
https://community.slickedit.com/index.php/topic,16714.msg64622.html#msg64622

so you could have
Code: [Select]
void _workspace_opened_set_cpus()
{
   switch ( _workspace_filename ) {
   case 'whatever' :
      set_env('NUM_CPUS', (_str)((int)get_env('NUMBER_OF_PROCESSORS') + 2));
   default:
      set_env('NUM_CPUS', (_str)((int)get_env('NUMBER_OF_PROCESSORS') + 1));

   }
}
Then
make -j %(NUM_CPUS) -f makefile

For Linux  - don't know.  You might have to run a shell script to set an environment variable.
execute('my_shell_script.sh');
execute is a slick C command.

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2389
  • Hero Points: 133
Re: Number of CPUs as variable in project
« Reply #2 on: February 06, 2019, 11:12:08 am »
How many projects are in your workspace?

claus_stovgaard

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
Re: Number of CPUs as variable in project
« Reply #3 on: February 06, 2019, 11:40:43 am »
Thanks for the help with the environment variable. I think I can fix it with this.
A very good idea to use it like this.
@Dan - usually only 1 project.