go to post Stuart Salzer · May 17, 2017 The problem is both OPEN statements are for TCP/IP servers. One OPEN has to be a client. You distinguish between the two by giving a DNS or IP address in the OPEN. If everything is running locally, use "127.0.0.1", So OPEN dev:("127.0.0.1":33568):3 Also on one OPEN us are using "\n" for the terminators argument. That makes reads break on backslash and lowercase n. Is that really what you want? This isn't "C". Generally you should specify a mode for TCP/IP I/O. For text based messaging over TCP/IP "PTSE" ≣ "M" works best. Add an "A", that is "MA", for a multi-server. For a binary channel, using mode "S" is still a good idea. Thus: OPEN dev:(:33568:"M"):3 ; Open the server. OPEN dev:("127.0.0.1":33568:"M"):3 ; Open the client.
go to post Stuart Salzer · May 12, 2017 $ZUTIL(132) or ##CLASS(%Device).ChangePrincipal() have no effect on the parent process. Actually, what do you mean by parent process? If a process is created with a JOB command, while the job ID of of the created process does appear in $ZCHILD, the two processes don't have any lasting parent/child relationship.
go to post Stuart Salzer · May 12, 2017 IJC devices work! They come in pairs, and all may not be defined on your system. Start at the beginning and try writing to 225 and reading from 224. Each process must OPEN their devices before reading or writing. You get to write a certain amount to 225 before the device blocks. The reader can read with a zero second time-out, if you don't want the reader waiting. In the system management portal gotoSystem Administration → Configuration → Additional Settings → Advanced Memory. ijcbuff controls the amount of memory per IJC device. The bigger the more you can write to an IJC device with an lagging reader, before the device blocks. ijcnum is the number of defined IJC device pairs.Calling $ZUTIL(132) with no extra arguments makes the current device the principal device. It was documented in the Caché ObjectScript Language Reference up until Caché 2009.1. It has been replaced with ##CLASS(%Device).ChangePrincipal(), which does the same thing. This isn't typically very useful.Often more useful is the former $ZUTIL(82,12,bool), now ##CLASS(%Device).ReDirectIO(bool) which lets you redirect I/O through routines that can filter, redirect, record, though routines. Unfortunately, while the workings of $ZUTIL(82,12,bool) did eventually make it into the documentation, the workings were removed from the ##CLASS(%Device).ReDirectIO(bool) documentation. The details are the same, look at the old documentation on-line.
go to post Stuart Salzer · Mar 23, 2017 I have no idea what your code is really trying to do. Some comments would be helpful. Même un commentaire en français serait utile. In addition to adding parenthesis needed because COS does not have operator precedence. Also,1. $a($e(string,i)) is unnecessary, $a(string,i) does the same thing.2. You are obviously doing some kind of translation. Look at $ZCONVERT() in the documentation.3. For other simple translation, $TRANSLATE() is a simple solution. For example if you have old data in AFNOR NF Z 62010-1982, you could translate it to Unicode with $TRANSLATE(string,"#'@[\]`{|}~","£’à°ç§µéùè¨").
go to post Stuart Salzer · Mar 22, 2017 You want to read Appendix B (Calculating System Parameters for UNIX® and Linux) of the Caché Installation Guide, available here: http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCI_unixparms.Some simple advice that I can add is for routine buffers, this depends upon your application. In general you want to allocate enough routine buffers to contain all the routines that you use on a day to day basis, and not worry about the routines that are only used once a year.For 2 kio buffers, Do you still have databases with 2 kio blocks? If so, why? If you don't have 2 kio databases, or you can convert them to 8 kio databases, do so, and eliminae the 2 kio database buffers.For 8 kio buffers, this is usually the big user of memory, and where you get the best boost in performance by adding more memory. By default we take 1/8 of memory for each Caché configuration, subtract what we need for routine buffers and shared memory heap, and use the rest for 8 kio buffers. If this will be the only instance of Caché on a machine, you can compute this yourself using 1/2 of memory.You can also decide if you have enough memory for 8 kio buffers, by just monitoring the performance of your database. Just look at Cache efficiency. (Global References/(Disk Reads+Disk Writes)). The high the better. Keep adding memory until the improvement is not significant, or you run into some other problem.
go to post Stuart Salzer · Jan 20, 2017 I have a simple .INT routine editor available here:<http://code.intersystems.com/code/Code.View.Code.cls?ID=894>Unfortunately, this only edits .INT routines, and it only works on UNIX. However, it should not be impossible to adapt to OpenVMS, especially if GNV is available.
go to post Stuart Salzer · Dec 30, 2016 Wouldn't a server side method including $ZF(-1,"PRINT "_uncpath) work?
go to post Stuart Salzer · Nov 16, 2016 Once your process receives a <STORE> error, it is almost out of memory. It is almost too late for the process to do any self-analysis as to the source of its problem. Still, if you use InterSystems ^%ETN error trap, you might have local variables, and they may show a pattern of waste.If you believe you know approximately where your local variable waste is located, you can add debug statements like:SET ^%DEBUG($JOB,$I(^%DEBUG))=$ZDT($H,3,1)_" Now at mumble "_$SA more advanced approach is to run the code under trace, watching $STORAGE change with each line. Like this:USER>SET f="/Users/salzer/Desktop/storage.txt"USER>ZBREAK TRACE:all:fUSER>ZBREAK $:"T"::"WRITE $STORAGE"USER>DO ^MEMORYLEAKUSER>ZBREAK /TRACE:OFFDoing this your application will run rather slow. But if it is a batch load, that is fine. Batch loaders don't usually include time-outs. The result is a file that traces your application application and the memory it uses. Here is the start of a program to analyse that trace:ZSTORE ; SRS 2016-11-16 KILL ^||ZSTORE SET f="/Users/salzer/Desktop/storage.txt" CLOSE f OPEN f:"RS":1 IF '$TEST { WRITE !,"Can't open ",f QUIT } USE f SET label="",last=0 TRY { FOR i=0:1 { READ x IF x["Trace: ZBREAK at " { SET label=$EXTRACT(x,18,*) CONTINUE } IF last>0 { SET used=x-last,^||ZSTORE(label,$INCREMENT(^||ZSTORE))=used } SET last=+x } } CATCH err { } CLOSE f SET label="" WHILE 1 { SET label=$ORDER(^||ZSTORE(label)) IF label="" { QUIT } WRITE !,label SET i="",np=0 FOR n=0:1 { SET i=$ORDER(^||ZSTORE(label,i),1,v) IF i="" { QUIT } IF v'>0 { CONTINUE } IF np=0 { SET min=v,max=v,sum=v,np=1 CONTINUE } SET np=np+1 IF v<min { SET min=v } IF v>max { SET max=v } SET sum=sum+v } WRITE " hits:",n IF np'>0 { CONTINUE } WRITE " positive:",np," min:",min," max:",max," avg:",sum/np } QUIT
go to post Stuart Salzer · Nov 3, 2016 My colleague provided you a very detailed answer to your first request. That is the “Why” part of your request. For the “How” part, rather than round away the the apparent error that you don’t understand, there is a whole branch of mathematics dealing with transforming your math to make it work on computers. While many programming languages optimize code to correct inefficient logic, few (including COS) will fix your math. Some, simple examples are: (1) When adding a vector of floating point numbers, it is wise to sort the numbers by their absolute value, then and add the small numbers to the accumulator first. (2) When evaluating a polynomial like a·x³+b·x²+c·x+d, rewrite this as ((a·x+b)·x+c)·x+d, and this can be conveniently be written in COS without any parenthesis: SET ans=a*x+b*x+c*x+d (3) Your problem: Divide last, unless it would cause an overflow. That is if your general equation is (x÷y)·z, why not rewrite it as (x·z)÷y. If (x·z) would cause an overflow, then use either (x÷y)·z, or (z÷y)·x, which ever gives a better answer. The simple way to decide which answer is better, is which answer has the fewest digits after the decimal point. Here is some code if not resorting to rounding is important to you. MATH ; SRS 2016-11-03 FOR { READ !,"x/y*z enter: ",t QUIT:t="" SET x=$PIECE(t,"/"),t=$PIECE(t,"/",2) SET y=$PIECE(t,"*"),z=$PIECE(t,"*",2) IF x'=+x||(y'=+y)||(z'=+z) { SET ans=$CHAR(9785) } ELSE { TRY { SET ans=x*z/y } CATCH e { TRY { SET xovery=x/y,zovery=z/y IF $LENGTH($PIECE(xovery,".",2))<$LENGTH($PIECE(zovery,".",2)) { SET ans=xovery*z } ELSE { SET ans=zovery*x } CATCH e { SET ans=$CHAR(8734) } } } WRITE " = ",ans } QUIT
go to post Stuart Salzer · Jul 9, 2016 How is "best" defined here? If you wan't fastest, and shortest, I have two options for you. This following code also works with both locals and globals, and avoids the bug of using $PIECE() to trim off the global/local name which won't work on globals which contain a "(" in their namespace (admittedly unlikely). This is the fast version: ; $$FDQ($NAME(a),$NAME(b)) ; Find first different nodes in two trees (or subtrees). Will ; work with locals or globals, except locals of the form % or ; %<digit>. Returns a string containing the two references where ; the first difference separated by "'=". If a node is found in ; one tree that is not present in the other, the missing ; reference is replaced by a question mark ("?"). If both trees ; are the same, an empty string is returned. ; FDQ(%1,%2) ; [10] NEW %3,%4,%5,%6,%7,%8,%9,%0,% ; [20] SET %3=$DATA(@%1,%5)#10,%4=$DATA(@%2,%6)#10 QUIT:%3'=%4||(%3&&(%5'=%6)) $S(%3:%1,1:"?")_"'="_$S(%2:b,1:"?") ; [30] SET %7=%1,%8=%2,%3=$QLENGTH(%1),%4=$QLENGTH(%2) lq SET %1=$QUERY(@%1,1,%5),%2=$QUERY(@%2,1,%6) ; [40] SET:%1'=""&&(%7'=$NAME(@%1,%3)) %1="" ; [50] SET:%2'=""&&(%8'=$NAME(@%2,%4)) %2="" QUIT:%1="" $SELECT(%2="":"",1:"?'="_%2) QUIT:%2="" %1_"'=?" ; [60] FOR %=1:1 SET %9=$QS(%1,%3+%),%0=$QS(%2,%4+%) Q:%9'=%0 Q:%9="" ; [70] IF %9="",%0="" GOTO:%5=%6 lq QUIT %1_"'="_%2 ; [80] QUIT:%9]]%0 "?'="_%2 QUIT %1_"'=?" ; [90] ; ------------ ; [10] %1,%2 Reference to nodes under test. ; [20] %3,%4 Upto [30] used for Do %1,%2 exist (respectively)? ; After [30] used for count of subscripts of %1,%2. ; %5,%6 Values of %1,%2. ; %7,%8 Copies of %1,%2 used to help find end subtree. ; %9,%0 First different subscript of %1,%2. ; % Loop index for scanning down subscript list. ; [30] Return if the existence of %1 and %2 differ or if either exist ; (doesn't matter which), and the values differ. ; [40] Go to next node on each side (which we know exist). ; [50] Check if we have moved past the end of the subtree. ; [60] If either or both %1,%2 put us at end of subtree, return. ; [70] Find the first different subscript or both will be "". ; [80] If both final subscripts "", subscripts are the same so check ; values, and either return of loop. ; [90] Subscripts don't match, return determine order so we can return ; node that is missing. This version may take 30% longer in my test runs, but is a lot simpler by using recursion: ; $$FDR($NAME(a),$NAME(b)) ; Find first different nodes in two trees (or subtrees). Will ; work with locals or globals, except locals of the for %, %1, ; %2, %3, or %4. Returns a string containing the two references ; where the first difference separated by "'=". If a node is ; found in one tree that is not present in the other, the missing ; reference is replaced by a question mark ("?"). If both trees ; are the same, an empty string is returned. ; FDR(%1,%2) ; [10] NEW %3,%4,% ; [20] SET %3=$DATA(@%1,%5)#10,%4=$DATA(@%2,%6)#10 QUIT:%3'=%4||(%3&&(%5'=%6)) $S(%3:%1,1:"?")_"'="_$S(%2:b,1:"?") ; [30] SET (%3,%4)="" lr SET %3=$ORDER(@%1@(%3)),%4=$ORDER(@%2@(%4)) Q:%3=""&&(%4="") "" ; [40] IF %3=%4 SET %=$$FDR($NA(@%1@(%3)),$NA(@%2@(%4))) G:%="" lr Q % ; [50] QUIT:%3]]%4 "?'="_$NAME(@%2@(%4)) QUIT $NAME(@%1@(%3))_"'=?" ; [60] ; ------------ ; [10] %1,%2 Reference to nodes under test. ; [20] %3,%4 Upto [30] used for Do %1,%2 exist (respectively)? ; After [30] Subscripts of %1,%2. ; % Results of recursive call. ; [30] Return if the existence of %1 and %2 differ or if either exist ; (doesn't matter which), and the values differ. ; [40] Go to next subscript at this level. ; [50] If the subscripts are the same, check the sub-tree ; recursively. Loop or quit, depending upon finding a difference. ; [60] If subscripts differ, there is a missing node. Return the ; missing one.
go to post Stuart Salzer · Jun 30, 2016 If you are really sensitive as to not defining new local variables, and having them pollute your variable list, use the variable named % (yes, just a percent sign is a valid variable name, and happens to sort first. Here is the simple case: WRITE:$DATA(%) !,"%" NEW % SET %="%" FOR SET %=$ORDER(@%) QUIT:%="" WRITE !,% Putting that into a routine requires one more temporary variable. %0 sorts next, then %00, %000, and so on. VARLIST() ; SRS 2016-06-30, Returns list of local variables. IF $DATA(%) ; This places the existence of variable % into $TEST. NEW % SET %=$SELECT($TEST:$LISTBUILD("%"),1:"") SET:$DATA(%0) %=%_$LISTBUILD("%0") NEW %0 SET %0="%0" FOR SET %0=$ORDER(@%0) QUIT:%0="" SET %=%_$LISTBUILD(%0) QUIT % Many programmers consider it acceptable, if not desirable, to use variables %, and % followed by any digits for introspection only, and therefore not worry about if % and %digits are predefined, Using %, %1, %2, %3, etc, and starting loops with SET %="%9" or something like that.