Skip to content

Instantly share code, notes, and snippets.

View qqwqqw689's full-sized avatar
:octocat:

qqwqqw689

:octocat:
  • China
View GitHub Profile
@qqwqqw689
qqwqqw689 / nextPowerOfTwo.cpp
Created May 16, 2024 15:28
A function to find the next power of two greater than a given number.
#include <iostream>
#include <bitset>
typedef unsigned int uint;
static uint nextPowerOfTwo(uint x) {
std::bitset<32> a(x);
std::cout << a << '\n';
--x;
a = x;
@qqwqqw689
qqwqqw689 / dup2.c
Last active March 17, 2024 15:31
dup2
#define _POSIX_SOURCE
// If you define this macro, then the functionality from
// the POSIX.1 standard (IEEE Standard 1003.1) is available
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#undef _POSIX_SOURCE
#include <stdio.h>
@qqwqqw689
qqwqqw689 / membenchmark.c
Created March 15, 2024 02:17
memory access benchmarking program(MS).
#include <stdio.h>
#include <time.h>
#include <tchar.h>
#define ARRAY_MIN (1024) /* 1/4 smallest cache */
#define ARRAY_MAX (4096*4096) /* 1/4 largest cache */
int x[ARRAY_MAX]; /* array going to stride through */
double get_seconds() { /* routine to read time in seconds */
__time64_t ltime;
_time64(&ltime);
@qqwqqw689
qqwqqw689 / prlimit.c
Created February 23, 2024 07:53
prlimit function
#define _GNU_SOURCE
/*
If you define this macro, everything is included: ISO C89, ISO C99,
POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.
*/
#define _FILE_OFFSET_BITS 64
/*
This macro determines which file system interface
shall be used, one replacing the other.
*/
@qqwqqw689
qqwqqw689 / MPILOOP.c
Last active February 23, 2024 07:55
MPI-split-loop
#include <stdio.h>
#include <mpi.h>
int main (int argc, char *argv[])
{
int rank, comm_size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &comm_size);