{
	"auto_complete":
	{
		"selected_items":
		[
		]
	},
	"buffers":
	[
		{
			"contents": "#include <stdlib.h>\n\n// ---\n// Header includes\n#include \"base/base_inc.h\"\n#include \"os/os_inc.h\"\n\n\n// CUDA headers\n#include \"kernels.h\"\n\n// ---\n// .C includes\n#include \"base/base_inc.c\"\n#include \"os/os_inc.c\"\n#include \"os/os_entry_point.c\"\n#include \"test_mkl.c\"\n\n#define grid_file_path_bin \"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\grid.bin\"\n#define grid_file_path \"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\grid.dat\"\n#define knotpoints_file_path \"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\knotpoints.dat\"\n#define bspline_array_file_path \"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bsplines.dat\"\n\nglobal U32 enable_logging = 1;\n\n// Complex number with double precision\ntypedef struct Z64 Z64;\nstruct Z64\n{\n  F64 re;\n  F64 im;\n};\n\ntypedef struct Grid Grid;\nstruct Grid \n{\n  F64 start;\n  F64 end;\n  U32 num_steps;\n  F64 *points;\n};\n\n\ntypedef struct BSplineCtx BSplineCtx;\nstruct BSplineCtx \n{\n  Arena* arena;\n  U32 order;\n  F64 *knotpoints;\n  U32 num_knotpoints;\n  U32 num_bsplines;\n  U32 num_phys_points;\n  F64 *bsplines;\n};\n\n\n\n//~ Globals\nglobal Grid g_grid = {0};\nglobal BSplineCtx g_bspline_ctx = {0};\n\n//~ Functions\n\nfunction inline void\nlogger_debug(String8 msg)\n{\n  OutputDebugString(msg.str);\n}\n\n#define LOG(msg) if(enable_logging) { logger_debug(msg) };\n\n\nfunction void\nwrite_array_binary_F64(String8 path_to_file, F64 *values, U32 array_size) \n{\n  OS_Handle file_handle = OS_file_open(OS_AccessFlag_Write | OS_AccessFlag_CreateNew, \n      path_to_file);\n  { \n    ArenaTemp scratch = scratch_get(0, 0);\n    String8List list = {0};\n    String8 temp = {0};\n    temp.str = (U8*)values;\n    temp.size = sizeof(F64)*array_size;\n    str8_list_push(scratch.arena, &list, temp);\n    OS_file_write(scratch.arena, file_handle, 0, list, 0);\n    \n    String8List log_list = {0};\n    str8_list_push(scratch.arena, &log_list, str8_lit(\"Wrote binary array data to\"));\n    str8_list_push(scratch.arena, &log_list, path_to_file);\n    StringJoin join = {0};\n    join.sep = str8_lit(\" \");\n    join.post = str8_lit(\"\\n\");\n    String8 log_msg = str8_list_join(scratch.arena, log_list, &join);\n    OutputDebugString(log_msg.str);\n  }\n  OS_file_close(file_handle);\n}\n\nfunction void\nwrite_string_list_to_file(Arena *arena, String8 path, String8List *list)\n{\n\n  OS_Handle file_handle = OS_file_open(OS_AccessFlag_Write | OS_AccessFlag_CreateNew, \n      path);\n  OS_file_write(arena, file_handle, 0, *list, 0);\n\n  U32 debug = 1;\n  if(debug)\n  {\n    String8List log_list = {0};\n    str8_list_push(arena, &log_list, str8_lit(\"Wrote array to\"));\n    str8_list_push(arena, &log_list, path);\n    StringJoin join = {0};\n    join.sep = str8_lit(\" \");\n    join.post = str8_lit(\"\\n\");\n    String8 log_msg = str8_list_join(arena, log_list, &join);\n    OutputDebugString(log_msg.str);\n  }\n  OS_file_close(file_handle);\n}\n\n\n  function void\nwrite_array_F64(String8 path_to_file, F64 *values, U32 array_size, char* fmt) \n{\n    ArenaTemp scratch = scratch_get(0, 0);\n    String8List list = {0};\n    for(U32 i = 0; i < array_size; i++) \n    {\n      str8_list_pushf(scratch.arena, &list, fmt, values[i]);\n    }\n    write_string_list_to_file(scratch.arena, path_to_file, &list);\n}\n\n  function F64 \nbspline_recursion(F64 x, U32 k, U32 i)\n{\n  F64 *t = g_bspline_ctx.knotpoints;\n\n  if(k == 1)\n  {\n    if(i == g_bspline_ctx.num_bsplines-1 && x == g_grid.end) \n    {\n      // TODO(anton):\n      // This is like a hack to get the last bspline to be 1 at the last point.\n      // I dont get how the Cox-de Boor recursion formula can force the last bspline \n      // to unity at the last point, actually. I have to check this.\n      return 1.0;\n    }\n    else if(i < g_bspline_ctx.num_bsplines && (x >= t[i] && x < t[i+1]))\n    {\n      return 1.0;\n    } else {\n      return 0.0;\n    }\n  } \n  else \n  {\n    F64 recursion1 = bspline_recursion(x, k-1, i);\n    F64 term1_enum = (x - t[i]);\n    F64 term1_denom = (t[i+k-1] - t[i]);\n    F64 term1 = recursion1 > 0.0 ? (term1_enum/term1_denom)*recursion1 : 0.0;\n\n    F64 recursion2 = bspline_recursion(x, k-1, i+1);\n    F64 term2_enum = (t[i+k] - x);\n    F64 term2_denom = (t[i+k] - t[i+1]);\n    F64 term2 = recursion2 > 0.0 ? (term2_enum/term2_denom)*recursion2 : 0.0;\n\n    return term1 + term2;\n  }\n\n\n}\n\n\n  function F64 \nget_bspline_F64(F64 x_coord, U32 index)\n{\n  U32 k = g_bspline_ctx.order;\n  F64 out = bspline_recursion(x_coord, k, index);\n  return out;\n}\n\n  function void\nset_up_grid(Arena *arena)\n{\n  g_grid.start = 0.0;\n  g_grid.end = 10.0;\n  g_grid.num_steps = 100;\n\n  g_grid.points = PushArray(arena, F64, g_grid.num_steps);\n  F64 step_size = (g_grid.end-g_grid.start)/(F64)g_grid.num_steps;\n  g_grid.points[0] = g_grid.start;\n  g_grid.points[g_grid.num_steps-1] = g_grid.end;\n  for(U32 i = 1; i < g_grid.num_steps-1; i++)\n  {\n    g_grid.points[i] = g_grid.points[i-1] + step_size;\n  }\n\n}\n\n\n  function void\nset_up_bspline_context(Arena* arena)\n{\n  // Create knotpoint sequence.\n  U32 k = 4;\n  U32 bspl_N = 14;\n  g_bspline_ctx.order = k; \n  g_bspline_ctx.num_knotpoints = bspl_N; \n  g_bspline_ctx.num_bsplines = bspl_N-k;\n  g_bspline_ctx.num_phys_points = bspl_N-(2*k)+2; // Remove k points at each end, and then add back the first and last points.\n  g_bspline_ctx.arena = arena;\n  g_bspline_ctx.knotpoints = PushArray(arena, F64, g_bspline_ctx.num_knotpoints);\n  // Set up physical points;\n  F64 delta = (g_grid.end-g_grid.start)/(g_bspline_ctx.num_phys_points-1);\n  // Set ghost points including first physical\n  U32 phys_point_last_index = g_bspline_ctx.num_phys_points + k-1;\n  for(U32 i = 0; i < k; i++) \n  {\n    g_bspline_ctx.knotpoints[i] = g_grid.start;\n  }\n  for(U32 i = k; i < phys_point_last_index; i++) \n  {\n    g_bspline_ctx.knotpoints[i] = g_bspline_ctx.knotpoints[i-1] + delta;\n  }\n  // Set the last points\n  F64 last_physical = g_grid.end;\n  for(U32 i = phys_point_last_index; i < g_bspline_ctx.num_knotpoints; i++)\n  {\n    g_bspline_ctx.knotpoints[i] = last_physical;\n  }\n}\n\n\n  function void\nwrite_bsplines_to_matrix_F64(Arena *arena)\n{\n\n  U64 num_bsplines = g_bspline_ctx.num_bsplines;\n  U64 k = g_bspline_ctx.order;\n  F64 *t = g_bspline_ctx.knotpoints;\n  U32 grid_size = g_grid.num_steps;\n\n  // For sanity check we make the first 4 bsplines by hand.\n  {\n    F64 *bspl0 = PushArray(arena, F64, grid_size);\n    F64 *bspl1 = PushArray(arena, F64, grid_size);\n    F64 *bspl2 = PushArray(arena, F64, grid_size);\n    F64 *bspl3 = PushArray(arena, F64, grid_size);\n    F64 *bspl9 = PushArray(arena, F64, grid_size);\n    for(U32 i = 0; i < grid_size; i++)\n    {\n      F64 x = g_grid.points[i];\n      bspl0[i] = get_bspline_F64(x, 0);\n      bspl1[i] = get_bspline_F64(x, 1);\n      bspl2[i] = get_bspline_F64(x, 2);\n      bspl3[i] = get_bspline_F64(x, 3);\n      bspl9[i] = get_bspline_F64(x, 9);\n    }\n\n    F64 test = get_bspline_F64(g_grid.points[grid_size-1], 9);\n\n    write_array_F64(str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bspline0.dat\"), bspl0, grid_size, \"%13.6e\\n\");\n    write_array_F64(str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bspline1.dat\"), bspl1, grid_size, \"%13.6e\\n\");\n    write_array_F64(str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bspline2.dat\"), bspl2, grid_size, \"%13.6e\\n\");\n    write_array_F64(str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bspline3.dat\"), bspl3, grid_size, \"%13.6e\\n\");\n    write_array_F64(str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\bspline9.dat\"), bspl9, grid_size, \"%13.6e\\n\");\n  }\n\n  g_bspline_ctx.bsplines = PushArray(arena, F64, grid_size*num_bsplines);\n  for(U32 i = 0; i < g_grid.num_steps; i++)\n  {\n    for(U32 j = 0; j < num_bsplines; j++)\n    {\n      U32 index = g_grid.num_steps * i + j;\n      g_bspline_ctx.bsplines[index] = get_bspline_F64(g_grid.points[i], j);\n    }\n  }\n\n  ArenaTemp scratch = scratch_get(0, 0);\n  String8 bspline_filename = str8_lit(\"D:\\\\dev\\\\eigsol_gpu\\\\out\\\\Bsplines.dat\");\n\n  // First line is just the bspline indices.\n  String8List first_line_list = {0};\n  StringJoin join = {0};\n  join.sep = str8_lit(\"\\t\\t\");\n  for(U32 i = 0; i < num_bsplines; i++) \n  {\n    str8_list_pushf(scratch.arena, &first_line_list, \"%i\", i);\n  }\n  String8 first_line = str8_list_join(scratch.arena, first_line_list, &join);\n\n  String8List bspline_array_list = {0};\n  for(U32 i = 0; i < g_grid.num_steps; i++)\n  {\n    String8List row = {0};\n    for(U32 j = 0; j < num_bsplines; j++)\n    {\n      U32 index = g_grid.num_steps * i + j;\n      F64 bspline_value = g_bspline_ctx.bsplines[index];\n      str8_list_pushf(scratch.arena, &row, \"%13.6e\", bspline_value);\n    }\n    StringJoin bspl_join = {0};\n    bspl_join.sep = str8_lit(\"   \");\n    bspl_join.post = str8_lit(\"\\n\");\n    String8 row_joined = str8_list_join(scratch.arena, row, &bspl_join);\n    str8_list_push(scratch.arena, &bspline_array_list, row_joined);\n  }\n\n  write_string_list_to_file(scratch.arena, str8_lit(bspline_array_file_path), &bspline_array_list);\n\n}\n\n\nfunction\nvoid EntryPoint(void) \n{\n  OS_InitReceipt os_receipt = OS_init();\n  OS_InitGfxReceipt os_gfx_receipt = OS_gfx_init(os_receipt);\n\n  Arena *arena = m_make_arena();\n \n  //- Set up grid and write to file.\n  set_up_grid(arena);adsa\n  write_array_binary_F64(str8_lit(grid_file_path_bin), g_grid.points, g_grid.num_steps);\n  write_array_F64(str8_lit(grid_file_path), g_grid.points, g_grid.num_steps, \"%13.6e\\n\");\n\n  //- The BSpline context is the knotpoints and the BSpline order etc.\n  set_up_bspline_context(arena);\n  write_array_F64(str8_lit(knotpoints_file_path), \n      g_bspline_ctx.knotpoints, g_bspline_ctx.num_knotpoints,\n      \"%13.6e\\n\");\n\n  //- Then we generate the BSplines and save them off for reference and debugging.\n  write_bsplines_to_matrix_F64(arena);\n\n\n  //- Test MKL\n\n\n  test_mkl_zgeev();\n\n  cuda_entry_point();\n\n}\n",
			"file": "src/main.c",
			"file_size": 9881,
			"file_write_time": 133734533939436461,
			"settings":
			{
				"buffer_size": 9529,
				"encoding": "UTF-8",
				"line_ending": "Windows"
			}
		},
		{
			"file": "src/os/os_core.h",
			"settings":
			{
				"buffer_size": 2543,
				"line_ending": "Unix"
			}
		},
		{
			"file": "build.bat",
			"settings":
			{
				"buffer_size": 1425,
				"line_ending": "Windows"
			}
		}
	],
	"build_system": "Packages/C++/C Single File.sublime-build",
	"build_system_choices":
	[
		[
			[
				[
					"Packages/C++/C Single File.sublime-build",
					""
				],
				[
					"Packages/C++/C Single File.sublime-build",
					"Run"
				],
				[
					"Packages/User/eigsol_gpu.sublime-build",
					""
				]
			],
			[
				"Packages/C++/C Single File.sublime-build",
				""
			]
		]
	],
	"build_varint": "",
	"command_palette":
	{
		"height": 0.0,
		"last_filter": "",
		"selected_items":
		[
			[
				"View",
				"View Package File"
			],
			[
				"Color",
				"Colorsublime: Install Theme"
			],
			[
				"Pack",
				"Package Control: Install Package"
			],
			[
				"Install Pack",
				"Package Control: Install Package"
			],
			[
				"Package Insta",
				"Package Control: Install Package"
			],
			[
				"Color Sch",
				"UI: Select Color Scheme"
			],
			[
				"Install Pac",
				"Package Control: Install Package"
			],
			[
				"Package",
				"Install Package Control"
			],
			[
				"View ",
				"View Package File"
			]
		],
		"width": 0.0
	},
	"console":
	{
		"height": 0.0,
		"history":
		[
		]
	},
	"distraction_free":
	{
		"menu_visible": true,
		"show_minimap": false,
		"show_open_files": false,
		"show_tabs": false,
		"side_bar_visible": false,
		"status_bar_visible": false
	},
	"expanded_folders":
	[
		"/D/dev/eigsol_gpu"
	],
	"file_history":
	[
		"/D/dev/eigsol_gpu/build.bat",
		"/C/Users/anton/AppData/Roaming/Sublime Text 3/Packages/User/buildbat.sublime-build",
		"/D/dev/eigsol_gpu/eigsol_gpu.sublime-build",
		"/D/dev/eigsol_gpu/eigsol_gpu.sublime-project",
		"/D/repos/raddebugger/src/base/base_arena.h",
		"/D/repos/raddebugger/src/base/base_core.h",
		"/D/repos/raddebugger/src/base/base_command_line.c",
		"/C/Users/anton/AppData/Roaming/Sublime Text 3/Packages/Default/Default (Windows).sublime-keymap",
		"/C/sbs/sb1/java/guidesign/src/com/comsol/guidesign/views/%USER%",
		"/C/Users/antonlj/AppData/Roaming/Sublime Text 3/Packages/Colorsublime/Colorsublime.sublime-settings",
		"/C/Users/antonlj/AppData/Roaming/Sublime Text 3/Packages/User/Colorsublime.sublime-settings",
		"/C/sbs/sb1/java/guidesign/src/com/comsol/guidesign/actions/DesignCreatorActionFactory.java",
		"/C/sbs/sb1/java/design/src/com/comsol/design/operations/DesignOperation.java",
		"/C/Users/antonlj/AppData/Roaming/Sublime Text 3/Packages/Default/symbol.py",
		"/C/Program Files/Sublime Text 3/Packages/Default.sublime-package",
		"/C/Users/antonlj/AppData/Roaming/Sublime Text 3/Packages/User/Preferences.sublime-settings",
		"/C/sbs/sb1/java/testgui/src/com/comsol/testgui/builder/TBuilderFeatures.java",
		"/C/Users/antonlj/AppData/Roaming/Sublime Text 3/Packages/Default/Preferences.sublime-settings"
	],
	"find":
	{
		"height": 25.0
	},
	"find_in_files":
	{
		"height": 103.333333333,
		"where_history":
		[
		]
	},
	"find_state":
	{
		"case_sensitive": false,
		"find_history":
		[
		],
		"highlight": true,
		"in_selection": false,
		"preserve_case": false,
		"regex": false,
		"replace_history":
		[
		],
		"reverse": false,
		"show_context": true,
		"use_buffer2": true,
		"whole_word": false,
		"wrap": true
	},
	"groups":
	[
		{
			"selected": 0,
			"sheets":
			[
				{
					"buffer": 0,
					"file": "src/main.c",
					"semi_transient": false,
					"settings":
					{
						"buffer_size": 9529,
						"regions":
						{
						},
						"selection":
						[
							[
								8726,
								8726
							]
						],
						"settings":
						{
							"syntax": "Packages/C++/C.sublime-syntax",
							"tab_size": 2,
							"translate_tabs_to_spaces": true
						},
						"translation.x": 0.0,
						"translation.y": 4414.0,
						"zoom_level": 1.0
					},
					"stack_index": 0,
					"type": "text"
				},
				{
					"buffer": 1,
					"file": "src/os/os_core.h",
					"semi_transient": false,
					"settings":
					{
						"buffer_size": 2543,
						"regions":
						{
						},
						"selection":
						[
							[
								635,
								635
							]
						],
						"settings":
						{
							"syntax": "Packages/C++/C++.sublime-syntax",
							"tab_size": 2,
							"translate_tabs_to_spaces": true
						},
						"translation.x": 0.0,
						"translation.y": 0.0,
						"zoom_level": 1.0
					},
					"stack_index": 1,
					"type": "text"
				},
				{
					"buffer": 2,
					"file": "build.bat",
					"semi_transient": false,
					"settings":
					{
						"buffer_size": 1425,
						"regions":
						{
						},
						"selection":
						[
							[
								1425,
								1425
							]
						],
						"settings":
						{
							"syntax": "Packages/Batch File/Batch File.sublime-syntax"
						},
						"translation.x": 0.0,
						"translation.y": 0.0,
						"zoom_level": 1.0
					},
					"stack_index": 2,
					"type": "text"
				}
			]
		},
		{
			"sheets":
			[
			]
		}
	],
	"incremental_find":
	{
		"height": 25.0
	},
	"input":
	{
		"height": 0.0
	},
	"layout":
	{
		"cells":
		[
			[
				0,
				0,
				1,
				1
			],
			[
				1,
				0,
				2,
				1
			]
		],
		"cols":
		[
			0.0,
			0.5,
			1.0
		],
		"rows":
		[
			0.0,
			1.0
		]
	},
	"menu_visible": true,
	"output.exec":
	{
		"height": 425.0
	},
	"output.find_results":
	{
		"height": 0.0
	},
	"pinned_build_system": "Packages/User/buildbat.sublime-build",
	"project": "eigsol_gpu.sublime-project",
	"replace":
	{
		"height": 46.0
	},
	"save_all_on_build": true,
	"select_file":
	{
		"height": 0.0,
		"last_filter": "",
		"selected_items":
		[
			[
				"eig",
				"eigsol_gpu.sublime-build"
			],
			[
				"eigsol",
				"eigsol_gpu.sublime-build"
			],
			[
				"build",
				"build.bat"
			],
			[
				"",
				"src\\main.c"
			],
			[
				"main",
				"src\\main.c"
			],
			[
				"base_are",
				"src\\base\\base_arena.h"
			],
			[
				"base_core",
				"src\\base\\base_core.h"
			],
			[
				"BuilderInf",
				"design\\src\\com\\comsol\\design\\util\\link\\BuilderInfoVisitor.java"
			],
			[
				"DesignPhysicsM",
				"design\\src\\com\\comsol\\design\\DesignPhysicsMaker.java"
			],
			[
				"TBuilderFeat",
				"testgui\\src\\com\\comsol\\testgui\\builder\\TBuilderFeatures.java"
			]
		],
		"width": 0.0
	},
	"select_project":
	{
		"height": 0.0,
		"last_filter": "",
		"selected_items":
		[
		],
		"width": 0.0
	},
	"select_symbol":
	{
		"height": 392.0,
		"last_filter": "",
		"selected_items":
		[
			[
				"DesignPhysicsMak",
				"DesignPhysicsMaker"
			],
			[
				"DeviceModelFeatu",
				"DeviceModelFeatureOperation"
			]
		],
		"width": 592.0
	},
	"selected_group": 0,
	"settings":
	{
	},
	"show_minimap": false,
	"show_open_files": false,
	"show_tabs": true,
	"side_bar_visible": false,
	"side_bar_width": 145.0,
	"status_bar_visible": true,
	"template_settings":
	{
	}
}
