distributed multi-threading in gnu-prolog

21

Click here to load reader

Upload: nuno-morgadinho

Post on 27-May-2015

1.928 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Distributed Multi-Threading in GNU-Prolog

Distributed Multi-Threading in GNU PrologNuno Morgadinho, Salvador Abreu

{nm, spa}@di.uevora.pt

Departamento de Informática

Évora 2007

Page 2: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Distributed - one or more computers communicating over a network

• Multi-Threading - more than one thread of execution

• Thread - a flow of execution

2

Introduction

Page 3: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Obtain results faster for problems where performance is critical

• The problem can be divided into smaller tasks which can be carried out simultaneously

• Parallelism

3

Introduction

Page 4: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• PM2 - a distributed multi-threading programming environment

• GNU Prolog - efficient native Prolog compiler

• Combination of both

4

What We Present

Page 5: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• GNU Prolog produces stand-alone executables

• The size of the executables is relatively small

• Doesn’t work with machine independent saved-states

5

GNU Prolog and PM2: Why?

Page 6: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Established a model for connecting PM2 and GNU Prolog

• The approach doesn’t involve modifications to GNU Prolog neither to PM2

• Compatibility with GNU Prolog libraries is retained

Implementation

6

Page 7: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Tabard - new program that manages distributed instances of GNU Prolog engines

• pm2prolog - new library that allows the development of distributed multithreaded Prolog applications

Approach

7

Page 8: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Allow to execute computations remotely

• Manage the engines responsible for the computations

• Manage the communication involved between the several machines

• Based on distributed memory and explicit message-passing

8

Functionality

Page 9: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS9

Example

:- initialization(init).:- include('pm2prolog').

% thread with rank 0init:- pm2_is_master, !, pm2_max_rank(MaxRank), start_prolog_workers(MaxRank), test_prolog_workers(MaxRank), read_test(MaxRank), stop_prolog_workers.

% thread != 0init:- worker_code.

Page 10: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Configuration that specifies the list of machines

• Each machine is mapped to one or more processing nodes or virtual processors (VPs)

Before Running

10

Page 11: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Binary is copied to all machines

• In VP0 (master) a gprolog engine is created

• In the other VPs (workers) a pthread in C is created and stands awaiting messages

Execution Model

11

Page 12: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• In the master, now in the Prolog thread, a predicate is called to send a message to every worker

• The workers receive the message, initiate a gprolog engine and the thread stands awaiting more messages to come

12

Execution Model

Page 13: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• In the master, work is distributed throughout the workers through message-passing

• The workers receive tasks which they execute locally. As soon as they finish, they send their results back to the master

13

Execution Model

Page 14: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• The master assembles the work results by reading as many messages as the number of previously sent messages

• The master redistributes work again or orders the workers to finish their execution

• The workers terminate

• The master reiniciates the workers or terminates itself

14

Execution Model

Page 15: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

...

READ WRITE

WRITE

Prolog ThreadC Thread Listener

RECEIVE SEND

Message Queue

write_message_queue()

Start_Prolog()

Stop_Prolog()

... ...

thread_send_message/2

thread_get_message/2

pm2_self/1

UNLOCK

LOCK

SOCKET

Inside a Virtual Processor

15

Page 16: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Several VPs per physical machine is possible

Prolog Proc

Node 1

VP 0

Prolog Proc

VP 1

...

Prolog Proc

VP 2

...

Node 2

Prolog Proc

VP 2

Node 3

16

Page 17: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• ISO/IEC Draft Technical Report 13211-5:2007, Prolog Multi-Threading Support

• Extensions to take into consideration remote threads

17

ISO Support

Page 18: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• thread_create/2

• vid(Rank, ThreadID)

• Rank - VP identifier

• ThreadID - identifier of the thread inside

18

PM2-Prolog Remote Threads

Page 19: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS19

Experimental Evaluation

0

25

50

75

100

2004 2005 2006 2007

Results obtained with 7x Intel(R) Pentium(R) 4 2.80 Mhz each, Hyperthreading enabled, 512 Mbytes each, Linux 2.4.19 kernel, 100 Mbits TCP/IP Ethernet network

Page 20: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• We presented a distributed multi-threading GNU Prolog system on top of PM2

• First results show that it can obtain substantial speedups, even for real-world

• Proved the approach to be technically possible and can be of use to other implementers

20

Conclusions

Page 21: Distributed Multi-Threading in GNU-Prolog

Slide ICLP ’07 CICLOPS

• Improving our proposal

• Extend the API with introspection and monitoring predicates

• Experiment with more programs and bigger configurations

• Build our own applications using this technology

21

Further Work