Welcome, Guest

Author Topic: Coding  (Read 276159 times)

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Coding
« Reply #360 on: February 07, 2014, 03:28:21 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '117061'.

« Last Edit: March 22, 2021, 01:07:37 AM by FiahOwl »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Coding
« Reply #361 on: February 07, 2014, 03:55:28 PM »
Here it is:

Time Dilation Visualization

The code:

Code: [Select]
% Timestep
dt = 0.025;
% Properties of clocks
x1 = 0;     y1 = 1;
x2 = 0;     y2 = 2;         vx2 = 0.75;     t2 = 0;
x3 = 0;     y3 = 3;         vx3 = 0.95;     t3 = 0;
% Properties of light particles in clocks
x1l = 0;    y1l = y1-0.25;                  vy1l = 1;
x2l = 0;    y2l = y2-0.25;  vx2l = vx2;     vy2l = sqrt(1-vx2.^2);
x3l = 0;    y3l = y3-0.25;  vx3l = vx3;     vy3l = sqrt(1-vx3.^2);
% Properties of light wave (black line)
xl = 0;                     vxl = 1;
% Gamma factor of clocks
g2 = 1/sqrt(1-(vx2.^2));
g3 = 1/sqrt(1-(vx3.^2));
% Figure properties
scrsz = get(0,'ScreenSize'); % Get screen resolution
figure('OuterPosition',[0 50 scrsz(3) scrsz(4)-50]) % Figure window set to fill the screen except bottom 50 pixels
for t=0:dt:10
    plot(x1, y1, 'sr', 'MarkerFaceColor', 'r', 'MarkerSize', 1); hold on; % This ensures that the plot works
    % Feynman-clock rectangles
    patch([x1-0.1 x1-0.1 x1+0.1 x1+0.1],[y1-0.25 y1+0.25 y1+0.25 y1-0.25],'r');
    patch([x2-0.1 x2-0.1 x2+0.1 x2+0.1],[y2-0.25 y2+0.25 y2+0.25 y2-0.25],'g');
    patch([x3-0.1 x3-0.1 x3+0.1 x3+0.1],[y3-0.25 y3+0.25 y3+0.25 y3-0.25],'b');
    % Light particles in clocks
    plot(x1l, y1l, 'sk', 'MarkerFaceColor', 'k', 'MarkerSize', 5);
    plot(x2l, y2l, 'sk', 'MarkerFaceColor', 'k', 'MarkerSize', 5);
    plot(x3l, y3l, 'sk', 'MarkerFaceColor', 'k', 'MarkerSize', 5);
    % Lines at x-axis
    line([x1 x1], [0 0.25], 'Color', 'r');
    line([x2 x2], [0 0.25], 'Color', 'g');
    line([x3 x3], [0 0.25], 'Color', 'b');
    line([xl xl], [0 0.25], 'Color', 'k');
    hold off;
    % Axis properties
    axis([-0.5, 10.5, 0, 4]) % Format: [xmin, xmax, ymin, ymax].
    xlabel('x-distance [ct]') % X-axis label.
    ylabel('y-distance [ct]') % Y-axis label.
    set(gca,'ytick',[0 0.5 1 1.5 2 2.5 3 3.5 4])
    set(gca,'xtick',[-0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5])
    % Display text in plot
    text(x1, 0.5, ['Black line (light), velocity = ', num2str(1),' c'])
    text(x1, y1+0.5, ['Red Feynman clock, velocity = ', num2str(0),' c, gamma = ', num2str(1),' time = ', num2str(round(t*10)/10),' s'])
    text(x1, y2+0.5, ['Green Feynman clock, velocity = ', num2str(vx2),' c, gamma = ', num2str(round(g2*10)/10),' time = ', num2str(round(t2*10)/10),' s'])
    text(x1, y3+0.5, ['Blue Feynman clock, velocity = ', num2str(vx3),' c, gamma = ', num2str(round(g3*10)/10),' time = ', num2str(round(t3*10)/10),' s'])
    % Display time next to objects
    text(x1+0.25, y1, [num2str(round(t*10)/10),' s'])
    text(x2+0.25, y2, [num2str(round(t2*10)/10),' s'])
    text(x3+0.25, y3, [num2str(round(t3*10)/10),' s'])
    drawnow();
    % Update x-coordinates of moving frames and lightwave
    x2 = x2 + vx2*dt;
    x3 = x3 + vx3*dt;
    xl = xl + vxl*dt;
    % Update time for moving frames
    t2 = t2 + dt/g2;
    t3 = t3 + dt/g3;
    % Update coordinates of light particles in clocks
    y1l = y1l + vy1l*dt;
    x2l = x2l + vx2l*dt;
    y2l = y2l + vy2l*dt;
    x3l = x3l + vx3l*dt;
    y3l = y3l + vy3l*dt;
    % Make light particles in clocks bounce (reverse velocities)
    if (y1l >= y1+0.25) || (y1l <= y1-0.25)
        vy1l = vy1l*(-1);
    end
    if (y2l >= y2+0.25) || (y2l <= y2-0.25)
        vy2l = vy2l*(-1);
    end
    if (y3l >= y3+0.25) || (y3l <= y3-0.25)
        vy3l = vy3l*(-1);
    end
    % Pause at start
    if t == 0
        pause(2);
    end
end

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #362 on: February 07, 2014, 09:02:31 PM »
another framework for musics and sample

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #363 on: February 08, 2014, 10:03:02 PM »
here's a text editor in python. it's pretty basic and i hacked it together in about half an hour but it does have some features

it'll print out how many characters of text you have every hundred seconds, which is useful for seeing how much you've done

the first ten characters (or less) of the first line becomes the title

backups are saved every hundred seconds with the title and the timestamp
the editor also records how much text you have every second and writes it to a log every hundred seconds.

of course put this in a folder before using -- it spawns about 72 files per hour. which probably need to be frequently cleared. in anycase i just wanted to see how my writing speed is over the course of a research paper

requires tkinter which is probably installed already

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #364 on: February 10, 2014, 01:55:34 PM »
and here are the results of the above experiment with time on the x axis and characters on the y axis. if you download the svg you can actually zoom it and see the individual seconds.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #365 on: February 11, 2014, 10:54:20 PM »
Code: [Select]
import numpy as np

def a_rk4(h, t, v, f): #t is a scalar, v is a vector, f is a function of a vector, h is a function of a scalar
    s = h(np.linalg.norm(f(v)))
    k1 = f(t, v)
    k2 = f(t+s/2,v+s*k1/2)
    k3 = f(t+s/2,v+s*k2/2)
    k4 = f(t+s,v+s*k3)
    return v + h*(k1+2*k2+2*k3+k4)/6

adaptive runge kutta integrator. i'll explain how it works
t is the variable you're integrating with respect to, in most cases, time.
v is the vector. it could just be x, or [x,y], or [x,y,z] for a 3d gravity simulator
f is a function of vector v, in the case of gravitational attraction to the origin it might be 1/(x**2+y**2)
of course if you have multiple points you'll have to loop over them and get the sum.
h is the adaptive time step. for example, you might set it to be 1/x, so time step is inversely proportional to force, so that accuracy is maintained

if you see i multiply and add the vectors using numpy arrays. it would be possible to do so without numpy but then i'll also have to add an argument for an adding and multiplying function and this is just simpler i think

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #366 on: February 12, 2014, 06:50:21 PM »

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Coding
« Reply #367 on: February 13, 2014, 04:53:07 AM »
Amazing

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Coding
« Reply #368 on: February 13, 2014, 06:54:41 AM »
that makes a lot more sense than the wierd swirlies you had

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #369 on: February 15, 2014, 12:26:48 PM »

movie coder/decoder in python
i suspect there's an error i haven't found but i'm done with this project
the code is unreadable btw

i created a custom movie codec and it is really buggy.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #370 on: February 15, 2014, 02:31:12 PM »
niceplot2 with some updates

-you can pick font size now
-unicode support
-option to automatically plot ticks at mean and standard deviations
-bounds of plot is not determined by numbers but my standard deviations
-bounds of plot do not have to be symmetric anymore
-ticks can have custom labels

sample included

matty406

  • *****
  • Posts: 82
Re: Coding
« Reply #371 on: February 15, 2014, 03:10:49 PM »

movie coder/decoder in python
i suspect there's an error i haven't found but i'm done with this project
the code is unreadable btw

i created a custom movie codec and it is really buggy.
It's perfect don't change anything

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #372 on: February 18, 2014, 06:14:02 PM »
polygon collision detection that comes with examples. you can just run the script

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #373 on: February 21, 2014, 02:58:47 PM »
Code: [Select]
import numpy as np
import math

n_body = lambda bodies, accel_function = lambda a, b: (a[4]+b[4])/math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2), dintegrator = lambda a, b, t, f, d: lambda a, b, t, f, d, integrator = lambda a, b, t, f, d: np.concantenate(a[:2],a[2:4]+[np.cos(d), np.sin(d)]*t*f(a,b),a[4:]): np.concantenate(a[:2]+t*a[2:4], a[2:]), timestep = 1.0: map(lambda a: np.concantenate(a[:4]+sum((dintegrator(a, b, timestep, accel_function, d = math.atan2(a[1]-b[1], a[0], b[0])) for b in bodies)), a[4:]), bodies)

#body is in the format [posx, posy, velx, vely, mass, ...]
#all vectors are numpy arrays

a one line n-body simulator (aka gravity sim).
« Last Edit: February 21, 2014, 03:13:17 PM by vh »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #374 on: February 21, 2014, 05:50:16 PM »
uranium enrichment simulation. completed but there are bugs.

should i continue it?

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #375 on: February 22, 2014, 12:00:17 PM »
right. update of uranco which actually works now. if you haven't figured it out yet, this is a simulator where you can put together a uranium enrichment cluster and test how well it works. when you run it, four numbers will be shown

Code: [Select]
4761.9047619 0.0077
5238.0952381 0.00636363636364

this means that there are 4761.9 units of ore enriched to 0.0077 and 5238.09 units of ore disposed with 0.00636 enrichment. obviously this isn't a good uranium enricher

does anyone want a gui for this

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #376 on: February 22, 2014, 06:42:27 PM »
this simulates a crystal growing. i haven't made the graph animated yet, so you'll just have to close the window and another one will pop up. 10 steps are simulated between each stage.

unfortunately the way i structured the code makes it relatively inflexible. the only thing that'll happen is a strangely shaped circle

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #377 on: February 24, 2014, 06:34:54 PM »
this code illustrates the depletion force which causes particles to be 'attracted' to each other and the edges of the container.

shown are histograms (binned and smoothed) of the location of particle positions. note the exponentially decaying wave

https://en.wikipedia.org/wiki/Depletion_force

i've also updated niceplot two with two more arguments, bw and cov, both of which seem to do the same thing, which is to determine how smooth the gaussian kde is

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #378 on: February 25, 2014, 10:01:30 PM »
blalert.pyw is a blacraft alert. upon finding that there is a player on the server (after a period where no one is on), it will emit a 3 second long beep. for each additional player that joins, a one second beep will follow.


this should run without a window appearing. if it doesn't work or you want a window remove the w in the fiel name.

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Coding
« Reply #379 on: February 25, 2014, 10:09:27 PM »
kol a such excellent

Bla

  • Global Moderator
  • *****
  • Posts: 1013
  • The stars died so you can live.
Re: Coding
« Reply #380 on: February 26, 2014, 01:46:16 PM »
Kol, nice program.
I tried double-clicking it, it said a beep-sound when it started, but besides from that I didn't see or notice anything from the program. I tried logging on Blacraft after opening it, it didn't react. I haven't been on Blacraft since the weekend.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #381 on: February 26, 2014, 02:28:58 PM »
the problem was that the code thought empty string counted as one player, so even when the server was empty it thought there was someone on. don't know how i missed that bug. here's the fix.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #382 on: February 26, 2014, 03:26:56 PM »
cloud coding thingy which comes with a vm to let you run online collaboratively.

referral link (gives me and you an extra 1gb):
https://koding.com/R/osmotischen

you can register with github
« Last Edit: February 26, 2014, 03:40:45 PM by vh »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #383 on: February 28, 2014, 10:42:13 PM »
scrapes historical eod stock market data which you usually can't get for free from yahoo. the symbols.txt file you need is here:
Code: [Select]
ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqlisted.txt

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #384 on: March 04, 2014, 09:28:40 PM »
c++ application that computes the number of primes from one to n. run it, then enter the number n, then enter the number of times you want to run it. it is quite optimized. i can't release the source code yet but i will. the first number printed for each trial is the count, the second is the number of miliseconds taken.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #385 on: March 05, 2014, 04:07:08 PM »
wrapper for the pycrypto, exchange keys and shit. will be used to send encrypted messages over irc. not tested yet.

https://pypi.python.org/pypi/pycrypto

installation of pycrypto (32 bit python. if you don't use 32 bit python install seperately in a folder such as python27_x86)

download file and extract to c:\python27\lib\site-packages

cd c:\python27\lib\site-packages\pycryptowhatever
python setup.py install



vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #386 on: March 05, 2014, 09:17:57 PM »
Code: [Select]
from collections import namedtuple
screen = namedtuple('screen', ('item','to'))

class Interface:
    def __init__(self, mtext, mid):
        self.main = mid
        self.v = {mid:screen(mtext, [])}
    def addscreen(self, id, item):
        self.v[id] = screen(item,[])
    def connec(self, s1, s2):
        self.v[s1].to.append(s2)
    def disp(self, id):
        itm = self.v[id].item
        if type(item) == str:
            print self.v[id].item
        else:
            self.v[id].item()
        l = len(self.v[id].to)
        for i in xrange(0,l):
            print self.v[id].to[i] +':' + str(i)
        while 1:
            try:
                k = int(raw_input())
                break
            except:
                pass
        if 0 <= k < l:
            self.disp(self.v[id].to[k])
    def startloop(self):
        self.disp(main)

so what is this? an interface of sorts.

normally, if you have a few user inputs for a program, you'd just write them into the function. but supposed your program revolved around text inputs, as in an interactive story or menu selection thing. certainly, all the if statements, loops, and raw_inputs would be confusing.

this class consists of a bunch of screen objects which you can add and connect. Each screen is represented by an id, an item, and a list of connections. the id is a string used to identify the screen, the item is either a function or a piece of text, and the list of connections contains the ids of other screens that can be accessed.

if the item is a piece of text, it will be printed, then the user will choose which screen to go to next.
if the item is a function, it will be executed. however, in order to keep the code concise, i have not allowed any arguments to be passed to the function.

so what if i have a writefile function you say, and you want to pass the filename of log.dat to the function? well, before you add the screen, do this:

Code: [Select]
logwritefile = lambda: writefile('log.dat', raw_input('hi'))and then pass the logwritefile function to the screen creator.

i have to say this is not tested at all but i will be using it soon so if there are bugs they will be fixed

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #387 on: March 06, 2014, 06:57:55 PM »
if you have a bunch of python programs you run simultaneously, like an irc bot, a web scraper, imgget, a key logger, or whatever, this script runs them all on threads which means they will only ever take up one cpu core.

many pieces of code where you have
while time.time()-start < 1:
or something similar, this while loop can eat up a lot of cpu power by running very quickly. by threading all the scripts onto one core, the loop is slowed down, which means less cpu use with the same performance

Code: [Select]
import threading

names = ['agent.py', 'crypto.py', 'interface.py', 'top.py', 'connect.py'] #fill this with a list of whatever shit

tlist = []
for name in names:
    tlist.append(threading.Thread(target = lambda : execfile(name)))
for thread in tlist:
    thread.start()

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #388 on: March 07, 2014, 07:46:53 PM »

a few months later i've started coding the majority of it. here's another view of how it works again

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Coding
« Reply #389 on: March 29, 2014, 10:37:30 PM »
i present to you the 150 line "HelloWorld" program in opencl. well actually it's a bit more complicated. the program takes the string "GdkknVnqkc", then adds 1 to all the ascii values, and prints the result.

here's the heavily commented main code

Code: [Select]
#include "stdafx.h" //standard something
#include <stdlib.h> //standard library
#include <string.h> //for string
#include <stdio.h> //standard input and output
#include <iostream> //input output stream
#include <string> //also for string
#include <fstream> //file stream
#include <CL/cl.h> //for opencl

using namespace std; //we don't have to type std every time

int convertToString(const char *filename, string& s){
//filename is the name of the file
//s the address of the string

size_t size; //an unsigned long long int that contains size of object
char * str; //initialize pointer str

fstream f(filename, (fstream::in | fstream::binary));
//make f a file object with the filename and mode is input and binary

if(f.is_open()){ // if file opened
size_t fileSize; //unsigned long long int that contains size of file object
f.seekg(0, fstream::end); //go to the end of the file, then offset by zero
size = (size_t)f.tellg(); //get the current position, convert it to type size_t, store in size
fileSize = size; //set filesize equal to size
f.seekg(0, fstream::beg); //go back to beginning of file and offset by zero
str = new char[size+1]; //initialize array of characters just big enough to store the file

if(!str){ //if the array is empty
f.close(); //close the file
return 0; //signifies success
}else{ //if the array is not empty
f.read(str, fileSize); //read the file until the end, store it in the char array
f.close(); //close the file
str[size] = '\0'; //set the last character to 0, termiating the string

s = str; //put the character array into s
delete[] str; //delete str, saves memory
return 0;//success
}
}else{ //the file did not open
return 1; //1 signifies failure
}
}

int main(){ //the main program or whatever
cl_uint numPlatforms; //number of platforms stored as a unsigned cl integer
cl_platform_id platform = NULL; //set the platform to none or something
cl_int status = clGetPlatformIDs(0,NULL,&numPlatforms);//get the platform id of null, assign it to numplatforms

if(status != CL_SUCCESS){ //if the platform failed
return 1; //failure
} //if it did not fail
if(numPlatforms > 0){ //if more than one platform available
cl_platform_id* platforms = (cl_platform_id* )malloc(numPlatforms* sizeof(cl_platform_id));
//allocate an array to store all the platform IDs
status = clGetPlatformIDs(numPlatforms, platforms, NULL); //put all the platforms ids into the array
platform = platforms[0]; //set the platform to the first platform found
free(platforms); //unallocate the array from before
}

cl_uint numDevices = 0; //zero devices
cl_device_id *devices; //stores device ids
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0 , NULL, &numDevices);
//get devices of type gpu, available on platform, of type gpu, and store the number in numDevices

if(numDevices == 0){//there are no gpus
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 0, NULL, &numDevices);
//get the devices of type cpu, available on platform, and store number in numdevices
devices = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id));
//allocate an array to store all the devices
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, numDevices, devices, NULL);
//store the devices into the devices array
}else{//there are at least 1 gpu
devices = (cl_device_id*)malloc(numDevices * sizeof(cl_device_id));
//allocate an array to store all the devices
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
//store all the devices into the devices array
}

cl_context context = clCreateContext(NULL,1, devices,NULL,NULL,NULL);
//create a context with one device, and pass the devices to it

cl_command_queue commandQueue = clCreateCommandQueue(context, devices[0], 0, NULL);
//create a command queue, give it the context, and the first devices

const char *filename = "HelloWorld_Kernel.cl"; //the name of the file where the kernel is stored
string sourceStr; //initialize the string that will store the code
status = convertToString(filename, sourceStr); //get the code, place it in sourceSTR

const char *source = sourceStr.c_str(); //get a pointer to the string containing the kernel
size_t sourceSize[] = {strlen(source)}; //array of length 1 containing the size of the kernel
cl_program program = clCreateProgramWithSource(context, 1, &source, sourceSize, NULL);
//now we create the program with given context, the kernel string, and the size of the kernel

status=clBuildProgram(program, 1,devices,NULL,NULL,NULL); //build the program for the device

const char* input = "GdkknVnqkc"; //initialize an object that is the same size of helloworld
size_t strlength = strlen(input); //store the size of this object
char *output = (char*) malloc(strlength + 1); //allocate an output one char bigger than input

cl_mem inputBuffer = clCreateBuffer(context, //allocate memory (a buffer)
CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, //it is read only | copies the input
(strlength + 1) * sizeof(char), //the size enough to contain hello world
(void *) input, //and give it a pointer to the input
NULL);
cl_mem outputBuffer = clCreateBuffer(context, //allocate memory ( a buffer)
CL_MEM_WRITE_ONLY , //it is write only
(strlength + 1) * sizeof(char), //size enough to contain hello world
NULL, NULL);

cl_kernel kernel = clCreateKernel(program,"helloworld", NULL); //create the kernel object with hello world string

status = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&inputBuffer); //set the kernel's in buffer
status = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&outputBuffer); //set the kerels' out buffer

size_t global_work_size[1] = {strlength}; //use as many workers as there are characters
status = clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, global_work_size, NULL, 0, NULL, NULL);
//send the instructions to the workers using the specified command queue, kernel, and worksize
status = clEnqueueReadBuffer(commandQueue, outputBuffer, CL_TRUE, 0, strlength * sizeof(char), output, 0, NULL, NULL);
//read back in the data with command queue, the output buffer, put the memory into the output string

output[strlength] = '\0'; //add terminating character to the output
printf(output); //print the string
printf("\n");

status = clReleaseKernel(kernel); //release kernel
status = clReleaseProgram(program); //release the program object
status = clReleaseMemObject(inputBuffer); //release input buffer
status = clReleaseMemObject(outputBuffer); //release output buffer
status = clReleaseCommandQueue(commandQueue); //release command queue
status = clReleaseContext(context); //release the context
if (output != NULL){ //if the output contains a string
free(output); //remove it
output = NULL; //dereference the pointer
}
if (devices != NULL){ //if devices exist
free(devices); //free the devices
devices = NULL; //dereference the pointer
}
system("pause"); //makes sure the window doesn't close out immediately
return 0; //signifies success
}

and here's the kernel, which is used on 10 of your gpu/cpu/whatever cores

Code: [Select]
__kernel void helloworld(__global char* in, __global char* out) //make a kernel function
{
int num = get_global_id(0); //read in the id
out[num] = in[num] + 1; //get the character, add one
}