[fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread fredvs
Hello.

Some developers treat me as dinosaur because I use threads in place of doing
parallelism.

Huh, ok, but why parallelism is better and how to do it with fpc ?

Thanks.

Fre;D



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Dimitrios Chr. Ioannidis via fpc-pascal

Hi,

On 29/3/2017 9:57 μμ, fredvs wrote:

Hello.

Some developers treat me as dinosaur because I use threads in place of doing
parallelism.

Huh, ok, but why parallelism is better and how to do it with fpc ?


  a nice article I've found long ago when I was researching the same 
topic "Threading/Concurrency vs. Parallelism" is the following :


http://tutorials.jenkov.com/java-concurrency/concurrency-vs-parallelism.html

 and I tried the multithreadprocslaz package in Lazarus :

http://wiki.freepascal.org/Parallel_procedures

Happy coding 

Regards,

--
Dimitrios Chr. Ioannidis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Michael Van Canneyt



On Wed, 29 Mar 2017, Dimitrios Chr. Ioannidis via fpc-pascal wrote:


Hi,

On 29/3/2017 9:57 μμ, fredvs wrote:

Hello.

Some developers treat me as dinosaur because I use threads in place of 

doing

parallelism.

Huh, ok, but why parallelism is better and how to do it with fpc ?


  a nice article I've found long ago when I was researching the same 
topic "Threading/Concurrency vs. Parallelism" is the following :


http://tutorials.jenkov.com/java-concurrency/concurrency-vs-parallelism.html

 and I tried the multithreadprocslaz package in Lazarus :

http://wiki.freepascal.org/Parallel_procedures


Showing nicely that parallelism in a single process implies threads.
I would not pay too much attention to what these developers are saying.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Dimitrios Chr. Ioannidis via fpc-pascal

Hi,

On 29/3/2017 11:15 μμ, Michael Van Canneyt wrote:

< snip >


Showing nicely that parallelism in a single process implies threads.
I would not pay too much attention to what these developers are saying.


besides hardware parallelism, how software parallelism ( in the sense of 
true simultaneous execution ) in a single process without using ( OS 
dependent ) threads can be achieved ?


regards,

--
Dimitrios Chr. Ioannidis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread fredvs
> I would not pay too much attention to what these developers are saying. 

Excellent idea, I will do the same ;-)

> how software parallelism ( in the sense of true simultaneous execution ) 
> in a single process without using ( OS dependent ) threads can be achieved
> ? 

Huh, it is exactly was I do not understand...

Thanks.

Fre;D




-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728022.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread fredvs
> besides hardware parallelism,

Is it possible, with fpc, to assign one processor (if multi) for a thread
and say to the system to use this one only for the thread ?
But maybe it will gives more problems than solutions.

Fre;D 



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728023.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Karoly Balogh (Charlie/SGR)
Hi,

On Wed, 29 Mar 2017, fredvs wrote:

> > besides hardware parallelism,
>
> Is it possible, with fpc, to assign one processor (if multi) for a
> thread and say to the system to use this one only for the thread ? But
> maybe it will gives more problems than solutions.

Yes, it's called thread/process affinity, and most operating systems have
a specific API for it. But one should treat such things extremely
carefully, otherwise with badly designed data access concurrency you end
up with potentially hard to identify structural problems like false
sharing (see Wikipedia on this) and others. This can be especially bad for
for example on NUMA architectures, or others, where data storage locality
to a given core is not obvious. (Just think about clusters, etc.)

In other words, as the OS knows best your hardware's layout and how it can
best provide performance, energy, bandwith, etc, it's usually very wise to
rely on the OS to solve the thread to CPU core assignments for you.

Bottom line: parallelism and threading is a very complex problem and very
diverse area, and anyone laughing at any approach is just shows how little
they know about true depth of the whole topic, IMO. Thinking about any
technical solution, or way of implementation as a silver bullet for
everything is a very "expert beginner" approach.

My 2 cents.

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread fredvs
@Karoly Balogh (Charlie/SGR)

Perfect, I have now all the arguments to defend the "Dinosaur Threading"
choice. 

Thanks.

Fre;D




-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728025.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Ryan Gonzalez
Parallelism is what hipster Node programmers do, threads are everything
else.

/jk

--
Ryan (ライアン)
Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else
http://refi64.com

On Mar 29, 2017 1:57 PM, "fredvs"  wrote:

> Hello.
>
> Some developers treat me as dinosaur because I use threads in place of
> doing
> parallelism.
>
> Huh, ok, but why parallelism is better and how to do it with fpc ?
>
> Thanks.
>
> Fre;D
>
>
>
> -
> Many thanks ;-)
> --
> View this message in context: http://free-pascal-general.
> 1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018.html
> Sent from the Free Pascal - General mailing list archive at Nabble.com.
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Threading vs Parallelism ?

2017-03-29 Thread Ryan Joseph

> On Mar 30, 2017, at 4:25 AM, fredvs  wrote:
> 
>> 
>> how software parallelism ( in the sense of true simultaneous execution ) 
>> in a single process without using ( OS dependent ) threads can be achieved
>> ? 
> 
> Huh, it is exactly was I do not understand...

Look at an OpenCL tutorial for more information. If you select a CPU device 
(instead of a GPU device with hundreds of compute units) then the API will 
automatically allocate the amount of threads available on the all cores 
available (which may be only 2). It’s still threaded but scales easily 
depending on the task. I don’t know why but I got the OpenCL CPU target to 
process multiple times faster than just using the CPU directly.

Parallelism is only helpful if you have a problem involving massive amounts of 
discrete tasks which are part of larger task and can be designed as such. If 
your problem is designed like this then you can offload the processing to the 
GPU and get some serious performance benefits. The catch is that 
reading/writing memory to the GPU is slow so unless you’re processing on large 
batches of data you’ll spend more time accessing memory than processing.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Delphi RTTI vs Free Pascal RTTI

2017-03-29 Thread African Wild Dog
2017-03-25 5:40 GMT-03:00 Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org>:

> Am 24.03.2017 19:55 schrieb "Michael Van Canneyt"  >:
> >
> >
> >
> > On Fri, 24 Mar 2017, African Wild Dog wrote:
> >
> >> Hello,
> >>
> >> I need to write a code compatilble with both free pascal and delphi
> using
> >> the old style RTTI.
> >> What are the diferences between delphi's and free pascal's
> approach/types?
> >>
> >> I took a look at delphi's and fpc's TypInfo unit and it looks like the
> >> types/functions are compatible.
> >
> >
> > They are. There is one dereference on Delphi which is not present in fpc,
> > although in fpc trunk, this additional dereference is there. If you use
> the
> > standard functions you should not notice this.
>
> The binary data of RTTI added before 3.1.1 now has the double indirection,
> but the Delphi-compatible "field" names have only a single indirection for
> backwards compatibility (they are properties to the double indirection
> fields). RTTI data added in 3.1.1 only has the double indirection.
> So this difference needs to be kept in mind and will always result in
> ifdefs for RTTI code that handles both Delphi and FPC.
>
> Regards,
> Sven
>
>
Thanks for the clarifications.

Regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Critical Section and Recursive Calls

2017-03-29 Thread African Wild Dog
Hello,

I'm writing a function protected by a critical section which can have
recursive calls under certain conditions.

Using the TCriticalSection class, after my thread acquires a critical
section, if my thread make 6 additional calls to TCriticalSection.Enter, to
release the critical section my thread will have to make 6 additional calls
to TCriticalSection.Leave?

If so, is this behaviour the same on all platforms?

>From the Windows API:

*"After a thread has ownership of a critical section, it can make
additional calls to EnterCriticalSection or TryEnterCriticalSection without
blocking its execution. This prevents a thread from deadlocking itself
while waiting for a critical section that it already owns. The thread
enters the critical section each time EnterCriticalSection and
TryEnterCriticalSection succeed. A thread must call LeaveCriticalSection
once for each time that it entered the critical section."*

Regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Questions About Constructors

2017-03-29 Thread African Wild Dog
Hello,

1 - What happens if my constructor raise an exception? Is my destructor
automatically called?

2 - Are the class fields automatically initialized to Default(T) just like
in Delphi?


Regards
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal