* * *

Author Topic: Volunteers for migrating a nice project to pascal  (Read 500 times)

apexcol

  • New member
  • *
  • Posts: 42
Volunteers for migrating a nice project to pascal
« on: January 30, 2018, 10:13:35 am »
Hi, I saw this project primesieve.org and it's so impressive.

I'm finding some volunteers that help to migrate this code written in C++ to pascal, or at least translate the C code, or write FreePascal bindings for primesieve's C API (see http://primesieve.org/api/). Usually it is easier in most languages to write bindings for a C API than for a C++ API.

:)

engkin

  • Hero Member
  • *****
  • Posts: 1859
Re: Volunteers for migrating a nice project to pascal
« Reply #1 on: February 13, 2018, 08:33:44 am »
Thanks for bringing this up. I just did a quick test:
Code: Pascal  [Select]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, sysutils
  10.   { you can add units after this };
  11.  
  12. const
  13.   PrimeSieveLib='primsiev.dll';
  14.  
  15. type
  16.   TPrimeType = (
  17.   //* Generate primes of short type
  18.   SHORT_PRIMES,
  19.   //* Generate primes of unsigned short type
  20.   USHORT_PRIMES,
  21.   //* Generate primes of int type
  22.   INT_PRIMES,
  23.   //* Generate primes of unsigned int type
  24.   UINT_PRIMES,
  25.   //* Generate primes of long type
  26.   LONG_PRIMES,
  27.   //* Generate primes of unsigned long type
  28.   ULONG_PRIMES,
  29.   //* Generate primes of long long type
  30.   LONGLONG_PRIMES,
  31.   //* Generate primes of unsigned long long type
  32.   ULONGLONG_PRIMES,
  33.   //* Generate primes of int16_t type
  34.   INT16_PRIMES,
  35.   //* Generate primes of uint16_t type
  36.   UINT16_PRIMES,
  37.   //* Generate primes of int32_t type
  38.   INT32_PRIMES,
  39.   //* Generate primes of uint32_t type
  40.   UINT32_PRIMES,
  41.   //* Generate primes of int64_t type
  42.   INT64_PRIMES,
  43.   //* Generate primes of uint64_t type
  44.   UINT64_PRIMES
  45. );
  46.  
  47. function primesieve_version():pchar; cdecl; external PrimeSieveLib;
  48. function primesieve_count_primes(start, stop: UInt64): UInt64; cdecl; external PrimeSieveLib;
  49. function primesieve_parallel_count_primes(start, stop: UInt64): UInt64; cdecl; external PrimeSieveLib;
  50. function primesieve_nth_prime(n,start: uint64): UInt64; cdecl; external PrimeSieveLib;
  51. function primesieve_generate_primes(start, stop: uint64;  size: pinteger; &type: TPrimeType): pointer; cdecl; external PrimeSieveLib;
  52. procedure primesieve_free(primes: pointer); cdecl; external PrimeSieveLib;
  53. function primesieve_generate_n_primes(n, start: uint64; &type: TPrimeType): pointer; cdecl; external PrimeSieveLib;
  54.  
  55.  
  56. procedure Test_CountPrimes;
  57. var
  58.   count: QWord;
  59. begin
  60.   count := primesieve_count_primes(0, 1000);
  61.   writeln('Primes below 1000 = ', count);
  62.  
  63.   // use multi-threading for large intervals
  64.   count := primesieve_parallel_count_primes(0, 1000000000);
  65.   writeln('Primes below 10^9 = ', count);
  66. end;
  67.  
  68. procedure Test_nth_prime(n: uint64);
  69. var
  70.   prime: uint64;
  71. begin
  72.   prime := primesieve_nth_prime(n, 0);
  73.   writeln(n,'th prime = ', prime);
  74. end;
  75.  
  76. procedure Test_store_primes_in_array;
  77. var
  78.   start, stop, n: uint64;
  79.   i, size: integer;
  80.   primes: PInteger;
  81. begin
  82.   start := 0;
  83.   stop := 1000;
  84.  
  85.   // store the primes below 1000
  86.   primes := primesieve_generate_primes(start, stop, @size, INT_PRIMES);
  87.  
  88.   for i := 0 to size-1 do
  89.     writeLn(i,': ', primes[i]);
  90.  
  91.   primesieve_free(primes);
  92.   n := 1000;
  93.  
  94.   // store the first 1000 primes
  95.   primes := primesieve_generate_n_primes(n, start, INT_PRIMES);
  96.  
  97.   for i := 0 to n-1 do
  98.     writeLn(i+1,'\',n,': ', primes[i]);
  99.  
  100.   primesieve_free(primes);
  101. end;
  102.  
  103. begin
  104.   WriteLn('Dll Version: ',primesieve_version);
  105.   Test_CountPrimes;
  106.   Test_nth_prime(1000);
  107.   Test_store_primes_in_array;
  108. end.

The output of the project is:
Quote
Dll Version: 5.7.3
Primes below 1000 = 168
Primes below 10^9 = 50847534
1000th prime = 7919
0: 2
1: 3
2: 5
3: 7
4: 11
5: 13
6: 17
7: 19
8: 23
9: 29
[snip]
164: 977
165: 983
166: 991
167: 997
1\1000: 2
2\1000: 3
3\1000: 5
4\1000: 7
5\1000: 11
6\1000: 13
7\1000: 17
8\1000: 19
9\1000: 23
10\1000: 29
11\1000: 31
12\1000: 37
13\1000: 41
14\1000: 43
15\1000: 47
16\1000: 53
17\1000: 59
18\1000: 61
19\1000: 67
20\1000: 71
21\1000: 73
22\1000: 79
[snip]
994\1000: 7873
995\1000: 7877
996\1000: 7879
997\1000: 7883
998\1000: 7901
999\1000: 7907
1000\1000: 7919

In case someone wants to test, attached is the 32-bit DLL I generated using the original PrimeSieve C++ code version 5.7.3.

Thaddy

  • Hero Member
  • *****
  • Posts: 5378
Re: Volunteers for migrating a nice project to pascal
« Reply #2 on: February 13, 2018, 12:10:35 pm »
Ahummm. Do we need it? This is basic school math and should be just as fast in pure Pascal.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

taazz

  • Hero Member
  • *****
  • Posts: 4762
Re: Volunteers for migrating a nice project to pascal
« Reply #3 on: February 13, 2018, 12:31:18 pm »
Ahummm. Do we need it? This is basic school math and should be just as fast in pure Pascal.
do we have it? if its so basic then is there any unit that can be used?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 3153
Re: Volunteers for migrating a nice project to pascal
« Reply #4 on: February 13, 2018, 12:32:10 pm »
Ahummm. Do we need it? This is basic school math and should be just as fast in pure Pascal.
Hence the question from the topicstarter :)
I'm finding some volunteers that help to migrate this code written in C++ to pascal...

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus