This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct distnce | |
{ | |
int *cost; | |
} distance; | |
typedef struct problem | |
{ | |
distance dist; | |
} problem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 図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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 図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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
OlderNewer