问:
Why is the WebGL instancing extension only drawing one triangle instead of two?
I'm trying to use instancing with WebGL based on this guide. I've tried to create a simple example that draws a red triangle on the left and a blue triangle on the right. When I run it, it draws a blue triangle on the left and I don't understand why.

I've tried changing the arguments to drawArraysInstancedANGLE but that doesn't help. I've tried changing the order of lines for binding buffers and setting attribute pointers, etc. What am I doing wrong? Thanks

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const ext = gl.getExtension("ANGLE_instanced_arrays");
const vert = gl.createShader(gl.VERTEX_SHADER);
const frag = gl.createShader(gl.FRAGMENT_SHADER);
const program = gl.createProgram();

gl.shaderSource(vert, `
  attribute vec4 a_position;
  attribute vec4 a_color;
  varying vec4 v_color;

  void main() {
    gl_Position = a_position;
    v_color = a_color;
  }
`);

gl.shaderSource(frag, `
  precision mediump float;
  varying vec4 v_color;

  void main() {
    gl_FragColor = v_color;
  }
`);

gl.compileShader(vert);
gl.compileShader(frag);
gl.attachShader(program, vert);
gl.attachShader(program, frag);
gl.linkProgram(program);

const a_position = gl.getAttribLocation(program, "a_position");
const buffer1 = gl.createBuffer();
const positions = [-0.5, 0, -0.5, 0.2, -0.3, 0, 0.5, 0, 0.5, 0.2, 0.3, 0];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

const a_color = gl.getAttribLocation(program, "a_color");
const buffer2 = gl.createBuffer();
const colors = [1, 0, 0, 1, 0, 0, 1, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);

gl.viewport(0, 0, 300, 300);
gl.useProgram(program);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.enableVertexAttribArray(a_position);
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.enableVertexAttribArray(a_color);
gl.vertexAttribPointer(a_color, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_color, 1);

ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 3, 2);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><canvas id="canvas" width="300" height="300"></canvas></code>```

答:
So I see you mostly already got an answer in the comments.

The code is drawing the first triangle twice, once in red, then once in blue.

But, ... you mentioned indexing a uniform array. That would be unusual

Normally you'd put per instance data in a buffer. The example on the site linked used a matrix just to be generic since a matrix well will let you do just about any math (translation, rotation, scale, 3d projection, ...) but just as an example, you could just pass in single x offset.

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const ext = gl.getExtension("ANGLE_instanced_arrays");
const vert = gl.createShader(gl.VERTEX_SHADER);
const frag = gl.createShader(gl.FRAGMENT_SHADER);
const program = gl.createProgram();

gl.shaderSource(vert, `
  attribute vec4 a_position;
  attribute float a_xoffset;
  attribute vec4 a_color;
  varying vec4 v_color;

  void main() {
    gl_Position = a_position;
    gl_Position.x += a_xoffset;
    v_color = a_color;
  }
`);

gl.shaderSource(frag, `
  precision mediump float;
  varying vec4 v_color;

  void main() {
    gl_FragColor = v_color;
  }
`);

gl.compileShader(vert);
gl.compileShader(frag);
gl.attachShader(program, vert);
gl.attachShader(program, frag);
gl.linkProgram(program);

const a_position = gl.getAttribLocation(program, "a_position");
const buffer1 = gl.createBuffer();
const positions = [-0.5, 0, -0.5, 0.2, -0.3, 0];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

const a_color = gl.getAttribLocation(program, "a_color");
const buffer2 = gl.createBuffer();
const colors = [1, 0, 0, 1, 0, 0, 1, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);

const a_xoffset = gl.getAttribLocation(program, "a_xoffset");
const buffer3 = gl.createBuffer();
const xoffsets = [0, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer3);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(xoffsets), gl.STATIC_DRAW);

gl.viewport(0, 0, 300, 300);
gl.useProgram(program);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.enableVertexAttribArray(a_position);
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.enableVertexAttribArray(a_color);
gl.vertexAttribPointer(a_color, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_color, 1);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer3);
gl.enableVertexAttribArray(a_xoffset);
gl.vertexAttribPointer(a_xoffset, 1, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_xoffset, 1);

ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 3, 2);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><canvas id="canvas" width="300" height="300"></canvas></code>```

I'm just pointing that out because you have millions of values in a buffer but uniforms are far more limited so indexing a uniform for instancing is not common.

If you actually wanted different data per instance then yes you'd have to do something else.

One example is here

Body:
I'm trying to use instancing with WebGL based on this guide. I've tried to create a simple example that draws a red triangle on the left and a blue triangle on the right. When I run it, it draws a blue triangle on the left and I don't understand why.

I've tried changing the arguments to drawArraysInstancedANGLE but that doesn't help. I've tried changing the order of lines for binding buffers and setting attribute pointers, etc. What am I doing wrong? Thanks

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const ext = gl.getExtension("ANGLE_instanced_arrays");
const vert = gl.createShader(gl.VERTEX_SHADER);
const frag = gl.createShader(gl.FRAGMENT_SHADER);
const program = gl.createProgram();

gl.shaderSource(vert, `
  attribute vec4 a_position;
  attribute vec4 a_color;
  varying vec4 v_color;

  void main() {
    gl_Position = a_position;
    v_color = a_color;
  }
`);

gl.shaderSource(frag, `
  precision mediump float;
  varying vec4 v_color;

  void main() {
    gl_FragColor = v_color;
  }
`);

gl.compileShader(vert);
gl.compileShader(frag);
gl.attachShader(program, vert);
gl.attachShader(program, frag);
gl.linkProgram(program);

const a_position = gl.getAttribLocation(program, "a_position");
const buffer1 = gl.createBuffer();
const positions = [-0.5, 0, -0.5, 0.2, -0.3, 0, 0.5, 0, 0.5, 0.2, 0.3, 0];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

const a_color = gl.getAttribLocation(program, "a_color");
const buffer2 = gl.createBuffer();
const colors = [1, 0, 0, 1, 0, 0, 1, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);

gl.viewport(0, 0, 300, 300);
gl.useProgram(program);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.enableVertexAttribArray(a_position);
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.enableVertexAttribArray(a_color);
gl.vertexAttribPointer(a_color, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_color, 1);

ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 3, 2);

<canvas id="canvas" width="300" height="300"></canvas>

Body:
So I see you mostly already got an answer in the comments.

The code is drawing the first triangle twice, once in red, then once in blue.

But, ... you mentioned indexing a uniform array. That would be unusual

Normally you'd put per instance data in a buffer. The example on the site linked used a matrix just to be generic since a matrix well will let you do just about any math (translation, rotation, scale, 3d projection, ...) but just as an example, you could just pass in single x offset.

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const ext = gl.getExtension("ANGLE_instanced_arrays");
const vert = gl.createShader(gl.VERTEX_SHADER);
const frag = gl.createShader(gl.FRAGMENT_SHADER);
const program = gl.createProgram();

gl.shaderSource(vert, `
  attribute vec4 a_position;
  attribute float a_xoffset;
  attribute vec4 a_color;
  varying vec4 v_color;

  void main() {
    gl_Position = a_position;
    gl_Position.x += a_xoffset;
    v_color = a_color;
  }
`);

gl.shaderSource(frag, `
  precision mediump float;
  varying vec4 v_color;

  void main() {
    gl_FragColor = v_color;
  }
`);

gl.compileShader(vert);
gl.compileShader(frag);
gl.attachShader(program, vert);
gl.attachShader(program, frag);
gl.linkProgram(program);

const a_position = gl.getAttribLocation(program, "a_position");
const buffer1 = gl.createBuffer();
const positions = [-0.5, 0, -0.5, 0.2, -0.3, 0];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

const a_color = gl.getAttribLocation(program, "a_color");
const buffer2 = gl.createBuffer();
const colors = [1, 0, 0, 1, 0, 0, 1, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);

const a_xoffset = gl.getAttribLocation(program, "a_xoffset");
const buffer3 = gl.createBuffer();
const xoffsets = [0, 1];
gl.bindBuffer(gl.ARRAY_BUFFER, buffer3);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(xoffsets), gl.STATIC_DRAW);

gl.viewport(0, 0, 300, 300);
gl.useProgram(program);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer1);
gl.enableVertexAttribArray(a_position);
gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer2);
gl.enableVertexAttribArray(a_color);
gl.vertexAttribPointer(a_color, 4, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_color, 1);

gl.bindBuffer(gl.ARRAY_BUFFER, buffer3);
gl.enableVertexAttribArray(a_xoffset);
gl.vertexAttribPointer(a_xoffset, 1, gl.FLOAT, false, 0, 0);
ext.vertexAttribDivisorANGLE(a_xoffset, 1);

ext.drawArraysInstancedANGLE(gl.TRIANGLES, 0, 3, 2);

<canvas id="canvas" width="300" height="300"></canvas>

I'm just pointing that out because you have millions of values in a buffer but uniforms are far more limited so indexing a uniform for instancing is not common.

If you actually wanted different data per instance then yes you'd have to do something else.

One example is here


来源: stackexchange

问:
bug nestjs/config when set config nestjs
i create new project with nest new new-project
npm run start -> it run good
then i  install nest/config by npm i -save @nest/config

```<code>imports: ConfigModule.forRoot({
  envFilePath: '.development.env',
})
</code>```

npm run start -> it show errorr:

No valid exports main found for

'/home/..../node_modules/@nestjs/config/node_modules/uuid'

error be this line

config/dist/utils/create-config-factory.util.js:3:16

答: There are several closed issues on GitHub. It's an issue with your Node version, 13.6.0 has a problem with the UUID package, but 14 on doesn't.</p>

ContentLicense: CC BY-SA 4.0

Body:
i create new project with nest new new-project
npm run start -> it run good
then i  install nest/config by npm i -save @nest/config

imports: ConfigModule.forRoot({
  envFilePath: '.development.env',
})

npm run start -> it show errorr:

No valid exports main found for

'/home/..../node_modules/@nestjs/config/node_modules/uuid'

error be this line

config/dist/utils/create-config-factory.util.js:3:16


问:
Uncaught ReferenceError: function is not defined with onclick
I'm trying to make a userscript for a website to add custom emotes. However, I've been getting a lot of errors.

Here is the function:

```<code>function saveEmotes() {
    removeLineBreaks();
    EmoteNameLines = EmoteName.value.split("\n");
    EmoteURLLines = EmoteURL.value.split("\n");
    EmoteUsageLines = EmoteUsage.value.split("\n");

    if (EmoteNameLines.length == EmoteURLLines.length && EmoteURLLines.length == EmoteUsageLines.length) {
        for (i = 0; i < EmoteURLLines.length; i++) {
            if (checkIMG(EmoteURLLines[i])) {
                localStorage.setItem("nameEmotes", JSON.stringify(EmoteNameLines));
                localStorage.setItem("urlEmotes", JSON.stringify(EmoteURLLines));
                localStorage.setItem("usageEmotes", JSON.stringify(EmoteUsageLines));
                if (i == 0) {
                    console.log(resetSlot());
                }
                emoteTab[2].innerHTML += '<span style="cursor:pointer;" onclick="appendEmote(\'' + EmoteUsageLines[i] + '\')"><img src="' + EmoteURLLines[i] + '" /></span>';
            } else {
                alert("The maximum emote(" + EmoteNameLines[i] + ") size is (36x36)");
            }
        }
    } else {
        alert("You have an unbalanced amount of emote parameters.");
    }
}
</code>```

The span tag's onclick calls this function:

```<code>function appendEmote(em) {
    shoutdata.value += em;
}
</code>```

Every time I click a button that has an onclick attribute, I get this error:

Uncaught ReferenceError: function is not defined.

Update

I tried using:

```<code>emoteTab[2].innerHTML += '<span style="cursor:pointer;" id="'+ EmoteNameLines[i] +'"><img src="' + EmoteURLLines[i] + '" /></span>';
document.getElementById(EmoteNameLines[i]).addEventListener("click", appendEmote(EmoteUsageLines[i]), false);
</code>```

But I got an undefined error.

Here is the script.

I tried doing this to test if listeners work and they don't for me:

```<code>emoteTab[2].innerHTML = '<td class="trow1" width="12%" align="center"><a id="togglemenu" style="cursor: pointer;">Custom Icons</a></br><a style="cursor: pointer;" id="smilies" onclick=\'window.open("misc.php?action=smilies&popup=true&editor=clickableEditor","Smilies","scrollbars=yes, menubar=no,width=460,height=360,toolbar=no");\' original-title="">Smilies</a><br><a style="cursor: pointer;" onclick=\'window.open("shoutbox.php","Shoutbox","scrollbars=yes, menubar=no,width=825,height=449,toolbar=no");\' original-title="">Popup</a></td></br>';
document.getElementById("togglemenu").addEventListener("click", changedisplay,false);
</code>```

答: If the function is not defined when using that function in html, such as onclick = ‘function () ', it means function is in a callback, in my case is 'DOMContentLoaded'.</p>

Body:
I'm trying to make a userscript for a website to add custom emotes. However, I've been getting a lot of errors.

Here is the function:

function saveEmotes() {
    removeLineBreaks();
    EmoteNameLines = EmoteName.value.split("\n");
    EmoteURLLines = EmoteURL.value.split("\n");
    EmoteUsageLines = EmoteUsage.value.split("\n");

    if (EmoteNameLines.length == EmoteURLLines.length && EmoteURLLines.length == EmoteUsageLines.length) {
        for (i = 0; i < EmoteURLLines.length; i++) {
            if (checkIMG(EmoteURLLines[i])) {
                localStorage.setItem("nameEmotes", JSON.stringify(EmoteNameLines));
                localStorage.setItem("urlEmotes", JSON.stringify(EmoteURLLines));
                localStorage.setItem("usageEmotes", JSON.stringify(EmoteUsageLines));
                if (i == 0) {
                    console.log(resetSlot());
                }
                emoteTab[2].innerHTML += '';
            } else {
                alert("The maximum emote(" + EmoteNameLines[i] + ") size is (36x36)");
            }
        }
    } else {
        alert("You have an unbalanced amount of emote parameters.");
    }
}

The span tag's onclick calls this function:

function appendEmote(em) {
    shoutdata.value += em;
}

Every time I click a button that has an onclick attribute, I get this error:

Uncaught ReferenceError: function is not defined.

Update

I tried using:

emoteTab[2].innerHTML += '';
document.getElementById(EmoteNameLines[i]).addEventListener("click", appendEmote(EmoteUsageLines[i]), false);

But I got an undefined error.

Here is the script.

I tried doing this to test if listeners work and they don't for me:

emoteTab[2].innerHTML = 'Custom Icons
Smilies
Popup
';
document.getElementById("togglemenu").addEventListener("click", changedisplay,false);


问:
System.NullReferenceException: Object reference not set to an instance of an object

Possible Duplicate:

  System.NullReferenceException: Object reference not set to an instance of an object

look at my code

```<code>if (ViewState["Edit"].ToString() == "new") {
}
else {
      row = _section.GetBannerEntry(ViewState["Edit"].ToString());
}
</code>```

I was getting the error on this line if (ViewState["Edit"].ToString() == "new") I replaced with if (ViewState["Edit"] != null && ViewState["Edit"].ToString() == "new") it works.

Now I am getting the same error here in else row = _section.GetBannerEntry(ViewState["Edit"].ToString());

please help

答:
Try</p>

```<code>protected void btnSaveDetails_Click(object sender, EventArgs e)
{
DataRow row = null;
 if (ViewState["Edit"] != null && ViewState["Edit"].ToString() == "new")
 {
 }
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Possible Duplicate:

  System.NullReferenceException: Object reference not set to an instance of an object

look at my code

if (ViewState["Edit"].ToString() == "new") {
}
else {
      row = _section.GetBannerEntry(ViewState["Edit"].ToString());
}

I was getting the error on this line if (ViewState["Edit"].ToString() == "new") I replaced with if (ViewState["Edit"] != null && ViewState["Edit"].ToString() == "new") it works.

Now I am getting the same error here in else row = _section.GetBannerEntry(ViewState["Edit"].ToString());

please help

Body:
Try

protected void btnSaveDetails_Click(object sender, EventArgs e)
{
DataRow row = null;
 if (ViewState["Edit"] != null && ViewState["Edit"].ToString() == "new")
 {
 }
}


问:
(Java) How to store selected elements from a list into array
I have a list of elements:

```<code>private List<Track> selection;
</code>```

And I want to implement a function public Track[] selection()

which returns an array of selected tracks. How to implement this?

I was going to implement this: Swings: storing the selected values from List into an array. method, however it applies only for known number of elements.

EDIT: Sorry to ask such a newbie question, but I tried any possible ways previously and nothing worked. OOP is new for me, and where else to find answers for questions if not here? ^_^

答:
Consider the following minimal example for copying a list of Strings into an array and printing it:</p>

```<code>import java.util.Arrays;
import java.util.List;

public class Main {

  public static void main (String[] args) {
    List<String> stringList = Arrays.asList("H", "e", "l", "l", "o");
    String[] stringArray = stringList.toArray(new String[0]);
    System.out.println(Arrays.toString(stringArray)); // [H, e, l, l, o]
  }
}
</code>```

Body:
I have a list of elements:

private List<Track> selection;

And I want to implement a function public Track[] selection()

which returns an array of selected tracks. How to implement this?

I was going to implement this: Swings: storing the selected values from List into an array. method, however it applies only for known number of elements.

EDIT: Sorry to ask such a newbie question, but I tried any possible ways previously and nothing worked. OOP is new for me, and where else to find answers for questions if not here? ^_^

Body:
Consider the following minimal example for copying a list of Strings into an array and printing it:

import java.util.Arrays;
import java.util.List;

public class Main {

  public static void main (String[] args) {
    List<String> stringList = Arrays.asList("H", "e", "l", "l", "o");
    String[] stringArray = stringList.toArray(new String[0]);
    System.out.println(Arrays.toString(stringArray)); // [H, e, l, l, o]
  }
}


问:
How configure inky-rb in rail API-only
Im trying to install the inky-rb gem to use the foundation-email themes in rails API-Only. This api only read/send data but we want to send emails for user from her.

I aready added the gem

```<code># Preprocessor for email HTML to convert components in table structure https://get.foundation/emails/docs/gem-guide.html

gem 'inky-rb', require: 'inky'

# Stylesheet inlining for email (used by inky)
gem 'premailer-rails'
</code>```

but when run

```<code>rails g inky:install
</code>```

And added the foundation_emails.scss the ruby on rails email preview breaks

so i aready try uncomment

```<code>require 'action_view/railtie'
</code>```

in application.rb and add config.assets.precompile += ['foundation_email.css' ] in the same file.

but now when i go to mailers preview i recive this error

```<code>LoadError in Rails::MailersController#preview
cannot load such file -- sassc
</code>```

To try solve this i tried added the gem

```<code>gem 'sprockets', '~> 4.0'
gem 'sassc-rails'
</code>```

but din't worked

答:
So this is what you should do

1 - Create you mailer with

```<code>rails g mailer folder_name email_name
</code>```

2 - Add the inky-rb, sassc-rails and sprockets gems in your Gemfile.

```<code>gem 'inky-rb', require: 'inky'
gem 'sprockets'
gem 'premailer-rails'
gem 'sassc-rails'
</code>```

For install the gems run bundle install and after rails s

3 - now you have to install the inky whit

```<code>rails g inky:install
</code>```

OBS: This add to arquives foundation_emails.scss the ruby on rails email preview breaks css and a new mailer layout

4 - in aplication.rb uncomment require sprockets/railtie and add after the line config.api_only = true

```<code>config.assets.precompile += %w( foundation_mails.css )
</code>```

you al so need to add a manifest.js inside assets/config

```<code>//= link_directory ../stylesheets .css
</code>```

5 - Now in views/folder_name_mailer you change the file name, from email_name.html.erb to email_name.html.inky and add one layout like this one

```<code><container>
  <columns>
    <spacer size="16"></spacer>
       <h4 class="text-center"> This Works \0/ </h4>
    </columns>
  </row>
</container>
</code>```

6- you can watch your changes in localhost:3000/rails/mailers/folder_name_mailer/email_name.html

This tutorial for full Ruby and Rails helped me alot to fix this problem Mail Previews and Templates Tutorial in Youtube

Title: How configure inky-rb in rail API-only

Body:
Im trying to install the inky-rb gem to use the foundation-email themes in rails API-Only. This api only read/send data but we want to send emails for user from her.

I aready added the gem

# Preprocessor for email HTML to convert components in table structure https://get.foundation/emails/docs/gem-guide.html

gem 'inky-rb', require: 'inky'

# Stylesheet inlining for email (used by inky)
gem 'premailer-rails'

but when run

rails g inky:install

And added the foundation_emails.scss the ruby on rails email preview breaks

so i aready try uncomment

require 'action_view/railtie'

in application.rb and add config.assets.precompile += ['foundation_email.css' ] in the same file.

but now when i go to mailers preview i recive this error

LoadError in Rails::MailersController#preview
cannot load such file -- sassc

To try solve this i tried added the gem

gem 'sprockets', '~> 4.0'
gem 'sassc-rails'

but din't worked

Body:
So this is what you should do

1 - Create you mailer with

rails g mailer folder_name email_name

2 - Add the inky-rb, sassc-rails and sprockets gems in your Gemfile.

gem 'inky-rb', require: 'inky'
gem 'sprockets'
gem 'premailer-rails'
gem 'sassc-rails'

For install the gems run bundle install and after rails s

3 - now you have to install the inky whit

rails g inky:install

OBS: This add to arquives foundation_emails.scss the ruby on rails email preview breaks css and a new mailer layout

4 - in aplication.rb uncomment require sprockets/railtie and add after the line config.api_only = true

config.assets.precompile += %w( foundation_mails.css )

you al so need to add a manifest.js inside assets/config

//= link_directory ../stylesheets .css

5 - Now in views/folder_name_mailer you change the file name, from email_name.html.erb to email_name.html.inky and add one layout like this one

<container>
  <columns>
    <spacer size="16"></spacer>
       <h4 class="text-center"> This Works \0/ </h4>
    </columns>
  </row>
</container>

6- you can watch your changes in localhost:3000/rails/mailers/folder_name_mailer/email_name.html

This tutorial for full Ruby and Rails helped me alot to fix this problem Mail Previews and Templates Tutorial in Youtube


问:
One to one relationship in EF Core throws
I am trying to define a one to one relationship ,where one side has a nullable foreign key, using EF Core and i keep getting the following error:

'The child/dependent side could not be determined for the one-to-one
  relationship between 'Product.Transaction' and 'Transaction.Product'.
  To identify the child/dependent side of the relationship, configure
  the foreign key property. If these navigations should not be part of
  the same relationship configure them without specifying the inverse.
  See http://go.microsoft.com/fwlink/?LinkId=724062 for more details.'

I do not understand what the problem is since i just did it like i would do for a one to many relationship (placing both the Object and its id in both sides):

```<code>public class Product
{
   [Key]
   public long Id{get;set;}

   [ForeignKey("transactionId")]
   public Guid? TransactionId{get;set;}
   public Transaction? Transaction{get;set;}
}
public class Transaction
{
   [Key]
   public Guid Id{get;set;}
   [ForeignKey("productId")]
   public long ProductId{get;set;}
   public Product Product{get;set;}
}
</code>```

P.S I have also checked this article and the only difference is that i am also placing the Id as a field in both sides of the relationship.
I do that because i want easy access to the foreign key.

答:
You should not need to specify the ForeignKey due to the standardized naming you are using. If you remove the ForeignKey attributes, your application shoudl not run in to this issue.

This link should show you how EF core's defaults work and how to specify the foreign key if you use more complex naming. https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-first.aspx

Body:
I am trying to define a one to one relationship ,where one side has a nullable foreign key, using EF Core and i keep getting the following error:

'The child/dependent side could not be determined for the one-to-one
  relationship between 'Product.Transaction' and 'Transaction.Product'.
  To identify the child/dependent side of the relationship, configure
  the foreign key property. If these navigations should not be part of
  the same relationship configure them without specifying the inverse.
  See http://go.microsoft.com/fwlink/?LinkId=724062 for more details.'

I do not understand what the problem is since i just did it like i would do for a one to many relationship (placing both the Object and its id in both sides):

public class Product
{
   [Key]
   public long Id{get;set;}

   [ForeignKey("transactionId")]
   public Guid? TransactionId{get;set;}
   public Transaction? Transaction{get;set;}
}
public class Transaction
{
   [Key]
   public Guid Id{get;set;}
   [ForeignKey("productId")]
   public long ProductId{get;set;}
   public Product Product{get;set;}
}

P.S I have also checked this article and the only difference is that i am also placing the Id as a field in both sides of the relationship.
I do that because i want easy access to the foreign key.


问:
How to remove mapped network drive when created with a random letter
I am creating a mapped network drive with a random letter like this:

```<code> $drive = Get-ChildItem function:[f-z]: -n | Where { !(Test-Path $_) } | select -First 1
 $PsDrive = New-PSDrive -Name ($drive)[0] -PSProvider "FileSystem" -Root $somePath
</code>```

This code works fine. I have a problem when want to remove the newly created mapped drive at the end of my script. How I do it:

```<code>$someEnv = Remove-PSDrive -Name $drive
</code>```

The problem here is that $drive adds the colon after the name ':'. For example if $drive is called M, it will be "M:" and Remove-PsDrive fails.

Probably it will be removed automatically when the session is over, but I want to remove it explicitly.

Do you guys have an idea how I can remove this drive?

Thanks

答:
You can remove the ':' from the $drive variable using Replace

```<code>$drive.Replace(':','')
</code>```

So your code to remove the drive looks like this

```<code>$someEnv = Remove-PSDrive -Name  $drive.Replace(':','')
</code>```

Body:
I am creating a mapped network drive with a random letter like this:

 $drive = Get-ChildItem function:[f-z]: -n | Where { !(Test-Path $_) } | select -First 1
 $PsDrive = New-PSDrive -Name ($drive)[0] -PSProvider "FileSystem" -Root $somePath

This code works fine. I have a problem when want to remove the newly created mapped drive at the end of my script. How I do it:

$someEnv = Remove-PSDrive -Name $drive

The problem here is that $drive adds the colon after the name ':'. For example if $drive is called M, it will be "M:" and Remove-PsDrive fails.

Probably it will be removed automatically when the session is over, but I want to remove it explicitly.

Do you guys have an idea how I can remove this drive?

Thanks

Body:
You can remove the ':' from the $drive variable using Replace

$drive.Replace(':','')

So your code to remove the drive looks like this

$someEnv = Remove-PSDrive -Name  $drive.Replace(':','')


问:
Hide parent elements when routed to child in Angular
So I have a parent component tours, which has a list. When clicked on a list item it routes to /tours/tour-one, that is to the details of that particular tour.

My issue: when the detail is routed, I would like all the elements of the parent compontent(tours) not to be visible in the view. Initially I had done this whole master-detail view with ngIf and services but now I am forced to use Routing, which is also better, but I am unable to get the desired UI.

Here is my tours.component.html:

                <picture>

{{ tour.fields.tourTitle }}

                </picture>

        <router-outlet></router-outlet>

```

From the HTML, I would like to have everything within div.tours-list-wrapper to be hidden or removed from the DOM when url is at tours/<tour detail>

Any input is much appreciated! :)

答:
From my understanding, you need to replace the details page with the list page.

If you have the root router-outlet in the App Component, then you can just remove the  <router-outlet></router-outlet> from you code and it should work as you want. Angular will replace the whole page with the new one.

Body:
So I have a parent component tours, which has a list. When clicked on a list item it routes to /tours/tour-one, that is to the details of that particular tour.

My issue: when the detail is routed, I would like all the elements of the parent compontent(tours) not to be visible in the view. Initially I had done this whole master-detail view with ngIf and services but now I am forced to use Routing, which is also better, but I am unable to get the desired UI.

Here is my tours.component.html:

                <picture>

{{ tour.fields.tourTitle }}

                </picture>

        <router-outlet></router-outlet>

From the HTML, I would like to have everything within div.tours-list-wrapper to be hidden or removed from the DOM when url is at tours/<tour detail>

Any input is much appreciated! :)


问:
Writing Algebraic Data Type in Scala
In Haskell, I can define a Tree:

data Tree a = Empty | Node a (Tree a) (Tree a)
```

How could I write this in Scala?

I'm not sure how to keep the type parameter [A] in Scala for Node to match Tree's type, a.

答:
Starting in Scala 3, and the new union type, this will become possible:

type Tree[A] = Node[A] | Empty.type
case object Empty
case class Node[A](value: A, left: Tree[A], right: Tree[A])
```
<p>which you can instantiate as such:</p>
<pre class="lang-scala prettyprint-override"><code>val empty: Tree[String] = Empty
val tree:  Tree[String] = Node("foo", Node("bar", Empty, Empty), Empty)
</code>```

and use as part of a concrete example:

def depth[A](tree: Tree[A]): Int =
  tree match {
    case Empty                => 0
    case Node(_, left, right) => 1 + (depth(left) max depth(right))
  }

depth(tree)  // 2
depth(empty) // 0
```

Title: Writing Algebraic Data Type in Scala

Body:
In Haskell, I can define a Tree:

data Tree a = Empty | Node a (Tree a) (Tree a)

How could I write this in Scala?

I'm not sure how to keep the type parameter [A] in Scala for Node to match Tree's type, a.

Body:
Starting in Scala 3, and the new union type, this will become possible:

type Tree[A] = Node[A] | Empty.type
case object Empty
case class Node[A](value: A, left: Tree[A], right: Tree[A])

which you can instantiate as such:

val empty: Tree[String] = Empty
val tree:  Tree[String] = Node("foo", Node("bar", Empty, Empty), Empty)

and use as part of a concrete example:

def depth[A](tree: Tree[A]): Int =
  tree match {
    case Empty                => 0
    case Node(_, left, right) => 1 + (depth(left) max depth(right))
  }

depth(tree)  // 2
depth(empty) // 0


问:
The executable python file outputs fatal error message
I have written a python script that communicates with the web page and makes an online order. In addition to that I have added some GUI, which allows the user to select the day of the order. Here is the python script

```<code>import easygui
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

import tkinter as tk
import tkinter.font as tkFont

badge_number = 111111

# Widget pop up for selection of the order day
root = tk.Tk()
def center_window(w=300, h=200):
    # get screen width and height
    ws = root.winfo_screenwidth()
    hs = root.winfo_screenheight()
    # calculate position x, y
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    root.geometry('%dx%d+%d+%d' % (w, h, x, y))

root.geometry("400x450")

Label = tk.Label(root, text = "Select lunch Order Day", font = ("Helvetica", 15))
Label.pack(pady=50, padx=40)

helv15 = tkFont.Font(family = "Helvetica", size = 15)
root.lift()
v = tk.StringVar()
v.set("Today")
tk.Label(root, textvariable = v).pack()

def close_window():
    root.destroy()

today = tk.Radiobutton(root, text = "Today", variable = v, value = "Today", font = helv15).pack()
tomorrow = tk.Radiobutton(root, text = "Tomorrow", variable = v, value = "Tomorrow", font = helv15).pack()
cancel = tk.Radiobutton(root, text = "Cancel", variable = v, value = "Cancel", font = helv15).pack()
submit = tk.Button(root, text = "Submit", command = close_window, font = helv15).pack()

center_window(400, 400)

root.mainloop()

if v.get() == "Cancel":
    sys.exit("Ordering was terminated")

driver = webdriver.Chrome(executable_path = "C:\webdrivers\chromedriver.exe")
driver.get("http://web_page/")

element = driver.find_element_by_name('employee_id')
element.send_keys(badge_number)

driver.find_element_by_xpath("/html/body/section/header/form/div/button").click()

# /html/body/section/header/form/div/button
delay = 60

todayBut = "/html/body/section/div[1]/div[2]/div/div/div/span[2]/span[1]/form/button"
tomorBut = "/html/body/section/div[1]/div[2]/div/div/div/span[1]/span[1]/form/button"
favorButToday = "/html/body/section/div/div[1]/button"
favorButTomor = "/html/body/section/div/div[1]/button/a"
myFavOrderID = "fav_order_view"

try:
    element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, todayBut)))
except TimeoutException:
    print ("Loading Day Selection page took too much time!")

if v.get() == "Today":
    driver.find_element_by_xpath(todayBut).click()

    #favorite choice
    try:
        element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, favorButToday)))
        driver.find_element_by_xpath(favorButToday).click()
        try:
            element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, myFavOrderID)))
            driver.find_element_by_id(myFavOrderID).click()

            ### select floor, order date and order now
            select_floor = Select(driver.find_element_by_name("floor_number"))
            select_floor.select_by_index("9")
            select_day = Select(driver.find_element_by_name("order_date"))
            select_day.select_by_value("today")
            orderNowBtn = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
            driver.find_element_by_xpath(orderNowBtn).click()
            print("Today's order was successfully made!")
        except TimeoutException:
            print ("Loading Favorites page took too much time!")
    except TimeoutException:
        print ("Loading took too much time!")

else:

    driver.find_element_by_xpath(tomorBut).click()

    #favorite choice
    try:
        element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, favorButTomor)))
        driver.find_element_by_xpath(favorButTomor).click()
        try:
            myFavOrderIDTomor = "fav_order_view"
            element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, myFavOrderIDTomor)))
            driver.find_element_by_id(myFavOrderIDTomor).click()

            ### select floor, order date and order now
            select_floor = Select(driver.find_element_by_name("floor_number"))
            select_floor.select_by_index("9")
            select_day = Select(driver.find_element_by_name("order_date"))
            select_day.select_by_value("tomorrow")
            orderNowBtnTomor = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
            driver.find_element_by_xpath(orderNowBtnTomor).click()
            print("Tomorrow's order was successfully made!")
        except TimeoutException:
            print ("Loading Favorites page took too much time!")
    except TimeoutException:
        print ("Loading took too much time!")
</code>```

However, I wanted to have it as an .exe file to run it with just double-click from my desktop. So, I have installed pyinstaller from git and run the simple line in the cmd (pyinstaller.exe --onefile --windowed --icon=app.ico LunchOrder.py). Unfortunately, the .exe isn't doign anything, it just pops up the "Fatal error detected" message, without any GUI (that I have written into the script itself). Any help would be appreciated!

答:
Here i will tell you a better way to make .py to .exe . First make sure your python is added to system PATH, which i assume is. If not check some tutorials on how to add python to PATH then you can open your cmd and type in:

```<code>pip install pyinstaller
</code>```

After this, you go to your path where the LunchOrder.py exists and open a cmd there, in windows you can type simply type in cmd in the address bar (after clearing adressbar), or else open a cmd and navigate to your path where LunchOrder.py file exists and simply type in:

```<code>pyinstaller -w -F -i "app.ico" LunchOrder.py
</code>```

This should make a folder dist inside which your .exe will be there. MAKE SURE TO COPY THE .exe to outside the dist folder and run it there. Or else you might still get fatal error message. You can delete all the other extra files that was generated like build and LunchOrder.spec . If it still gives you error try following this method https://www.youtube.com/watch?v=OZSZHmWSOeM

Body:
I have written a python script that communicates with the web page and makes an online order. In addition to that I have added some GUI, which allows the user to select the day of the order. Here is the python script

import easygui
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

import tkinter as tk
import tkinter.font as tkFont

badge_number = 111111

# Widget pop up for selection of the order day
root = tk.Tk()
def center_window(w=300, h=200):
    # get screen width and height
    ws = root.winfo_screenwidth()
    hs = root.winfo_screenheight()
    # calculate position x, y
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    root.geometry('%dx%d+%d+%d' % (w, h, x, y))

root.geometry("400x450")

Label = tk.Label(root, text = "Select lunch Order Day", font = ("Helvetica", 15))
Label.pack(pady=50, padx=40)

helv15 = tkFont.Font(family = "Helvetica", size = 15)
root.lift()
v = tk.StringVar()
v.set("Today")
tk.Label(root, textvariable = v).pack()

def close_window():
    root.destroy()

today = tk.Radiobutton(root, text = "Today", variable = v, value = "Today", font = helv15).pack()
tomorrow = tk.Radiobutton(root, text = "Tomorrow", variable = v, value = "Tomorrow", font = helv15).pack()
cancel = tk.Radiobutton(root, text = "Cancel", variable = v, value = "Cancel", font = helv15).pack()
submit = tk.Button(root, text = "Submit", command = close_window, font = helv15).pack()

center_window(400, 400)

root.mainloop()

if v.get() == "Cancel":
    sys.exit("Ordering was terminated")

driver = webdriver.Chrome(executable_path = "C:\webdrivers\chromedriver.exe")
driver.get("http://web_page/")

element = driver.find_element_by_name('employee_id')
element.send_keys(badge_number)

driver.find_element_by_xpath("/html/body/section/header/form/div/button").click()

# /html/body/section/header/form/div/button
delay = 60

todayBut = "/html/body/section/div[1]/div[2]/div/div/div/span[2]/span[1]/form/button"
tomorBut = "/html/body/section/div[1]/div[2]/div/div/div/span[1]/span[1]/form/button"
favorButToday = "/html/body/section/div/div[1]/button"
favorButTomor = "/html/body/section/div/div[1]/button/a"
myFavOrderID = "fav_order_view"

try:
    element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, todayBut)))
except TimeoutException:
    print ("Loading Day Selection page took too much time!")

if v.get() == "Today":
    driver.find_element_by_xpath(todayBut).click()

    #favorite choice
    try:
        element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, favorButToday)))
        driver.find_element_by_xpath(favorButToday).click()
        try:
            element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, myFavOrderID)))
            driver.find_element_by_id(myFavOrderID).click()

            ### select floor, order date and order now
            select_floor = Select(driver.find_element_by_name("floor_number"))
            select_floor.select_by_index("9")
            select_day = Select(driver.find_element_by_name("order_date"))
            select_day.select_by_value("today")
            orderNowBtn = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
            driver.find_element_by_xpath(orderNowBtn).click()
            print("Today's order was successfully made!")
        except TimeoutException:
            print ("Loading Favorites page took too much time!")
    except TimeoutException:
        print ("Loading took too much time!")

else:

    driver.find_element_by_xpath(tomorBut).click()

    #favorite choice
    try:
        element = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.XPATH, favorButTomor)))
        driver.find_element_by_xpath(favorButTomor).click()
        try:
            myFavOrderIDTomor = "fav_order_view"
            element = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, myFavOrderIDTomor)))
            driver.find_element_by_id(myFavOrderIDTomor).click()

            ### select floor, order date and order now
            select_floor = Select(driver.find_element_by_name("floor_number"))
            select_floor.select_by_index("9")
            select_day = Select(driver.find_element_by_name("order_date"))
            select_day.select_by_value("tomorrow")
            orderNowBtnTomor = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
            driver.find_element_by_xpath(orderNowBtnTomor).click()
            print("Tomorrow's order was successfully made!")
        except TimeoutException:
            print ("Loading Favorites page took too much time!")
    except TimeoutException:
        print ("Loading took too much time!")

However, I wanted to have it as an .exe file to run it with just double-click from my desktop. So, I have installed pyinstaller from git and run the simple line in the cmd (pyinstaller.exe --onefile --windowed --icon=app.ico LunchOrder.py). Unfortunately, the .exe isn't doign anything, it just pops up the "Fatal error detected" message, without any GUI (that I have written into the script itself). Any help would be appreciated!

Body:
Here i will tell you a better way to make .py to .exe . First make sure your python is added to system PATH, which i assume is. If not check some tutorials on how to add python to PATH then you can open your cmd and type in:

pip install pyinstaller

After this, you go to your path where the LunchOrder.py exists and open a cmd there, in windows you can type simply type in cmd in the address bar (after clearing adressbar), or else open a cmd and navigate to your path where LunchOrder.py file exists and simply type in:

pyinstaller -w -F -i "app.ico" LunchOrder.py

This should make a folder dist inside which your .exe will be there. MAKE SURE TO COPY THE .exe to outside the dist folder and run it there. Or else you might still get fatal error message. You can delete all the other extra files that was generated like build and LunchOrder.spec . If it still gives you error try following this method https://www.youtube.com/watch?v=OZSZHmWSOeM


问:
Load a different form on different pages using the same page template
Kentico 12, not MVC:
I have a page template that is used on several pages.  On some of those pages I want to display a form. (a biz form from the Forms application) I don't necessarily want the same form on each of those pages. I need a way to specify which form to display.  I expect I could create a field in the page type to specify the form name, but it would be nicer to be able to have designers add a page with the form on it, and have a repeater display that page in a webpartzone on the aforementioned page template.  I'm not sure how to do this, though.  Anyone have an example or suggestions?  </p>

答: In addition to adding a widget zone, you can simply add an editable text webpart to the template and in the WYSIWYG editor you can click on the BizForm icon to insert that widget there. This doesn't require you to change the page template to a widget zone template. </p>


问:
Null values best practices in Parquet files
I'm trying to figure out what is the best practice if I have a string column with possible null values.

In SQL databases null is a legit value, but from reading around I've found lots of issues and people's questions about null value in parquet files.

If I want to process these parquet files later with abroad set of tools such as Drill, Spark, etc.
what is the best approach for storing null values, as nulls or empty strings?

答:
Well this is not about other tools or Spark its about your business logic considers a null or a empty string "" differently because many other application considers them as separate logical entity,

But if your application treats them same then you can just mark them to more safer option as empty string "" which would avoid all future NullpointerExceptions for that column.

AFAIK all other Big data component (Drill,Spark,etc including Parquet file format) handles null value very well.


问:
MPI Segmentation Fault On Multiple Nodes Only
So I am currently building the basis of a control program to run on multiple raspberry Pis that will use all of the available cores on each pi. When I test my code on one of the nodes using all of the cores it works fine, but using multiple nodes gives me a segmentation fault.

I looked at all the similar questions asked in the past, but they all had issues that would have broken my code on only one node too.

The full code:

```<code>#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <time.h>
int main(int argc, char *argv[])
{
        FILE *input;
        char batLine[86];   //may need to be made larger if bat commands get longer
        char sentbatch[86];
        int currentTask;
        int numTasks, rank, rc, i;
        MPI_Status stat;
        bool exitFlag = false;

        //mpi stuff
        MPI_Init(&argc,&argv);  //initilize mpi enviroment
        MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
        MPI_Comm_rank(MPI_COMM_WORLD,&rank);
        //printf("Number of tasks: %d \n", numTasks);
        //printf ("MPI task %d has started...\n", rank);
        if(argc != 2)
        {
            printf("Usage: batallocation *.bat");
            exit(1); //exit with 1 indicates a failure
        }
        //contains file name: argv[1]
        input = fopen(argv[1],"r");

        currentTask = 0;
        if (rank ==0)
        {
            while(1)
            {
                if(exitFlag)
                    break; //allows to break out of while and for when no more lines exist
                char command[89] = "./";
                for(i=0; i < 16; i++) //will need to be 16 for full testing
                {

                    //fgets needs to be character count of longest line + 2 or it fails
                    if(fgets(batLine,86,input) != NULL)
                    {
                        printf("preview:%s\n",batLine);
                        if(i==0)
                        {
                            strcat(command,batLine);
                            printf("rank0 gets: %s\n", command);
                            //system(command);
                        }
                        else
                        {
                            //MPI_Send(buffer,count,type,dest,tag,comm)
                            MPI_Send(batLine,85,MPI_CHAR,i,i,MPI_COMM_WORLD);
                            printf("sent rank%d: %s\n",i,batLine);
                        }
                    }
                    else
                    {
                        exitFlag = true; //flag to break out of while loop
                        break;
                    }

                }
                //need to recieve data from other nodes here
                //put the data together in proper order
                //and only after that can the next sets be sent out

            }
        }
        else
        {
            char command[89] = "./";
            //MPI_Recv(buffer,count,type,source,tag,comm,status)
            MPI_Recv(sentbatch,86,MPI_CHAR,0,rank,MPI_COMM_WORLD,&stat);
            //using rank as flag makes it so only the wanted rank gets sent the data
            strcat(command,sentbatch); //adds needed ./ before batch data
            printf("rank=%d recieved data:%s",rank,sentbatch);
            //system(command); //should run batch line
        }
        fclose(input);
        MPI_Finalize();
        return(0);
}
</code>```

The contents of the file being passed:

```<code>
LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f
</code>```

You will notice I am not yet doing a few things that will be done in the final version and they are in comments to make trouble shooting easier. Mostly because the LAMOST code is not fast, and I do not want to be waiting for it to complete.

The command prompt that works and the output for it:

```<code> $mpiexec -N 4 --host 10.0.0.3 -oversubscribe batTest2 shortpass2.bat
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
</code>```

Shortpass2 is just the same file but with only the first 4 lines. My code should theoretically work with all 16 lines but I will test it with a full file after fixing the current issue.

Running on multiple nodes command and output:

```<code>$mpiexec -N 4 --host 10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6 -oversubscribe batTest2 shortpass.bat

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
sent rank4: LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

rank=4 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
[node2:27622] *** Process received signal ***
[node2:27622] Signal: Segmentation fault (11)
[node2:27622] Signal code: Address not mapped (1)
[node2:27622] Failing at address: (nil)
[node2:27622] *** End of error message ***
--------------------------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
corrupted double-linked list
Aborted
</code>```

Sometimes it will successfully get to rank 5 before aborting completely, and there will be multiple instances of the same error message. Additionally, Open MPI was installed with multiple thread support so that isn't the issue. This is my first time using MPI but this is not the first part of the whole project and I have done a ton of research into MPI to even get this far with it.

I know it isn't caused by my arrays since then it would be breaking on node1 as well. All of the pis are identical so it wouldn't make sense for the arrays to be causing the segmentation faults. (Although I admit I have had that issue come up several times working on the different parts of this project because I am more used to how Java and C# handle arrays)

Edit: I checked to see if I could run it across 4 cores from one of the other nodes and that works fine and produces the same output as it did on node1. So that confirms it not being an array issue that only happens on the other nodes.
Also added a line that was missing in the code for the preview print out.

Edit2: Per Gilles suggestion: The code works with running 16 tasks all on one node as well. Here is the output from that:

```<code>$ mpiexec -N 16 --host 10.0.0.3 -oversubscribe batTest4 shortpass.bat
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

sent rank4: LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

sent rank5: LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f

sent rank6: LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f

sent rank7: LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f

sent rank8: LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f

sent rank9: LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f

sent rank10: LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f

sent rank11: LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f

sent rank12: LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f

sent rank13: LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f

sent rank14: LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f

sent rank15: LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f

rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
rank=5 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f
rank=6 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f
rank=7 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f
rank=11 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f
rank=12 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f
rank=9 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f
rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
rank=4 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
rank=8 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f
rank=10 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f
rank=15 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f
rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
rank=13 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f
rank=14 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f
</code>```

答:
After more attempts of searching for similar issues, I finally found the answer of what is wrong in the code. It just took searching for the error message in so many different possible inputs.

The lines:

```<code>input = fopen(argv[1],"1");
fclose(input);
</code>```

needed to be within rank 0 only. Meaning the correct code to get it to run on multiple nodes is:

```<code>//has file open and closed moved to hopefully work on multiple nodes
//now only occurs for task0 which is on node1
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <time.h>
int main(int argc, char *argv[])
{
        FILE *input;
        char batLine[86];   //may need to be made larger if bat commands get longer
        char sentbatch[86];
        int currentTask;
        int numTasks, rank, rc, i;
        MPI_Status stat;
        bool exitFlag = false;

        //mpi stuff
        MPI_Init(&argc,&argv);  //initilize mpi enviroment
        MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
        MPI_Comm_rank(MPI_COMM_WORLD,&rank);
        //printf("Number of tasks: %d \n", numTasks);
        //printf ("MPI task %d has started...\n", rank);
        if(argc != 2)
        {
            printf("Usage: batallocation *.bat");
            exit(1); //exit with 1 indicates a failure
        }
        if (rank ==0)
        {
            //contains file name: argv[1]
            input = fopen(argv[1],"r");
            while(1)
            {
                if(exitFlag)
                    break; //allows to break out of while and for when no more lines exist
                char command[89] = "./";
                for(i=0; i < 16; i++) //will need to be 16 for full testing
                {

                    //fgets needs to be character count of longest line + 2 or it fails
                    if(fgets(batLine,86,input) != NULL)
                    {
                        if(i==0)
                        {
                            strcat(command,batLine);
                            printf("rank0 gets: %s\n", command);
                            //system(command);
                        }
                        else
                        {
                            //MPI_Send(buffer,count,type,dest,tag,comm)
                            MPI_Send(batLine,85,MPI_CHAR,i,i,MPI_COMM_WORLD);
                            printf("sent rank%d: %s\n",i,batLine);
                        }
                    }
                    else
                    {
                        exitFlag = true; //flag to break out of while loop
                        break;
                    }

                }
                //need to recieve data from other nodes here
                //put the data together in proper order
                //and only after that can the next sets be sent out

            }
            fclose(input);
        }
        else
        {
            char command[89] = "./";
            //MPI_Recv(buffer,count,type,source,tag,comm,status)
            MPI_Recv(sentbatch,86,MPI_CHAR,0,rank,MPI_COMM_WORLD,&stat);
            //using rank as flag makes it so only the wanted rank gets sent the data
            strcat(command,sentbatch); //adds needed ./ before batch data
            printf("rank=%d recieved data:%s",rank,sentbatch);
            //system(command); //should run batch line
        }

        MPI_Finalize();
        return(0);
}
</code>```

I don't know how acceptable it is to answer your own question, but I wanted to ensure that if anyone has the same issue they know how to fix it. I know I hate when I find a similar question only to see that the asker edited in that they fixed the issue without explaining how they fixed it.

Body:
So I am currently building the basis of a control program to run on multiple raspberry Pis that will use all of the available cores on each pi. When I test my code on one of the nodes using all of the cores it works fine, but using multiple nodes gives me a segmentation fault.

I looked at all the similar questions asked in the past, but they all had issues that would have broken my code on only one node too.

The full code:

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <time.h>
int main(int argc, char *argv[])
{
        FILE *input;
        char batLine[86];   //may need to be made larger if bat commands get longer
        char sentbatch[86];
        int currentTask;
        int numTasks, rank, rc, i;
        MPI_Status stat;
        bool exitFlag = false;

        //mpi stuff
        MPI_Init(&argc,&argv);  //initilize mpi enviroment
        MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
        MPI_Comm_rank(MPI_COMM_WORLD,&rank);
        //printf("Number of tasks: %d \n", numTasks);
        //printf ("MPI task %d has started...\n", rank);
        if(argc != 2)
        {
            printf("Usage: batallocation *.bat");
            exit(1); //exit with 1 indicates a failure
        }
        //contains file name: argv[1]
        input = fopen(argv[1],"r");

        currentTask = 0;
        if (rank ==0)
        {
            while(1)
            {
                if(exitFlag)
                    break; //allows to break out of while and for when no more lines exist
                char command[89] = "./";
                for(i=0; i < 16; i++) //will need to be 16 for full testing
                {

                    //fgets needs to be character count of longest line + 2 or it fails
                    if(fgets(batLine,86,input) != NULL)
                    {
                        printf("preview:%s\n",batLine);
                        if(i==0)
                        {
                            strcat(command,batLine);
                            printf("rank0 gets: %s\n", command);
                            //system(command);
                        }
                        else
                        {
                            //MPI_Send(buffer,count,type,dest,tag,comm)
                            MPI_Send(batLine,85,MPI_CHAR,i,i,MPI_COMM_WORLD);
                            printf("sent rank%d: %s\n",i,batLine);
                        }
                    }
                    else
                    {
                        exitFlag = true; //flag to break out of while loop
                        break;
                    }

                }
                //need to recieve data from other nodes here
                //put the data together in proper order
                //and only after that can the next sets be sent out

            }
        }
        else
        {
            char command[89] = "./";
            //MPI_Recv(buffer,count,type,source,tag,comm,status)
            MPI_Recv(sentbatch,86,MPI_CHAR,0,rank,MPI_COMM_WORLD,&stat);
            //using rank as flag makes it so only the wanted rank gets sent the data
            strcat(command,sentbatch); //adds needed ./ before batch data
            printf("rank=%d recieved data:%s",rank,sentbatch);
            //system(command); //should run batch line
        }
        fclose(input);
        MPI_Finalize();
        return(0);
}

The contents of the file being passed:

LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f
LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f

You will notice I am not yet doing a few things that will be done in the final version and they are in comments to make trouble shooting easier. Mostly because the LAMOST code is not fast, and I do not want to be waiting for it to complete.

The command prompt that works and the output for it:

 $mpiexec -N 4 --host 10.0.0.3 -oversubscribe batTest2 shortpass2.bat
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

Shortpass2 is just the same file but with only the first 4 lines. My code should theoretically work with all 16 lines but I will test it with a full file after fixing the current issue.

Running on multiple nodes command and output:

$mpiexec -N 4 --host 10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6 -oversubscribe batTest2 shortpass.bat

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
sent rank4: LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

rank=4 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
[node2:27622] *** Process received signal ***
[node2:27622] Signal: Segmentation fault (11)
[node2:27622] Signal code: Address not mapped (1)
[node2:27622] Failing at address: (nil)
[node2:27622] *** End of error message ***
--------------------------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
corrupted double-linked list
Aborted

Sometimes it will successfully get to rank 5 before aborting completely, and there will be multiple instances of the same error message. Additionally, Open MPI was installed with multiple thread support so that isn't the issue. This is my first time using MPI but this is not the first part of the whole project and I have done a ton of research into MPI to even get this far with it.

I know it isn't caused by my arrays since then it would be breaking on node1 as well. All of the pis are identical so it wouldn't make sense for the arrays to be causing the segmentation faults. (Although I admit I have had that issue come up several times working on the different parts of this project because I am more used to how Java and C# handle arrays)

Edit: I checked to see if I could run it across 4 cores from one of the other nodes and that works fine and produces the same output as it did on node1. So that confirms it not being an array issue that only happens on the other nodes.
Also added a line that was missing in the code for the preview print out.

Edit2: Per Gilles suggestion: The code works with running 16 tasks all on one node as well. Here is the output from that:

$ mpiexec -N 16 --host 10.0.0.3 -oversubscribe batTest4 shortpass.bat
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

rank0 gets: ./LAMOSTv108 spec-56321-GAC099N59V1_sp01-001.flx spec-56321-GAC099N59V1_sp01-001.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

sent rank1: LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f

sent rank2: LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

sent rank3: LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

sent rank4: LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

sent rank5: LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f

sent rank6: LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f

sent rank7: LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f

sent rank8: LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f

sent rank9: LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f

sent rank10: LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f

sent rank11: LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f

sent rank12: LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f

sent rank13: LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f

sent rank14: LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f

preview:LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f

sent rank15: LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f

rank=3 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-005.flx spec-56321-GAC099N59V1_sp01-005.nor f
rank=5 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-008.flx spec-56321-GAC099N59V1_sp01-008.nor f
rank=6 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-010.flx spec-56321-GAC099N59V1_sp01-010.nor f
rank=7 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-013.flx spec-56321-GAC099N59V1_sp01-013.nor f
rank=11 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-023.flx spec-56321-GAC099N59V1_sp01-023.nor f
rank=12 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-024.flx spec-56321-GAC099N59V1_sp01-024.nor f
rank=9 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-018.flx spec-56321-GAC099N59V1_sp01-018.nor f
rank=2 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-004.flx spec-56321-GAC099N59V1_sp01-004.nor f
rank=4 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-006.flx spec-56321-GAC099N59V1_sp01-006.nor f
rank=8 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-015.flx spec-56321-GAC099N59V1_sp01-015.nor f
rank=10 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-022.flx spec-56321-GAC099N59V1_sp01-022.nor f
rank=15 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-029.flx spec-56321-GAC099N59V1_sp01-029.nor f
rank=1 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-003.flx spec-56321-GAC099N59V1_sp01-003.nor f
rank=13 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-025.flx spec-56321-GAC099N59V1_sp01-025.nor f
rank=14 recieved data:LAMOSTv108 spec-56321-GAC099N59V1_sp01-028.flx spec-56321-GAC099N59V1_sp01-028.nor f

Body:
After more attempts of searching for similar issues, I finally found the answer of what is wrong in the code. It just took searching for the error message in so many different possible inputs.

The lines:

input = fopen(argv[1],"1");
fclose(input);

needed to be within rank 0 only. Meaning the correct code to get it to run on multiple nodes is:

//has file open and closed moved to hopefully work on multiple nodes
//now only occurs for task0 which is on node1
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <time.h>
int main(int argc, char *argv[])
{
        FILE *input;
        char batLine[86];   //may need to be made larger if bat commands get longer
        char sentbatch[86];
        int currentTask;
        int numTasks, rank, rc, i;
        MPI_Status stat;
        bool exitFlag = false;

        //mpi stuff
        MPI_Init(&argc,&argv);  //initilize mpi enviroment
        MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
        MPI_Comm_rank(MPI_COMM_WORLD,&rank);
        //printf("Number of tasks: %d \n", numTasks);
        //printf ("MPI task %d has started...\n", rank);
        if(argc != 2)
        {
            printf("Usage: batallocation *.bat");
            exit(1); //exit with 1 indicates a failure
        }
        if (rank ==0)
        {
            //contains file name: argv[1]
            input = fopen(argv[1],"r");
            while(1)
            {
                if(exitFlag)
                    break; //allows to break out of while and for when no more lines exist
                char command[89] = "./";
                for(i=0; i < 16; i++) //will need to be 16 for full testing
                {

                    //fgets needs to be character count of longest line + 2 or it fails
                    if(fgets(batLine,86,input) != NULL)
                    {
                        if(i==0)
                        {
                            strcat(command,batLine);
                            printf("rank0 gets: %s\n", command);
                            //system(command);
                        }
                        else
                        {
                            //MPI_Send(buffer,count,type,dest,tag,comm)
                            MPI_Send(batLine,85,MPI_CHAR,i,i,MPI_COMM_WORLD);
                            printf("sent rank%d: %s\n",i,batLine);
                        }
                    }
                    else
                    {
                        exitFlag = true; //flag to break out of while loop
                        break;
                    }

                }
                //need to recieve data from other nodes here
                //put the data together in proper order
                //and only after that can the next sets be sent out

            }
            fclose(input);
        }
        else
        {
            char command[89] = "./";
            //MPI_Recv(buffer,count,type,source,tag,comm,status)
            MPI_Recv(sentbatch,86,MPI_CHAR,0,rank,MPI_COMM_WORLD,&stat);
            //using rank as flag makes it so only the wanted rank gets sent the data
            strcat(command,sentbatch); //adds needed ./ before batch data
            printf("rank=%d recieved data:%s",rank,sentbatch);
            //system(command); //should run batch line
        }

        MPI_Finalize();
        return(0);
}

I don't know how acceptable it is to answer your own question, but I wanted to ensure that if anyone has the same issue they know how to fix it. I know I hate when I find a similar question only to see that the asker edited in that they fixed the issue without explaining how they fixed it.


问:
How to configure SWD pins using registers in STM32?
Info: I create Blink using registers in STM32. This works, except that after the firmware the SWD connector stops working for me. The reason most likely is that the SWD is on the same port along with the LED. When configuring the port and the LED pin, I probably reset the SWD settings.

Code:

```<code>#include "main.h"

void SystemClock_Config(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();

  __HAL_RCC_GPIOA_CLK_ENABLE();
  // Set PA8 to OUTPUT mode
  GPIOA->MODER = 0x00010000;
  // Set PUSH-PULL mode
  GPIOA->OTYPER = 0x00000000;
  // Set pin speed
  GPIOA->OSPEEDR = 0x64010000;
  // Set not pull
  GPIOA->PUPDR = 0x64000000;
  // Set pin bit
  GPIOA->BSRR = 0x00000100;

  static int pin_state = 0;

  while (1)
  {
      // LED blink
      if(pin_state == 0) {
        // Bit set
        GPIOA->BSRR = 0x00000100;
        pin_state = 1;
      } else {
        // Bit clear
        GPIOA->BSRR = 0x01000000;
        pin_state = 0;
      }

      HAL_Delay(3000);

  }
}

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

void Error_Handler(void) {}

#ifdef  USE_FULL_ASSERT
void assert_failed(char *file, uint32_t line) {}
#endif
</code>```

In the STM32F334K8Tx datasheet, I did not find much information about setting registers for SWD contacts (which mode, setting the clock, pull-up, and more).

Question: how can this be done? Or where can I find information?

答:
Instead of using magic number, you should use something like that:

```<code>// Set PA8 to OUTPUT mode
GPIOA->MODER |= GPIO_MODER_MODER8_1; // Ref.: 9.4.1
// Set PUSH-PULL mode
//GPIOA->OTYPER = 0x00000000; // Reset value is 0x0000 0000
// Set pin speed
//GPIOA->OSPEEDR = 0x6401 0000;
GPIOA->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR8_0; // 9.4.3

// Set not pull
//GPIOA->PUPDR  // Reset value is: 0x6400 0000 9.4.4
// Set pin bit
GPIOA->BSRR |= GPIO_BSRR_BS_8; // 9.4.7
</code>```

In the loop, you could use:

```<code>// The BSRR register is read only
GPIOA->BSRR |= GPIO_BSRR_BS_8; // set ON
GPIOA->BSRR |= GPIO_BSRR_BR_8; // reset
// You could also use:
GPIOA->BRR |= GPIO_BSRR_BS_8; // set ON 9.4.11
</code>```

If you want to reset a register, use something like that:

```<code>GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR8_1; // reset the value
</code>```

Body:
Info: I create Blink using registers in STM32. This works, except that after the firmware the SWD connector stops working for me. The reason most likely is that the SWD is on the same port along with the LED. When configuring the port and the LED pin, I probably reset the SWD settings.

Code:

#include "main.h"

void SystemClock_Config(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();

  __HAL_RCC_GPIOA_CLK_ENABLE();
  // Set PA8 to OUTPUT mode
  GPIOA->MODER = 0x00010000;
  // Set PUSH-PULL mode
  GPIOA->OTYPER = 0x00000000;
  // Set pin speed
  GPIOA->OSPEEDR = 0x64010000;
  // Set not pull
  GPIOA->PUPDR = 0x64000000;
  // Set pin bit
  GPIOA->BSRR = 0x00000100;

  static int pin_state = 0;

  while (1)
  {
      // LED blink
      if(pin_state == 0) {
        // Bit set
        GPIOA->BSRR = 0x00000100;
        pin_state = 1;
      } else {
        // Bit clear
        GPIOA->BSRR = 0x01000000;
        pin_state = 0;
      }

      HAL_Delay(3000);

  }
}

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

void Error_Handler(void) {}

#ifdef  USE_FULL_ASSERT
void assert_failed(char *file, uint32_t line) {}
#endif

In the STM32F334K8Tx datasheet, I did not find much information about setting registers for SWD contacts (which mode, setting the clock, pull-up, and more).

Question: how can this be done? Or where can I find information?

Body:
Instead of using magic number, you should use something like that:

// Set PA8 to OUTPUT mode
GPIOA->MODER |= GPIO_MODER_MODER8_1; // Ref.: 9.4.1
// Set PUSH-PULL mode
//GPIOA->OTYPER = 0x00000000; // Reset value is 0x0000 0000
// Set pin speed
//GPIOA->OSPEEDR = 0x6401 0000;
GPIOA->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR8_0; // 9.4.3

// Set not pull
//GPIOA->PUPDR  // Reset value is: 0x6400 0000 9.4.4
// Set pin bit
GPIOA->BSRR |= GPIO_BSRR_BS_8; // 9.4.7

In the loop, you could use:

// The BSRR register is read only
GPIOA->BSRR |= GPIO_BSRR_BS_8; // set ON
GPIOA->BSRR |= GPIO_BSRR_BR_8; // reset
// You could also use:
GPIOA->BRR |= GPIO_BSRR_BS_8; // set ON 9.4.11

If you want to reset a register, use something like that:

GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR8_1; // reset the value


问:
lighttpd mod_cgi set http error from script
lighttpd mod_cgi is configured as following

```<code>server.modules += ( "mod_cgi", "mod_alias", "mod_setenv" )

cgi.assign += ( "" => "" )  ## run exectables with shebang

$HTTP["url"] == "network" {
   $HTTP["request-method"] == "GET" {
      alias.url += ( "network"  => "/usr/bin/network" )
      setenv.add-response-header = ( "Content-Type" => "application/xml" )
   }
}
</code>```

when file /usr/bin/network returned error, lighttpd responds to client with 500 Internal server error.

How can I handle that error and turn it into 400 Bad request from cgi-script?

答:
Script should always return 0. To set HTTP status use next approach.

```<code>#!/bin/sh

echo "Status: 400 Bad request"; echo
echo "message"
</code>```

More samples and info about CGI are on wikipedia

Body:
lighttpd mod_cgi is configured as following

server.modules += ( "mod_cgi", "mod_alias", "mod_setenv" )

cgi.assign += ( "" => "" )  ## run exectables with shebang

$HTTP["url"] == "network" {
   $HTTP["request-method"] == "GET" {
      alias.url += ( "network"  => "/usr/bin/network" )
      setenv.add-response-header = ( "Content-Type" => "application/xml" )
   }
}

when file /usr/bin/network returned error, lighttpd responds to client with 500 Internal server error.

How can I handle that error and turn it into 400 Bad request from cgi-script?

Body:
Script should always return 0. To set HTTP status use next approach.

#!/bin/sh

echo "Status: 400 Bad request"; echo
echo "message"

More samples and info about CGI are on wikipedia


问:
Installing Two version of MSSQL SQL Server 2017 and SQL Server 2019 on same CENTOS 7 machine
Can we install Microsoft SQL Server version 2017 and 2019 on same OS for Linux especially CENTOS as we can do for Windows?</p>

答:
CentOS is not a supported version of Linux to install SQL Server (for Linux) on, so it's recommended that you use one that is supported.

Regardless, however, of what operating system you install it on (supported or not), on Linux you can only run one instance at a time on a single host. The documation on Work with multiple versions and instances of SQL Server explicitly states it is a Windows Only Feature.

If you do need to run multiple instances of SQL Server on the same physical host, then the recommendation is to use containers. Then you can run a single SQL Server (on Linux) instance inside each container.

This question is also answered in the SQL Server on Linux Frequently Asked Questions (FAQ) in the Administration section:

2. Does SQL Server on Linux support multiple instances on the same host?

We recommend running multiple containers on a host to have multiple distinct instances. This is easily achieved using docker, but each container needs to listen on a different port. For more information, see Run multiple SQL Server containers.


问:
RabbitMQ - Send a JSON message
I send the following message with content type application/json:

However whene i get messages from the same RabbitMQ Web console, it shows the payload as String.

What am I doing wrong? Or am I fundamentally misunderstanding and the Payload is always of type String?

答:
from here

Content Type and Encoding

The content (MIME media) type and content encoding fields allow publishers communicate how message payload should be deserialized and decoded by consumers.

RabbitMQ does not validate or use these fields, it exists for applications and plugins to use and interpret.

by the way, using the rabbitMQ web gui, you use the words content_type, however in code (javascript confirmed), you use the key name contentType. it's a subtle difference, but enough to drive you crazy.

Title: RabbitMQ - Send a JSON message


问:
Can I modify Woocommerce dashboard
I am using Woocommerce plugin on my WordPress website, and now I want to modify dashboard for users, but when I open the page i have only this [woocommerce_my_account] short code, so now I want to know where it is coming from, and how can I change it?
<br>
So in that dashboard I want to add some new pages, tabs and videos. </p>

答:
You can use this free plugin to change basic things.

My Account Page details are shown in the form of side bars. These
side bars are: ‘Dashboard’, ‘My Downloads’, ‘My Orders’, ‘Edit
Account’ and ‘Edit Address’

Option to edit the text of the menu options.

Option to deactivate the menu option temporarily.

Option to reorder the menus.

Download Plugin

Title: Can I modify Woocommerce dashboard

Body:
I am using Woocommerce plugin on my WordPress website, and now I want to modify dashboard for users, but when I open the page i have only this [woocommerce_my_account] short code, so now I want to know where it is coming from, and how can I change it?

So in that dashboard I want to add some new pages, tabs and videos.


问:
Is it possible to write a program without using main() function?
I keep getting this question asked in interviews:

Write a program without using main() function?

One of my friends showed me some code using Macros, but i could not understand it.

So the question is:

Is it really possible to write and compile a program without main()?

答:
By using C++ constructors you write a C++ program without the main function with nothing it it. Let's say for example we can print a hello world without writing anything in the main function as follows:</p>

```<code>class printMe{
   private:
   //
   public:
   printMe(){
       cout<<"Hello Wold! "<<endl;
  }
       protected:
       //
 }obj;

 int main(){}
</code>```

Body:
By using C++ constructors you write a C++ program without the main function with nothing it it. Let's say for example we can print a hello world without writing anything in the main function as follows:

class printMe{
   private:
   //
   public:
   printMe(){
       cout<<"Hello Wold! "<<endl;
  }
       protected:
       //
 }obj;

 int main(){}