From 6eb1ca1dd4b0bda6433923a65ab9e1ed3b268c10 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 5 Apr 2017 23:15:05 +0200 Subject: Multithread on windows --- attract.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/attract.c b/attract.c index 9209a16..5ac8094 100644 --- a/attract.c +++ b/attract.c @@ -10,6 +10,19 @@ #include #include "lodepng.h" +#ifdef _WIN32 +#include +int number_of_cores(void){ + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +} +#else +int number_of_cores(void){ + return sysconf(_SC_NPROCESSORS_ONLN); +} +#endif + #ifndef CMPLX #define CMPLX(r,i) ((r) + (i)*I) #endif @@ -134,8 +147,8 @@ static void* thread_entry(void *arg_vp){ } int main(int argc,char **argv){ - const double minx=-1.5,miny=-1.5; - const double maxx=1.5,maxy=1.5; + const double minx=-0.3,miny=0.6; + const double maxx=-0.1,maxy=0.8; const double width=1000; struct config cfg={ @@ -165,9 +178,9 @@ int main(int argc,char **argv){ unsigned char *img=malloc(cfg.width*cfg.height*3); - int nthreads=sysconf(_SC_NPROCESSORS_ONLN); - if(nthreads==4)nthreads/=2; + int nthreads=number_of_cores(); if(nthreads>=999||nthreads<1)nthreads=1; + // nthreads=1; fprintf(stderr,"Using %d thread%s\n",nthreads,nthreads==1?"":"s"); -- cgit v1.2.3-70-g09d2