Skip to content

Instantly share code, notes, and snippets.

View ibaned's full-sized avatar

Dan Ibanez ibaned

  • Sandia National Laboratories
  • Albuquerque, NM
View GitHub Profile
@ibaned
ibaned / string_array.c
Created April 21, 2012 00:29
functions for handling arrays of strings
char* create_string_buffer(unsigned number_of_strings, unsigned max_string_length)
{
return (char*) malloc(number_of_strings*max_string_length);
}
void copy_string_into_buffer(char* buffer, unsigned index, unsigned max_string_length, char* string)
{
strncpy(buffer + (max_string_length*index), string, max_string_length);
}
@ibaned
ibaned / copy_by_cd.c
Created April 22, 2012 14:53
copying file between directories without pathname manipulation
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#define CALL(f) assert(0==(f))
#define PCALL(f) assert(NULL!=(f))
#define BUFFER_SIZE 256
//this program copies dir1/filename to dir2/filename
@ibaned
ibaned / fits.c
Created May 22, 2012 20:10
FITS file processor
#include <stdio.h>
#include <fitsio.h>
#include <dirent.h>
#include <string.h>
#include <mpi.h>
/*If status != 0, report the error and return 1.*/
#define FITS_ERROR_CHECK if(status){fits_report_error(stdout, status); return 1;}
int countNumFits(int limit, char * dir);
@ibaned
ibaned / quine.c
Created August 15, 2012 13:06
My solution to the quine problem: a program that prints itself
#include<stdio.h>
#include<string.h>
void p(const char*c,int d)
{
for(;d;++c,--d)
putchar(*c);
}
void q(const char*c,int d)
{
for(;d;++c,--d)
@ibaned
ibaned / deadlock.c
Last active December 30, 2015 03:59
hybrid MPI/thread program that deadlocks on Blue Gene/Q
/* This program should be run on a single Blue Gene/Q node
using 5 or more parallel processes and 8 threads per process
(threads per process is the only argument to the program)
mpirun -np 5 ./deadlock 8
It has a high probability of going into a deadlocked state
(or at least timing out at 5~10 minutes).
The probability increases as LOOPS is increased */
#include <mpi.h>
#include <pthread.h>
@ibaned
ibaned / 2048.c
Created May 13, 2014 22:11
a simple C version of the popular 2048 game
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <termios.h>
#include <unistd.h>
#define SIZE 4
struct game {
int tiles[SIZE][SIZE];
@ibaned
ibaned / orientation.cc
Last active August 29, 2015 14:05
parallel element-to-element orientation arrays
#include <apfMesh.h>
#include <apfNumbering.h>
#include <PCU.h>
static int getOrientationCode(
int side_i,
long* verts,
int other_side_i,
long* other_verts)
{
@ibaned
ibaned / first.sh
Last active August 28, 2015 15:06
two-script solution to getting a 1B element case going
#!/bin/sh
#SBATCH --job-name=make1B
#SBATCH -t 02:00:00
## are we in fact able to do this with 16 ranks per node ?
#SBATCH -N 64
#SBATCH -n 1024
#SBATCH --partition small
#SBATCH -D /gpfs/u/scratch/PGES/PGESzhnl/Test/10x10/mesh
set +xe
EXE_DIR=/gpfs/u/home/PGES/PGESgnzw/scratch/core/build/test
#include <apf.h>
#include <gmi_null.h>
#include <apfMDS.h>
#include <apfMesh2.h>
#include <PCU.h>
#include <apfNumbering.h>
#include <apfShape.h>
#include <iostream>
#include <stdbool.h>
#!/home/dibanez/install/ParaView-5.1.0-Qt4-OpenGL2-MPI-Linux-64bit/bin/pvpython
import sys
from paraview import simple
reader = simple.OpenDataFile(sys.argv[1])
writer = simple.CreateWriter("copied.vtu", reader)
writer.DataMode = "Ascii"
writer.UpdatePipeline()