fallen_angel Posted January 11, 2015 Report Posted January 11, 2015 Write a computer program that by creating various numbers of processes or threads, will determine the number of processors of the computer.Are cineva vreo idee? O implementare?Mul?umesc. Quote
Silviu Posted January 11, 2015 Report Posted January 11, 2015 Write a computer program that by creating various numbers of processes or threads, will determine the number of processors of the computer.Are cineva vreo idee? O implementare?Mul?umesc.Linux implements max number of threads per process indirectly!!number of threads = total virtual memory / (stack size*1024*1024)Thus, the number of threads per process can be increased by increasing total virtual memory or by decreasing stack size. But, decreasing stack size too much can lead to code failure due to stack overflow while max virtual memory is equals to the swap memory.Check you machine:Total Virtual Memory: ulimit -v (default is unlimited, thus you need to increase swap memory to increase this)Total Stack Size: ulimit -s (default is 8Mb)Command to increase these values:ulimit -s newvalueulimit -v newvalue*Replace new value with the value you want to put as limit.References:http://dustycodes.wordpress.com/2012/02/09/increasing-number-of-threads-per-process/Sursa Quote
staticwater Posted January 11, 2015 Report Posted January 11, 2015 (edited) N-ai specificat sistemul de operare. Pe windows poti sa faci in felul urmator:1. Creaza un thread2. Cu ajutorul functiei: GetCurrentProcessorNumber(Vista, Windows Server 2003 GetCurrentProcessorNumberEx (Windows 7, Windows Server 2008 R2) GetCurrentProcessorNumberXP (XP)poti afla pe ce procesor ruleaza thread-ul respectiv. Teoretic dupa x00(x000?) de thread-uri create, ai "epuizat" toate procesoarele. PS: Sunt metode mult mai simple pt. a afla numarul procesoarelor, eu am incercat sa ma conformez cerintelor initiale. Edited January 11, 2015 by staticwater Quote
fallen_angel Posted January 11, 2015 Author Report Posted January 11, 2015 Pentru linux am nevoie. ?tiu c? sunt metode mai simple de a aflat nr de core-uri, dar asta e cerin?a. Mul?umesc Quote
gogusan Posted January 11, 2015 Report Posted January 11, 2015 #include <thread>unsigned int nthreads = std::thread::hardware_concurrency();Ref: http://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency Quote
nedo Posted January 11, 2015 Report Posted January 11, 2015 (edited) creezi 1 thread care sa faca ceva intensiv, si vezi cat iti ia sa executi threadul, dupa asta, pornesti mai multe threaduri in acelasi timp si contorizezi pentru fiecare cat iti ia sa executi, verifici timpi, cand ruleaza concurent, verifici timpi de inceput si terminare, numeri numarul de threaduri ce au timpi de pornire si terminare apropiati. Ala e numarul aproximativ de procesoare/threaduri fizice, ce pot rula pe acel procesor. @ceilalti se cere sa se gaseasca o metoda de detectie a numarului de procesoare folosindu-se de threaduri, nu chestii platform dependent.editat per specificatie Poate migra, atunci cand au unde, ideea era sa creezi mai multe procese simultane care sa ocupe toate corurile procesorului in acelasi timp, cu o actiune ce necesita multa putere de procesare, cum ar fi calcularea fibonnaci pentru un numar mare. Edited January 11, 2015 by nedo Quote
staticwater Posted January 11, 2015 Report Posted January 11, 2015 Expresia "restul" se folosea mai de mult in armata. Acum n-o sa-ti explic de ce, dar cuvantul "ceilal?i" ar fi mult mai potrivit in acest caz. Implementarea threadurilor difera de le un sistem de operare la alta + un thread/proces poate "migra" intre procesoare. Quote
Ganav Posted January 11, 2015 Report Posted January 11, 2015 In C:#include <stdlib.h>#include <stdio.h>int main(void) { system("lscpu"); // return 1;}Pentru core-uri CUDA de pe GPU-urile Nvidia poti urmari discutia de aici:http://stackoverflow.com/questions/5217167/cuda-how-many-cores-per-mp Quote