Skip to content

Instantly share code, notes, and snippets.

View JBlaschke's full-sized avatar

Johannes Blaschke JBlaschke

View GitHub Profile
@JBlaschke
JBlaschke / OpenMP_offload_object_composition.cpp
Created April 30, 2020 15:52 — forked from jmeyers314/OpenMP_offload_object_composition.cpp
OpenMP c++ GPU offload with object composition
#include <new>
#include <vector>
#include <iostream>
#pragma omp declare target
// polymorphic Abstract Base Class
class Base {
public:
virtual double doOne(double x) = 0; // do something interesting
virtual Base* getDevPtr() = 0; // get a device pointer to device shadow instance of class
@JBlaschke
JBlaschke / mpi4py_pycuda_demo.py
Created December 28, 2020 18:16 — forked from lebedov/mpi4py_pycuda_demo.py
Demo of how to pass GPU memory managed by pycuda to mpi4py.
#!/usr/bin/env python
"""
Demo of how to pass GPU memory managed by pycuda to mpi4py.
Notes
-----
This code can be used to perform peer-to-peer communication of data via
NVIDIA's GPUDirect technology if mpi4py has been built against a
CUDA-enabled MPI implementation.
@JBlaschke
JBlaschke / string.split.lua
Created May 24, 2023 22:28 — forked from jaredallard/string.split.lua
string.split in lua
-- split a string
function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end

A metatable can be defined like

local t = setmetatable({}, {
  __tostring = function() return 'custom tostring behavior!' end
})

Here are the metamethods that you can define, and their behavior

Operators