Skip to content

Instantly share code, notes, and snippets.

@U-MA
U-MA / gist:7546810
Last active December 28, 2015 18:59
typedef struct distnce
{
int *cost;
} distance;
typedef struct problem
{
distance dist;
} problem;
__global__ void kernel(...)
{
__shared__ int candidates[32], candidateSize;
int customer = threadIdx.x;
candidateSize = 0;
if (customer < 32 && !isVisited(customer))
{
atomicAdd(&candidate[candidateSize], customer);
atomicAdd(&candidateSize, 1);
__global__ void kernel(...)
{
__shared__ int candidates[32], candidateSize;
int customer = threadIdx.x;
candidateSize = 0;
if (customer < 32 && !isVisited(customer))
{
int old = atomicAdd(&candidateSize, 1);
candidate[old] = customer;
/* 図6.4の改良
* テキストと同様にグローバルメモリとshared memoryの間のコピーは省略
*/
__global__ reduction_kernel(float *array)
{
extern __shared__ float patrialSum[];
unsigned int t = threadIdx.x;
for (unsigned int stride = blockDim.x; stride > 0; stride >>= 1)
/* 図6.2の改良
* テキストと同様にグローバルメモリと共有メモリの間のコピーは除いている
*/
__global__ void reduction_kernel(float *array)
{
extern __shared__ float partialSum[];
unsigned int t = 2*threadIdx.x;
for (unsigned int stride = 1; stride <= blockDim.x; stride *= 2)
@U-MA
U-MA / exercise0603.cpp
Last active December 30, 2015 03:39
CUDA プログラミング実践講座 6.8演習 6.3
/* CUDA プログラミング実践講座 演習6.3の解答 */
/* 図6.2の改良版 */
__global__ void reduction_kernel0602(float *array)
{
extern __shared__ float partialSum[];
unsigned int tid = threadIdx.x;
unsigned int bid = blockIdx.x;
unsigned int arrayIdx = bid * blockDim.x + (2*tid); /* (2) */
/*
* this code is refered from Figure 1 of CUDA COMPILER DRIVER NVCC
* Reference Guide (TRM-06721-001_V5.5).
*
* CUDA COMPILER DRIVER NVCC Reference Guide
* http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html
*/
const int ACOS_TESTS = 5;
const int ACOS_THREAD_CNT = 128;
@U-MA
U-MA / near.java
Last active August 29, 2015 14:03
ArrayList<Sensor> nearest_neighbor(ArrayList<Sensor> field, User u)
{
double a = 28.29;
// 構築された経路
ArrayList<Sensor> route = new ArrayList<Sensor>();
// 次のノードの候補
ArrayList<Sensor> R = new ArrayList<Sensor>();
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Random;
// 普通のセンサクラス
class SensorBase {
private Point2D.Double position;
private double battery;
#include <stdio.h>
#include <stdlib.h>
// read the array a of n elements from fp
void reada(FILE *fp, int *a, int *n);
// output the array a of n elements
void printa(int *a, int n);
// randomized quick sort