Skip to content

Commit

Permalink
we can draw state of the system as a png now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tri Vo committed Dec 7, 2015
1 parent 0c30d55 commit b9cd47b
Show file tree
Hide file tree
Showing 8 changed files with 7,971 additions and 53 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all: compile

compile: main.o actor.o SchellingActor.o
/usr/local/cuda/bin/nvcc -arch sm_20 main.o actor.o SchellingActor.o -o ActorSim
compile: main.o actor.o SchellingActor.o lodepng.o
/usr/local/cuda/bin/nvcc -arch sm_20 main.o actor.o SchellingActor.o lodepng.o -o ActorSim

main.o: main.cu
/usr/local/cuda/bin/nvcc -arch sm_20 -c -dc main.cu
Expand All @@ -12,5 +12,8 @@ actor.o: actor.cu
SchellingActor.o: SchellingActor.cu
/usr/local/cuda/bin/nvcc -arch sm_20 -c -dc SchellingActor.cu

lodepng.o: lodepng.cpp
gcc -c lodepng.cpp

clean:
rm -rf *o
25 changes: 14 additions & 11 deletions SchellingActor.cu
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#include "SchellingActor.hxx"
#include <cstdio>

__device__ __host__ SchellingActor::SchellingActor(unsigned char type){
m_type = type;
}
__device__ __host__ SchellingActor::SchellingActor(unsigned char type)
: m_type(type), m_numberAdjacent(0) {};

__device__ __host__ SchellingActor::~SchellingActor(){
printf("SchellingActor constructor\n");
}

__device__ void SchellingActor::react() {
printf("SchellingActor react()\n");
//printf("SchellingActor react()\n");
for (int i = 1; i < 257; i <<= 1) {
if (atomicXor((int*)&m_type, i) >> i - 1 == 0)
if (atomicXor((int*)&m_type, i) >> i - 1 == 0) {
increaseNumberAdjacent();
}
}
}

__device__ void SchellingActor::send(Actor* receiver, char message) {
printf("SchellingActor send()\n");
if (message != 'f' && message != static_cast<SchellingActor*>(receiver)->type())
//static_cast<SchellingActor*>(receiver)->increaseNumberAdjacent();
this->increaseNumberAdjacent();
}
//printf("SchellingActor send()\n");
if (receiver == NULL) {
return;
}

message = this->type();
if (message != 'f' && message != static_cast<SchellingActor*>(receiver)->type()) {
this->increaseNumberAdjacent();
}
}
6 changes: 3 additions & 3 deletions SchellingActor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class SchellingActor : public Actor {
__device__ void receive(Actor*, unsigned char);
// ! Used to run after the actor receives all of its data. Reacts by sending the MapActor its coordinates and type.
__device__ virtual void react();

__device__ __host__ unsigned char type() { return m_type; }

__device__ __host__ unsigned int numberAdjacent() { return m_numberAdjacent; }

__device__ virtual void send(Actor* receiver, char message);
__device__ virtual void send(Actor* receiver, char message);

__device__ void increaseNumberAdjacent() { atomicAdd(&m_numberAdjacent, 1); }
// Used to increase the number of adjacent actors
// Used to reset the number of adjacent actors
Expand Down
2 changes: 1 addition & 1 deletion actor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "actor.h"

Actor::Actor(){
m_id = -1;
m_id = 0;
}

Actor::Actor(unsigned int id){
Expand Down
Loading

0 comments on commit b9cd47b

Please sign in to comment.