Need Program, which will make the processor work 100%

I need a program that will make my processor work 100%.

Preferably in C, a tiny program that will make the processor work 100%, and one that is not "optimized" by the compiler, so it does nothing.

Suggestions?

+3
source share
6 answers
int main(void) {
  volatile unsigned x=0, y=1;
  while (x++ || y++);
  return 0;
}

Or, if you have a multi-core processor - unverified ... exactly the same as above :)

int main(void) {
#pragma omp parallel
  {
    volatile unsigned x=0, y=1;
    while (x++ || y++);
  }
  return 0;
}
+6
source

How about this:

int main() { for (;;); }
+6
source

, .

#include <unistd.h>
int main(void)
{
  while(1)
    fork();
  return 0;
}
+3

source.c:

int main(int argc, char *argv) {
    while(1);
}

source.c: gcc source.c -o myprogram

: ./myprogram

+1

, , 50%, 25% ..

So, if this is a problem, you can use something like

void main(void)
{
    omp_set_dynamic(0);
    // In most implemetations omp_get_num_procs() return #cores 
    omp_set_num_threads(omp_get_num_procs());
    #pragma omp parallel for
    for(;;) {}
}
0
source

Built-in Windows solution for multi-threaded systems. Compiling in Visual C ++ (or Visual Studio) without any library.

/* Use 100% CPU on multithreaded Windows systems */

#include <Windows.h>
#include <stdio.h>
#define NUM_THREADS 4

DWORD WINAPI mythread(__in LPVOID lpParameter)
{
    printf("Thread inside %d \n", GetCurrentThreadId());
    volatile unsigned x = 0, y = 1;
    while (x++ || y++);
    return 0;
}


int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE handles[NUM_THREADS];
    DWORD mythreadid[NUM_THREADS];
    int i;

    for (i = 0; i < NUM_THREADS; i++)
    {
        handles[i] = CreateThread(0, 0, mythread, 0, 0, &mythreadid[i]);
        printf("Thread after %d \n", mythreadid[i]);
    }

    getchar();
    return 0;
}
0
source

All Articles