• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. buildString using a ForLoop to load and delete data on the...

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 9501
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

buildString using a ForLoop to load and delete data on the fly

Yasso
Yasso over 3 years ago

Hello, I'm trying to create a list() using the function buildString and a loop, then destroy the elements when the operation ends. The reason is because a stack overflow occurs when my list() has nearly 200k elements. I have a schematic with a circuit that contains roughly 200k instance pCells, and I want to save the voltage of each pCell when the simulation is done. For that in my ocean.ocn script i have these lines.

Out = outfile("text.txt" "w")

Volt = list( "/I1/Vp" "/I2/Vp" "/I3/Vp" .....)

  foreach(j VoltocnPrint(?output Out value(VT(j) 30m))

)

close(Out)

It's not efficient, but works when the elements of Volt are few. When the list reaches the 140k elements, stack overflow happens and the script doesnt launch. I was looking for a fix; first trying to add a table (using readTable() in a ocean script doesnt work), then I tought of using a for loop that creates an element in a list, "VoltocnPrint()" takes place, then the element is deleted, so stack overflow doesnt happen. For that I was looking for a function like buildString and by my surprise it doesnt work with a for loop. I'm not sure why. The code is the following.

Volt= list()
sum = 5
for( i 5
     sum = sum - 1
     g = buildString( '("/" "I" sum "/" "Vp") "")  ;I want to add the number where sum is
     Volt= xcons(Volt g)
     foreach(j Volt
          ocnPrint(?output Out value(VT(j) 30m))
    setq Volt remove(nth(0 Volt))
)

This creates a list, a loop in which the list is fille, then for each element of the list, the first one created is saved in the output, after that I eliminate that element and repeat the process. But for some strange reason the buildString doesnt add the number, maybe because it has to be a string too (hence why it is build string), so what should I change in order to fix this? 

Thanks, Yass

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    Yass,

    I'm sure you're fixing the wrong problem here. Looping over a list with 200k elements should present no problem at all and would be highly efficient. I'm not sure what's actually failing, but I'm guessing it might just be because you're reading a lot of simulation data and maybe something is not being garbage collected? In other words, the repeated VT() calls might be the real problem.

    I cannot fathom out what your code with the for loop is trying to do, but it's got several mistakes:

    1. The for function is missing an initial value (so it would try to do a for loop from 5 up to sum-1 (i.e. 4) which means it will do nothing.
    2. The buildString is trying to assemble a list of literal values (it's a quoted list) and so will always produce "/Isum/Vp" which is not what you want, I assume. Using buildString doesn't seem terribly sensible here - maybe sprintf(g "/I%d/Vp" sum) would be what you want?
    3. I can't see what the point of adding this element onto beginning of a list and then removing it afterwards Surely you'd just do ocnPrint(?out Out value(VT(g) 30m)) and avoid the foreach loop
    4. The setq line is missing parentheses and the remove() function has the wrong number of arguments.

    Overall the code just won't work. Perhaps you could do:

    for(i1 5
      sum = sum - 1
      sprintf(g "/I%d/Vp") sum)
      ocnPrint(?output Out value(VT(g) 30m))
    )

    that avoids constructing the list of signals, but I'm sure that's not your real problem.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Yasso
    Yasso over 3 years ago in reply to Andrew Beckett

    Hello, I noticed these errors thanks. The code runs perfect without the list() that has 200k elements, it doesnt display any stackoverflow, only when the list ia present. The script code for ocean is like this.

    simulator( 'spectre )
    design( ".../PixelArray/spectre/schematic/netlist/netlist")
    resultsDir( ".../PixelArray/spectre/schematic" )
    modelFile(
    ...
    )

    analysis('tran ?stop "31m" ?save "selected" ?compression "all"
    ?finalTimeOp nil )

    desVar("x1" ---)
    desVar("x2" ---)
    .
    .
    .

    envOption(
    'enableNoiseRefactor t
    'analysisOrder list("tran")
    )
    option( 'dc_pivot_check "yes"
    'gmin "0"
    )
    option( ?categ 'turboOpts
    'apsplus t
    'errorLevel "Moderate"
    'uniMode "APS"
    )

    temp( 27 )
    Out = outfile("TextFile.txt" "w")

    run()


    for(i 1 262144
    sum = sum + 1
    sprintf(g "/I%d/Vp") sum)
    ocnPrint(?output Out value(VT(g) 30m))
    )

    results()
    close(Out)

    I changed the names of a couple of things, trying not to leak important stuff. But basically it's an array of pixels, and each "/I1/Vp" has a value that I want to save in the Out file for later. I'm sorry for all the errors, I didnt paste correctly most of the code, and your tips are helping me a lot to understand what I'm doing wrong. The proposed solution with the code using sprintf brings an error.

    Doesnt it need to be a string too? like convert sum into a string?

    Thanks for the quick response, Yass

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Yasso
    Yasso over 3 years ago in reply to Andrew Beckett

    Checked the Intro_to_skill and the ")" was the issue. Changed the code to this.

    sum = 0

    for(i 1 262144

        sum = sum + 1

         sprintf(g "I%d/Vp" sum)

         ocnPrint(?output Out value(VT(g) 30m))

    )

    Runs smoothly! Thanks for the help

    Yass

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Yasso

    There must have been something wrong with your code with the foreach loop, because there's no way that just using a foreach loop on a list with only that number of elements could cause this problem - it must have been some other coding error you'd made. For example:

    nodes=nil
    for(i 1 262144
      nodes=cons(lsprintf("I%d/Vp" i) nodes)
    )
    foreach(elem nodes
      printf("Output: %s\n" elem)
    )

    works with absolutely no problem. The first builds the list, and the second loops over the list (I'm not using ocnPrint() or VT() in the second loop in my example, but that can't make a difference).

    Anyway, glad you've got something working.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Yasso
    Yasso over 3 years ago in reply to Andrew Beckett

    It may be the version? 6.1.7-64b, subversion 6.1.7-64b.500.4. It can be that I'm putting the full list and not using any loop to generate it. In the code originally i had this.

    Volt = list( "/I1/Vp" "/I2/Vp" "/I3/Vp" ..... "I262144/Vp")

    Maybe if you do that you can replicate the error. But right now using the loop everything goes perfect. Thanks again!

    Yass

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to Yasso

    Yass,

    OK, you didn't mention that rather important detail. The problem is not the foreach at all, it's the fact that the list() function has too many arguments - it would fail on that. Having a long list in itself isn't an issue, but trying to build it with a single call to the list() function with over 260,000 arguments is going to be a problem.

    If instead it was a quoted list:

    Volt = '( "/I1/Vp" "/I2/Vp" "/I3/Vp" ..... "I262144/Vp")

    then it would have been fine. Of course, if the names are incrementing, this is a bit pointless - generating it with code makes far more sense.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information