# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=518

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 519

---

## [Reading an unknown number of lines from a socket using asynchronous IO](https://discourse.julialang.org/t/reading-an-unknown-number-of-lines-from-a-socket-using-asynchronous-io/71609)

<div class="topic-metadata">

**Author:** [@Paulo\_Jabardo](https://discourse.julialang.org/u/Paulo_Jabardo)\
**Replies:** 3\
**Last updated:** [November 17, 2021, 3:19pm UTC](https://discourse.julialang.org/t/reading-an-unknown-number-of-lines-from-a-socket-using-asynchronous-io/71609 "2021-11-17T15:19:53Z")

</div>

I have an instrument (pressure scanner) that measures pressure and communicates using TCP/IP. I’m having difficulty with asynchronous IO: some operations when reading the instrument return several lines of text and I don…

---

## [BenchmarkTools setup isn't run between each iteration?](https://discourse.julialang.org/t/benchmarktools-setup-isnt-run-between-each-iteration/36258)

<div class="topic-metadata">

**Author:** [@DNF](https://discourse.julialang.org/u/DNF)\
**Replies:** 6\
**Last updated:** [November 17, 2021, 2:37pm UTC](https://discourse.julialang.org/t/benchmarktools-setup-isnt-run-between-each-iteration/36258 "2021-11-17T14:37:02Z")

</div>

Can someone explain to me what’s going on here? I would not expect the error that happens for the short input vector: julia\> using BenchmarkTools julia\> @btime pop!(v) setup=(v=rand(1000)); 8.295 ns (0 allocations: 0…

---

## [Addprocs(\["ip.ip.ip.ip"\], ...) hangs on Windows, works on Linux VM on same machine](https://discourse.julialang.org/t/addprocs-ip-ip-ip-ip-hangs-on-windows-works-on-linux-vm-on-same-machine/71659)

<div class="topic-metadata">

**Author:** [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Replies:** 0\
**Last updated:** [November 17, 2021, 1:31pm UTC](https://discourse.julialang.org/t/addprocs-ip-ip-ip-ip-hangs-on-windows-works-on-linux-vm-on-same-machine/71659 "2021-11-17T13:31:19Z")

</div>

I have 3 Julia instances, Windows, Linux in a QEMU VM on the same machine and remote Linux. I mention the Remote / VM thing to eliminate network issues. The same happens from the Windows machine to the VM. Julia on Wi…

---

## [Unix2datetime issue?](https://discourse.julialang.org/t/unix2datetime-issue/71645)

<div class="topic-metadata">

**Author:** [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Replies:** 4\
**Last updated:** [November 17, 2021, 1:30pm UTC](https://discourse.julialang.org/t/unix2datetime-issue/71645 "2021-11-17T13:30:16Z")

</div>

Take the following timestamp: 1634587200000 Convert it with: unix2datetime(1634587200000) 53768-01-03T08:00:00 If I go to: Unix Time Stamp - Epoch Converter, the result is Mon Oct 18 2021 20:00:00 GMT+0000 What am I …

---

## [Can not update registry because download fails for "unexpected end of data"](https://discourse.julialang.org/t/can-not-update-registry-because-download-fails-for-unexpected-end-of-data/67041)

<div class="topic-metadata">

**Author:** [@melonedo](https://discourse.julialang.org/u/melonedo)\
**Replies:** 2\
**Last updated:** [November 17, 2021, 1:05pm UTC](https://discourse.julialang.org/t/can-not-update-registry-because-download-fails-for-unexpected-end-of-data/67041 "2021-11-17T13:05:50Z")

</div>

When I try to install a package or update, package manager errors because downloaded file is corrupted (I checked with 7-zip and it complains with unexpected end of data too). Contrasted to download failure, pkg errors o…

---

## [UndefVarError from macro](https://discourse.julialang.org/t/undefvarerror-from-macro/71630)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 1\
**Last updated:** [November 17, 2021, 12:53pm UTC](https://discourse.julialang.org/t/undefvarerror-from-macro/71630 "2021-11-17T12:53:32Z")

</div>

How can I fix this error? using MacroTools: postwalk macro mymac(e) postwalk(x -\> (x isa Expr && x.head isa Symbol && x.head == :. ? esc(:($x isa String ? (return $x) : $x isa Int ? $(x).val : throw("invalid"…

---

## [Printing output on screen](https://discourse.julialang.org/t/printing-output-on-screen/71656)

<div class="topic-metadata">

**Author:** [@Dan.phi](https://discourse.julialang.org/u/Dan.phi)\
**Replies:** 1\
**Last updated:** [November 17, 2021, 12:53pm UTC](https://discourse.julialang.org/t/printing-output-on-screen/71656 "2021-11-17T12:53:31Z")

</div>

Consider the following small example: for i in 1:10 println("Iteration: $(i)/10") end This shows up on the screen as follows: In each iteration, a new line is added. Is there any way that would ensure that visua…

---

## [2D nested loop gives big performance hit in interpolation routine while it should not](https://discourse.julialang.org/t/2d-nested-loop-gives-big-performance-hit-in-interpolation-routine-while-it-should-not/71651)

<div class="topic-metadata">

**Author:** [@Chiil](https://discourse.julialang.org/u/Chiil)\
**Replies:** 2\
**Last updated:** [November 17, 2021, 12:29pm UTC](https://discourse.julialang.org/t/2d-nested-loop-gives-big-performance-hit-in-interpolation-routine-while-it-should-not/71651 "2021-11-17T12:29:22Z")

</div>

I have written a macro that generates fast trilinear interpolation functions for 2x2x2 upsampling with threading. The code runs fine and is on average an order of magnitude faster than Interpolations.jl (which I probably…

---

## [How to benchmark append!?](https://discourse.julialang.org/t/how-to-benchmark-append/47272)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 13\
**Last updated:** [November 17, 2021, 11:43am UTC](https://discourse.julialang.org/t/how-to-benchmark-append/47272 "2021-11-17T11:43:50Z")

</div>

I am trying to benchmark a code that calls append, but the results do not seem to make sense. The minimal working example which I do not understand is: julia\> using BenchmarkTools julia\> x = \[0\]; y = zeros(100); @btime …

---

## [Comparison between MPI.jl and Distributed.jl](https://discourse.julialang.org/t/comparison-between-mpi-jl-and-distributed-jl/71646)

<div class="topic-metadata">

**Author:** [@thudjx](https://discourse.julialang.org/u/thudjx)\
**Replies:** 1\
**Last updated:** [November 17, 2021, 10:49am UTC](https://discourse.julialang.org/t/comparison-between-mpi-jl-and-distributed-jl/71646 "2021-11-17T10:49:35Z")

</div>

What is the difference between MPI.jl and Distributed.jl? Are they designed for different usage? If not, which one should I go deep?

---

## [Use pmap(f,x) when f takes multiple arguments?](https://discourse.julialang.org/t/use-pmap-f-x-when-f-takes-multiple-arguments/65761)

<div class="topic-metadata">

**Author:** [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Replies:** 3\
**Last updated:** [November 17, 2021, 9:44am UTC](https://discourse.julialang.org/t/use-pmap-f-x-when-f-takes-multiple-arguments/65761 "2021-11-17T09:44:22Z")

</div>

How can I call pmap(f,x) where f is a function that takes additional parameters? I have a function f(x,y) where y is always known and I want to run pmap on elements of x. Here is an example that works (without distribu…

---

## [Getting function signature expression from method instance](https://discourse.julialang.org/t/getting-function-signature-expression-from-method-instance/71639)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 0\
**Last updated:** [November 17, 2021, 9:08am UTC](https://discourse.julialang.org/t/getting-function-signature-expression-from-method-instance/71639 "2021-11-17T09:08:20Z")

</div>

Is there an existing function to get a method definition expression from the Method instance? As example, I would like to have some function signature\_expression such that: ff(a::T, b::C, c::Tuple{Real,Real}) where {T \<…

---

## [Broadcasting sampling of the variable size](https://discourse.julialang.org/t/broadcasting-sampling-of-the-variable-size/71632)

<div class="topic-metadata">

**Author:** [@Oko](https://discourse.julialang.org/u/Oko)\
**Replies:** 1\
**Last updated:** [November 17, 2021, 8:02am UTC](https://discourse.julialang.org/t/broadcasting-sampling-of-the-variable-size/71632 "2021-11-17T08:02:13Z")

</div>

I would like to use broadcast to do repetitive sampling from an array with the added twist that samples are of variable sizes. In plain English I would like to replace the following for loop with a fancy code using Stat…

---

## [Unable to precompile DifferentialEquations.jl in Juno IDE in new environment and empty project](https://discourse.julialang.org/t/unable-to-precompile-differentialequations-jl-in-juno-ide-in-new-environment-and-empty-project/71608)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 7\
**Last updated:** [November 17, 2021, 7:08am UTC](https://discourse.julialang.org/t/unable-to-precompile-differentialequations-jl-in-juno-ide-in-new-environment-and-empty-project/71608 "2021-11-17T07:08:30Z")

</div>

I am trying to precompile DifferentialEquations.jl into an empty environment , but i am encountering following error suddenly julia\> new environment at \`~/nikhil/s rao reduction of chem reaction/model\_red\_julia/Projec…

---

## [How can I easily skip indices in an array?](https://discourse.julialang.org/t/how-can-i-easily-skip-indices-in-an-array/70317)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 16\
**Last updated:** [November 17, 2021, 6:40am UTC](https://discourse.julialang.org/t/how-can-i-easily-skip-indices-in-an-array/70317 "2021-11-17T06:40:19Z")

</div>

I have arrays with 2 dimensions. Elements in the arrays are only considered valid for certain values on the indices. For example, consider the arrays A and B below: A = round.(rand(10, 2) .\* 100) A\[1:3, 2\] .= NaN B = ro…

---

## [Broadcasting and the function keyword arguments](https://discourse.julialang.org/t/broadcasting-and-the-function-keyword-arguments/71629)

<div class="topic-metadata">

**Author:** [@Oko](https://discourse.julialang.org/u/Oko)\
**Replies:** 2\
**Last updated:** [November 17, 2021, 6:13am UTC](https://discourse.julialang.org/t/broadcasting-and-the-function-keyword-arguments/71629 "2021-11-17T06:13:52Z")

</div>

In the lieu of the fact that the broadcast is faster than the dot syntax I would like to replace the following code snippet #!/usr/bin/julia using Graphs n = 10 p = 0.1:0.01:0.5 erdos\_renyi.(n,p;is\_directed=true, see…

---

## [Question: Function not returning a value?](https://discourse.julialang.org/t/question-function-not-returning-a-value/71590)

<div class="topic-metadata">

**Author:** [@mdhe1248](https://discourse.julialang.org/u/mdhe1248)\
**Replies:** 9\
**Last updated:** [November 17, 2021, 3:38am UTC](https://discourse.julialang.org/t/question-function-not-returning-a-value/71590 "2021-11-17T03:38:39Z")

</div>

Could anyone help with this function? I would like to get a return value, but it returns nothing. The below is my function: function retrieve(dict, key\_of\_interest, value\_of\_interest) for (key, value) in dict if k…

---

## [Parametric surface plot of custom indexed array](https://discourse.julialang.org/t/parametric-surface-plot-of-custom-indexed-array/71359)

<div class="topic-metadata">

**Author:** [@Oko](https://discourse.julialang.org/u/Oko)\
**Replies:** 1\
**Last updated:** [November 16, 2021, 9:37pm UTC](https://discourse.julialang.org/t/parametric-surface-plot-of-custom-indexed-array/71359 "2021-11-16T21:37:59Z")

</div>

I am struggling with something which seems pretty trivial problem. Namely, I have a stochastic process on a random graph depending on the two parameters. The first parameter is the probability of an edge between two node…

---

## [Plot a Differential Equation or a 3 variable function](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625)

<div class="topic-metadata">

**Author:** [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Replies:** 6\
**Last updated:** [November 17, 2021, 1:47am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625 "2021-11-17T01:47:55Z")

</div>

How do I plot a function with 3 variables, either in 3d or a 2d contour plot. U(x,y)=16\*log(x)+9\*log(y)

---

## [DiffEqFlux gradient error: breaks with increasing size of problem, size should not affect autodiff](https://discourse.julialang.org/t/diffeqflux-gradient-error-breaks-with-increasing-size-of-problem-size-should-not-affect-autodiff/71610)

<div class="topic-metadata">

**Author:** [@evolbio](https://discourse.julialang.org/u/evolbio)\
**Replies:** 7\
**Last updated:** [November 17, 2021, 12:32am UTC](https://discourse.julialang.org/t/diffeqflux-gradient-error-breaks-with-increasing-size-of-problem-size-should-not-affect-autodiff/71610 "2021-11-17T00:32:25Z")

</div>

I am optimizing a simple ODE problem with DiffEqFlux to get started with Julia. This code worked on TensorFlow. In the following code, running main(S=5, B=256) works, but main(S=7, B=256) fails. I previously used Ensemb…

---

## [How to implement an efficient Readers-Writer lock?](https://discourse.julialang.org/t/how-to-implement-an-efficient-readers-writer-lock/27446)

<div class="topic-metadata">

**Author:** [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Replies:** 6\
**Last updated:** [November 17, 2021, 12:14am UTC](https://discourse.julialang.org/t/how-to-implement-an-efficient-readers-writer-lock/27446 "2021-11-17T00:14:43Z")

</div>

I read a blog about Readers-Writer Lock here Implementing reader-writer locks last week. The original code was written in Golang. And I attempted to rewrite the code in Julia. The reader count based implementation is st…

---

## [Strategies for parallelization of fast non-uniform tasks](https://discourse.julialang.org/t/strategies-for-parallelization-of-fast-non-uniform-tasks/71531)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 12\
**Last updated:** [November 16, 2021, 11:11pm UTC](https://discourse.julialang.org/t/strategies-for-parallelization-of-fast-non-uniform-tasks/71531 "2021-11-16T23:11:50Z")

</div>

Which are the recommended strategies/packages to deal with the parallelization of many (thousands of) tasks that are: Individually relatively fast (costs associated to spawning may not be negligible). Possibly somewha…

---

## [Function definitions with literal parameters](https://discourse.julialang.org/t/function-definitions-with-literal-parameters/71538)

<div class="topic-metadata">

**Author:** [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Replies:** 7\
**Last updated:** [November 16, 2021, 6:28pm UTC](https://discourse.julialang.org/t/function-definitions-with-literal-parameters/71538 "2021-11-16T18:28:41Z")

</div>

I’m tinkering with groups, bitstrings and XOR. I don’t care about efficiency - but it’s always nice… I create the type then I want functions dispatching on value :slight\_smile: @enum Bit zero one ⨁(zero, zero) = zero …

---

## [Plot with three y-axes (, so one y-axis has to be double)](https://discourse.julialang.org/t/plot-with-three-y-axes-so-one-y-axis-has-to-be-double/58699)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 10\
**Last updated:** [November 16, 2021, 5:49pm UTC](https://discourse.julialang.org/t/plot-with-three-y-axes-so-one-y-axis-has-to-be-double/58699 "2021-11-16T17:49:07Z")

</div>

Hello, I need to put on the same graph three lines with different y-axis). I know how to do it with two y-axises (one is right and the other is left). How to do it with 3 lines, so the left y-axis has to be double. th…

---

## [Preferred OS for Raspberry Pi](https://discourse.julialang.org/t/preferred-os-for-raspberry-pi/71586)

<div class="topic-metadata">

**Author:** [@Jake](https://discourse.julialang.org/u/Jake)\
**Replies:** 1\
**Last updated:** [November 16, 2021, 2:08pm UTC](https://discourse.julialang.org/t/preferred-os-for-raspberry-pi/71586 "2021-11-16T14:08:44Z")

</div>

I mostly use Windows and VSCode when using Julia. I am familiar with Ubuntu. I have a Raspberry Pi 4 with 8 Gig of RAM and an MCC\_172 HAT, which I am working on getting accessible to Julia. So far I have used Raspbian…

---

## [Struct initialization error](https://discourse.julialang.org/t/struct-initialization-error/71582)

<div class="topic-metadata">

**Author:** [@emanuellima](https://discourse.julialang.org/u/emanuellima)\
**Replies:** 2\
**Last updated:** [November 16, 2021, 12:49pm UTC](https://discourse.julialang.org/t/struct-initialization-error/71582 "2021-11-16T12:49:20Z")

</div>

I am having an error that I don’t understand. The code works on the REPL but it doesn’t when called from the terminal (after being compiled with Comonicon): There is this struct called State, and it’s constructor tha…

---

## [How to pass an IOBuffer to \`ccall\`](https://discourse.julialang.org/t/how-to-pass-an-iobuffer-to-ccall/71547)

<div class="topic-metadata">

**Author:** [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Replies:** 0\
**Last updated:** [November 16, 2021, 11:02am UTC](https://discourse.julialang.org/t/how-to-pass-an-iobuffer-to-ccall/71547 "2021-11-16T11:02:04Z")

</div>

What is the correct way to interface with C for buffers (IOStream)? Can I just pass the file descriptor using Base.fd? (I don’t see any indications about this on either the IOStream or the ccall doc pages). My example i…

---

## [Does declaring jacobian and redefining ODEProblem with jacobian accelerate \`solve\`?](https://discourse.julialang.org/t/does-declaring-jacobian-and-redefining-odeproblem-with-jacobian-accelerate-solve/71507)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 5\
**Last updated:** [November 16, 2021, 10:45am UTC](https://discourse.julialang.org/t/does-declaring-jacobian-and-redefining-odeproblem-with-jacobian-accelerate-solve/71507 "2021-11-16T10:45:49Z")

</div>

https://diffeq.sciml.ai/dev/features/performance\_overloads/#ode\_explicit\_jac following from this example,… Does explicitly declaring jacobian for an ODEproblem like this accelerate the solution using solve()

---

## [Eltype changed during broadcast with missing](https://discourse.julialang.org/t/eltype-changed-during-broadcast-with-missing/71312)

<div class="topic-metadata">

**Author:** [@bgctw](https://discourse.julialang.org/u/bgctw)\
**Replies:** 2\
**Last updated:** [November 16, 2021, 7:49am UTC](https://discourse.julialang.org/t/eltype-changed-during-broadcast-with-missing/71312 "2021-11-16T07:49:45Z")

</div>

How do I tell julia to use the original eltype when broadcasting over a vector and a scalar? In the following example I would like (and expected) the eltype of the result to be in all three cases Union{Missing,Float64}.…

---

## [\`isempty(enumerate(Iterators.Stateful(...)))\` advances the stateful iterator?](https://discourse.julialang.org/t/isempty-enumerate-iterators-stateful-advances-the-stateful-iterator/71475)

<div class="topic-metadata">

**Author:** [@bzinberg](https://discourse.julialang.org/u/bzinberg)\
**Replies:** 3\
**Last updated:** [November 16, 2021, 3:51am UTC](https://discourse.julialang.org/t/isempty-enumerate-iterators-stateful-advances-the-stateful-iterator/71475 "2021-11-16T03:51:02Z")

</div>

On Julia 1.6.2: itr = enumerate(Iterators.Stateful(\[:a, :b, :c\])) isempty(itr) && println("It's empty") isempty(itr) && println("It's empty") isempty(itr) && println("It's empty") isempty(itr) && println("It's empty") I…

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=517)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=519)
