Including parts of a diet template in another

2023-03-25 Thread seany via Digitalmars-d-learn

Hello

If we are creating a multipage Vibe.d application, we need to use 
diet templates. I can't find any info on how to include parts or 
whole of a diet template in another.


So for example, if i had pages :

1 =>

```
html
  head
//stuff in head
  body
// a common div goes here
.commonDiv
   // common div stuff here
.first-page-specific-div
   // first page specific stuff ...


```

and

2 =>

```
html
  head
//stuff in head
  body
// a common div goes here
.commonDiv
   // common div stuff here
.second-page-specific-div
   // second page specific stuff ...
```

I would like to do something like this

commonDivFile.extension =>

.commonDiv
   \\ common div stuff goes here
   \\ add css file affecting the common div
   \\ add javascript with event listeners for common div 
elements..


and then

1 =>

```
html
  head
//stuff in head
  body
// some method to include commonDiv here, unknow to me
.first-page-specific-div
   // first page specific stuff ...


```

and

2 =>

```
html
  head
//stuff in head
  body
// some method to include commonDiv here, unknow to me
.second-page-specific-div
   // second page specific stuff ...
```


I can't find a way to do this in documents. If it is in the 
documentation, please point me to it. I do not want to use an 
iframe.


What can be done in this case? Thank you.


What makes vibe.d Incredibly Slow on a VPS?

2023-03-18 Thread seany via Digitalmars-d-learn

Consider this fraction of code Please:



void createNewOwner(HTTPServerRequest req, 
HTTPServerResponse res) {	

writeln("NEW OWNER requests are : -");


writeln(req.form);
			writeln(req.files); 
writeln("==");



	// TASK EXTRACT the data from the POST variable// 
--//

// TODO check security with req.form["loginToken"];

string avatarPath ;

if( req.files.length != 0) {

// HERE we only check if file is supplied...
// no "existing avatar" yet, as fresh new user.

auto file = "file" in req.files;

if (file.filename != "" ) {

		string k = genNonce();// Generate a random 
number to ensure there is no conflict


			string rp = req.form["username"].replace(" ", 
"-").replace("@", "-")~"-"~k~"-"~(file.filename.name).replace(" 
", "-").replace("@", "-");
			// replaced spaces with "-" and @ with 
-, to avoid loading problems

try {

moveFile(file.tempPath.toString(), 
"assets/images/avatars/" ~ rp);			writeln("Uploaded 
successfully!");

avatarPath = "/" ~ "assets/images/avatars/" ~ 
rp;
} catch (Exception e) {
			writeln("Exception thrown, trying 
copy");
copyFile(file.tempPath.toString(), 
"assets/images/avatars/" ~ rp);

avatarPath = "/" ~ "assets/images/avatars/" ~ 
rp;
}
}
} else {

		avatarPath = 
"assets/images/avatars/noFace.png";		// Here it is 
allowed. IF no image, then set a default.

}


	avatarPath = avatarPath.replace(" ", "");	// 
should not be needed, but just in case

avatarPath = avatarPath.replace("@", "-");

string e2fa = "";
	req.form["en2fa"] == "true" ? (e2fa = "1") : (e2fa = 
"0");// converted e2FA to 0 or 1, in string format



	// TASK confirm no conclict // 
--//


	auto check_existingUser = loginRoutines.get_userAllInfo( 
req.form["username"]);


	if (check_existingUser.length != 0) {		// 
username already exists The only valid value here is 0
			// = no records. anything  != 0 will 
be rejected


		res.writeBody("ERROR: 30LX-USEREX. Username existiert 
schon... Verwenden Sie bitte einen anderen Username.");

return;
}



	// TASK set entry details // 
//


	int usrCnt  = 
loginRoutines.get_userCount();write("user count is: 
"); writeln(usrCnt);

if (usrCnt < 0) {
		res.writeBody("ERROR: 71QM-UKNDBR. Unbekannter 
Datenbankfehler. Versuchen Sie später erneut.");

return;

}
	string cntr = to!string(usrCnt +1);		// next 
item in file.


	string[string] nuInfo ;	// container for new 
user Info


nuInfo["username"]= req.form["username"];
nuInfo["fName"]   = req.form["fName"];
nuInfo["lName"]   = req.form["lName"];
nuInfo["avatarPath"]= avatarPath;
nuInfo["mail"]= req.form["mail"];
nuInfo["tel"] = req.form["tel"];
nuInfo["mob"] = req.form["mob"];


string[string] lgInfo;

lgInfo["username"]= req.form["username"];
lgInfo["role"]= "owner";
	lgInfo["active"]	= "-1";	write("going to add 
signUp line in user dtls : "); writeln(lgInfo);



	string loginInfo = cntr ~ "," ~ req.form["username"] ~ "," ~ 
"++" ~ "," ~ e2fa ~ ", 0";
			// enter new user with supplied 2FA, 
but set the last field = 0,



// as not yet paired.



	// TASK insert the data // 
--//



	bool stat;write("going to add signUp 
line in owner dtls : "); writeln(nuInfo);
	stat = databas

Re: vibe.d

2023-03-11 Thread seany via Digitalmars-d-learn
On Saturday, 11 March 2023 at 12:56:16 UTC, Steven Schveighoffer 
wrote:

On 3/11/23 5:12 AM, seany wrote:
email.headers["Sender"] = "<"; // 
valid mail


Looks like an extra `<`, is that correct?



No, i mistyped that when i changed the email address after 
copying it in here. The original code does not have that extra < 
sign


Thank you.



vibe.d

2023-03-11 Thread seany via Digitalmars-d-learn

Hi

I am trying to send an email via vibe .d

Here is the code snippet.

```
Mail email = new Mail;

	email.headers["Date"] = 
Clock.currTime(PosixTimeZone.getTimeZone("America/New_York")).toRFC822DateTimeString(); // uses UFCS
	email.headers["Sender"] = "<"; // valid 
mail
	email.headers["From"] = ""; // valid 
email

email.headers["To"] = "";  // valid mail.
email.headers["Subject"] = "Betreff";
email.headers["Content-Type"] = "text/plain;charset=utf-8";
email.bodyText = "Textinfo";

setLogLevel(LogLevel.verbose4);   
  writeln("00");



auto settings = new SMTPClientSettings("smtp.gmail.com", 587);
settings.connectionType = SMTPConnectionType.startTLS;
settings.authType = SMTPAuthType.login;
settings.username = "myapp_de.s...@gmail.com";
settings.password = "mypass_veryStronk";

logInfo("Sending mail...");
sendMail(settings, email);
logInfo("done.");

res.writeBody("An email has been sent to the user ");
```









I get this error :


```
[main(toaW) INF] Sending mail...
Thread exit Eventcore DNS Lookup (index 9) (main=false)
Socket 43, read 86 bytes: ok
Socket 43, read 192 bytes: ok
EHLO response: 250-smtp.gmail.com at your service, 
[2a02:3030:9:4f1a:bd94:4bec:9e39:c9fa]

EHLO response: 250-SIZE 35882577
EHLO response: 250-8BITMIME
EHLO response: 250-STARTTLS
EHLO response: 250-ENHANCEDSTATUSCODES
EHLO response: 250-PIPELINING
EHLO response: 250-CHUNKING
EHLO response: 250 SMTPUTF8
Socket 43, read 30 bytes: ok
Socket 43, read 2416 bytes: ok
Socket 43, read 1208 bytes: ok
Socket 43, read 572 bytes: ok
validate callback for /C=US/O=Google Trust Services LLC/CN=GTS 
Root R1

SSL cert initial error: unable to get local issuer certificate
SSL cert not trusted or unknown issuer: /C=BE/O=GlobalSign 
nv-sa/OU=Root CA/CN=GlobalSign Root CA

SSL validation result: 0 (20)
OpenSSL error at ssl/statem/statem_clnt.c:1889: 
error:0A86:SSL routines::certificate verify failed (-)

-
HTTP server response:
-
HTTP/1.1 500 Internal Server Error
Server: vibe.d/1.22.6
Date: Sat, 11 Mar 2023 10:09:49 GMT
Keep-Alive: timeout=10
Content-Type: text/plain; charset=UTF-8
Content-Length: 6133
-
Exception while handling request POST /createNewOwner: 
object.Exception@/home/monsoon/.dub/packages/vibe-d-0.9.6-alpha.1/vibe-d/tls/vibe/stream/openssl.d(668): Connecting TLS tunnel: error:0A86:SSL routines::certificate verify failed (167772294)

```


Note that dub is running on localhost.

How can I resolve this? Please help. Thank you


How can I easily determine the last charachter of a file?

2023-02-14 Thread seany via Digitalmars-d-learn

Hello

Consider the content of a file


First line \n
Second line 

data data data data  ... last char



My goal is to find out whether the last character is a new line 
or not. Please not, it will be sufficient if this works on Linux.


More specifically I want to insert a new line at the end of the 
file. File.writeline inserts a line at the end of the _newly 
added line_.


Thus if I had



First line \n
Second line 

data data data data  ... non-NL-char



and wanted to insert : `newline-word-word-word ... non-NLchar`

Via `file.writeln`, it would end up as


First line \n
Second line 

data data data data  ... non-NL-char{no newline or whitespace 
here}Newline-word-word-word ... non-NLchar{newline}




This is not unexpected. But, I want to make sure, that my 
appending automatically adds a new line. However, it should not 
add empty lines.


One brute force method is to copy every line of the file to a 
temp file or in the RAM and then write back in the original file. 
I would like to avoid that if possible.


Thanks.



MongoDB and vibe troubles.

2023-02-09 Thread seany via Digitalmars-d-learn

Please consider the code:

mClient = connectMongoDB("127.0.0.1");
auto db = mClient.getDatabase("webAppMaster");
writeln(db);
auto users  = db["users"];
writeln(users);


This follows this example: 
https://github.com/vibe-d/vibe.d/blob/master/examples/mongodb/source/app.d


This results in :

MongoDatabase("webAppMaster", "webAppMaster.$cmd", 
vibe.db.mongo.client.MongoClient)


and in the Next line:

MongoCollection(vibe.db.mongo.client.MongoClient, 
MongoDatabase("webAppMaster", "webAppMaster.$cmd", 
vibe.db.mongo.client.MongoClient), "users", "webAppMaster.users")


This makes me think that MongoDB driver has successfully found 
the database and the collection. But now, this line is causing a 
problem :


auto result = users.findOne(["_id": userName, "password" 
: passHash]);



The error is, seen on the web page i am trying to serve:



vibe.db.mongo.connection.MongoDriverException@/root/.dub/packages/vibe-d-0.9.5/vibe-d/mongodb/vibe/db/mongo/cursor.d(304): Query failed. Does the database ex



and on the root console where vibe.d is running i have this :

MongoDB reply was longer than expected, skipping the 
rest: 223 vs. 36



The database and collection exists:

> mongosh
> use webAppMaster
> db.webAppMaster.users.findOne({"_id": "testuser", 
"password" : "1234"})


shows me what I want to see.

Where do I start debugging, please? Thank you


vibe.d + mongoDB

2023-01-20 Thread seany via Digitalmars-d-learn
Hi I am googling to find some vibe.d and mongoDB tutorial. Are 
their some available? Thank you


How to Add CSS and JS to vibe.d templates

2023-01-19 Thread seany via Digitalmars-d-learn

Hi

Howcan one add CSS and JS to vibe.d templates? Here is my setup 
(vibe.d project initiated with dub using dub init myproject 
vibe.d):


./public:
main.css  main.js

./source:
app.d

./views:
auth2fa.dt  fail.dt  login.dt  pair.dt  passfail.dt  userfail.dt


I am trying to add a css file using `link(rel="stylesheet", 
type="text/css", href="main.css")` in the diet templates, but it 
has no effect. I took the files from here: 
https://codepen.io/ricardoolivaalonso/pen/YzyaRPN


Note that (as discussed in my previous post by Steven 
Schveighoffer) , there are some errors in the jade/pug template 
file. But even if we correct them, and then I try to use the 
setup, I do not get the styles. (Of course, i can't point my 
browser to www.my.server/main.css or so, because those endpoints 
are not defined. However, as I understood, all non-defined 
endpoints should anyway be redirected to public)


Thank you.


Re: Vibe.d Diet Templatesand Forms

2023-01-19 Thread seany via Digitalmars-d-learn
On Friday, 20 January 2023 at 01:32:04 UTC, Steven Schveighoffer 
wrote:

On 1/19/23 6:24 PM, seany wrote:

[...]


Did you mean to include straight HTML here? I don't think that 
is supported.


[...]


You are indeed right. The Link was a problem, and removing the 
link actually have sorted the issue. Thank you.


Vibe.d Diet Templatesand Forms

2023-01-19 Thread seany via Digitalmars-d-learn

Hello

Please consider this diet template:

doctype html
html(lang="es", dir="ltr")
head
meta(name="viewport", 
content="width=device-width, user-scalable=no, initial-scale=1.0")

meta(charset="utf-8")
link(rel="stylesheet", type="text/css", 
href="main.css")
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700;800&display=swap"; rel="stylesheet">


body

div.main
div.container.a-container#a-container
form(id="loginfrm", class="frm", 
method="post", action="/login_attempt")

h2.form_title.title Create Account
span.form__span or use email for 
registration
input.form__input(type="text", 
placeholder="Name" )
input.form__input(type="text", 
placeholder="Email")
input.form__input(type="password", 
placeholder="Password")
button().form__button.button.submit 
SIGN UP


Please notice the line `form(id= ...`. This line is causing the 
following error:





login.dt(29,45): Error: found `method` when expecting `;` 
following `return` statement

login.dt(29,51): Error: found `=` instead of statement
login.dt(28,12): Error: missing closing `)` after `if 
("form"`
login.dt(28,21): Error: found `)` when expecting `;` 
following statement

login.dt(28,36): Error: found `method` when expecting `)`
login.dt(28,42): Error: found `=` when expecting `)`
login.dt(28,43): Error: found `""` when expecting `)`
login.dt(28,45): Error: found `)` instead of statement

/root/.dub/packages/diet-ng-1.8.1/diet-ng/source/diet/html.d(246,8): Error: template instance `diet.html.compileHTMLDietFileString!("login.dt", contents, DefaultDietFilters).exec!(StreamOutputRange!(InterfaceProxy!(OutputStream), 1024LU))` error instantiating

/root/.dub/packages/vibe-d-0.9.5/vibe-d/http/vibe/http/server.d(351,66):instantiated from here: `compileHTMLDietFileString!(StreamOutputRange!(InterfaceProxy!(OutputStream), 1024LU))`
source/app.d(41,5):instantiated from here: 
`render!"login.dt"`



What is the problem? How can I resolve it? Thank you.



Re: Nested sibling classes

2023-01-12 Thread seany via Digitalmars-d-learn

On Thursday, 12 January 2023 at 17:41:39 UTC, Salih Dincer wrote:

On Thursday, 12 January 2023 at 17:05:04 UTC, seany wrote:

How can I make it, that classes b and c can access each other, 
and create instances of each other freely? Thank you.


Ignoring the typos you could try auto and static:

```d
class a
{ //outer

  static class b
  { // inner 1

c C;
this()
{
  this.C = new c;
  //writeln(this.C.i);
}
  }

  static class c
  { // inner 2
int i = 10;
  }
}

int main ()
{
  int[21][1] test;
  test[0][20] = 19;

  assert(test[0][20] == 19);

  auto B = new a.b;
  auto C = new a.c;

  assert(B.C.i == 10);
  assert(C.i == 10);

  return 0;
 }
```
SDB@79


Hi

Moving the "new c" within the this() function indeed solved it. 
Thank you for pointing out the typos.


Please, can you explain what role "static" plays here? Thank you 
again


Nested sibling classes

2023-01-12 Thread seany via Digitalmars-d-learn

Please Consider the code:

import std.stdio;

class a {

public:
 this(){}
~this(){}

class b {

public:
this.outer.c C = new this.outer.c();
 this() {
writeln(this.C.i);
}
~this() {}

}

class c {
public:
 this() {}
~this() {}
int i = 10;
}

}


int main () {

int [int][int] test;

test[0][20] = 19;
writeln(Test[0][20]);


a A = new A();
a.b B = a.new a.b();
return 0;
}


Compiling with dmd tells me:
`test.d(12): Error: undefined identifier `` this.outer.c `` ` (i 
used two backticks, but i can't seem tobe escaping the backtick 
character correctly in this forum)


On fish shell we have:
❯ dmd --version
DMD64 D Compiler v2.101.2

Copyright (C) 1999-2022 by The D Language Foundation, All Rights 
Reserved written by Walter Bright



If i remove the "this.outer" and just write, c C = new c(); then 
i have:


`test.d(12): Error: cannot construct nested class ` c ` because 
no implicit ` this ` reference to outer class ` a ` is available`



How can I make it, that classes b and c can access each other, 
and create instances of each other freely? Thank you.




yet another segfault - array out of bound is not caught by try catch

2021-09-17 Thread seany via Digitalmars-d-learn

I have now this function, as a private member in a Class :


double calculate_lineLength( int i)  {
field.rawData [] * rd;   // ignore 
the details, this works;
rd = cast (field.rawData [] *)  dataSet; // ignore 
the details, this works;


auto l = this.allLines[i];   // this is 
defined as
 // int [][] 
allLines =
 //   
 new int [][] (0,0)
 // in case 
of failure, this is empty

double r = 0;
try {
writeln("l ", l);// prints []
writeln("i ", i);// prints i, 
in this case, i is set to 0

writeln(l.length);   // prints 0
writeln("l0 ", l[0]);// segfault 
- i want it to be caught

write("will print");
writeln("rd", (*rd));
write("will not print...");
auto p0 = (*rd)[l[0]];
auto p1 = (*rd)[l[1]];
	r = calculate_geoDistance_vincenty(p0.lat,p1.lat, 
p0.lon, p1.lon);

} catch (RangeError er) {
writeln("range error");
}
return r;
}


Compile with `dub build --compiler=ldc2 `. this should enable 
array bound checking options.



I am debugging with gdb :

`gdb ./myprogram`

Then, in gdb console :

`run arg1 arg2 `

Result is :

91753
91754
91755
91756
[New Thread 0x77560640 (LWP 45344)]
[New Thread 0x7fffe640 (LWP 45345)]
[New Thread 0x76d5f640 (LWP 45346)]
[New Thread 0x7655e640 (LWP 45347)]
[New Thread 0x75d5d640 (LWP 45348)]
[New Thread 0x7555c640 (LWP 45349)]
[New Thread 0x74d5b640 (LWP 45350)]
[New Thread 0x7fffef7fe640 (LWP 45351)]
[New Thread 0x7fffeeffd640 (LWP 45352)]
[New Thread 0x7fffee7fc640 (LWP 45353)]
[New Thread 0x7fffedffb640 (LWP 45354)]
[New Thread 0x7fffed7fa640 (LWP 45355)]
[New Thread 0x7fffecff9640 (LWP 45356)]
[New Thread 0x7fffb640 (LWP 45357)]
[New Thread 0x7fffbf7fe640 (LWP 45358)]
[New Thread 0x7fffbeffd640 (LWP 45359)]
[New Thread 0x7fffbe7fc640 (LWP 45360)]
[New Thread 0x7fffbdffb640 (LWP 45361)]
[New Thread 0x7fffbd7fa640 (LWP 45362)]
getting LINES done
alllines: []
l []
i 0
0
Thread 1 "myprogram" received signal SIGSEGV, 
Segmentation fault.
_D14analysisEngine9geoEngine20calculate_lineLengthMFiZd 
(this=, i=0) at source/analysisEngine.d:15526

15526
writeln("l0 ", l[0]);

So, to see what is going on, i use the command `bt`:


#0  
_D14analysisEngine9geoEngine20calculate_lineLengthMFiZd 
(this=, i=0) at source/analysisEngine.d:15526
#1  0x555dba40 in 
_D14analysisEngine9geoEngine13add_turnLinesMFZv (this=out>) at source/analysisEngine.d:7387
#2  0x555e375a in 
_D14analysisEngine9geoEngine15analyze_tillageMFZv 
(this=0x7756a000) at source/analysisEngine.d:5329
#3  0x5560d082 in _Dmain (args=...) at 
source/AI.d:123



Okey, I know where to look for : it's the line asking for 
`writeln("l0 ", l[0]);`.



But should it not be caught by range error ? If I do `print 
l`in gdb, i find :

$1 = {length = 0, ptr = 0x0}

With `print l[0]` i get: `Attempt to take address of value not 
located in memory.`. I believe the array printing syntax is 
valid; see 
[here](https://phoenix.goucher.edu/~kelliher/cs23/gdb.html).


What absolute rookie mistake am I committing? What does it mean : 
"Attempt to take address of value not located in memory" ? I am 
not even calling / accessing a pointer. I am trying to extract a 
value outside an array bound.


I imagine they all have their addresses. But with the bound 
checking operation in place, would the bound error be triggered 
before the attempt to take unavailable address error has a chance 
to trigger?


Thank you.




Re: dub segfault and range error handling

2021-09-16 Thread seany via Digitalmars-d-learn

On Thursday, 16 September 2021 at 20:49:28 UTC, seany wrote:

I create a new project with : `dub init myproj`.

Then I change the source/app.d file with this :

[...]


PS :compiling with : `dub build -b release ` ( i.e. no ldc2) is a 
direct segfault of the code posted above.


PPS : my system is : Linux glassplanet 5.9.16-1-MANJARO #1 SMP 
PREEMPT Mon Dec 21 22:00:46 UTC 2020 x86_64 GNU/Linux


dub segfault and range error handling

2021-09-16 Thread seany via Digitalmars-d-learn

I create a new project with : `dub init myproj`.

Then I change the source/app.d file with this :



`
import std.stdio;
import std.math;
import std.stdio;
import std.conv;
import std.format;
import std.math;
import std.algorithm;
import std.net.curl;
import std.json;
//import dlib.image;
import std.path;
import std.array;
import std.net.curl;
import core.stdc.stdlib;
import std.datetime;
import std.file;
//import opmix.dup;
import std.parallelism;
import std.exception;
import core.exception;




void main() {

int[] a = new int[] (0);
try {
// writeln(a[1]);
test();
} catch ( RangeError re) {
writeln("wrong");
} catch (Throwable T){
writeln("something else");
}
}

void test() {


int [] b =  new int[0];
int c = b[4];
writeln(c);

}

`

I compile with : `dub build -b release --compiler=ldc2`

The result executing the compiled binary 'myproj' is is ( whether 
`writeln (a[1])` is uncommented, or the  `test()` function is 
uncommented) some random number, usually negative with large 
absolute value, such as `-1894658200` .


If this is embedded in a class, then the result is segfault.

Is this expected behavior?

Thank you.



Re: associative array with Parallel

2021-07-23 Thread seany via Digitalmars-d-learn
On Thursday, 22 July 2021 at 16:39:45 UTC, Steven Schveighoffer 
wrote:

On 7/22/21 1:46 AM, seany wrote:

[...]


Correct. You must synchronize on ii.


[...]


This isn't valid code, because you can't append to an integer. 
Though I think I know what you meant. Is it thread-safe 
(assuming the array elements are appendable)? I think so, but 
I'd have to see a working example.


[...]



you are right. in the pseudocode, i wanted to say: `ii[i] = 
somefunc(dummy);`


Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn

On Thursday, 22 July 2021 at 15:12:37 UTC, Adam D Ruppe wrote:

On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote:

how can I specify this with dub ?


Probably easiest to just copy the memoryerror.d file from 
druntime into your dub source dir.


I did copy in subfolder /etc/linux. same as this :

`.dub/build/application-release-linux.posix-x86_64-ldc_v1.24.0-5496805BDFFAF7D74739CE42F7A6E3B0/tracker_ai.o:traits.d:function
 _D14analysisEngine9geoEngine15analyze_tillageMFZv: error: undefined reference 
to '_D3etc5linux11memoryerror26registerMemoryErrorHandlerFZb`


Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn

On Thursday, 22 July 2021 at 14:19:37 UTC, seany wrote:

On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote:

On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote:

What will it return to me?


true if it succeeded.

I want to catch the segfault and a segfault has occured, I 
want run a different code at that point.


You mean transparently rerun some code? That's better done 
with the lowlevel sigaction handler.


But if you just want to standard try/catch then do something 
in the catch block, this is fine.



import etc.linux.memoryerror;

void main() {
registerMemoryErrorHandler();
int* a;
try {
*a = 4;
} catch(Throwable e) {
import std.stdio;
writeln("Caught");
}
}


It can be used on ldc2 too but it isn't as reliable since ldc 
considers null access to be undefined behavior anyway and thus 
may optimize out your catch


You also need to compile in the module with ldc so build it 
like


$ ldc2 seg.d ~/d/ldc/import/etc/linux/memoryerror.d

just including the memoryerror file o the command line lets it 
link.



how can I specify this with dub ?


If i do `dub build -b release --compiler=ldc2 
/usr/include/dmd/druntime/import/etc/linux/memoryerror.d` ; I 
get : `Package 
'/usr/include/dmd/druntime/import/etc/linux/memoryerror.d' was 
neither found locally nor online.`


I have added this to my dub.json :

"mylib":{
"versions": "~master",
"path": 
"/usr/include/dmd/druntime/import/"

},


Result : 
`.dub/build/application-release-linux.posix-x86_64-ldc_v1.24.0-5496805BDFFAF7D74739CE42F7A6E3B0/tracker_ai.o:traits.d:function _D14analysisEngine9geoEngine15analyze_tillageMFZv: error: undefined reference to '_D3etc5linux11memoryerror26registerMemoryErrorHandlerFZb'

`





Re: catching segfault using try_ catch

2021-07-22 Thread seany via Digitalmars-d-learn

On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote:

On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote:

What will it return to me?


true if it succeeded.

I want to catch the segfault and a segfault has occured, I 
want run a different code at that point.


You mean transparently rerun some code? That's better done with 
the lowlevel sigaction handler.


But if you just want to standard try/catch then do something in 
the catch block, this is fine.



import etc.linux.memoryerror;

void main() {
registerMemoryErrorHandler();
int* a;
try {
*a = 4;
} catch(Throwable e) {
import std.stdio;
writeln("Caught");
}
}


It can be used on ldc2 too but it isn't as reliable since ldc 
considers null access to be undefined behavior anyway and thus 
may optimize out your catch


You also need to compile in the module with ldc so build it like

$ ldc2 seg.d ~/d/ldc/import/etc/linux/memoryerror.d

just including the memoryerror file o the command line lets it 
link.



how can I specify this with dub ?


If i do `dub build -b release --compiler=ldc2 
/usr/include/dmd/druntime/import/etc/linux/memoryerror.d` ; I get 
: `Package 
'/usr/include/dmd/druntime/import/etc/linux/memoryerror.d' was 
neither found locally nor online.`






Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn

On Thursday, 22 July 2021 at 09:02:56 UTC, jfondren wrote:

On Thursday, 22 July 2021 at 07:51:04 UTC, seany wrote:


OK.
Sorry for the bad question : what if i pregenerate every 
possible key, and fill the associative array where each such 
key contains some invalid number, say -1 ?


You mean where each value contains some invalid number, and the 
AA's keys are never changed during the parallel code? Yeah, 
that should work.


Yes, the keys are never changed during the parallel code 
execution. keys are pre-generated.


Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn

On Thursday, 22 July 2021 at 07:27:52 UTC, jfondren wrote:

On Thursday, 22 July 2021 at 07:23:36 UTC, seany wrote:

On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote:

No. Consider 
https://programming.guide/hash-tables-open-vs-closed-addressing.html




The page says :


A key is always stored in the bucket it's hashed to.


What if my keys are always unique?


That has no bearing on the problem. Two of your unique keys 
might map to the same bucket.


OK.
Sorry for the bad question : what if i pregenerate every possible 
key, and fill the associative array where each such key contains 
some invalid number, say -1 ?


Then in process, the parallel code can grab the specific key 
locations. Will that also create the same problem ?


Re: associative array with Parallel

2021-07-22 Thread seany via Digitalmars-d-learn

On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote:

No. Consider 
https://programming.guide/hash-tables-open-vs-closed-addressing.html




The page says :


A key is always stored in the bucket it's hashed to.


What if my keys are always unique?


associative array with Parallel

2021-07-21 Thread seany via Digitalmars-d-learn

Consider :

int [] ii;
foreach(i,dummy; parallel(somearray)) {
  ii ~= somefunc(dummy);
}


This is not safe, because all threads are accessing the same 
array and trying to add values and leading to collision.



But :

int [] ii;
ii.length = somearray.length;
foreach(i,dummy; parallel(somearray)) {
  ii[i] ~= somefunc(dummy);
}


This is safe. In this case, threads are accessing an unique 
memory location each.


But what about this :

int [ string ] ii;
ii.length = somearray.length;
foreach(i,dummy; parallel(somearray)) {
  string j = generateUniqueString(i);
  ii[j] ~= somefunc(dummy);
}


Is this also guaranteed thread safe?


In my 5 runs, I did not see any problems, but I'd like to 
confirm. Thank you.





Re: Performance issue with fiber

2021-07-21 Thread seany via Digitalmars-d-learn

On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote:
Hi, I'm new to D lang and encounter some performance issues 
with fiber, not sure if there's something obviously wrong with 
my code.


[...]


Following.

I am also in need of more information to increase speed of D 
binaries using parallel code.


Associative Array with double[][]

2021-07-21 Thread seany via Digitalmars-d-learn
I have a perimeter of a shape, given by a `double [][]` . I want 
to keep the lengths of various diagonals in another associative 
array.


So,

/// define some associative array to keep track of diagonals 
here..


auto perimeter = new double[][] (0,0);

/// --- fill up perimeter here ---

for(int i = 0; i < perimeter.length; i++) {
  for ( int j = 0; j < perimeter.length; j++) {

   fill up the associative array here

  }
}


So, I would like to do this:

double[ double[][]] diagonalLengths;
auto perimeter = new double[][] (0,0);

/// --- fill up perimeter here ---

for(int i = 0; i < perimeter.length; i++) {
  for ( int j = 0; j < perimeter.length; j++) {

  auto diag_point_i = perimeter[i];
  auto diag_point_j = perimeter[j];

  diagonalLengths [ [diag_point_i, diag_point_j]] = 
calculate_length (i,j);


  }
}


This is necessary, as further processing will change the indices 
of the points in the perimeter. I can't therefore use ` 
diagonalLengths [ [i,j]] = calculate_length (i,j);`


However, trying to do this is resulting to :

`test.d(29): Error: associative arrays can only be assigned 
values with immutable keys, not `double[][]`


What are my options now?  Do I have to convert the array which i 
plan to use as a key to a struct and define opEquals and toHash?


Are there automatic hashing mechanisms for this?

If there are multiple possibilities, what is the fastest in terms 
of memory? Thank you.


Re: Yet another parallel foreach + continue question

2021-07-19 Thread seany via Digitalmars-d-learn

On Tuesday, 20 July 2021 at 02:58:50 UTC, H. S. Teoh wrote:
On Tue, Jul 20, 2021 at 02:39:58AM +, seany via 
Digitalmars-d-learn wrote:

> [...]

[...]

[...]


Logically speaking, the size of the work unit should not change 
the semantics of the loop. That's just an implementation detail 
that should not affect the semantics of the overall 
computation.  In order to maintain consistency, loop iterations 
should not affect each other (unless they deliberately do so, 
e.g., read/write from a shared variable -- but parallel foreach 
itself should not introduce such a dependency).


[...]


Okey, thank you.

If you later have some time, and find out about the exact 
implementation - and help me to understand it -  I would be most 
grateful.


I have checked: [this 
link](https://github.com/dlang/phobos/blob/master/std/parallelism.d) - but did not understand completely.


Re: Yet another parallel foreach + continue question

2021-07-19 Thread seany via Digitalmars-d-learn

On Tuesday, 20 July 2021 at 02:31:14 UTC, H. S. Teoh wrote:
On Tue, Jul 20, 2021 at 01:07:22AM +, seany via 
Digitalmars-d-learn wrote:

On Tuesday, 20 July 2021 at 00:37:56 UTC, H. S. Teoh wrote:
> [...]

Ok, therefore it means that, if at `j = 13 `i use a continue, 
then the thread where I had `10`... `20` as values of `j`, 
will only execute for `j = 10, 11, 12 ` and will not reach 
`14`or later ?


No, it will.

Since each iteration is running in parallel, the fact that one 
of them terminated early should not affect the others.



T


Even tho, the workunit specified 11 values to a single thread?


Re: Yet another parallel foreach + continue question

2021-07-19 Thread seany via Digitalmars-d-learn

On Tuesday, 20 July 2021 at 00:37:56 UTC, H. S. Teoh wrote:
On Tue, Jul 20, 2021 at 12:07:10AM +, seany via 
Digitalmars-d-learn wrote:

[...]

[...]

I didn't test this, but I'm pretty sure `continue` inside a 
parallel foreach loop simply terminates that iteration early; I 
don't think it will skip to the next iteration.


[...]


Ok, therefore it means that, if at `j = 13 `i use a continue, 
then the thread where I had `10`... `20` as values of `j`, will 
only execute for `j = 10, 11, 12 ` and will not reach `14`or 
later ?




Yet another parallel foreach + continue question

2021-07-19 Thread seany via Digitalmars-d-learn

Consider :

for (int i = 0; i < max_value_of_i; i++) {
foreach ( j, dummyVar; 
myTaskPool.parallel(array_to_get_j_from, my_workunitSize) {


if ( boolean_function(i,j) ) continue;
double d = expensiveFunction(i,j);
// ... stuff ...
}
}

I understand, that the parallel iterator will pick lazily values 
of `j` (up to `my_workunitsize`), and execute the for loop for 
those values in its own thread.


Say, values of `j` from `10`to `20` is filled where 
`my_workunitsize` = 11. Say, at `j = 13` the `boolean_function` 
returns true.


Will then the for loop just jump to the next value of `j = 14`  
like a normal for loop? I am having a bit of difficulty to 
understand this. Thank you.





Re: catching segfault using try_ catch

2021-07-13 Thread seany via Digitalmars-d-learn

On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote:

On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote:

[...]


true if it succeeded.


[...]


You mean transparently rerun some code? That's better done with 
the lowlevel sigaction handler.


[...]


Thank you.

Is there a tutorial on the low level sigaction handlers you speak 
of? Thank oyu


Re: catching segfault using try_ catch

2021-07-13 Thread seany via Digitalmars-d-learn

On Monday, 12 July 2021 at 00:04:05 UTC, Adam D Ruppe wrote:

On Sunday, 11 July 2021 at 23:34:38 UTC, seany wrote:

Is there an example i can use Thank you.


You just call the registerMemoryHandler() function from that 
module at some point in your main function before doing other 
work.


PS will the function will work with LDC / LLVM based compiler?


Re: catching segfault using try_ catch

2021-07-13 Thread seany via Digitalmars-d-learn

On Monday, 12 July 2021 at 00:04:05 UTC, Adam D Ruppe wrote:

On Sunday, 11 July 2021 at 23:34:38 UTC, seany wrote:

Is there an example i can use Thank you.


You just call the registerMemoryHandler() function from that 
module at some point in your main function before doing other 
work.


OK

Here, the 
[source](https://druntime.dpldocs.info/etc.linux.memoryerror.registerMemoryErrorHandler.html) says that function is undocumented. What will it return to me?


I want to catch the segfault and a segfault has occured, I want 
run a different code at that point.


Re: catching segfault using try_ catch

2021-07-11 Thread seany via Digitalmars-d-learn

 On Sunday, 11 July 2021 at 21:15:30 UTC, Paul Backus wrote:
I know it's possible on Linux using the `etc.linux.memoryerror` 
module [1]. Not sure about Windows.



Linux would be sufficient.
Is there an example i can use Thank you.


catching segfault using try_ catch

2021-07-11 Thread seany via Digitalmars-d-learn

Is it possible to catch a segfault - using try/catch loop?
Thank you


Re: vibe.d compilation error

2021-07-04 Thread seany via Digitalmars-d-learn

On Monday, 5 July 2021 at 01:11:22 UTC, Mathias LANG wrote:

On Sunday, 4 July 2021 at 12:36:24 UTC, seany wrote:


Is there any way, I can avoid this error?


You are using an old version of Vibe.d, change your dependency 
to "~>0.9.0".


Okey, thank you. That resolved it.


vibe.d compilation error

2021-07-04 Thread seany via Digitalmars-d-learn

Compiling a simple vibe.d project throws tis error :

`/root/.dub/packages/vibe-d-0.8.6/vibe-d/utils/vibe/internal/memory_legacy.d(9,8): Error: 
module `std.exception` import `enforceEx` not found, did you mean template 
`std.exception.enforce(E : Throwable = Exception) if (is(typeof(new E("", 
string.init, size_t.init)) : Throwable) || is(typeof(new E(string.init, size_t.init)) : 
Throwable))`


There is a github issue raised 
[here](https://github.com/vibe-d/vibe.d/issues/2578) .


However, I am not compiling with botan. My dub.json is :

dub.json
{
"authors": [
    "Seany"
],
"copyright": "Copyright © 2021, Seany",
"dependencies": {
"vibe-d": "~>0.8.0",
},
"description": "Econsor data receive",
"license": "proprietary",
"name": "rawdatareceiver"
}

Is there any way, I can avoid this error?


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 19:30:16 UTC, jfondren wrote:

On Friday, 25 June 2021 at 19:17:38 UTC, seany wrote:

If i use `parallel(...)`it runs.

If i use `prTaskPool.parallel(...`, then in the line : `auto 
prTaskPool = new TaskPool(threadCount);` it hits the error. 
Please help.


parallel() reuses a single taskPool that's only established 
once.


Your code creates two TaskPools per a function invocation and 
you

call that function in a loop.

stracing your program might again reveal the error you're 
hitting.


I have removed one - same problem.
Yes, I do call it in a loop. how can I create a taskpool in a 
function that itself will be called in a loop?


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 16:37:44 UTC, seany wrote:

On Friday, 25 June 2021 at 16:37:06 UTC, seany wrote:

On Friday, 25 June 2021 at 15:50:37 UTC, seany wrote:

On Friday, 25 June 2021 at 15:16:30 UTC, jfondren wrote:

[...]


Try : (this 
version)[https://github.com/naturalmechanics/mwp/tree/nested-loops]


The goal is to parallelize : 
`calculate_avgSweepDist_pairwise` at line `3836`. Notice 
there we have 6 nested loops. Thank you.


Ok, i stopped the buss error and the segfault. It was indeed 
an index that was written wrong in the flattened version .


No, I dont have the seg fault any more. But I have "error 
creating thread" - time to time.  Not always.


But, even with the taskpool, it is not spreading to multiple 
cores.


PS: this is the error message : 
"core.thread.threadbase.ThreadError@src/core/thread/threadbase.d(1219): Error creating thread"


If i use `parallel(...)`it runs.

If i use `prTaskPool.parallel(...`, then in the line : `auto 
prTaskPool = new TaskPool(threadCount);` it hits the error. 
Please help.


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 15:50:37 UTC, seany wrote:

On Friday, 25 June 2021 at 15:16:30 UTC, jfondren wrote:

On Friday, 25 June 2021 at 14:44:13 UTC, seany wrote:


This particular location does not cause segfault.
It is segfaulting down the line in a completely unrelated 
location... Wait I will try to make a MWP.


[Here is MWP](https://github.com/naturalmechanics/mwp).

Please compile with `dub build -b release --compiler=ldc2 `. 
Then to run, please use : `./tracker_ai --filename 
21010014-86.ptl `


With ldc2 this segfaults for me even if std.parallelism is 
removed
entirely. With DMD and std.parallelism removed it runs to 
completion.

With DMD and no changes it never seems to finish.

I reckon that there's some other memory error and that the 
parallelism

is unrelated.


Try : (this 
version)[https://github.com/naturalmechanics/mwp/tree/nested-loops]


The goal is to parallelize : `calculate_avgSweepDist_pairwise` 
at line `3836`. Notice there we have 6 nested loops. Thank you.


Ok, i stopped the buss error and the segfault. It was indeed an 
index that was written wrong in the flattened version .


No, I dont have the seg fault any more. But I have "error 
creating thread" - time to time.  Not always.


But, even with the taskpool, it is not spreading to multiple 
cores.


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 16:37:06 UTC, seany wrote:

On Friday, 25 June 2021 at 15:50:37 UTC, seany wrote:

On Friday, 25 June 2021 at 15:16:30 UTC, jfondren wrote:

[...]


Try : (this 
version)[https://github.com/naturalmechanics/mwp/tree/nested-loops]


The goal is to parallelize : `calculate_avgSweepDist_pairwise` 
at line `3836`. Notice there we have 6 nested loops. Thank you.


Ok, i stopped the buss error and the segfault. It was indeed an 
index that was written wrong in the flattened version .


No, I dont have the seg fault any more. But I have "error 
creating thread" - time to time.  Not always.


But, even with the taskpool, it is not spreading to multiple 
cores.


PS: this is the error message : 
"core.thread.threadbase.ThreadError@src/core/thread/threadbase.d(1219): Error creating thread"


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 15:16:30 UTC, jfondren wrote:

On Friday, 25 June 2021 at 14:44:13 UTC, seany wrote:


This particular location does not cause segfault.
It is segfaulting down the line in a completely unrelated 
location... Wait I will try to make a MWP.


[Here is MWP](https://github.com/naturalmechanics/mwp).

Please compile with `dub build -b release --compiler=ldc2 `. 
Then to run, please use : `./tracker_ai --filename 
21010014-86.ptl `


With ldc2 this segfaults for me even if std.parallelism is 
removed
entirely. With DMD and std.parallelism removed it runs to 
completion.

With DMD and no changes it never seems to finish.

I reckon that there's some other memory error and that the 
parallelism

is unrelated.


Try : (this 
version)[https://github.com/naturalmechanics/mwp/tree/nested-loops]


The goal is to parallelize : `calculate_avgSweepDist_pairwise` at 
line `3836`. Notice there we have 6 nested loops. Thank you.


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 15:08:38 UTC, Ali Çehreli wrote:

On 6/25/21 7:21 AM, seany wrote:

> The code without the parallel foreach works fine. No segfault.

That's very common.

What I meant is, is the code written in a way to work safely in 
a parallel foreach loop? (i.e. Is the code "independent"?) (But 
I assume it is because it's been the common theme in this 
thread; so there must be something stranger going on.)


Ali


I have added MWP. did you have a chance to look at it?



Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 14:22:25 UTC, seany wrote:

On Friday, 25 June 2021 at 14:13:14 UTC, jfondren wrote:

On Friday, 25 June 2021 at 13:53:17 UTC, seany wrote:

[...]


A self-contained and complete example would help a lot, but 
the likely
problem with this code is that you're accessing pnts[y][x] in 
the
loop, which makes the loop bodies no longer independent 
because some
of them need to first allocate an int[] to replace the 
zero-length

pnts[y] that you're starting with.

Consider:

```
$ rdmd --eval 'int[][] p; p.length = 5; 
p.map!"a.length".writeln'

[0, 0, 0, 0, 0]
```


This particular location does not cause segfault.
It is segfaulting down the line in a completely unrelated 
location... Wait I will try to make a MWP.


[Here is MWP](https://github.com/naturalmechanics/mwp).

Please compile with `dub build -b release --compiler=ldc2 `. Then 
to run, please use : `./tracker_ai --filename 21010014-86.ptl `


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 14:13:14 UTC, jfondren wrote:

On Friday, 25 June 2021 at 13:53:17 UTC, seany wrote:

[...]


A self-contained and complete example would help a lot, but the 
likely
problem with this code is that you're accessing pnts[y][x] in 
the
loop, which makes the loop bodies no longer independent because 
some
of them need to first allocate an int[] to replace the 
zero-length

pnts[y] that you're starting with.

Consider:

```
$ rdmd --eval 'int[][] p; p.length = 5; 
p.map!"a.length".writeln'

[0, 0, 0, 0, 0]
```


This particular location does not cause segfault.
It is segfaulting down the line in a completely unrelated 
location... Wait I will try to make a MWP.


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 14:10:52 UTC, Ali Çehreli wrote:

On 6/25/21 6:53 AM, seany wrote:

>  [...]
workUnitSize)) {
> [...]

Performance is not guaranteed depending on many factors. For 
example, inserting a writeln() call in the loop would make all 
threads compete with each other for stdout. There can be many 
contention points some of which depending on your program 
logic. (And "Amdahl's Law" applies.)


Another reason: 1 can be a horrible value for workUnitSize. Try 
100, 1000, etc. and see whether it helps with performance.


> [...]
line...
> [...]

Do you still have two parallel loops? Are both with explicit 
TaskPool objects? If not, I wonder whether multiple threads are 
using the convenient 'parallel' function, stepping over each 
others' toes. (I am not sure about this because perhaps it's 
safe to do this; never tested.)


It is possible that the segfaults are caused by your code. The 
code you showed in your original post (myFunction0() and 
others), they all work on independent data structures, right?


Ali


The code without the parallel foreach works fine. No segfault.

In several instances, I do have multiple nested loops, but in 
every case. only the outer one in parallel foreach.


All of them are with explicit taskpool definition.






Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Friday, 25 June 2021 at 13:53:17 UTC, seany wrote:

On Thursday, 24 June 2021 at 21:19:19 UTC, Ali Çehreli wrote:

[...]


I tried this .

int[][] pnts ;
pnts.length = fld.length;

enum threadCount = 2;
auto prTaskPool = new TaskPool(threadCount);

scope (exit) {
prTaskPool.finish();
}

enum workUnitSize = 1;

foreach(i, fLine; prTaskPool.parallel(fld, workUnitSize)) {
  //
}


This is throwing random segfaults.
CPU has 2 cores, but usage is not going above 37%

Even much deeper down in program, much further down the line...
And the location of segfault is random.


PS. line 
[this](https://forum.dlang.org/thread/gomhpxzolddnodaey...@forum.dlang.org) I am running into bus errors Too , sometimes way down the line after these foreach calls are completed...


Re: How to call stop from parallel foreach

2021-06-25 Thread seany via Digitalmars-d-learn

On Thursday, 24 June 2021 at 21:19:19 UTC, Ali Çehreli wrote:

On 6/24/21 1:41 PM, seany wrote:

> Is there any way to control the number of CPU cores used in
> parallelization ?

Yes. You have to create a task pool explicitly:

import std.parallelism;

void main() {
  enum threadCount = 2;
  auto myTaskPool = new TaskPool(threadCount);
  scope (exit) {
myTaskPool.finish();
  }

  enum workUnitSize = 1; // Or 42 or something else. :)
  foreach (e; myTaskPool.parallel([ 1, 2, 3 ], workUnitSize)) {
// ...
  }
}

I've touched on a few parallelism concepts at this point in a 
presentation:


  https://www.youtube.com/watch?v=dRORNQIB2wA&t=1332s

Ali


I tried this .

int[][] pnts ;
pnts.length = fld.length;

enum threadCount = 2;
auto prTaskPool = new TaskPool(threadCount);

scope (exit) {
prTaskPool.finish();
}

enum workUnitSize = 1;

foreach(i, fLine; prTaskPool.parallel(fld, workUnitSize)) {
  //
}


This is throwing random segfaults.
CPU has 2 cores, but usage is not going above 37%

Even much deeper down in program, much further down the line...
And the location of segfault is random.




Re: How to call stop from parallel foreach

2021-06-24 Thread seany via Digitalmars-d-learn

On Thursday, 24 June 2021 at 20:33:00 UTC, Bastiaan Veelo wrote:

By the way, nesting parallel `foreach` does not make much 
sense, as one level already distributes the load across all 
cores (but one). Additional parallelisation will likely just 
add overhead, and have a net negative effect.


— Bastiaan.


Okey. So consider :

foreach(array_elem; parallel(an_array)) {
  dothing(array_elem);
}


and then in `dothing()` :

foreach(subelem; array_elem) {

  dootherthing(subelem);
}

- Will this ALSO cause the same overhead?

Is there any way to control the number of CPU cores used in 
parallelization ?


E.g : take 3 cores for the first parallel foreach - and then for 
the second one, take 3 cores each -> so 3 + 3 * 3 = 12 cores out 
of a 16 core system? Thank you.




Re: How to call stop from parallel foreach

2021-06-24 Thread seany via Digitalmars-d-learn

On Thursday, 24 June 2021 at 20:08:06 UTC, seany wrote:

On Thursday, 24 June 2021 at 19:46:52 UTC, Jerry wrote:

On Thursday, 24 June 2021 at 18:23:01 UTC, seany wrote:

[...]


Maybe I'm wrong here, but I don't think there is any way to do 
that with parallel.
What I would do is negate someConditionCheck and instead only 
do work when there is work to be done.

Obviously that may or may not be suitable.
But with parallel I don't see any way to make it happen.


The parallel() function is running a taskpool. I should be able 
to stop that in any case...


PS :

I have done this :

parallelContainer: while(true) {
outer: foreach(i, a; parallel(array_of_a)) {
   foreach(j, b; parallel(array_of_b)) {
 auto c = myFunction0(i,j);
 auto d = myFunction1(a,b);
 auto f = myFunction2(i,b);
 auto g = myFunction3(a,j);

 if(someConditionCheck(c,d,f,g)) {
   break parallelContainer;
 }

   }
break;
}

Is this safe? Will this cause any problem that I can't foresee 
now? Thank you


Re: How to call stop from parallel foreach

2021-06-24 Thread seany via Digitalmars-d-learn

On Thursday, 24 June 2021 at 19:46:52 UTC, Jerry wrote:

On Thursday, 24 June 2021 at 18:23:01 UTC, seany wrote:

[...]


Maybe I'm wrong here, but I don't think there is any way to do 
that with parallel.
What I would do is negate someConditionCheck and instead only 
do work when there is work to be done.

Obviously that may or may not be suitable.
But with parallel I don't see any way to make it happen.


The parallel() function is running a taskpool. I should be able 
to stop that in any case...


How to call stop from parallel foreach

2021-06-24 Thread seany via Digitalmars-d-learn
I have seen 
[this](https://forum.dlang.org/thread/akhbvvjgeaspmjntz...@forum.dlang.org).


I can't call break form parallel foreach.

Okey, Is there a way to easily call .stop() from such a  case?

Here is a case to consider:

outer: foreach(i, a; parallel(array_of_a)) {
   foreach(j, b; parallel(array_of_b)) {
 auto c = myFunction0(i,j);
 auto d = myFunction1(a,b);
 auto f = myFunction2(i,b);
 auto g = myFunction3(a,j);

 if(someConditionCheck(c,d,f,g)) {
   // stop the outer foreach loop here
 }

   }
}

Thank you


How to I get pointer to an Array and cast to a void * and back ?

2021-06-24 Thread seany via Digitalmars-d-learn

I have a struct :

struct a {
   int i;
   // some more stuff ...
}

In a Class, I define public global `void * dataSet; `

In a function `f`, of the same class:  i call :

void f() {
a[] rd_flattened;   
a[] * rd;   

// DO SOME WORK HERE 

this.dataSet = & rd_flattened;  
rd = cast (a [] *)  dataSet;

write("length of rd is : "); writeln((*rd).length); // <--- 
this works..

// do some work on rd

this.dataSet = rd;
rd = cast (field.rawData [] *)  dataSet;

write("length of rd for a second time is : ");
writeln((*rd).length); // <--- this ALSO works..
}

Now outside `f`, in the same class, i call :

void f2() {

f();

a[] *aa ;
aa = cast (a [] *)  this.dataSet; // recall dataset is public 
global
// if i print the address of this.dataSet here, this is the 
same as inside f()
write("after calling f, count is: "); writeln((*aa).length); 
readln();
// here the situation completely blows up . the length is 
wrong.

}


I need some help here. Sorry, can't post code. It is proprietary.

What is causing this issue ?

thank you.




Re: Parallel For

2021-06-15 Thread seany via Digitalmars-d-learn

On Tuesday, 15 June 2021 at 09:09:29 UTC, Ali Çehreli wrote:

On 6/14/21 11:39 PM, seany wrote:

> [...]

I gave an example of it in my DConf Online 2020 presentation as 
well:


  https://www.youtube.com/watch?v=dRORNQIB2wA&t=1324s

>  [...]

That is violating a parallelism requirement that loop bodies 
must be independent. (I use a similar example during my 
presentation above.) You need to either pre-allocate the array 
(as jfondren said) or not store the elements at all but use 
them independently in the loop body.


Yes, std.concurrency is another option. I show a "recipe" of 
usage here:


  https://www.youtube.com/watch?v=dRORNQIB2wA&t=1737s

Ali


Ali Chehreli is an angel, Thank you.


Re: Parallel For

2021-06-15 Thread seany via Digitalmars-d-learn

On Tuesday, 15 June 2021 at 07:41:06 UTC, jfondren wrote:

On Tuesday, 15 June 2021 at 06:39:24 UTC, seany wrote:

[...]


add a `writeln(c.length);` in your inner loop and consider
the output. If you were always pushing to the end of c, then
only unique numbers should be output. But I see e.g. six
occurrences of 0, four of 8 ...

[...]


My attempt is to make such huge O(N^4) or O(N^5) algorithms 
faster.


Wouldn't all these calculation of unique `i` make the program 
slow?  I would like to know how to do this properly.


Re: Parallel For

2021-06-14 Thread seany via Digitalmars-d-learn

On Tuesday, 15 June 2021 at 06:39:24 UTC, seany wrote:
I know that c# has parallel for [like 
this](https://dotnettutorials.net/lesson/parallel-for-method-csharp/) .


[...]


PS :

I need the entire include list - while they are not necessary for 
this minimal example - they are needed for the ful project. That 
is why I kept them here.


DMD DMD64 D Compiler v2.096.1


Parallel For

2021-06-14 Thread seany via Digitalmars-d-learn
I know that c# has parallel for [like 
this](https://dotnettutorials.net/lesson/parallel-for-method-csharp/) .


I know that D has parallel foreach [like 
this](http://ddili.org/ders/d.en/parallelism.html).


I want to do the following :

Given 4 sets , A = {a_1, a_2, ... }; B = {b_1, b_2, ... } ; C = 
{c_1 , ... } ; D = {d_1, ... } - I need to make all Cartesian 
products, such as {a_1, b_1, c_1, d_1 }; {a_1, b_1, c_1, d_2}; 
... {a_n, b_n, c_n, d_n} ; then run an operation on the elements .


Then, I need to extract the maximum and minimum values of the 
results - either by storing them in an array, or by some other 
suitable means.


My attempt to solve can be seen in this minimal example :

import std.stdio;
import std.math;
import std.stdio;
import std.conv;
import std.format;
import std.math;
import std.algorithm;
import std.net.curl;
import std.json;
//import dlib.image;
import std.path;
import std.array;
import std.net.curl;
import core.stdc.stdlib;
import std.datetime;
import std.file;
import opmix.dup;
import std.parallelism;


void main() {

int[] a = [1,2,3,4,5,6,7,8,9];
int[] b = [11,12,13,14,15,16,17,18];

int[] c ;
foreach(aa; parallel (a)) {
foreach (bb; parallel(b)) {

c ~= aa+bb;

}

}
writeln(c);

}


I expect the output : `[ 12, 13, 14 27 ]` ( not necessarily 
in this order - but that is okey).


I am getting the output : `[12, 13, 14, 15, 16, 17, 18, 19, 14, 
15, 16, 17, 18, 19, 20, 21, 15, 16, 17, 18, 19, 20, 21, 22, 0, 0, 
0, 0, 0, 0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 19, 20, 21, 22, 
18, 0, 0, 0, 16, 21, 18, 22, 23, 24, 25, 20, 21, 22, 19]`.


In the next run : `[12, 13, 14, 15, 16, 17, 18, 19, 14, 15, 16, 
17, 18, 19, 20, 21, 15, 16, 17, 18, 19, 20, 21, 22, 16, 17, 18, 
19, 20, 21, 22, 23, 18, 19, 20, 21, 22, 23, 24, 25, 17, 18, 19, 
19, 21, 20, 23, 23, 24, 24, 20, 21, 22, 23, 24, 25, 26, 27]`


In the next run : `[12, 13, 14, 15, 16, 17, 18, 19, 14, 15, 16, 
17, 0, 0, 16, 18, 19, 20, 21, 17, 18, 19, 20, 15, 16, 17, 18, 19, 
20, 21, 22, 18, 19, 20, 21, 22, 23, 24, 25, 19, 20, 21, 22, 16, 
17, 20, 21, 22, 23, 24, 21, 22, 27, 23]`


In the 4th run : `[12, 13, 14, 15, 16, 17, 18, 19, 15, 16, 17, 
18, 19, 20, 21, 22, 14, 13, 14, 15, 16, 17, 18, 19, 20, 20, 21, 
22, 23, 24, 25, 26, 27, 18, 20, 22, 23, 24, 25, 20, 21, 22, 23, 
24]`


What am I doing wrong?

Thank you .


Re: Flaoting point operations : unexpected results

2021-06-10 Thread seany via Digitalmars-d-learn

On Thursday, 10 June 2021 at 19:51:51 UTC, Dennis wrote:

On Thursday, 10 June 2021 at 19:37:36 UTC, seany wrote:
However, i sometimes see, that the results are _radically_ 
different.


Are you using uninitialized memory or multi-threading?


I am using things like :

`double [][] myArr = new double [][] (0,0);`

and

 `double [][] tempArr;`

and

class myclass {

 int a ;
 this(){}
 ~this(){}
}

followed by :

myclass mc = new myclass;


I dont think these are "uninitialized"?



Flaoting point operations : unexpected results

2021-06-10 Thread seany via Digitalmars-d-learn

I have (as mentioned before) an AI project in D.
It is doing several million Floating Point operations.

However, i sometimes see, that the results are _radically_ 
different.


The same input, fed to the same system .

I do not have and random values. There are some *foreach* loops.

By radically different, i mean, that the computation whether some 
points are within some bound or not goes completely out of 
control. Sometimes they produce correct result, sometimes all 
results are zero.


Is there a "reproducability" problem?

Thank you.



Re: Faster Dlang Execution

2021-06-08 Thread seany via Digitalmars-d-learn

On Tuesday, 8 June 2021 at 18:03:32 UTC, H. S. Teoh wrote:



But more importantly, if you can elaborate a bit more on what 
your program is trying to do, it would help us give more 
specific recommendations. There may be domain-specific 
optimizations that you could apply as well.



T



Hi

The program is trying to categorize GPS tracks.
It has to identify track that count as (somewhat) parallel (this 
is difficult to define) .


So I draw lines through points that have at most 5 m (as measured 
by vicenty -'s formula) RMS error from the trend line. Then i 
look for lines that can be considered "turn lines" ( a turn 
joining two parallel lines).


Then I draw a best fit boundary around it. I lay a square grid, 
and remove the squares where no line can be found.


Then I use this algorithm :
https://stackoverflow.com/questions/50885339/polygon-from-a-grid-of-squares

This runs at O(N²) for sure.

Does this help?



Faster Dlang Execution

2021-06-08 Thread seany via Digitalmars-d-learn

Hello

How can I increase the speed of executable files created via :

`dub build -b release`

I am unable to parallellise all of it, as it depends on part of 
the result being calculated before something else can be 
calculated.


I have many `nonsafe, nonpure` functions. Classes are virtual by 
defalut. Profiling doesn't help, because different input is 
causing different parts of the program to become slow.


Thank you.




Re: dub build output redirect

2021-06-08 Thread seany via Digitalmars-d-learn
On Tuesday, 8 June 2021 at 14:15:47 UTC, Steven Schveighoffer 
wrote:

On 6/8/21 10:05 AM, seany wrote:


Hi

Thank you for pointing this out.

Indeed, much later in the code, there is a `readln()`.
But, the program needs to run 1-2 minutes, until it reaches 
that point - it is doing a complex AI calculation.


However, for these 1-2 minutes, there is no output. Not via 
`tee`command, also not when i do a `tail -f a` (`a` is the 
logfile as in my last mail). I expect  the output of these 1-2 
minutes, until the `readln` point to be visible via either of 
these to methods.


Is it still the same case as you describe?


Yes, that is exactly the case. `tee` and `tail` commands are 
not considered a console.


Insert a `stdout.flush;` every time you want more output to 
appear, and it should fix the issue.


-Steve


Ok, thank you. it works.


Re: dub build output redirect

2021-06-08 Thread seany via Digitalmars-d-learn
On Tuesday, 8 June 2021 at 13:51:10 UTC, Steven Schveighoffer 
wrote:

On 6/8/21 8:38 AM, seany wrote:

I have compiled a complex project via `dub build`.

I used both `-b release` and `-b debug`.

But i cant redirect the output (generated by `writeln`) to a 
file.


I call by : `./executable --param p1 > a`. But execution hangs 
immediately. If I do `./executable --param p1 ` no issue.


What am I doing wrong?

thank you.


Are you expecting input as well as sending output?

A common behavior difference between console streams and file 
streams (including in D) is that when the library detects it's 
sending to a console, it flushes buffered output after every 
newline. When it's sending to a file (or other stream type), it 
only sends output when the buffer is full (usually about 4k 
bytes).


The hang sounds like it has buffered up its output ready to 
send, and then is waiting for input to continue.


-Steve


Hi

Thank you for pointing this out.

Indeed, much later in the code, there is a `readln()`.
But, the program needs to run 1-2 minutes, until it reaches that 
point - it is doing a complex AI calculation.


However, for these 1-2 minutes, there is no output. Not via 
`tee`command, also not when i do a `tail -f a` (`a` is the 
logfile as in my last mail). I expect  the output of these 1-2 
minutes, until the `readln` point to be visible via either of 
these to methods.


Is it still the same case as you describe?


dub build output redirect

2021-06-08 Thread seany via Digitalmars-d-learn

I have compiled a complex project via `dub build`.

I used both `-b release` and `-b debug`.

But i cant redirect the output (generated by `writeln`) to a file.

I call by : `./executable --param p1 > a`. But execution hangs 
immediately. If I do `./executable --param p1 ` no issue.


What am I doing wrong?

thank you.


Question about initialization

2021-06-04 Thread seany via Digitalmars-d-learn

Consider initializing a dictionary or associative array :

T[U] AA;

For example :

double [int] AA;


This will be dynamic in size.

Now consider initializing a dynamic array :

T[] A = new T[] (0);

or

U[][] B = new U [][] (0,0);


This will also be dynamic in size.

In my untrained eye, this seems haphazard. One requires the use 
of the new keyword, the other does not. Why is it? Has It got 
something to do with random access mechanism? I would like to 
know the rationale please.


Re: vibe.de multiple ports.

2020-09-30 Thread seany via Digitalmars-d-learn
On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak 
wrote:
Dne st 30. 9. 2020 13:25 uživatel seany via Digitalmars-d-learn 
< digitalmars-d-learn@puremagic.com> napsal:



Hello

I am trying to use this example for a iot application: 
https://aberba.com/2018/using-vibe-d-web-interface/


The code i use is:

ushort port   =   5504;

void main(char[][] args)
{

 auto router = new URLRouter;
 router.post("/archive", &savedata);
 router.get("/archive", &savedata);

 auto settings = new HTTPServerSettings;
 settings.port = port;
 settings.bindAddresses = ["::1", "0.0.0.0"];
 listenHTTP(settings, router);

 runApplication();
}


This is fine. But now that we have ~ 100 IoT devices in the 
field, I would like to assign each a new port.




Why? I do not see any reason for that.


to separate the messages from the IoT responses quickly and 
forward them to different programs, and to have the capability in 
hand, so that when later i have an idea to exploit the 
capability, I can also do it.


vibe.de multiple ports.

2020-09-30 Thread seany via Digitalmars-d-learn

Hello

I am trying to use this example for a iot application: 
https://aberba.com/2018/using-vibe-d-web-interface/


The code i use is:

ushort port   =   5504;

void main(char[][] args)
{

auto router = new URLRouter;
router.post("/archive", &savedata);
router.get("/archive", &savedata);

auto settings = new HTTPServerSettings;
settings.port = port;
settings.bindAddresses = ["::1", "0.0.0.0"];
listenHTTP(settings, router);

runApplication();
}


This is fine. But now that we have ~ 100 IoT devices in the 
field, I would like to assign each a new port. The devices should 
be communicating over HTTP as the vendor software running 
thereupon uses http.


What is the best practice to make a vibe.d server listen to 
multiple ports? Make a loop scanning each loop seems wasteful. Is 
there a function in vibe.d that can take multiple ports, and 
launch a set of threads assigned to each port?


Thank you


Re: vibe.d no routes match path

2020-02-04 Thread seany via Digitalmars-d-learn

* sorry, i meant 'archive'


This is a production server. Is there anything i am doing wrong?





vibe.d no routes match path

2020-02-04 Thread seany via Digitalmars-d-learn

Please consider the code:


import vibe.vibe;
import std.conv;
import std.file;
import std.stdio;


ushort port   =  5502;






void main(char[][] args)
{

auto router = new URLRouter;
router.post("/archive", &savedata);
router.get("/archive", &savedata); //also tested without 
this line


auto settings = new HTTPServerSettings;
settings.port = port;
settings.bindAddresses = ["::1", "0.0.0.0"];
listenHTTP(settings, router);

runApplication();
}

void savedata(HTTPServerRequest req, HTTPServerResponse res) {


   // do things
return;

}


This was working fine until yesterday

Today, it says (after a dub build) : 404 - Not Found

Not Found

Internal error information:
No routes match path '/a'

This is a production server. Is there anything i am doing wrong?


More vibe.d : Receiving Post params

2020-02-01 Thread seany via Digitalmars-d-learn

Consider this :

import vibe.vibe;
import std.conv;




ushort port =   5502;






void main(char[][] args)
{

auto router = new URLRouter;
router.post("/archive", &savedata);
router.get("/archive", &savedata);

auto settings = new HTTPServerSettings;
settings.port = port;
settings.bindAddresses = ["::1", "0.0.0.0"];
listenHTTP(settings, router);

runApplication();
}

void savedata(HTTPServerRequest req, HTTPServerResponse res) {

res.writeBody("srver received : " ~ req.queryString);

// also tested with to!string(req.params)

}



Now, I will send POST values like "line=abcdefgh..." to the port 
under "/archive".


I test it under linux :curl  -X POST -d "line=000" 
http://my.secret.site:5502/archive


The response is : srver received :

How do I intercept POST params? Thank you


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

On Saturday, 1 February 2020 at 22:25:38 UTC, Danny Arends wrote:

On Saturday, 1 February 2020 at 20:06:42 UTC, seany wrote:

[...]


Hey Seany,

A quick follow up post. I think/suspect that something might be 
broken in your dub installation if the mean import is not 
found. This is the first import from the phobos standard 
library in the project.


Could you try compiling the DaNode web server without using dub 
?


git clone https://github.com/DannyArends/DaNode.git
cd DaNode
rdmd danode/server.d -p=8080

This should work, when you have a working D+Phobos standard 
library installation. If this throws error of being unable to 
find the canFind import (now the first one) then somehing in 
your dub/dmd installation is broken and you will probably have 
to reinstall dmd+dub


Kind regards,
Danny


I will test this tomorrow.


Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

I solved this by following:

sudo wget 
https://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list

sudo apt-get update --allow-insecure-repositories
sudo apt-get -y --allow-unauthenticated install --reinstall 
d-apt-keyring

sudo apt-get update && sudo apt-get install dmd-compiler dub


then dub showed the error : out of memory.

I applied: dub --build-mode=singleFile

That seems to work


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

On Saturday, 1 February 2020 at 14:42:58 UTC, Seb wrote:

On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:

Hi
I want to start a small server, that will be accessible form 
outside. Not a huge deal right?

Not quite.

[...]


What version of dub did you install? 1.19 should be the latest.


PS:
As suggested, i try to build dub from github, following: 
https://github.com/dlang/dub/releases


I call ./build.d - and everything stops, and machine crashes.

Same for the master branch


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

On Saturday, 1 February 2020 at 14:42:58 UTC, Seb wrote:

On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:

Hi
I want to start a small server, that will be accessible form 
outside. Not a huge deal right?

Not quite.

[...]


What version of dub did you install? 1.19 should be the latest.


1.18.2


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn
On Saturday, 1 February 2020 at 14:30:36 UTC, Steven 
Schveighoffer wrote:


How is your network connection to the dub server? Maybe there 
is a separate problem with network connectivity.


This thing works for me (dub upgrade takes about 2.5 seconds 
and finishes). How long does it take for your process to give 
up?


In any case, maybe the dub check to see if it's "taking too 
long" needs to take into account progress that is being made (a 
"pathalogical case" suggests it's not making progress).


-Steve


With dub 1.18 more than 5 minutes.

If i use dub search dub, it finishes in seconds.

dub fetch dub is fine too.

dub run dub takes 10-12 seconds, and throws the same dependency 
error


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

On Saturday, 1 February 2020 at 11:15:49 UTC, seany wrote:
On Saturday, 1 February 2020 at 11:08:46 UTC, Ferhat Kurtulmuş 
wrote:

[...]


I even tried:

$ dub fetch dub
Fetching dub 1.19.0...
Please note that you need to use `dub run ` or add it to 
dependencies of your package to actually use/run it. dub does not 
do actual installation of packages outside of its own ecosystem.



$ dub run dub
Building package dub in /root/.dub/packages/dub-1.19.0/dub/
Fetching libevent 2.0.2+2.0.16 (getting selected version)...
Fetching diet-ng 1.6.0 (getting selected version)...
Fetching taggedalgebraic 0.11.8 (getting selected version)...
Fetching botan 1.12.10 (getting selected version)...
Fetching stdx-allocator 2.77.5 (getting selected version)...
Fetching vibe-d 0.8.6 (getting selected version)...
Fetching mir-linux-kernel 1.0.1 (getting selected version)...
Fetching memutils 0.4.13 (getting selected version)...
Fetching vibe-core 1.8.1 (getting selected version)...
Fetching libasync 0.8.4 (getting selected version)...
Fetching botan-math 1.0.3 (getting selected version)...
Fetching eventcore 0.8.48 (getting selected version)...
The dependency resolution process is taking too long. The 
dependency graph is likely hitting a pathological case in the 
resolution algorithm. Please file a bug report at 
https://github.com/dlang/dub/issues and mention the package 
recipe that reproduces this error.




Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn
On Saturday, 1 February 2020 at 11:08:46 UTC, Ferhat Kurtulmuş 
wrote:



Have you tried
dub upgrade



$ dub init server -t vibe.d
Package recipe format (sdl/json) [json]:
Name [server]:
Description [A simple vibe.d server application.]:
Author name [root]:
License [proprietary]:
Copyright string [Copyright © 2020, root]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in '/root/progs/D/server'.
Package successfully created in server

$ cd server
$ dub upgrade
Upgrading project in /root/progs/D/server
The dependency resolution process is taking too long. The 
dependency graph is likely hitting a pathological case in the 
resolution algorithm. Please file a bug report at 
https://github.com/dlang/dub/issues and mention the package 
recipe that reproduces this error.



$ dub upgrade vibe.d
Upgrading project in /root/progs/D/server
The dependency resolution process is taking too long. The 
dependency graph is likely hitting a pathological case in the 
resolution algorithm. Please file a bug report at 
https://github.com/dlang/dub/issues and mention the package 
recipe that reproduces this error.



$ cd
$ dub upgrade
There was no package description found for the application in 
'/root/progs/D'.

Upgrading project in /root/progs/D


Now I repeated:

$ cd server
$ dub upgrade
Upgrading project in /root/progs/D/server
The dependency resolution process is taking too long. The 
dependency graph is likely hitting a pathological case in the 
resolution algorithm. Please file a bug report at 
https://github.com/dlang/dub/issues and mention the package 
recipe that reproduces this error.



$ dub upgrade vibe.d
Upgrading project in /root/progs/D/server
The dependency resolution process is taking too long. The 
dependency graph is likely hitting a pathological case in the 
resolution algorithm. Please file a bug report at 
https://github.com/dlang/dub/issues and mention the package 
recipe that reproduces this error.


Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn
On Saturday, 1 February 2020 at 10:58:14 UTC, Ferhat Kurtulmuş 
wrote:

On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:

As suggested, i try to build dub from github, following: 
https://github.com/dlang/dub/releases



I don't know if it is a solution. But you can try using ~master 
branch, not a release on GitHub.



You can also try my vibed app skeleton:
https://github.com/aferust/simplerestvibed
İ simply run it with dub command.


sadly, also doesn't work. same as the full system crash


Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread seany via Digitalmars-d-learn

Hi
I want to start a small server, that will be accessible form 
outside. Not a huge deal right?

Not quite.

My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 
UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


DMD : DMD64 D Compiler v2.090.0
Copyright (C) 1999-2019 by The D Language Foundation, All Rights 
Reserved written by Walter Bright



Now, I try to install dub from the official repo.
Then I do

* dub init server -t vibe.d
* cd server
* dub

I hit this issue : https://github.com/dlang/dub/issues/1712

As suggested, i try to build dub from github, following: 
https://github.com/dlang/dub/releases


I call ./build.d - and everything stops, and machine crashes.

I then try to install DaNode: 
https://github.com/DannyArends/DaNode


It breaks with : module std.algorithm import 'mean' not found

Then I try to install the Hunt Framework. It breaks with : basic 
type

expected, not foreach


Please help. I really want this issue to be resolved-


Estimating free system resource at runtime

2017-08-20 Thread seany via Digitalmars-d-learn

Hi

I have a system that has to deal with 30+GB files. They can't be 
loaded to the amount of memory I have.


So my idea was to create a way to estimate available system RAM, 
and read a chunk from file which is 1/10 of size of available 
RAM, and process it as far as i can. If the read chunk is too 
small to meaningfully process, then i wait until resources are 
free.  If i read a chunk with some trailing things at the end 
that cant be processed, then i trim it, and reset the seek 
position.


However, i cant find anything on google to tell me how to 
estimate system resource using D. for C++ and windowes, i could 
find some API-s


Can e do this in D?



Cross platform Development

2015-01-23 Thread seany via Digitalmars-d-learn

Hello

I read this page, but I still have questions : 
http://forum.dlang.org/thread/fzbaxwcrbztqedqgm...@forum.dlang.org#post-mailman.1142.1332716016.4860.digitalmars-d:40puremagic.com


I also read this : 
http://stackoverflow.com/questions/1510989/can-c-be-compiled-into-platform-independent-code-why-not


However, I am wondering what are the ways to develop in a native 
64 bit linux machine, and deploy similar linux machines as well 
as in 64 + 32 bit windowes machines.


Are there ways to do so? I will need some detailed guidance.


Re: vibe.d Subdirectory?

2015-01-14 Thread seany via Digitalmars-d-learn
On Wednesday, 14 January 2015 at 12:25:12 UTC, ketmar via 
Digitalmars-d-learn wrote:

just forgot about that
crappy scripting stuff and write your code in D!


Actually I want to serve some JSON packed weather data (heck I 
also wrote my Global Climate Model partially in D and in C) - so 
I guess, I can use vibe.d to build a cgi.


However I also want to recieve some userinput, and parse it - and 
sometimes, php is simpler, because for a very small parsing task 
you dont want to worry abotu types and all. Does vibe.d support 
any HTML Preprocessor in the first place? If not PHP then Neco? 
Falcon? So that I do not always have to access my vibe.d based 
app, but I can simply change the page itself a bit?


vibe.d Subdirectory?

2015-01-14 Thread seany via Digitalmars-d-learn



I am new to vibe.d and plying a bit with it.

I notice, that in case of Apache, there is a "root" directory, 
often by default under /var/www or /srv/http (resp. ftp) if you 
are using linux, and then every time the client sends a request, 
apache looks in to the root directory, deduces the subdirectory 
from the URI, and pulls the page up from there. Then it parses 
the PHP / other scripting commands, and prints the HTML as is, 
before serving it over http.


I want to know the equivalent of all these in vibe.d. The website 
has a documentation, but all what I find is that you will need an 
app.d, in a predefined directory structure. I however, do not 
understand, what the root directory is going to be.


Is it going to be the directry where vibe.d is started?

Say, I start my vibe.d under /server, then I have an app.d under 
/server/a/app.d and /server/b/app.d


Do I access them via http://top.level.domain/a, resp /b, and 
app.d is like index.html / index.php which vibe.d looks for by 
default, or do i have to use http://top.level.domain/a/app.d




regex problems

2014-09-20 Thread seany via Digitalmars-d-learn

consider this:


import std.conv, std.algorithm;
import core.vararg;
import std.stdio, std.regex;

void main()
{

string haystack = "ID : generateWorld;
Position : { &
 
 {ID : \" absolute ; Coordinate : , NULL OMEGA;}
 
 {ID : \" inclusion ; Coordinate : UNDEF;}
 
 {ID : \" subarc; Coordinate : , NULL OMEGA;  }
  }; ID : ";

// thus, something like *{B}* can not end here,
// but something like X can start here.

string needle = 
"(?

auto r = regex(needle, "g");
auto m = matchAll(haystack, r);

foreach (c; m)
  writeln(c.hit);

}


So let us break up needle:

(
?Do not match somthing, that may contain a "*{*" as a leading 
match, * this time means any character, including \n and \r


(ID(\\p{White_Space})*:(\\p{White_Space})*)

however, look for the form : "ID"  ":" < more 
blank spaces>


(?!(([.\n\r])*(\\})([.\n\r])*))

but no trailing "*}*" as a trailing match.

In haystack, there are two such "ID :" -s. once at the beginning, 
ID : generateWorld. and then the final, last ID


However, this is returning all 5 ID-s as match

what am I doing wrong?


Re: String[] pointer to void* and back

2014-09-19 Thread seany via Digitalmars-d-learn

On Thursday, 18 September 2014 at 22:16:48 UTC, Ali Çehreli wrote:

If you are holding an address in a void*, you must make sure 
that the original object is still at that location when you 
attempt to access the object.


Does that mean, that there is no way to make a global stack 
accessible accross modules, of runtime generated stack variables, 
unless i define such variable species beforehand?


Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn
what if i needed to access many such runtime variables  of many 
types, and did not want to create a member for each type?


Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn

Yes, thank you, I corrected that.

However, if this v is a member of a class, like



import std.stdio;
import std.conv;
import core.vararg;

struct S
  {
void *v;
  }

class C
{


  S* sx = new S;

  void dothings()
  {
 string[] ss = ["1", "2", "4"];
 string[] *s;
 void *vv;

 s = &ss;
 vv = s;

 sx.v = vv;

  }

}


void main() {

 C c = new C;
 c.dothings();
 writeln("done");

 string[]* sh;
 sh = cast(string[]*)c.sx.v;
 writeln(sh);// upto this, works, the same pointer as 
set in
 // c.dothings(), checked with write 
instructions


 string[] si = *sh;
 writeln(si);
}



and then casted back, then i notice that it does not work. 
Wondering why.




Re: String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn

Found, it should have been   v = cast(void*)ss;

sorry.


String[] pointer to void* and back

2014-09-18 Thread seany via Digitalmars-d-learn

Consider this snippet:



import std.stdio;
import std.conv;
import core.vararg;





void main() {

 string[] s = ["aa", "bb", "cc"];
 string []* ss;
 void * v;

 ss = &s;
 v = cast(void*)s;

 ss = cast(string[]*) v;

 s = *ss;

 writeln(s);

}

This fails, Stack overflow.

If s was a double array, it works.

What am I doing wrong?


Re: Extremely funny behavior .. could be a bug?

2014-09-12 Thread seany via Digitalmars-d-learn

On Friday, 12 September 2014 at 15:26:34 UTC, Ali Çehreli wrote:


you are right, it was a reduced form, of a very complex software.

in file a.d

module a;

class class_a
{

   struct RESULT{
   string[] raw;
   void* res;
  }


RESULT * r;

void dothing()
{
   r = new RESULT;

   string aa = "string";

   r.raw ~= aa;
   r.res = cast(void*) aa;
}

}


in file b.d

import a;// import path is okey

class class_b
{

   void doThings(class_a * ptr_a)
  {
 class_a A = *ptr_a;
 writeln(A.r.raw[0]); // prints aa;
 writeln(A.r.res);// fails : 
core.exception.OutOfMemoryError@(0)

  // but if i do comment the line :
  // writeln(A.r.raw[0]); out, then 
works

  }
}


in file c.d

import a;
import b;

void main() {

clsa = new class_a;
clsb = new class_b;

clsa.dothing();
clsa.doThings( & clsa);


}


Extremely funny behavior .. could be a bug?

2014-09-12 Thread seany via Digitalmars-d-learn

consider the following :

in file a.d

module a;

class class_a
{

   struct RESULT{
   string[] raw;
   void* res;
  }


RESULT r;

void dothing()
{
   r = new RESULT;

   string aa = "string";

   r.raw ~= aa;
   r.res = cast(void*) aa;
}

}


in file b.d

import a;// import path is okey

class class_b;
{

   void doThings(class_a * ptr_a)
  {
 class_a A = &ptr_a;
 writeln(A.r.raw[0]); // prints aa;
 writeln(A.r.res);// fails : 
core.exception.OutOfMemoryError@(0)

  // but if i do comment the line :
  // writeln(A.r.raw[0]); out, then 
works

  }
}


in file c.d

import a;
import b;

void main() {

clsa = new class_a;
clsb = new class_b;

clsa.dothing();
clsa.doThings( & clsa);


}


I can not find a reason why accessing A.r.raw will erase (invoke 
the garbage collector) to remove A.r.res. Please help.


Re: Reading unicode chars..

2014-09-03 Thread seany via Digitalmars-d-learn

On Tuesday, 2 September 2014 at 21:13:04 UTC, monarch_dodra wrote:

What's wrong with reading line by line, but processing the 
characters in said lines 1 by 1? That works "out of the box".


import std.stdio;
import std.conv;
import core.vararg;

void main() {

string aa = "abc „";
foreach (aaa; aa)
writeln(aaa);

}


output :

a
b
c

�
�
�

Linux 64 bit netrunner, console font set to Raleway,, then to 
Quivira - both supports the character in discussion.


Re: Reading unicode chars..

2014-09-02 Thread seany via Digitalmars-d-learn

Your example reads the file by lines, i need to get them by chars.


Re: Reading unicode chars..

2014-09-02 Thread seany via Digitalmars-d-learn

On Tuesday, 2 September 2014 at 18:22:54 UTC, Ali Çehreli wrote:

That would happen when you you treat the chars on the input and 
individual dchars.


That is precisely where the problem is.

If you use the character in a file, and then open it as a stream, 
then use


File.getc()

or file.getcw()

until EOF is reached, then you get this prblem.

I want to read the file char by char,

and problem is i dont know where this char will appear, meaning I 
dont know where i have to treat multiple dchars, read by getc() 
or getcw() as a single char.





Re: Reading unicode chars..

2014-09-02 Thread seany via Digitalmars-d-learn

Linux 64 bit, D2, phobos only.


Re: Reading unicode chars..

2014-09-02 Thread seany via Digitalmars-d-learn

Hi Ali, i know this example from your book.

But try to capture „ the low quotation mark, appearing in the 
All-purpose punctuations plane of unicode, with \u201e - I worte 
I am having problems with \u1FFF and up.


This particular symbol, is seen as a dchar array "\x1e\x20" - so 
two dchars, using wchar returns the same result, when I directly 
profide the symbol to the code.


SO I was thinking of using two dchars, and printing the dstring, 
the problem then is that I do not know beforehand if a particular 
character read out of the file is a pair of dchars, or a single 
dchar.


And yes, it was stream.getcw, sorry, not file.getcw(). Indeed.

Reading this character from a file (using a while loop until EOF) 
produces an â and an unknown charcter given by a question mark in 
a white polygon.






Reading unicode chars..

2014-09-02 Thread seany via Digitalmars-d-learn
How do I read unicode chars that has code points \u1FFF and 
higher from a file?


file.getcw() reads only part of the char, and D identifies this 
character as an array of three or four characters.


Importing std.uni does not change the behavior.

Thank you.


Re: Tango Problems..

2014-08-31 Thread seany via Digitalmars-d-learn

On Sunday, 31 August 2014 at 21:40:51 UTC, seany wrote:
On the other hand, phobos works. But I want some tango 
functionality, without having to hack it all by hand ...


Re: Tango Problems..

2014-08-31 Thread seany via Digitalmars-d-learn

About find command :

I use find / -iname *druntime*.a with root permission - how else 
will i find what is where, kfind probably uses find internally 
too, or boost, egal ...


for the nm command :
without ddemangle, i dont have the command installed :

 T 
_D4core4stdc6stdarg6va_endFNbPS4core4stdc6stdarg13__va_list_tagZv
 U 
_D4core4stdc6stdarg6va_endFNbPS4core4stdc6stdarg13__va_list_tagZv
 U 
_D4core4stdc6stdarg6va_endFNbPS4core4stdc6stdarg13__va_list_tagZv


now what?


Re: Tango Problems..

2014-08-31 Thread seany via Digitalmars-d-learn

On Sunday, 31 August 2014 at 20:40:06 UTC, Rémy Mouëza wrote:


-L-L/path/to/ldc/lib/ -L-Ldruntime-ldc .


there is no /path/to/ldc/lib in my system - i have an 
/etc/ldc.conf

and a /usr/bin/ldc2


Re: Tango Problems..

2014-08-31 Thread seany via Digitalmars-d-learn

On Sunday, 31 August 2014 at 15:40:04 UTC, Rémy Mouëza wrote:
From what I understand in the error message, the linker cannot 
find a druntime function: void core.stdc.stdarg.va_end(void*).


I would advise to check that the druntime lib is in the import 
path.
In your the dmd repository, you should have a dmd.conf file 
containing something like:

[Environment64]
DFLAGS=-I%@P%/../src/phobos -I%@P%/../src/druntime/import 
-L-L%@P%/../lib64 -L--export-dynamic


(%@P% means the compiler path).
This should help you to fix your command line adding for 
instance:

-I/usr/local/lib/dmd/druntime/

In my dmd installation (2.066.0), the druntime is contained in 
libphobos.a/libphobos.so. Are you linking with libphobos?







This is what I have :
Environment]
DFLAGS=-I/usr/include/dlang/dmd -L-L/usr/lib -L-L/usr/lib32 
-L--export-dynamic


  1   2   >