Skip to content

Instantly share code, notes, and snippets.

View yzchen's full-sized avatar
🏠
Working from home

yzchenmonkey yzchen

🏠
Working from home
  • HeFei, Anhui, China
View GitHub Profile
@yzchen
yzchen / macro.c
Created January 9, 2019 19:48
how to use macro to generate function names like a factory
#define CONCAT_2_EXPAND(A, B) A ## B
#define CONCAT_2(A, B) CONCAT_2_EXPAND(A, B)
#define CONCAT_3_EXPAND(A, B, C) A ## B ## C
#define CONCAT_3(A, B, C) CONCAT_3_EXPAND(A, B, C)
#define Vector_(NAME) CONCAT_3(Num, Vector_, NAME)
#define Vector CONCAT_2(Num, Vector)
#define num float
#define Num Float
@yzchen
yzchen / double-free.cc
Created January 9, 2019 19:47
A test about double free error, need a copy constructor
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
// This is a test about double free error
// You need to add a copy constructor for class Test
class Test{
int *myArray;
@yzchen
yzchen / gatherv.c
Created January 9, 2019 19:44
MPI_Gatherv function testing
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mpi.h"
#define nstrings 5
const char *const strings[nstrings] = {"Hello","world!","Bonjour","le","monde!"};
int main(int argc, char **argv) {
@yzchen
yzchen / sbatch.sh
Last active January 9, 2019 19:40
Slurm job script template
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=4
#SBATCH --ntasks-per-node=4 # 4 tasks per node
#SBATCH --gres=gpu:4 # 4 GPUs per node
#SBATCH --exclusive
#SBATCH --partition=batch
#SBATCH -J p1-weak
#SBATCH -o /scratch/P100-Exps/Weak/logs/p1.out
#SBATCH -e /scratch/P100-Exps/Weak/errs/p1.err
@yzchen
yzchen / test-mpi.py
Created January 9, 2019 19:37
mpi4py usage
import random
from mpi4py import MPI
comm = MPI.COMM_WORLD
# each thread will have different rank, we treat 0 as master, others as slave
rank = comm.Get_rank()
# total number of threads
size = comm.Get_size()