# HG changeset patch # User Merten Sach # Date 1313519491 -7200 # Node ID 3840d91821c44bb67062f84e3daa350e830e6e42 # Parent 4ae1d7ffb1ae85e1f22d0334df3d354905ed2ae0 VPThread version is working diff -r 4ae1d7ffb1ae -r 3840d91821c4 .hgignore --- a/.hgignore Wed Aug 03 14:26:31 2011 +0200 +++ b/.hgignore Tue Aug 16 20:31:31 2011 +0200 @@ -1,5 +1,6 @@ syntax: glob +histograms nbproject c-ray-mt *.ppm diff -r 4ae1d7ffb1ae -r 3840d91821c4 Makefile --- a/Makefile Wed Aug 03 14:26:31 2011 +0200 +++ b/Makefile Tue Aug 16 20:31:31 2011 +0200 @@ -1,11 +1,37 @@ -obj = c-ray-mt.o +obj = \ + VPThread_lib/VMS/Histogram/Histogram.o \ + VPThread_lib/VMS/Histogram/FloatHist.o \ + VPThread_lib/VMS/CoreLoop.o \ + VPThread_lib/VMS/VMS.o \ + VPThread_lib/VMS/MasterLoop.o \ + VPThread_lib/VMS/Queue_impl/PrivateQueue.o \ + VPThread_lib/VMS/Hash_impl/PrivateHash.o \ + VPThread_lib/VMS/DynArray/DynArray.o \ + VPThread_lib/VPThread_PluginFns.o \ + VPThread_lib/VPThread_lib.o \ + VPThread_lib/VMS/Histogram/DblHist.o \ + VPThread_lib/VPThread.o \ + VPThread_lib/VMS/probes.o \ + VPThread_lib/VMS/ProcrContext.o \ + VPThread_lib/VPThread_Request_Handlers.o \ + VPThread_lib/VPThread_helper.o \ + VPThread_lib/VMS/Hash_impl/MurmurHash2.o \ + VPThread_lib/VMS/vmalloc.o \ + VPThread_lib/VMS/contextSwitch.o \ + VPThread_lib/VMS/Queue_impl/BlockingQueue.o \ + VPThread_lib/VMS/vutilities.o \ + c-ray-mt.o + bin = c-ray-mt CC = gcc -CFLAGS = -O3 -ffast-math +CFLAGS = -m64 -ffast-math -fwrapv -fno-omit-frame-pointer -O3 -D VPTHREAD -D APPLICATION=C-RAY -g -Wall $(bin): $(obj) $(CC) -o $@ $(obj) -lm -lpthread + +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< .PHONY: clean clean: @@ -18,3 +44,6 @@ .PHONY: uninstall uninstall: rm -f /usr/local/bin/$(bin) + + +# $@ Name des Targets diff -r 4ae1d7ffb1ae -r 3840d91821c4 c-ray-mt.c --- a/c-ray-mt.c Wed Aug 03 14:26:31 2011 +0200 +++ b/c-ray-mt.c Tue Aug 16 20:31:31 2011 +0200 @@ -85,11 +85,11 @@ }; struct thread_data { - pthread_t tid; + VirtProcr *VP; int sl_start, sl_count; - uint32_t *pixels; }; +typedef struct thread_data thread_data; void render_scanline(int xsz, int ysz, int sl, uint32_t *fb, int samples); struct vec3 trace(struct ray ray, int depth); @@ -103,7 +103,7 @@ void load_scene(FILE *fp); unsigned long get_msec(void); -void *thread_func(void *tdata); +void thread_func(void *tdata, VirtProcr *VProc); #define MAX_LIGHTS 16 /* maximum number of lights */ #define RAY_MAG 1000.0 /* trace rays of this magnitude */ @@ -145,9 +145,10 @@ int thread_num = 1; struct thread_data *threads; -int start = 0; -pthread_mutex_t start_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t start_cond = PTHREAD_COND_INITIALIZER; +volatile int end = 0; +volatile int start = 0; +int32 end_mutex, end_cond; +int32 start_cond, start_mutex; #define NRAN 1024 #define MASK (NRAN - 1) @@ -168,12 +169,15 @@ " -h this help screen\n\n" }; -void raytrace(uint32_t *pixels); +char __ProgrammName[] = "c-ray"; +char __DataSet[255]; + + +void raytrace(void *pixels, VirtProcr *Vprocr); int main(int argc, char **argv) { int i; uint32_t *pixels; - double sl, sl_per_thread; FILE *infile = stdin, *outfile = stdout; for(i=1; iprocrID); + VPThread__mutex_lock(start_mutex, VProc); start_time = get_msec(); start = 1; - pthread_cond_broadcast(&start_cond); - pthread_mutex_unlock(&start_mutex); - - for(i=0; iprocrID); + VPThread__mutex_lock(end_mutex, VProc); + while(end < thread_num) + VPThread__cond_wait(end_cond, VProc); + VPThread__mutex_unlock(end_mutex, VProc); + rend_time = get_msec() - start_time; + + VPThread__free(threads,VProc); + VPThread__dissipate_thread(VProc); } /* render a frame of xsz/ysz dimensions into the provided framebuffer */ @@ -674,19 +693,23 @@ #error "I don't know how to measure time on your platform" #endif -void *thread_func(void *tdata) { +void thread_func(void *tdata, VirtProcr *VProc) { int i; struct thread_data *td = (struct thread_data*)tdata; - pthread_mutex_lock(&start_mutex); - while(!start) { - pthread_cond_wait(&start_cond, &start_mutex); - } - pthread_mutex_unlock(&start_mutex); - + VPThread__mutex_lock(start_mutex, VProc); + while(!start) + VPThread__cond_wait(start_cond, VProc); + VPThread__mutex_unlock(start_mutex, VProc); + for(i=0; isl_count; i++) { render_scanline(xres, yres, i + td->sl_start, td->pixels, rays_per_pixel); } + + VPThread__mutex_lock(end_mutex, VProc); + end++; + VPThread__cond_signal(end_cond, VProc); + VPThread__mutex_unlock(end_mutex, VProc); - return 0; + VPThread__dissipate_thread(VProc); } diff -r 4ae1d7ffb1ae -r 3840d91821c4 scene --- a/scene Wed Aug 03 14:26:31 2011 +0200 +++ b/scene Tue Aug 16 20:31:31 2011 +0200 @@ -7,7 +7,7 @@ s 0 -1000 2 999 0.1 0.2 0.6 80.0 0.5 # bouncing ball -s 0 0 2 1 1.0 0.5 0.1 60.0 0.7 +s 0 0 2 1 0.0 0.0 0.0 60.0 0.7 # lights... l -50 100 -50