summaryrefslogtreecommitdiff
path: root/ccc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-15 03:50:43 +0200
committerPatrick Simianer <p@simianer.de>2014-06-15 03:50:43 +0200
commit6ed9a9699997a2853ec1c9e91747c251e5cfc97b (patch)
tree56c96f18442fb06aeeb45cadc56355353a63ee99 /ccc
parent258e1b92ebbfdebefabc120969ab87c3d8b75c3d (diff)
damn
Diffstat (limited to 'ccc')
-rw-r--r--ccc/Makefile12
-rw-r--r--ccc/animal.cc37
-rw-r--r--ccc/cast.cc27
-rw-r--r--ccc/cat_char.cc16
-rw-r--r--ccc/class.cc31
-rw-r--r--ccc/class_member.cc33
-rw-r--r--ccc/compression_test.cc45
-rw-r--r--ccc/filelib.c87
-rw-r--r--ccc/filelib.h25
-rw-r--r--ccc/float_int.cc26
-rw-r--r--ccc/gz.c16
-rw-r--r--ccc/ooc.c78
-rw-r--r--ccc/ooc.h6
-rw-r--r--ccc/precedence.cc16
-rw-r--r--ccc/sort.cc47
-rw-r--r--ccc/split.cc55
-rw-r--r--ccc/stringstream.cc26
-rw-r--r--ccc/stringutil.c22
-rw-r--r--ccc/stringutil.h13
-rw-r--r--ccc/stringutil_test.c53
-rw-r--r--ccc/substr.cc23
-rw-r--r--ccc/to_hex.cc14
-rw-r--r--ccc/vector_addition.c29
-rw-r--r--ccc/vector_addition.cu61
-rw-r--r--ccc/vector_addition1.cu48
25 files changed, 0 insertions, 846 deletions
diff --git a/ccc/Makefile b/ccc/Makefile
deleted file mode 100644
index 662c75e..0000000
--- a/ccc/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-compression_test: compression_test.cc
- g++ compression_test.cc -lboost_filesystem -lboost_iostreams -o compression_test
-
-vector_addition: vector_addition.c
- gcc -Os vector_addition.c -o vector_addition
-
-vector_addition_cuda: vector_addition.cu
- nvcc vector_addition.cu -o vector_addition_cuda
-
-vector_addition_cuda1: vector_addition1.cu
- nvcc vector_addition1.cu -o vector_addition_cuda1
-
diff --git a/ccc/animal.cc b/ccc/animal.cc
deleted file mode 100644
index 3bad1b1..0000000
--- a/ccc/animal.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-class Animal
-{
- public:
- Animal() { // Konstruktor
- cout << "Der Konstruktor wird aufgerufen." << endl;
- m_alive = true;
- }
-
- ~Animal() {cout << "Der Destruktor wird aufgerufen." << endl;}
-
- bool isAlive() { // Methode
- return m_alive;
- }
-
- void kill() { // Methode
- m_alive=false;
- }
-
- private:
- bool m_alive; // Member-Variable
-};
-
-
-int main(void)
-{
- int i;
- bool alive;
-
- Animal a; // Instanz von Animal
- Animal b; // noch eine ^
-}
-
diff --git a/ccc/cast.cc b/ccc/cast.cc
deleted file mode 100644
index 2e84a64..0000000
--- a/ccc/cast.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-struct A {
- virtual void p() { cout << "A" << endl; }
- void q() { cout << "q" << endl; }
-};
-
-struct Ba : public A {
- void p() { cout << "Ba" << endl; }
-};
-
-struct Bb : public A {
- void p() { cout << "Bb" << endl; }
-};
-
-int main(void)
-{
- A* x = new A;
- x = dynamic_cast<Ba*>(new Ba);
- cout << "-" << endl;
- x->q();
- x->p();
-}
-
diff --git a/ccc/cat_char.cc b/ccc/cat_char.cc
deleted file mode 100644
index 3daf564..0000000
--- a/ccc/cat_char.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include <string.h>
-
-using namespace std;
-
-
-int main(void)
-{
- char c[] = "c";
- char x[1024];
- string s("s");
- strcpy(x, s.c_str());
- strcat(x, c);
- cout << x << endl;
-}
-
diff --git a/ccc/class.cc b/ccc/class.cc
deleted file mode 100644
index b493b51..0000000
--- a/ccc/class.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-class A {
- public:
- A(int a):_a(a) {}
- int geta() {
- return _a;
- }
- static int _b;
- private:
- int _a;
-};
-
-int A::_b = 0;
-
-int main(void){
- A a(2);
- A *b = new A(2);
- cout << b->geta() << endl;
- cout << b->_b << endl;
- cout << a._b << endl;
- A::_b = 42;
- cout << b->geta() << endl;
- cout << b->_b << endl;
- cout << a._b << endl;
- return 0;
-}
-
diff --git a/ccc/class_member.cc b/ccc/class_member.cc
deleted file mode 100644
index f78ca64..0000000
--- a/ccc/class_member.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-struct A
-{
-};
-
-struct B : public A
-{
-
-};
-
-struct C : public A
-{
-
-};
-
-struct D
-{
- A* a;
-};
-
-int main(void)
-{
- B b;
- D d;
- A a;
-
- d.a = &b;
-}
-
diff --git a/ccc/compression_test.cc b/ccc/compression_test.cc
deleted file mode 100644
index 21bfafc..0000000
--- a/ccc/compression_test.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <iostream>
-#include <fstream>
-#include <boost/iostreams/device/file.hpp>
-#include <boost/iostreams/filter/zlib.hpp>
-#include <boost/iostreams/filter/bzip2.hpp>
-#include <boost/iostreams/filter/gzip.hpp>
-#include <boost/iostreams/filtering_stream.hpp>
-
-using namespace boost::iostreams;
-using namespace std;
-
-
-int main(void)
-{
- //ofstream raw("out-raw");
- filtering_ostream out_z;
- out_z.push(gzip_compressor());
- //out_gz.push(gzip_compressor());
- out_z.push(file_sink("out-z", std::ios::binary));
- //out_gz.push(file_sink("out-gz", std::ios::binary));
- for (size_t i = 0; i < 10; i++) {
- out_z << "line #" << i << endl;
- //out_gz << "line #" << i << endl;
- //out_bz << "line #" << i << endl;
- //raw << "line #" << i << endl;
- }
- // flush(out);
- close(out_z);
- //close(out_gz);
- //close(out_bz);
- //raw.close();
-
- for (size_t i = 0; i < 5; i++) {
- ifstream file("out-z", ios_base::in | ios_base::binary);
- filtering_istream in;
- in.push(gzip_decompressor());
- in.push(file);
- string s;
- while (getline(in, s)) {
- cout << s << endl;
- }
- file.close();
- }
-}
-
diff --git a/ccc/filelib.c b/ccc/filelib.c
deleted file mode 100644
index 57a27c3..0000000
--- a/ccc/filelib.c
+++ /dev/null
@@ -1,87 +0,0 @@
-#include "filelib.h"
-
-
-typedef struct
-{
- hFile b_;
- FILE* fp;
-} hFile_;
-
-typedef struct
-{
- hFile b_;
- gzFile* fp;
-} hgzFile;
-
-gzmode(const char* mode)
-{
- // TODO
- return true;
-}
-
-hgzFile*
-gzmakef(char* fname, const char* mode)
-{
- hgzFile* hgz = malloc(sizeof(hgzFile));
- hgz->b_.name = fname;
- hgz->b_.gz = true;
- gzFile* fp = malloc(sizeof(gzFile));
- *fp = gzopen(fname, mode);
- hgz->fp = fp;
- return hgz;
-}
-
-hFile*
-makef(char* fname, const char* mode)
-{
- if (endswith(fname, GZIP_EXT))
- return gzmakef(fname, mode);
- hFile_* f = malloc(sizeof(hFile_));
- if (!f) return NULL;
- f->b_.name = fname;
- f->b_.gz = false;
- if (!strcmp(fname, "-")) {
- if (!strcmp(mode, "r") && !strcmp(mode, "r+")) f->fp = stdin;
- else f->fp = stdout;
- } else {
- f->fp = fopen(fname, mode);
- }
- return f;
-}
-
-bool
-gzwriteln(const char* s, hFile* f)
-{
- unsigned len = strlen(s);
- gzwrite(*((hgzFile*)f)->fp, s, len);
- gzwrite(*((hgzFile*)f)->fp, "\n", 1);
- return gzflush(*((hgzFile*)f)->fp, Z_FINISH) == Z_OK;
-}
-
-bool
-writeln(const char* s, hFile* f)
-{
- if (f->gz)
- return gzwriteln(s, f);
- return fputs(s, ((hFile_*)f)->fp)&&fputs("\n", ((hFile_*)f)->fp);
-}
-
-bool
-gzclosef(hFile* f)
-{
- bool ret = gzclose(*((hgzFile*)f)->fp);
- free(((hgzFile*)f)->fp);
- free(f);
- return ret;
-}
-
-bool
-closef(hFile* f)
-{
- if (f->gz)
- return gzclosef(f);
- bool ret = fclose(((hFile_*)f)->fp);
- free(f);
- return ret;
-}
-
diff --git a/ccc/filelib.h b/ccc/filelib.h
deleted file mode 100644
index 587cddf..0000000
--- a/ccc/filelib.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef FILELIB_H
-#define FILELIB_H
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <zlib.h>
-#include <assert.h>
-#include "util.h"
-
-#define GZIP_EXT ".gz"
-
-
-typedef struct
-{
- char* name; // relative
- bool gz;
-} hFile;
-
-hFile* makef(char* fname, const char* mode);
-bool writeln(const char* s, hFile* f);
-
-
-#endif
-
diff --git a/ccc/float_int.cc b/ccc/float_int.cc
deleted file mode 100644
index 9d0ece4..0000000
--- a/ccc/float_int.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-int main(void)
-{
- int a = 1;
- int b = 2;
- double q = (double)a/b;
- cout << q << endl;
-
- cout << 1 - (float)a/b << endl;
-
- float x = 0.1;
- unsigned y = 105;
- unsigned z = x*y;
- cout << z << endl;
-
- float u = -1;
- if (u) cout << "XXXXXX" << endl;
-
- float j = 0.0;
- if (j) cout << "j" << endl;
-}
-
diff --git a/ccc/gz.c b/ccc/gz.c
deleted file mode 100644
index a0dcd90..0000000
--- a/ccc/gz.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <zlib.h>
-#include <string.h>
-
-int
-main(void)
-{
- gzFile gz = gzopen("asdf.gz", "wb");
- int len = 0;
- gzwrite(gz, "asdf\n", len);
- char *s = "asdf\n";
- gzwrite(gz, "asdf\n", strlen(s));
- gzclose(gz);
-
- return 0;
-}
-
diff --git a/ccc/ooc.c b/ccc/ooc.c
deleted file mode 100644
index aa20488..0000000
--- a/ccc/ooc.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "ooc.h"
-#include "stdio.h"
-#include "string.h"
-
-
-struct van {
- struct vehicle base;
- int cubic_size;
-};
-
-struct bus {
- struct vehicle base;
- int seats;
-};
-
-struct van*
-make_van()
-{
- struct van* v = malloc(sizeof(struct van));
- v->base.type = "van";
- v->cubic_size = 12;
- return v;
-}
-
-struct bus*
-make_bus()
-{
- struct bus* v = malloc(sizeof(struct bus));
- v->base.type = "bus";
- v->seats=112;
- return v;
-}
-
-struct vehicle*
-make_vehicle(const char* type)
-{
- if(!strcmp(type, "van")) return make_van();
- if(!strcmp(type, "bus")) return make_bus();
- return NULL;
-}
-
-void
-do_something_with_a_bus(struct vehicle* v)
-{
- ((struct bus*)v)->seats = 13;
-}
-
-void
-do_something_with_a_van(struct vehicle* v)
-{
- ((struct van*)v)->cubic_size = 11;
-}
-
-void
-do_something(struct vehicle* v)
-{
- if(!strcmp(v->type, "van")) return do_something_with_a_van(v);
- if(!strcmp(v->type, "bus")) return do_something_with_a_bus(v);
-}
-
-int
-main(void) {
- struct van my_van;
- struct vehicle *something = &my_van;
- my_van.cubic_size = 100;
- my_van.base.power = 99;
- printf("%d\n", something->power);
- printf("%d\n", my_van.base.power);
-
- struct bus* bus = make_vehicle("bus");
- printf("%s\n", bus->base.type);
- printf("%d\n", bus->seats);
- do_something(bus);
- printf("%d\n", bus->seats);
-
- return 0;
-}
-
diff --git a/ccc/ooc.h b/ccc/ooc.h
deleted file mode 100644
index 0585d95..0000000
--- a/ccc/ooc.h
+++ /dev/null
@@ -1,6 +0,0 @@
-struct vehicle {
- int power;
- int weight;
- char* type;
-};
-
diff --git a/ccc/precedence.cc b/ccc/precedence.cc
deleted file mode 100644
index 08e29b6..0000000
--- a/ccc/precedence.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-int main(void)
-{
- bool a = false;
- bool b = true;
-
- cout << (!a && b) << endl;
-
- double c = 0;
- if (c) cout << "xx" << endl;
-}
-
diff --git a/ccc/sort.cc b/ccc/sort.cc
deleted file mode 100644
index 165b086..0000000
--- a/ccc/sort.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <iostream>
-#include <algorithm>
-#include <utility>
-#include <vector>
-
-using namespace std;
-
-
-struct X
-{
- pair<string,int> p;
-};
-
-bool myf(X a, X b)
-{
- return a.p.second > b.p.second;
-}
-
-int main(void)
-{
- X a;
- a.p.first = "a";
- a.p.second = 1;
-
- X b;
- b.p.first = "b";
- b.p.second = 2;
-
- X c;
- c.p.first = "c";
- c.p.second = 3;
-
- vector<X> v;
- v.push_back(a);
- v.push_back(b);
- v.push_back(c);
-
- for (unsigned i = 0; i < v.size(); i++) {
- cout << v[i].p.first << endl;
- }
- sort(v.begin(), v.end(), myf);
- cout << endl;
- for (unsigned i = 0; i < v.size(); i++) {
- cout << v[i].p.first << endl;
- }
-}
-
diff --git a/ccc/split.cc b/ccc/split.cc
deleted file mode 100644
index e01ad64..0000000
--- a/ccc/split.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-#include <iostream>
-#include <string>
-#include <sstream>
-#include <vector>
-
-using namespace std;
-
-
-int main(void)
-{
- string s("a\tb\tc\td");
- string::iterator it = s.begin();
- char d = '\t';
- string tmp;
- size_t parts = 4;
- size_t c = 0;
- while(true) {
- if (parts > 0 && c == parts-1) {
- while(it != s.end()) {
- tmp += *it;
- it++;
- }
- cout << tmp << endl;
- break;
- }
- if (it == s.end()) { cout << tmp << endl; break; }
- if (*it != d) tmp += *it;
- else {
- cout << tmp << endl;
- tmp.clear();
- c++;
- }
- it++;
- }
-
- cout << "---" << endl;
-
- stringstream ss(s);
- string si;
- parts = 0;
- c = 0;
-
- while(true)
- {
- if (parts > 0 && c == parts-1) {
- getline(ss, si);
- cout << si << endl;
- break;
- }
- if(!getline(ss, si, '\t')) break;
- cout << si << endl;
- c++;
- }
-}
-
diff --git a/ccc/stringstream.cc b/ccc/stringstream.cc
deleted file mode 100644
index 3d68db3..0000000
--- a/ccc/stringstream.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <iostream>
-#include <string>
-#include <sstream>
-#include <vector>
-#include <stdio.h>
-#include <iomanip>
-
-using namespace std;
-
-
-int main(void) {
- string s = "1 2 3 4";
- int i;
- vector<int> j;
- stringstream ss(s);
- while (ss >> i) {
- j.push_back(i);
- cout << i << endl;
- }
-
- printf("%4d %4d %4d %4d\n", j[0], j[1], j[2], j[3]);
-
- cout.width(100);
- cout << setw(100) << j.size() << endl;
-}
-
diff --git a/ccc/stringutil.c b/ccc/stringutil.c
deleted file mode 100644
index aab4f03..0000000
--- a/ccc/stringutil.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "stringutil.h"
-
-
-char*
-strend(char* s)
-{
- if (strlen(s) == 0) return '\0';
- while(*s != '\0')
- ++s;
- return --s;
-}
-
-bool
-endswith(char* s, char* suff)
-{
- if (strlen(s) < strlen(suff)) return false;
- char* a = strend(s)-(strlen(suff)-1);
- if (!a) return false;
- if (!strcmp(a, suff)) return true;
- return false;
-}
-
diff --git a/ccc/stringutil.h b/ccc/stringutil.h
deleted file mode 100644
index 153068a..0000000
--- a/ccc/stringutil.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef STRINGUTIL_H
-#define STRINGUTIL_H
-
-#include <string.h>
-#include <stdbool.h>
-
-
-char* strend(char* s);
-bool endswith(char* s, char* suff);
-
-
-#endif
-
diff --git a/ccc/stringutil_test.c b/ccc/stringutil_test.c
deleted file mode 100644
index 798bccd..0000000
--- a/ccc/stringutil_test.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "filelib.h"
-#include "stringutil.h"
-
-
-int
-main(void)
-{
- /*
- * strend
- *
- */
- char* s= "";
- char* end = strend(s);
- if (end)
- printf("should not output: %s\n", end);
-
- s = "asdf.gz";
- end = strend(s);
- if (end)
- printf("expect 'z': %s\n", end);
-
- /*
- * endswith
- *
- */
- if (endswith(s, ".gz"))
- printf("%s ends with %s\n", s, ".gz");
-
- if (endswith(".gz", ".gz"))
- printf(".gz ends with .gz\n");
-
- if(!endswith("gz", ".gz"))
- printf("gz does not end with .gz\n");
-
- /*
- * filelib
- *
- */
- hFile* f = makef("-", "a");
- if (!f)
- printf("Error creating file '%s'\n", "-");
- writeln("this goes to stdout", f);
- closef(f);
-
- hFile* g = makef("gzfile.gz", "a");
- if (!g)
- printf("Error creating file '%s'\n", "-");
- writeln("this should be compressed", g);
- closef(g);
-
- return 0;
-}
-
diff --git a/ccc/substr.cc b/ccc/substr.cc
deleted file mode 100644
index 9a91adc..0000000
--- a/ccc/substr.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <iostream>
-#include <string>
-
-using namespace std;
-
-
-int main(void)
-{
- // 0 12 34 56
- string s("aaax\tbx\tcxasd\tdx");
- unsigned f = 0;
- for(unsigned i = 0; i < 3; i++) {
- unsigned e = f;
- f = s.find("\t", f+1);
- cout << "e:" << e << " f:" << f << endl;
- if (e !=0) cout << "'" << s.substr(e+1, f-e-1) << "'" << endl;
- else cout << "'" << s.substr(0, f) << "'" << endl;
- }
- cout << "---" << endl;
- s.erase(0, f+1);
- cout << "'" << s << "'" <<endl;
-}
-
diff --git a/ccc/to_hex.cc b/ccc/to_hex.cc
deleted file mode 100644
index 6e577dc..0000000
--- a/ccc/to_hex.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-
-int main(void)
-{
- int r = 116;
- int g = 10;
- int b = 10;
-
- cout << hex << r << " " << g << " " << b << endl;
-}
-
diff --git a/ccc/vector_addition.c b/ccc/vector_addition.c
deleted file mode 100644
index decb3ff..0000000
--- a/ccc/vector_addition.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "stdio.h"
-#include "stdlib.h"
-
-
-int main(void) {
- int N = 10000, M=100000;
- float **x = malloc(N*sizeof(float*));
- float *y = malloc(M*sizeof(float*));
- int i,j;
- for (i = 0; i < N; i++) {
- x[i] = malloc(M*sizeof(float));
- for (j = 0; j < M; j++) {
- x[i][j] = (float) j;
- }
- }
-
- for (i = 0; i < N ; i++) {
- for (j = 0; j < M; j++) {
- y[i] += x[i][j];
- }
- }
-
- printf("%f\n", y[100]);
-
- free(x); free(y);
-
- return 0;
-}
-
diff --git a/ccc/vector_addition.cu b/ccc/vector_addition.cu
deleted file mode 100644
index 4f16bc3..0000000
--- a/ccc/vector_addition.cu
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "stdio.h"
-
-
-__global__ void add_arrays_gpu( float *in1, float *in2, float *out, int Ntot)
-{
- int idx=blockIdx.x*blockDim.x+threadIdx.x;
- if (idx < Ntot)
- out[idx]=in1[idx]+in2[idx];
-}
-
-
-int main(void)
-{
- /* pointers to host memory */
- float *a, *b, *c;
- /* pointers to device memory */
- float *a_d, *b_d, *c_d;
- int N=100000000;
- int i;
-
- /* Allocate arrays a, b and c on host*/
- a = (float*) malloc(N*sizeof(float));
- b = (float*) malloc(N*sizeof(float));
- c = (float*) malloc(N*sizeof(float));
-
- /* Allocate arrays a_d, b_d and c_d on device*/
- cudaMalloc ((void **) &a_d, sizeof(float)*N);
- cudaMalloc ((void **) &b_d, sizeof(float)*N);
- cudaMalloc ((void **) &c_d, sizeof(float)*N);
-
- /* Initialize arrays a and b */
- for (i=0; i<N; i++) {
- a[i]= (float) i;
- b[i]=(float) -i;
- }
-
-
- /* Copy data from host memory to device memory */
- cudaMemcpy(a_d, a, sizeof(float)*N, cudaMemcpyHostToDevice);
- cudaMemcpy(b_d, b, sizeof(float)*N, cudaMemcpyHostToDevice);
-
- /* Compute the execution configuration */
- int block_size=256;
- dim3 dimBlock(block_size);
- dim3 dimGrid ( (N/dimBlock.x) + (!(N%dimBlock.x)?0:1) );
-
- /* Add arrays a and b, store result in c */
- add_arrays_gpu<<<dimGrid,dimBlock>>>(a_d, b_d, c_d, N);
-
- /* Copy data from deveice memory to host memory */
- //cudaMemcpy(c, c_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
-
- /* Print c */
-/*for(i=0; i<N; i++)
- printf(" c[%d]=%f\n",i,c[i]);*/
-
- /* Free the memory */
- free(a); free(b); free(c);
- cudaFree(a_d); cudaFree(b_d);cudaFree(c_d);
-}
-
diff --git a/ccc/vector_addition1.cu b/ccc/vector_addition1.cu
deleted file mode 100644
index 9490ff3..0000000
--- a/ccc/vector_addition1.cu
+++ /dev/null
@@ -1,48 +0,0 @@
-#include "stdio.h"
-
-
-__global__ void add_arrays_gpu( float *in1, float *in2, float *out, int Ntot)
-{
- int idx=blockIdx.x*blockDim.x+threadIdx.x;
- if (idx < Ntot)
- out[idx]=in1[idx]+in2[idx];
-}
-
-
-int main(void)
-{
- int N=10000, M=100000;
- float **x = (float**) malloc(N*sizeof(float));
- float **x_d = (float**) malloc(N*sizeof(float));
- int i,j;
-
- for (i = 0; i < N; i++) {
- x[i] = (float*) malloc(M*sizeof(float));
- cudaMalloc ((void **) &x_d[i], sizeof(float)*M);
- for (j = 0; j < M; j++) {
- x[i][j] = (float) j;
- }
- cudaMemcpy(x_d[i], x[i], sizeof(float)*M, cudaMemcpyHostToDevice);
- }
-
-
- /* Compute the execution configuration */
-// int block_size=256;
- // dim3 dimBlock(block_size);
- //dim3 dimGrid ( (N/dimBlock.x) + (!(N%dimBlock.x)?0:1) );
-
- /** Add arrays a and b, store result in c */
- // add_arrays_gpu<<<dimGrid,dimBlock>>>(a_d, b_d, c_d, N);
-
- /* Copy data from deveice memory to host memory */
- //cudaMemcpy(c, c_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
-
- /* Print c */
-/*for(i=0; i<N; i++)
- printf(" c[%d]=%f\n",i,c[i]);*/
-
- /* Free the memory */
-// free(a); free(b); free(c);
-// cudaFree(a_d); cudaFree(b_d);cudaFree(c_d);
-}
-