You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SegString strip and peel throwing OOM exception when problem size > 10**4 #2389
I tried running the code and strip worked, so perhaps things have changed since then, but it's worth pointing out that this is going to require using a lot of memory regardless. The inputs to ak.random_strings_uniform are minLen, maxLen, and size. The length is chosen uniformly at random first, so the average string size is going to be somewhere around several thousand bytes. In fact, when I ran it, I did a.nbytes afterwards, which popped out as follows:
In [5]: a.nbytesOut[5]: 3284072539
For those of us that aren't computers, that's a bit more than 3 GB. Since this has to be copied into a different object, I can't say I'm particularly surprised that this has a decent chance of crashing the server. If you make somewhere around 5 copies of this object, you hit about 16 GB and if that's how much RAM you have available, that's it for the server. Don't forget that if you're running stuff in the background, you have less RAM available than you might realize.
I'm going to paste in the relevant parts of the Chapel code and let's see what's going on here.
First place we land is this (in SegmentedMsg.chpl)
proc segmentedStripMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
var pn = Reflection.getRoutineName();
var repMsg: string;
var objtype = msgArgs.getValueOf("objType").toUpper(): ObjType;
var name = msgArgs.getValueOf("name");
// check to make sure symbols defined
st.checkTable(name);
select (objtype) {
when (ObjType.STRINGS) {
var strings = getSegString(name, st);
var (off, val) = strings.strip(msgArgs.getValueOf("chars"));
var retString = getSegString(off, val, st);
repMsg = "created " + st.attrib(retString.name) + "+created bytes.size %?".format(retString.nBytes);
return new MsgTuple(repMsg, MsgType.NORMAL);
}
otherwise {
var errorMsg = notImplementedError(pn, "%s".format(objtype));
smLogger.error(getModuleName(),getRoutineName(),getLineNumber(),errorMsg);
return new MsgTuple(errorMsg, MsgType.ERROR);
}
}
}
You'll notice that it basically kicks the dirty work over to strings.strip, so let's take a look at SegmentedString.chpl
proc strip(chars: string) throws {
ref origOffsets = this.offsets.a;
ref origVals = this.values.a;
const lengths = this.getLengths();
var replacedLens = makeDistArray(this.offsets.a.domain, int);
forall (off, len, rlen) in zip(origOffsets, lengths, replacedLens) {
if chars.isEmpty() {
rlen = interpretAsBytes(origVals, off..#len).strip().size + 1;
} else {
rlen = interpretAsBytes(origVals, off..#len).strip(chars:bytes).size + 1;
}
}
var retVals: [makeDistDom(+ reduce replacedLens)] uint(8);
var retOffs = (+ scan replacedLens) - replacedLens;
forall (off, len, roff) in zip(origOffsets, lengths, retOffs) with (var valAgg = newDstAggregator(uint(8))) {
var i = 0;
if chars.isEmpty() {
for b in interpretAsBytes(origVals, off..#len).strip() {
valAgg.copy(retVals[roff+i], b:uint(8));
i += 1;
}
} else {
for b in interpretAsBytes(origVals, off..#len).strip(chars:bytes) {
valAgg.copy(retVals[roff+i], b:uint(8));
i += 1;
}
}
}
return (retOffs, retVals);
}
There's a couple refs at the top, so those aren't copies. The lengths does involve allocating some memory. It looks like there's a little bit of extra memory usage with the replacedLens, and then (+ scan replacedLens) - replacedLens does that again. But this is all based on the number of strings and there aren't that many strings anyways. Probably the largest use of memory happens on the line var retVals: [makeDistDom(+ reduce replacedLens)] uint(8);.
It wouldn't surprise me if performance could be improved here. On a whim I decided to check the comm diagnostics for 2 locales and I got this
The number of gets for locale 0 is out of whack. I wanted to see if it scaled with N so I shrunk the number of bytes per string and tried it like this (on four locales, certainly that will be worse comms... right?):
Activity
1RyanK commentedon Oct 1, 2025
I tried running the code and strip worked, so perhaps things have changed since then, but it's worth pointing out that this is going to require using a lot of memory regardless. The inputs to
ak.random_strings_uniformareminLen,maxLen, andsize. The length is chosen uniformly at random first, so the average string size is going to be somewhere around several thousand bytes. In fact, when I ran it, I dida.nbytesafterwards, which popped out as follows:For those of us that aren't computers, that's a bit more than 3 GB. Since this has to be copied into a different object, I can't say I'm particularly surprised that this has a decent chance of crashing the server. If you make somewhere around 5 copies of this object, you hit about 16 GB and if that's how much RAM you have available, that's it for the server. Don't forget that if you're running stuff in the background, you have less RAM available than you might realize.
I'm going to paste in the relevant parts of the Chapel code and let's see what's going on here.
First place we land is this (in
SegmentedMsg.chpl)You'll notice that it basically kicks the dirty work over to
strings.strip, so let's take a look atSegmentedString.chplThere's a couple
refs at the top, so those aren't copies. The lengths does involve allocating some memory. It looks like there's a little bit of extra memory usage with thereplacedLens, and then(+ scan replacedLens) - replacedLensdoes that again. But this is all based on the number of strings and there aren't that many strings anyways. Probably the largest use of memory happens on the linevar retVals: [makeDistDom(+ reduce replacedLens)] uint(8);.It wouldn't surprise me if performance could be improved here. On a whim I decided to check the comm diagnostics for 2 locales and I got this
The number of gets for locale 0 is out of whack. I wanted to see if it scaled with N so I shrunk the number of bytes per string and tried it like this (on four locales, certainly that will be worse comms... right?):
Okay so maybe the strings are too small...
Okay, there's some bad performance. I think maybe the comms are worth looking into here and I will follow up with more on
peelwhen I get the chance.