Arc Forumnew | comments | leaders | submitlogin
Parallelism and Data Oriented Design
4 points by cthammett 3227 days ago | 9 comments
Good Morning all,

I was wondering how to get Racket Parallelism into Anarki to experiment with Data Oriented Design and Entity Component Systems. Please find below the link to racket/future and code.

http://docs.racket-lang.org/reference/futures.html?q=parallelism

  ($:require racket/future)

  (mac future (thunk) `($:future ,thunk))					    
  (mac touch (f) `($:touch ,f))						    
  (mac futures-enabled? () `($:futures-enabled?))					    
  (mac current-future () `($:current-future))					    
  (mac future? (v) `($:future? ,v))						    
  (mac would-be-future (thunk) `($:would-be-future ,thunk)) 					    
  (mac processor-count () `($:processor-count)) 					
  (mac fsemaphore? (v) `($:fsemaphore ,v))						
  (mac fsemaphore-post (fsema) `($:fsemaphore-post ,fsema))					    
  (mac fsemaphore-wait (fsema) `($:fsemaphore-wait ,fsema))					
  (mac fsemaphore-try-wait? (fsema) `($:fsemaphore-try-wait? ,fsema))

  ($:define-syntax-rule (fn args . body)
 (lambda args . body))

  ($:define-syntax-rule (prn body)
  (printf body))

  (let f (future (fn () (+ 1 2)))
	(list (+ 3 4) (touch f)))

  (touch (future (fn ()
                 (prn "hello1")
                (prn "hello2")
                 (prn "hello3"))))

  As for the Racket struct future-event I am not sure what to do about it

  (struct future-event (future-id proc-id action time prim-name user-data) #:prefab)


2 points by akkartik 3226 days ago | link

Nice! I should warn you that arc is very deeply permeated with the assumption that there's only one thread of execution. See atomic, for example, which all the assignment operators use: https://arclanguage.github.io/ref/atomic.html. Couple with the statement that "The distinction between “future safe” and “future unsafe” operations may be far from apparent at the level of a Racket program," (http://docs.racket-lang.org/guide/parallelism.html) and I think you might be in for some interesting debugging times :)

Hmm, future-event seems like it's just for performance logging? Maybe ignore it for now and try to build something non-trivial with the primitives you have?

-----

2 points by cthammett 3225 days ago | link

Thanks for the tips, I'll keep on exploring the possibilities. On a side note, is there a c or python ffi for Anarki?

-----

2 points by akkartik 3225 days ago | link

In the past I just used the Racket FFI for C with anarki's $ operator.

Hold on, let me throw up this arc project of mine from many years ago. The FFI isn't on head, but here's how I imported a Porter stemming (https://en.wikipedia.org/wiki/Stemming) implementation and a keyword-guessing algorithm in C: https://github.com/akkartik/readwarp/blob/e281ecfefd/keyword.... C functions that that invokes: https://github.com/akkartik/readwarp/blob/e281ecfefd/keyword...

(There's a password for my mail delivery service in that repo, but that account is now defunct. Hopefully nothing else is confidential. Please be nice and let me know if you see something there that might damage me :)

-----

2 points by cthammett 3222 days ago | link

Thanks, I didn't see anything suspect. It should be a good learning experience calling c from Anarki. I saw a tutorial today how to create c callable functions using NASM x86-64 assembly code and it worked. Do you think assembly and Anarki can talk to each other through c?

-----

1 point by akkartik 3222 days ago | link

No reason they couldn't!

If you're into assembly I'd love to hear what you think of my current project to teach programming using a sort of idealized assembly: http://github.com/akkartik/mu. I'm co-designing the assembly language with the OS around it, in the spirit of C+unix.

-----

2 points by cthammett 3221 days ago | link

The project looks interesting. I would like to learn more about assembly to, have greater understanding and control over what my computer actually does. All the tests passed but I made mu crash using repl.mu, if this help in finding bugs?

  ./mu repl.mu
  ready! type in an instruction, then hit enter. ctrl-d exits.
  (+ 1 1)
  missing type in {name: "1", properties: ["1": ]}
  mu: 041name.cc:82 bool disqualified(reagent&): Assertion `!x.types.empty()' failed.
  Aborted (Core dumped)
Also my left, middle and right mouse button clicks were printing rubbish to the terminal after that. I restarted the terminal and mouse functionality was normal again.

-----

2 points by akkartik 3220 days ago | link

Thanks for trying it! It's not actually a Lisp :) Check out the examples in the readme.

The repl is sadly not done. Repl feels like the wrong metaphor. I'm writing on a more useful version in edit.mu, but that's far from done. For now sadly you have to type code into a file and run it as a separate step. Just for a couple more weeks, hopefully.

-----

2 points by cthammett 3220 days ago | link

Impressive project, how long have you been programming for? I'm not sure if I can be of much technical assistance but if you recommend a few tools I could probably learn more about testing and find bugs. Earlier this week I installed valgrind to check for errors and memory leaks and I'm looking for a debugger that will work with lubuntu. I am also learning assembly.

-----

1 point by akkartik 3220 days ago | link

I'm starting to feel old :) I've been programming for 16 years now.

Feel free to ask me more questions. I'm not looking for help, rather to help. But there's still some way to go. In the meantime I'll help in any other way. Valgrind is super useful for C programming.

-----