Quoted By:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <SDL2/SDL.h>
#define DEFAULT_WINDOW_WIDTH 1200
#define DEFAULT_WINDOW_HEIGHT 800
#define CELL_SIZE 8
__global__ void GameOfLife_CalculateNextMatrix(unsigned char* matrix,
unsigned char* next, unsigned int matrix_w, unsigned int matrix_h);
void GameOfLife_RandomGrid(unsigned char* matrix, unsigned matrix_w, unsigned matrix_h);
void GameOfLife_ClearGrid(unsigned char* matrix, unsigned matrix_w, unsigned matrix_h);
int main(int argc, char** argv) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL:: %s\n", SDL_GetError());
return -1;
}
SDL_Window* win;
SDL_Renderer* render;
SDL_Event event;
int return_code = 0; unsigned int win_w = DEFAULT_WINDOW_WIDTH,
win_h = DEFAULT_WINDOW_HEIGHT; unsigned char going = 1, GOL_going = 0;
unsigned long matrix_width = DEFAULT_WINDOW_WIDTH / CELL_SIZE, matrix_height = DEFAULT_WINDOW_HEIGHT / CELL_SIZE;
unsigned char* matrix = NULL; unsigned char* matrix_CUDA = NULL, * next_CUDA = NULL;
unsigned char mouse_left_down = 0; unsigned char mouse_down_cell_state = 0;
int mouse_x, mouse_y; unsigned int delay = 32;
win = SDL_CreateWindow("GOL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, win_w, win_h, SDL_WINDOW_SHOWN);
if (win == NULL) { printf("SDL::WINDOW::CREATION:: %s\n", SDL_GetError()); return_code = -1;
goto exit;}render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
if (render == NULL) {printf("SDL::RENDERER::CREATION:: %s\n", SDL_GetError());return_code = -2;
goto exit;}matrix = (unsigned char*)malloc(matrix_width * matrix_height * sizeof(unsigned char));
if (matrix == NULL) {printf("malloc() error: couldn't allocate %li bytes!\n",
matrix_width * matrix_height * sizeof(unsigned char));return_code = -3;goto exit;