Skip to content

Instantly share code, notes, and snippets.

View siddharths2710's full-sized avatar
🚩
Contributions - Off

Siddharth Srinivasan siddharths2710

🚩
Contributions - Off
View GitHub Profile
@siddharths2710
siddharths2710 / FW.cpp
Created May 12, 2017 05:44
Basic implementation of Floyd Warshall Algorithm.
#include <iostream>
#include <conio.h>
#include <climits>
using namespace std;
#define INF INT_MAX
void FloydWarshall(int **dist,int n)
{
int i, j, k;
10000
233
201
298
348
135
183
105
245
36
@siddharths2710
siddharths2710 / gap.py
Created April 2, 2017 15:20
GAP for CALIC
import numpy as np
from skimage import data,io
import matplotlib.pyplot as plt
def get(im, i, j):
if 0 <= i < im.shape[0] and 0 <= j < im.shape[1]:
return im[i, j]
return 0
def GAP(im, i, j):
@siddharths2710
siddharths2710 / Knapsack_Parallel.c
Last active November 3, 2020 11:48
Parallel implementation of the Knapsack Problem
/*
The Memory function is aligned to 64 byte boundary between values so that
the contents of the Memory Function "F" are spaced far enough to correct
False Sharing.
Note the __attribute__ compiler directive for this purpose in the 'elem' struct
//so that we can index "F" as a normal 2D array whist the compiler takes care
//of indirect addressing and any extra offsetting required (Instead of explicit mention).
Function used to allocate Dynamic Memory:
@siddharths2710
siddharths2710 / Knapsack_1_transpose.c
Created January 23, 2017 10:59
Transpose implementation of the Knapsack Algorithm
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <omp.h>
int knapsack(int, int);
int max(int, int);
int n;
int* weights;
int* values;
int W;
5
1 2 4 3 5
10 5 41 30 52
8
@siddharths2710
siddharths2710 / Knapsack_2.c
Created January 17, 2017 15:29
Computing Memory Function of the Knapsack Algorithm to its entirety
#include <stdio.h>
#include <stdlib.h>
int MFKnapsack(int, int); //Function returning the optimal value for a given n and W
void knapsack(int,int); //Function used to populate the Knapsack Memory Function
int max(int, int);
int n;
int* weights;
int* values;
int W;
int** F;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int knapsack(int, int); //Returns the required optimal value by creating part of the Memory Function
int max(int, int);
int n;
int* weights; //Array containing weights of all items
int* values; //Array containing value of all items
int W; //Capacity of KnapSack
int** F; //Memory Function