# Basis

Parallel programming it not an expedition of the by turns program. It is complete record of algorithm since the flowchart in which there are parts for by turns performance, and there are those parts which are independent from each other, and quite can is made in a parallel way.
For classical example sorting of units can be.

## Sorting

There are many varieties of the given algorithms, but some of them do not give in to improvement by parallelism application. For example, the algorithm "vial" cannot be improved applying parallelism as each step (change of positions of units) depends on result of the previous step. There is a good algorithm which can be improved, applying parallelism, it is quick sort.
Any unit is selected, it is desirable average on the value. All units of a vector divide on two parts: smaller the selected unit and big. Two turned out parts it is possible to sort independently and therefore in a parallel way. Applying parallelism it is possible to reach a maximum expedition from all processors of system. And speed of performance it will be proportional to quantity of processors.

```('vector  defmethod sortq (ind  last)
(nil  if  (nil  = ind)
(nil  setq  ind 0 last  ((this  size) - 1)))
(nil  cond
(((last - ind)  > 1)
(nil  let ((med ((ind + last) floor 2)))
; choose medium
(nil  if  ((this  elt ind)  > (this elt med))
(this swap  ind med))
(nil  when  ((this  elt med)  > (this elt last))
(this swap  med last)
(nil  if  ((this  elt ind)  > (this elt med))
(this swap  ind med)))
; decompose
(nil  let
((ind ((ind copy) +=  1))
(last ((last  copy) -=  1)))
(nil  while (last > ind)
(nil parallel
(nil  while ((this  elt ind)  < (this elt med))
(ind  +=  1))
(nil  while ((this  elt last) > (this elt med))
(last -=  1)))
(nil  cond
((med = last)
(nil  when  (ind  < med)
(this swap  ind med)
(med  setf  ind)
(last -=  1)))
((med = ind)
(nil  when  (med  < last)
(this swap  med last)
(med  setf  last)
(ind  +=  1)))
(true
(this swap  ind last)
(ind  +=  1)
(last -=  1)))))
; parallel sorting
(nil  parallel
(this sortq ind (med  - 1))
(this sortq (med  + 1)  last))))
(((last - ind)  = 1)
(nil  if  ((this  elt ind)  > (this elt last))
(this swap  ind last))))
this)```

## Quantity of processors

The quantity of processors can be learnt by means of system function nprocs.

```>(nil nprocs)
2```

## Fork

There are still tasks which should will be fulfilled in a parallel way and irrespective of other tasks. In operating systems it is named the driver. The fork is start of function (nil progn {task}), not expecting result.