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 / 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()
@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 / 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 / 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 / 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 / vector-merge.cc
Last active January 9, 2019 19:51
merge 2-d arrays(store them as 1-d vector, because it's easy to serialize)
#include <iostream>
#include <vector>
using namespace std;
#define IndexType int
void merge_local_vectors(vector<IndexType> &first, vector<IndexType> &second, int pair_size1, int pair_size2, int key1, int key2) {
int ssz1 = first.size(), ssz2 = second.size();
int i = 0, j = 0;
@yzchen
yzchen / test-qsort.c
Created January 9, 2019 19:55
qsort on struct, using one field as pivot to compare
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a, b, c;
}Int3;
int comp (const void * elem1, const void * elem2) {
Int3 f = *((Int3*)elem1);
Int3 s = *((Int3*)elem2);
@yzchen
yzchen / test-read.c
Last active April 28, 2019 18:29
benchmark c read functions
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#define BUFFER_SIZE (1 * 1024 * 1024)
#define ITERATIONS (10 * 1024)
@yzchen
yzchen / file-server.go
Created January 9, 2019 20:01
open a file server with golang
package main
import (
"fmt"
"net/http"
)
const PORT = "7777"
func main() {
fmt.Println("Start listening on port " + PORT)
@yzchen
yzchen / colorful-print-in-bash.sh
Created February 19, 2019 09:32
print things with color
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
RED='\033[0;31m'