Skip to content

Instantly share code, notes, and snippets.

View AndrewGaspar's full-sized avatar
🏎️
let's make it fast

Andrew Gaspar AndrewGaspar

🏎️
let's make it fast
View GitHub Profile
@AndrewGaspar
AndrewGaspar / global_arena.rs
Created April 30, 2020 15:14
Global Arena Rust
use std::cell::RefCell;
// `generational_arena` is a special type of arena that allows elements to be recycled, and the
// handles allocated from the arena do not hold a borrow on the arena. The handles are later used to
// retrieve concrete borrows on the arena temporarily. The check for live-ness is essentially
// performed at runtime, rather than being checked by the borrow checker.
use generational_arena::{Arena, Index};
// Allocate `ARENA` at global/thread scope. The arena is wrapped in a RefCell so we can get
// runtime-checked mutable borrows of the arena.

Keybase proof

I hereby claim:

  • I am andrewgaspar on github.
  • I am angasp (https://keybase.io/angasp) on keybase.
  • I have a public key ASCnI6uAMSHKa9yuy0uElVqSHwwbwed0ZB_PBP6OC8qzvQo

To claim this, I am signing this object:

@AndrewGaspar
AndrewGaspar / repro.cpp
Created February 20, 2020 06:32
Immediate barrier not completed on all ranks when interleaved with point to point communication
// STL Includes
#include <algorithm>
#include <vector>
#include <cstdint>
#include <iostream>
// Third Party Includes
#include <mpi.h>
using std::uint64_t;
#include <cstddef>
#include <cstdio>
struct A
{
int a;
};
struct B
{
@AndrewGaspar
AndrewGaspar / test.rs
Created February 15, 2018 05:14
Safe buffer access for MPI Receive RequestCollections
struct RequestCollection<'a, T: 'a + Copy> {
handles: Vec<bool>,
buffers: Vec<&'a mut [T]>,
}
impl<'a, T: 'a + Copy> RequestCollection<'a, T> {
fn new() -> Self {
RequestCollection {
handles: Vec::new(),
buffers: Vec::new(),
@AndrewGaspar
AndrewGaspar / vector-add-benchmarks.rs
Created December 21, 2017 00:32
Vector Add Benchmarks
#![feature(test)]
extern crate test;
#[macro_use] extern crate itertools;
use test::Bencher;
const VEC_SIZE: usize = 10000;
#[bench]
var queryResultsPromise = readListOfQueriesAsync("config.xml")
.then(function(queries) {
return promise.all(
queries.map(searchQueryAsync)
);
}).then(function(queryResults) {
return writeOutAsync(queryResults);
});
@AndrewGaspar
AndrewGaspar / typical.js
Last active December 24, 2015 15:49
Some typical asynchronous behavior
function handleFoobar(error, foobar) {
if(error) output(error);
var bar = deFoo(foobar);
// Matrix multiplication or something
output(bar);
}
fooButton.on("click", function (evt) {
$.get("/foobar/1", handleFoobar);

Asynchronous Javascript Notes

Unique problems for Javascript:

  • JavaScript is single threaded
  • Most I/O is performed asynchronously in JavaScript (by design)
  • On client side
    • App is driven by user input
    • Most CPU work presumably done by DOM
  • On server side