Skip to content

Commit

Permalink
threads
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Oct 28, 2023
1 parent 60b745c commit d38e127
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion emscripten/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:
emcc -pthread -I../src/ ../src/*.c -DOPENGL=1 -s EXPORTED_RUNTIME_METHODS='["cwrap","getValue"]' -sSTACK_SIZE=655360 -s USE_GLFW=3 -s FULL_ES3=1 -Wl,--whole-archive -s LINKABLE=1 -o rebound.html
emcc -pthread -I../src/ ../src/*.c -DOPENGL=1 -s EXPORTED_RUNTIME_METHODS='["cwrap","getValue"]' -sSTACK_SIZE=655360 -s USE_GLFW=3 -s FULL_ES3=1 -Wl,--whole-archive -s LINKABLE=1 -sPTHREAD_POOL_SIZE=2 -o rebound.html

serve:
python serve.py
3 changes: 1 addition & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static unsigned int linkProgram(int prog){

GLint logLength;
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
if (logLength > 1) { // 0 should work - bug in emscripten?
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
printf("\n\n%s\n\n",log);
Expand Down Expand Up @@ -298,7 +298,6 @@ static void reb_display_cursor(GLFWwindow* window, double x, double y){
}

static void reb_display_keyboard(GLFWwindow* window, int key, int scancode, int action, int mods){
printf("keypress!\n");
struct reb_display_data* data = glfwGetWindowUserPointer(window);
data->key_mods = mods;
if (action==GLFW_PRESS){
Expand Down
17 changes: 7 additions & 10 deletions src/rebound.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,8 @@ struct reb_simulation* reb_simulation_create(){
int main(void){
struct reb_simulation* r = reb_simulation_create();

printf("Simulation init done\n");
reb_simulation_add_plummer(r, 100, 1.0, 1.0);
printf("Simulation plummer done\n");
reb_simulation_integrate(r,100);
printf("Simulation integrate done\n");
return 0;
}
#endif
Expand Down Expand Up @@ -890,16 +887,16 @@ enum REB_STATUS reb_simulation_integrate(struct reb_simulation* const r, double
reb_display_init_data(r);
r->display_data->opengl_enabled = 1;

//pthread_t compute_thread;
//if (pthread_create(&compute_thread,NULL,reb_simulation_integrate_raw,&thread_info)){
// reb_simulation_error(r, "Error creating display thread.");
//}
pthread_t compute_thread;
if (pthread_create(&compute_thread,NULL,reb_simulation_integrate_raw,&thread_info)){
reb_simulation_error(r, "Error creating display thread.");
}

reb_display_init(r); // Display routines running on main thread.

//if (pthread_join(compute_thread,NULL)){
// reb_simulation_error(r, "Error joining display thread.");
// }
if (pthread_join(compute_thread,NULL)){
reb_simulation_error(r, "Error joining display thread.");
}
#else // OPENGL
reb_simulation_error(r,"REBOUND was not compiled/linked with OPENGL libraries.");
return REB_EXIT_ERROR;
Expand Down

0 comments on commit d38e127

Please sign in to comment.